three.source.unit.js 1.5 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681486824868348684486854868648687486884868948690486914869248693486944869548696486974869848699487004870148702487034870448705487064870748708487094871048711487124871348714487154871648717487184871948720487214872248723487244872548726487274872848729487304873148732487334873448735487364873748738487394874048741487424874348744487454874648747487484874948750487514875248753487544875548756487574875848759487604876148762487634876448765487664876748768487694877048771487724877348774487754877648777487784877948780487814878248783487844878548786487874878848789487904879148792487934879448795487964879748798487994880048801488024880348804488054880648807488084880948810488114881248813488144881548816488174881848819488204882148822488234882448825488264882748828488294883048831488324883348834488354883648837488384883948840488414884248843488444884548846488474884848849488504885148852488534885448855488564885748858488594886048861488624886348864488654886648867488684886948870488714887248873488744887548876488774887848879488804888148882488834888448885488864888748888488894889048891488924889348894488954889648897488984889948900489014890248903489044890548906489074890848909489104891148912489134891448915489164891748918489194892048921489224892348924489254892648927489284892948930489314893248933489344893548936489374893848939489404894148942489434894448945489464894748948489494895048951489524895348954489554895648957489584895948960489614896248963489644896548966489674896848969489704897148972489734897448975489764897748978489794898048981489824898348984489854898648987489884898948990489914899248993489944899548996489974899848999490004900149002490034900449005490064900749008490094901049011490124901349014490154901649017490184901949020490214902249023490244902549026490274902849029490304903149032490334903449035490364903749038490394904049041490424904349044490454904649047490484904949050490514905249053490544905549056490574905849059490604906149062490634906449065490664906749068490694907049071490724907349074490754907649077490784907949080490814908249083490844908549086490874908849089490904909149092490934909449095490964909749098490994910049101491024910349104491054910649107491084910949110491114911249113491144911549116491174911849119491204912149122491234912449125491264912749128491294913049131491324913349134491354913649137491384913949140491414914249143491444914549146491474914849149491504915149152491534915449155491564915749158491594916049161491624916349164491654916649167491684916949170491714917249173491744917549176491774917849179491804918149182491834918449185491864918749188491894919049191491924919349194491954919649197491984919949200492014920249203492044920549206492074920849209492104921149212492134921449215492164921749218492194922049221492224922349224492254922649227492284922949230492314923249233492344923549236492374923849239492404924149242492434924449245492464924749248492494925049251492524925349254492554925649257492584925949260492614926249263492644926549266492674926849269492704927149272492734927449275492764927749278492794928049281492824928349284492854928649287492884928949290492914929249293492944929549296492974929849299493004930149302493034930449305493064930749308493094931049311493124931349314493154931649317493184931949320493214932249323493244932549326493274932849329493304933149332493334933449335493364933749338493394934049341493424934349344493454934649347493484934949350493514935249353493544935549356493574935849359493604936149362493634936449365493664936749368493694937049371493724937349374493754937649377493784937949380493814938249383493844938549386493874938849389493904939149392493934939449395493964939749398493994940049401494024940349404494054940649407494084940949410494114941249413494144941549416494174941849419494204942149422494234942449425494264942749428494294943049431494324943349434494354943649437494384943949440494414944249443494444944549446494474944849449494504945149452494534945449455494564945749458494594946049461494624946349464494654946649467494684946949470494714947249473494744947549476494774947849479494804948149482494834948449485494864948749488494894949049491494924949349494494954949649497494984949949500495014950249503495044950549506495074950849509495104951149512495134951449515495164951749518495194952049521495224952349524495254952649527495284952949530495314953249533495344953549536495374953849539495404954149542495434954449545495464954749548495494955049551495524955349554495554955649557495584955949560495614956249563495644956549566495674956849569495704957149572495734957449575495764957749578495794958049581495824958349584495854958649587495884958949590495914959249593495944959549596495974959849599496004960149602496034960449605496064960749608496094961049611496124961349614496154961649617496184961949620496214962249623496244962549626496274962849629496304963149632496334963449635496364963749638496394964049641496424964349644496454964649647496484964949650496514965249653496544965549656496574965849659496604966149662496634966449665496664966749668496694967049671496724967349674496754967649677496784967949680496814968249683496844968549686496874968849689496904969149692496934969449695496964969749698496994970049701497024970349704497054970649707497084970949710497114971249713497144971549716497174971849719497204972149722497234972449725497264972749728497294973049731497324973349734497354973649737497384973949740497414974249743497444974549746497474974849749497504975149752497534975449755497564975749758497594976049761497624976349764497654976649767497684976949770497714977249773497744977549776497774977849779497804978149782497834978449785497864978749788497894979049791497924979349794497954979649797497984979949800498014980249803498044980549806498074980849809498104981149812498134981449815498164981749818498194982049821498224982349824498254982649827498284982949830498314983249833498344983549836498374983849839498404984149842498434984449845498464984749848498494985049851498524985349854498554985649857498584985949860498614986249863498644986549866498674986849869498704987149872498734987449875498764987749878498794988049881498824988349884498854988649887498884988949890498914989249893498944989549896498974989849899499004990149902499034990449905499064990749908499094991049911499124991349914499154991649917499184991949920499214992249923499244992549926499274992849929499304993149932499334993449935499364993749938499394994049941499424994349944499454994649947499484994949950499514995249953499544995549956499574995849959499604996149962499634996449965499664996749968499694997049971499724997349974499754997649977499784997949980499814998249983499844998549986499874998849989499904999149992499934999449995499964999749998499995000050001500025000350004500055000650007500085000950010500115001250013500145001550016500175001850019500205002150022500235002450025500265002750028500295003050031500325003350034500355003650037500385003950040500415004250043500445004550046500475004850049500505005150052500535005450055500565005750058500595006050061500625006350064500655006650067500685006950070500715007250073500745007550076500775007850079500805008150082500835008450085500865008750088500895009050091500925009350094500955009650097500985009950100501015010250103501045010550106501075010850109501105011150112501135011450115501165011750118501195012050121501225012350124501255012650127501285012950130501315013250133501345013550136501375013850139501405014150142501435014450145501465014750148501495015050151501525015350154501555015650157501585015950160501615016250163501645016550166501675016850169501705017150172501735017450175501765017750178501795018050181501825018350184501855018650187501885018950190501915019250193501945019550196501975019850199502005020150202502035020450205502065020750208502095021050211502125021350214502155021650217502185021950220502215022250223502245022550226502275022850229502305023150232502335023450235502365023750238502395024050241502425024350244502455024650247502485024950250502515025250253502545025550256502575025850259502605026150262502635026450265502665026750268502695027050271502725027350274502755027650277502785027950280502815028250283502845028550286502875028850289502905029150292502935029450295502965029750298502995030050301503025030350304503055030650307503085030950310503115031250313503145031550316503175031850319503205032150322503235032450325503265032750328503295033050331503325033350334503355033650337503385033950340503415034250343503445034550346503475034850349503505035150352503535035450355503565035750358503595036050361503625036350364503655036650367503685036950370503715037250373503745037550376503775037850379503805038150382503835038450385503865038750388503895039050391503925039350394503955039650397503985039950400504015040250403504045040550406504075040850409504105041150412504135041450415504165041750418504195042050421504225042350424504255042650427504285042950430504315043250433504345043550436504375043850439504405044150442504435044450445504465044750448504495045050451504525045350454504555045650457504585045950460504615046250463504645046550466504675046850469504705047150472504735047450475504765047750478504795048050481504825048350484504855048650487504885048950490504915049250493504945049550496504975049850499505005050150502505035050450505505065050750508505095051050511505125051350514505155051650517505185051950520505215052250523505245052550526505275052850529505305053150532505335053450535505365053750538505395054050541505425054350544505455054650547505485054950550505515055250553505545055550556505575055850559505605056150562505635056450565505665056750568505695057050571505725057350574505755057650577505785057950580505815058250583505845058550586505875058850589505905059150592505935059450595505965059750598505995060050601506025060350604506055060650607506085060950610506115061250613506145061550616506175061850619506205062150622506235062450625506265062750628506295063050631506325063350634506355063650637506385063950640506415064250643506445064550646506475064850649506505065150652506535065450655506565065750658506595066050661506625066350664506655066650667506685066950670506715067250673506745067550676506775067850679506805068150682506835068450685506865068750688506895069050691506925069350694506955069650697506985069950700507015070250703507045070550706507075070850709507105071150712507135071450715507165071750718507195072050721507225072350724507255072650727507285072950730507315073250733507345073550736507375073850739507405074150742507435074450745507465074750748507495075050751507525075350754507555075650757507585075950760507615076250763507645076550766507675076850769507705077150772507735077450775507765077750778507795078050781507825078350784507855078650787507885078950790507915079250793507945079550796507975079850799508005080150802508035080450805508065080750808508095081050811508125081350814508155081650817508185081950820508215082250823508245082550826508275082850829508305083150832508335083450835508365083750838508395084050841508425084350844508455084650847508485084950850508515085250853508545085550856508575085850859508605086150862508635086450865508665086750868508695087050871508725087350874508755087650877508785087950880508815088250883508845088550886508875088850889508905089150892508935089450895508965089750898508995090050901509025090350904509055090650907509085090950910509115091250913509145091550916509175091850919509205092150922509235092450925509265092750928509295093050931509325093350934509355093650937509385093950940509415094250943509445094550946509475094850949509505095150952509535095450955509565095750958509595096050961509625096350964509655096650967509685096950970509715097250973509745097550976509775097850979509805098150982509835098450985509865098750988509895099050991509925099350994509955099650997509985099951000510015100251003510045100551006510075100851009510105101151012510135101451015510165101751018510195102051021510225102351024510255102651027510285102951030510315103251033510345103551036510375103851039510405104151042510435104451045510465104751048510495105051051510525105351054510555105651057510585105951060510615106251063510645106551066510675106851069510705107151072510735107451075510765107751078510795108051081510825108351084510855108651087510885108951090510915109251093510945109551096510975109851099511005110151102511035110451105511065110751108511095111051111511125111351114511155111651117511185111951120511215112251123511245112551126511275112851129511305113151132511335113451135511365113751138511395114051141511425114351144511455114651147511485114951150511515115251153511545115551156511575115851159511605116151162511635116451165511665116751168511695117051171511725117351174511755117651177511785117951180511815118251183511845118551186511875118851189511905119151192511935119451195511965119751198511995120051201512025120351204512055120651207512085120951210512115121251213512145121551216512175121851219512205122151222512235122451225512265122751228512295123051231512325123351234512355123651237512385123951240512415124251243512445124551246512475124851249512505125151252512535125451255512565125751258512595126051261512625126351264512655126651267512685126951270512715127251273512745127551276512775127851279512805128151282512835128451285512865128751288512895129051291512925129351294512955129651297512985129951300513015130251303513045130551306513075130851309513105131151312513135131451315513165131751318513195132051321513225132351324513255132651327513285132951330513315133251333513345133551336513375133851339513405134151342513435134451345513465134751348513495135051351513525135351354513555135651357513585135951360513615136251363513645136551366513675136851369513705137151372513735137451375513765137751378513795138051381513825138351384513855138651387513885138951390513915139251393513945139551396513975139851399514005140151402514035140451405514065140751408514095141051411514125141351414514155141651417514185141951420514215142251423514245142551426514275142851429514305143151432514335143451435514365143751438514395144051441514425144351444514455144651447514485144951450514515145251453514545145551456514575145851459514605146151462514635146451465514665146751468514695147051471514725147351474514755147651477514785147951480514815148251483514845148551486514875148851489514905149151492514935149451495514965149751498514995150051501515025150351504515055150651507515085150951510515115151251513515145151551516515175151851519515205152151522515235152451525515265152751528515295153051531515325153351534515355153651537515385153951540515415154251543515445154551546515475154851549515505155151552515535155451555515565155751558515595156051561515625156351564515655156651567515685156951570515715157251573515745157551576515775157851579515805158151582515835158451585515865158751588515895159051591515925159351594515955159651597515985159951600516015160251603516045160551606516075160851609516105161151612516135161451615516165161751618516195162051621516225162351624516255162651627516285162951630516315163251633516345163551636516375163851639516405164151642516435164451645516465164751648516495165051651516525165351654516555165651657516585165951660516615166251663516645166551666516675166851669516705167151672516735167451675516765167751678516795168051681516825168351684516855168651687516885168951690516915169251693516945169551696516975169851699517005170151702517035170451705517065170751708517095171051711517125171351714517155171651717517185171951720517215172251723517245172551726517275172851729517305173151732517335173451735517365173751738517395174051741517425174351744517455174651747517485174951750517515175251753517545175551756517575175851759517605176151762517635176451765517665176751768517695177051771517725177351774517755177651777517785177951780517815178251783517845178551786517875178851789517905179151792517935179451795517965179751798517995180051801518025180351804518055180651807518085180951810518115181251813518145181551816518175181851819518205182151822518235182451825518265182751828518295183051831518325183351834518355183651837518385183951840518415184251843518445184551846518475184851849518505185151852518535185451855518565185751858518595186051861518625186351864518655186651867518685186951870518715187251873518745187551876518775187851879518805188151882518835188451885518865188751888518895189051891518925189351894518955189651897518985189951900519015190251903519045190551906519075190851909519105191151912519135191451915519165191751918519195192051921519225192351924519255192651927519285192951930519315193251933519345193551936519375193851939519405194151942519435194451945519465194751948519495195051951519525195351954519555195651957519585195951960519615196251963519645196551966519675196851969519705197151972519735197451975519765197751978519795198051981519825198351984519855198651987519885198951990519915199251993519945199551996519975199851999520005200152002520035200452005520065200752008520095201052011520125201352014520155201652017520185201952020520215202252023520245202552026520275202852029520305203152032520335203452035520365203752038520395204052041520425204352044520455204652047520485204952050520515205252053520545205552056520575205852059520605206152062520635206452065520665206752068520695207052071520725207352074520755207652077520785207952080520815208252083520845208552086520875208852089520905209152092520935209452095520965209752098520995210052101521025210352104521055210652107521085210952110521115211252113521145211552116521175211852119521205212152122521235212452125521265212752128521295213052131521325213352134521355213652137521385213952140521415214252143521445214552146521475214852149521505215152152521535215452155521565215752158521595216052161521625216352164521655216652167521685216952170521715217252173521745217552176521775217852179521805218152182521835218452185521865218752188521895219052191521925219352194521955219652197521985219952200522015220252203522045220552206522075220852209522105221152212522135221452215522165221752218522195222052221522225222352224522255222652227522285222952230522315223252233522345223552236522375223852239522405224152242522435224452245522465224752248522495225052251522525225352254522555225652257522585225952260522615226252263522645226552266522675226852269522705227152272522735227452275522765227752278522795228052281522825228352284522855228652287522885228952290522915229252293522945229552296522975229852299523005230152302523035230452305523065230752308523095231052311523125231352314523155231652317523185231952320523215232252323523245232552326523275232852329523305233152332523335233452335523365233752338523395234052341523425234352344523455234652347523485234952350523515235252353523545235552356523575235852359523605236152362523635236452365523665236752368523695237052371523725237352374523755237652377523785237952380523815238252383523845238552386523875238852389523905239152392523935239452395523965239752398523995240052401524025240352404524055240652407524085240952410524115241252413524145241552416524175241852419524205242152422524235242452425524265242752428524295243052431524325243352434524355243652437524385243952440524415244252443524445244552446524475244852449524505245152452524535245452455524565245752458524595246052461524625246352464524655246652467524685246952470524715247252473524745247552476524775247852479524805248152482524835248452485524865248752488524895249052491524925249352494524955249652497524985249952500525015250252503525045250552506525075250852509525105251152512525135251452515525165251752518525195252052521525225252352524525255252652527525285252952530525315253252533525345253552536525375253852539525405254152542525435254452545525465254752548525495255052551525525255352554525555255652557525585255952560525615256252563525645256552566525675256852569525705257152572525735257452575525765257752578525795258052581525825258352584525855258652587525885258952590525915259252593525945259552596525975259852599526005260152602526035260452605526065260752608526095261052611526125261352614526155261652617526185261952620526215262252623526245262552626526275262852629526305263152632526335263452635526365263752638526395264052641526425264352644526455264652647526485264952650526515265252653526545265552656526575265852659526605266152662526635266452665526665266752668526695267052671526725267352674526755267652677526785267952680526815268252683526845268552686526875268852689526905269152692526935269452695526965269752698526995270052701527025270352704527055270652707527085270952710527115271252713527145271552716527175271852719527205272152722527235272452725527265272752728527295273052731527325273352734527355273652737527385273952740527415274252743527445274552746527475274852749527505275152752527535275452755527565275752758527595276052761527625276352764527655276652767527685276952770527715277252773527745277552776527775277852779527805278152782527835278452785527865278752788527895279052791527925279352794527955279652797527985279952800528015280252803528045280552806528075280852809528105281152812528135281452815528165281752818528195282052821528225282352824528255282652827528285282952830528315283252833528345283552836528375283852839528405284152842528435284452845528465284752848528495285052851528525285352854528555285652857528585285952860528615286252863528645286552866528675286852869528705287152872528735287452875528765287752878528795288052881528825288352884528855288652887528885288952890528915289252893528945289552896528975289852899529005290152902529035290452905529065290752908529095291052911529125291352914529155291652917529185291952920529215292252923529245292552926529275292852929529305293152932529335293452935529365293752938529395294052941529425294352944529455294652947529485294952950529515295252953529545295552956529575295852959529605296152962529635296452965529665296752968529695297052971529725297352974529755297652977529785297952980529815298252983529845298552986529875298852989529905299152992529935299452995529965299752998529995300053001530025300353004530055300653007530085300953010530115301253013530145301553016530175301853019530205302153022530235302453025530265302753028530295303053031530325303353034530355303653037530385303953040530415304253043530445304553046530475304853049530505305153052530535305453055530565305753058530595306053061530625306353064530655306653067530685306953070530715307253073530745307553076530775307853079530805308153082530835308453085530865308753088530895309053091530925309353094530955309653097530985309953100531015310253103531045310553106531075310853109531105311153112531135311453115531165311753118531195312053121531225312353124531255312653127531285312953130531315313253133531345313553136531375313853139531405314153142531435314453145531465314753148531495315053151531525315353154531555315653157531585315953160531615316253163531645316553166531675316853169531705317153172531735317453175531765317753178531795318053181531825318353184531855318653187531885318953190531915319253193531945319553196531975319853199532005320153202532035320453205532065320753208532095321053211532125321353214532155321653217532185321953220532215322253223532245322553226532275322853229532305323153232532335323453235532365323753238532395324053241532425324353244532455324653247532485324953250532515325253253532545325553256532575325853259532605326153262532635326453265532665326753268532695327053271532725327353274532755327653277532785327953280532815328253283532845328553286532875328853289532905329153292532935329453295532965329753298532995330053301533025330353304533055330653307533085330953310533115331253313533145331553316533175331853319533205332153322533235332453325533265332753328533295333053331533325333353334533355333653337533385333953340533415334253343533445334553346533475334853349533505335153352533535335453355533565335753358533595336053361533625336353364533655336653367533685336953370533715337253373533745337553376533775337853379533805338153382533835338453385533865338753388533895339053391533925339353394533955339653397533985339953400534015340253403534045340553406534075340853409534105341153412534135341453415534165341753418534195342053421534225342353424534255342653427534285342953430534315343253433534345343553436534375343853439534405344153442534435344453445534465344753448534495345053451534525345353454534555345653457534585345953460534615346253463534645346553466534675346853469534705347153472534735347453475534765347753478534795348053481534825348353484534855348653487534885348953490534915349253493534945349553496534975349853499535005350153502535035350453505535065350753508535095351053511535125351353514535155351653517535185351953520535215352253523535245352553526535275352853529535305353153532535335353453535535365353753538535395354053541535425354353544535455354653547535485354953550535515355253553535545355553556535575355853559535605356153562535635356453565535665356753568535695357053571535725357353574535755357653577535785357953580535815358253583535845358553586535875358853589535905359153592535935359453595535965359753598535995360053601536025360353604536055360653607536085360953610536115361253613536145361553616536175361853619536205362153622536235362453625536265362753628536295363053631536325363353634536355363653637536385363953640536415364253643536445364553646536475364853649536505365153652536535365453655536565365753658536595366053661536625366353664536655366653667536685366953670536715367253673536745367553676536775367853679536805368153682536835368453685536865368753688536895369053691536925369353694536955369653697536985369953700537015370253703537045370553706537075370853709537105371153712537135371453715537165371753718537195372053721537225372353724537255372653727537285372953730537315373253733537345373553736537375373853739537405374153742537435374453745537465374753748537495375053751537525375353754537555375653757537585375953760537615376253763537645376553766537675376853769537705377153772537735377453775537765377753778537795378053781537825378353784537855378653787537885378953790537915379253793537945379553796537975379853799538005380153802538035380453805538065380753808538095381053811538125381353814538155381653817538185381953820538215382253823538245382553826538275382853829538305383153832538335383453835538365383753838538395384053841538425384353844538455384653847538485384953850538515385253853538545385553856538575385853859538605386153862538635386453865538665386753868538695387053871538725387353874538755387653877538785387953880538815388253883538845388553886538875388853889538905389153892538935389453895538965389753898538995390053901539025390353904539055390653907539085390953910539115391253913539145391553916539175391853919539205392153922539235392453925539265392753928539295393053931539325393353934539355393653937539385393953940539415394253943539445394553946539475394853949539505395153952539535395453955539565395753958539595396053961539625396353964539655396653967539685396953970539715397253973539745397553976539775397853979539805398153982539835398453985539865398753988539895399053991539925399353994539955399653997539985399954000540015400254003540045400554006540075400854009540105401154012540135401454015540165401754018540195402054021540225402354024540255402654027540285402954030540315403254033540345403554036540375403854039540405404154042540435404454045540465404754048540495405054051540525405354054540555405654057540585405954060540615406254063540645406554066540675406854069540705407154072540735407454075540765407754078540795408054081540825408354084540855408654087540885408954090540915409254093540945409554096540975409854099541005410154102541035410454105541065410754108541095411054111541125411354114541155411654117541185411954120541215412254123541245412554126541275412854129541305413154132541335413454135541365413754138541395414054141541425414354144541455414654147541485414954150541515415254153541545415554156541575415854159541605416154162541635416454165541665416754168541695417054171541725417354174541755417654177541785417954180541815418254183541845418554186541875418854189541905419154192541935419454195541965419754198541995420054201542025420354204542055420654207542085420954210542115421254213542145421554216542175421854219542205422154222542235422454225542265422754228542295423054231542325423354234542355423654237542385423954240542415424254243542445424554246542475424854249542505425154252542535425454255542565425754258542595426054261542625426354264542655426654267542685426954270542715427254273542745427554276542775427854279542805428154282542835428454285542865428754288542895429054291542925429354294542955429654297542985429954300543015430254303543045430554306543075430854309543105431154312543135431454315543165431754318543195432054321543225432354324543255432654327543285432954330543315433254333543345433554336543375433854339543405434154342543435434454345543465434754348543495435054351543525435354354543555435654357543585435954360543615436254363543645436554366543675436854369543705437154372543735437454375543765437754378543795438054381543825438354384543855438654387543885438954390543915439254393543945439554396543975439854399544005440154402544035440454405544065440754408544095441054411544125441354414544155441654417544185441954420544215442254423544245442554426544275442854429544305443154432544335443454435544365443754438544395444054441544425444354444544455444654447544485444954450544515445254453544545445554456544575445854459544605446154462544635446454465544665446754468544695447054471544725447354474544755447654477544785447954480544815448254483544845448554486544875448854489544905449154492544935449454495544965449754498544995450054501545025450354504545055450654507545085450954510545115451254513545145451554516545175451854519545205452154522545235452454525545265452754528545295453054531545325453354534545355453654537545385453954540545415454254543545445454554546545475454854549545505455154552545535455454555545565455754558545595456054561545625456354564545655456654567545685456954570545715457254573545745457554576545775457854579545805458154582545835458454585545865458754588545895459054591545925459354594545955459654597545985459954600546015460254603546045460554606546075460854609546105461154612546135461454615546165461754618546195462054621546225462354624546255462654627546285462954630546315463254633546345463554636546375463854639546405464154642546435464454645546465464754648546495465054651546525465354654546555465654657546585465954660546615466254663546645466554666546675466854669546705467154672546735467454675546765467754678546795468054681546825468354684546855468654687546885468954690546915469254693546945469554696546975469854699547005470154702547035470454705547065470754708547095471054711547125471354714547155471654717547185471954720547215472254723547245472554726547275472854729547305473154732547335473454735547365473754738547395474054741547425474354744547455474654747547485474954750547515475254753547545475554756547575475854759547605476154762547635476454765547665476754768547695477054771547725477354774547755477654777547785477954780547815478254783547845478554786547875478854789547905479154792547935479454795547965479754798547995480054801548025480354804548055480654807548085480954810548115481254813548145481554816548175481854819548205482154822548235482454825548265482754828548295483054831548325483354834548355483654837548385483954840548415484254843548445484554846548475484854849548505485154852548535485454855548565485754858548595486054861548625486354864548655486654867548685486954870548715487254873548745487554876548775487854879548805488154882548835488454885548865488754888548895489054891548925489354894548955489654897548985489954900549015490254903549045490554906549075490854909549105491154912549135491454915549165491754918549195492054921549225492354924549255492654927549285492954930549315493254933549345493554936549375493854939549405494154942549435494454945549465494754948549495495054951549525495354954549555495654957549585495954960549615496254963549645496554966549675496854969549705497154972549735497454975549765497754978549795498054981549825498354984549855498654987549885498954990549915499254993549945499554996549975499854999550005500155002550035500455005550065500755008550095501055011550125501355014550155501655017550185501955020550215502255023550245502555026550275502855029550305503155032550335503455035550365503755038550395504055041550425504355044550455504655047550485504955050550515505255053550545505555056550575505855059550605506155062550635506455065550665506755068550695507055071550725507355074550755507655077550785507955080550815508255083550845508555086550875508855089550905509155092550935509455095550965509755098550995510055101551025510355104551055510655107551085510955110551115511255113551145511555116551175511855119551205512155122551235512455125551265512755128551295513055131551325513355134551355513655137551385513955140551415514255143551445514555146551475514855149551505515155152551535515455155551565515755158551595516055161551625516355164551655516655167551685516955170551715517255173551745517555176551775517855179551805518155182551835518455185551865518755188551895519055191551925519355194551955519655197551985519955200552015520255203552045520555206552075520855209552105521155212552135521455215552165521755218552195522055221552225522355224552255522655227552285522955230552315523255233552345523555236552375523855239552405524155242552435524455245552465524755248552495525055251552525525355254552555525655257552585525955260552615526255263552645526555266552675526855269552705527155272552735527455275552765527755278552795528055281552825528355284552855528655287552885528955290552915529255293552945529555296552975529855299553005530155302553035530455305553065530755308553095531055311553125531355314553155531655317553185531955320553215532255323553245532555326553275532855329553305533155332553335533455335553365533755338553395534055341553425534355344553455534655347553485534955350553515535255353553545535555356553575535855359553605536155362553635536455365553665536755368553695537055371553725537355374553755537655377553785537955380553815538255383553845538555386553875538855389553905539155392553935539455395553965539755398553995540055401554025540355404554055540655407554085540955410554115541255413554145541555416554175541855419554205542155422554235542455425554265542755428554295543055431554325543355434554355543655437554385543955440554415544255443554445544555446554475544855449554505545155452554535545455455554565545755458554595546055461554625546355464554655546655467554685546955470554715547255473554745547555476554775547855479554805548155482554835548455485554865548755488554895549055491554925549355494554955549655497554985549955500555015550255503555045550555506555075550855509555105551155512555135551455515555165551755518555195552055521555225552355524555255552655527555285552955530555315553255533555345553555536555375553855539555405554155542555435554455545555465554755548555495555055551555525555355554555555555655557555585555955560555615556255563555645556555566555675556855569555705557155572555735557455575555765557755578555795558055581555825558355584555855558655587555885558955590555915559255593555945559555596555975559855599556005560155602556035560455605556065560755608556095561055611556125561355614556155561655617556185561955620556215562255623556245562555626556275562855629556305563155632556335563455635556365563755638556395564055641556425564355644556455564655647556485564955650556515565255653556545565555656556575565855659556605566155662556635566455665556665566755668556695567055671556725567355674556755567655677556785567955680556815568255683556845568555686556875568855689556905569155692556935569455695556965569755698556995570055701557025570355704557055570655707557085570955710557115571255713557145571555716557175571855719557205572155722557235572455725557265572755728557295573055731557325573355734557355573655737557385573955740557415574255743557445574555746557475574855749557505575155752557535575455755557565575755758557595576055761557625576355764557655576655767557685576955770557715577255773557745577555776557775577855779557805578155782557835578455785557865578755788557895579055791557925579355794557955579655797557985579955800558015580255803558045580555806558075580855809558105581155812558135581455815558165581755818558195582055821558225582355824558255582655827558285582955830558315583255833558345583555836558375583855839558405584155842558435584455845558465584755848558495585055851558525585355854558555585655857558585585955860558615586255863558645586555866558675586855869558705587155872558735587455875558765587755878558795588055881558825588355884558855588655887558885588955890558915589255893558945589555896558975589855899559005590155902559035590455905559065590755908559095591055911559125591355914559155591655917559185591955920559215592255923559245592555926559275592855929559305593155932559335593455935559365593755938559395594055941559425594355944559455594655947559485594955950559515595255953559545595555956559575595855959559605596155962559635596455965559665596755968559695597055971559725597355974559755597655977559785597955980559815598255983559845598555986559875598855989559905599155992559935599455995559965599755998559995600056001560025600356004560055600656007560085600956010560115601256013560145601556016560175601856019560205602156022560235602456025560265602756028560295603056031560325603356034560355603656037560385603956040560415604256043560445604556046560475604856049560505605156052560535605456055560565605756058560595606056061560625606356064560655606656067560685606956070560715607256073560745607556076560775607856079560805608156082560835608456085560865608756088560895609056091560925609356094560955609656097560985609956100561015610256103561045610556106561075610856109561105611156112561135611456115561165611756118561195612056121561225612356124561255612656127561285612956130561315613256133561345613556136561375613856139561405614156142561435614456145561465614756148561495615056151561525615356154561555615656157561585615956160561615616256163561645616556166561675616856169561705617156172561735617456175561765617756178561795618056181561825618356184561855618656187561885618956190561915619256193561945619556196561975619856199562005620156202562035620456205562065620756208562095621056211562125621356214562155621656217562185621956220562215622256223562245622556226562275622856229562305623156232562335623456235562365623756238562395624056241562425624356244562455624656247562485624956250562515625256253562545625556256562575625856259562605626156262562635626456265562665626756268562695627056271562725627356274562755627656277562785627956280562815628256283562845628556286562875628856289562905629156292562935629456295562965629756298562995630056301563025630356304563055630656307563085630956310563115631256313563145631556316563175631856319563205632156322563235632456325563265632756328563295633056331563325633356334563355633656337563385633956340563415634256343563445634556346563475634856349563505635156352563535635456355563565635756358563595636056361563625636356364563655636656367563685636956370563715637256373563745637556376563775637856379563805638156382563835638456385563865638756388563895639056391563925639356394563955639656397563985639956400564015640256403564045640556406564075640856409564105641156412564135641456415564165641756418564195642056421564225642356424564255642656427564285642956430564315643256433564345643556436564375643856439564405644156442564435644456445564465644756448564495645056451564525645356454564555645656457564585645956460564615646256463564645646556466564675646856469564705647156472564735647456475564765647756478564795648056481564825648356484564855648656487564885648956490564915649256493564945649556496564975649856499565005650156502565035650456505565065650756508565095651056511565125651356514565155651656517565185651956520565215652256523565245652556526565275652856529565305653156532565335653456535565365653756538565395654056541565425654356544565455654656547565485654956550565515655256553565545655556556565575655856559565605656156562565635656456565565665656756568565695657056571565725657356574565755657656577565785657956580565815658256583565845658556586565875658856589565905659156592565935659456595565965659756598565995660056601566025660356604566055660656607566085660956610566115661256613566145661556616566175661856619566205662156622566235662456625566265662756628566295663056631566325663356634566355663656637566385663956640566415664256643566445664556646566475664856649566505665156652566535665456655566565665756658566595666056661566625666356664566655666656667566685666956670566715667256673566745667556676566775667856679566805668156682566835668456685566865668756688566895669056691566925669356694566955669656697566985669956700567015670256703567045670556706567075670856709567105671156712567135671456715567165671756718567195672056721567225672356724567255672656727567285672956730567315673256733567345673556736567375673856739567405674156742567435674456745567465674756748567495675056751567525675356754567555675656757567585675956760567615676256763567645676556766567675676856769567705677156772567735677456775567765677756778567795678056781567825678356784567855678656787567885678956790567915679256793567945679556796567975679856799568005680156802568035680456805568065680756808568095681056811568125681356814568155681656817568185681956820568215682256823568245682556826568275682856829568305683156832568335683456835568365683756838568395684056841568425684356844568455684656847568485684956850568515685256853568545685556856568575685856859568605686156862568635686456865568665686756868568695687056871568725687356874568755687656877568785687956880568815688256883568845688556886568875688856889568905689156892568935689456895568965689756898568995690056901569025690356904569055690656907569085690956910569115691256913569145691556916569175691856919569205692156922569235692456925569265692756928569295693056931569325693356934569355693656937569385693956940569415694256943569445694556946569475694856949569505695156952569535695456955569565695756958569595696056961569625696356964569655696656967569685696956970569715697256973569745697556976569775697856979569805698156982569835698456985569865698756988569895699056991569925699356994569955699656997569985699957000570015700257003570045700557006570075700857009570105701157012570135701457015570165701757018570195702057021570225702357024570255702657027570285702957030570315703257033570345703557036570375703857039570405704157042570435704457045570465704757048570495705057051570525705357054570555705657057570585705957060570615706257063570645706557066570675706857069570705707157072570735707457075570765707757078570795708057081570825708357084570855708657087570885708957090570915709257093570945709557096570975709857099571005710157102571035710457105571065710757108571095711057111571125711357114571155711657117571185711957120571215712257123571245712557126571275712857129571305713157132571335713457135571365713757138571395714057141571425714357144571455714657147571485714957150571515715257153571545715557156571575715857159571605716157162571635716457165571665716757168571695717057171571725717357174571755717657177571785717957180571815718257183571845718557186571875718857189571905719157192571935719457195571965719757198571995720057201572025720357204572055720657207572085720957210572115721257213572145721557216572175721857219572205722157222572235722457225572265722757228572295723057231572325723357234572355723657237572385723957240572415724257243572445724557246572475724857249572505725157252572535725457255572565725757258572595726057261572625726357264572655726657267572685726957270572715727257273572745727557276572775727857279572805728157282572835728457285572865728757288572895729057291572925729357294572955729657297572985729957300573015730257303573045730557306573075730857309573105731157312573135731457315573165731757318573195732057321573225732357324573255732657327573285732957330573315733257333573345733557336573375733857339573405734157342573435734457345573465734757348573495735057351573525735357354573555735657357573585735957360573615736257363573645736557366573675736857369573705737157372573735737457375573765737757378573795738057381573825738357384573855738657387573885738957390573915739257393573945739557396573975739857399574005740157402574035740457405574065740757408574095741057411574125741357414574155741657417574185741957420574215742257423574245742557426574275742857429574305743157432574335743457435574365743757438574395744057441574425744357444574455744657447574485744957450574515745257453574545745557456574575745857459574605746157462574635746457465574665746757468574695747057471574725747357474574755747657477574785747957480574815748257483574845748557486574875748857489574905749157492574935749457495574965749757498574995750057501575025750357504575055750657507575085750957510575115751257513575145751557516575175751857519575205752157522575235752457525575265752757528575295753057531575325753357534575355753657537575385753957540575415754257543575445754557546575475754857549575505755157552575535755457555575565755757558575595756057561575625756357564575655756657567575685756957570575715757257573575745757557576575775757857579575805758157582575835758457585575865758757588575895759057591575925759357594575955759657597575985759957600576015760257603576045760557606576075760857609576105761157612576135761457615576165761757618576195762057621576225762357624576255762657627576285762957630576315763257633576345763557636576375763857639576405764157642576435764457645576465764757648576495765057651576525765357654576555765657657576585765957660576615766257663576645766557666576675766857669576705767157672576735767457675576765767757678576795768057681576825768357684576855768657687576885768957690576915769257693576945769557696576975769857699577005770157702577035770457705577065770757708577095771057711577125771357714577155771657717577185771957720577215772257723577245772557726577275772857729577305773157732577335773457735577365773757738577395774057741577425774357744577455774657747577485774957750577515775257753577545775557756577575775857759577605776157762577635776457765577665776757768577695777057771577725777357774577755777657777577785777957780577815778257783577845778557786577875778857789577905779157792577935779457795577965779757798577995780057801578025780357804578055780657807578085780957810578115781257813578145781557816578175781857819578205782157822578235782457825578265782757828578295783057831578325783357834578355783657837578385783957840578415784257843578445784557846578475784857849578505785157852578535785457855578565785757858578595786057861578625786357864578655786657867578685786957870578715787257873578745787557876578775787857879578805788157882578835788457885578865788757888578895789057891578925789357894578955789657897578985789957900579015790257903579045790557906579075790857909579105791157912579135791457915579165791757918579195792057921579225792357924579255792657927579285792957930579315793257933579345793557936579375793857939579405794157942579435794457945579465794757948579495795057951579525795357954579555795657957579585795957960579615796257963579645796557966579675796857969579705797157972579735797457975579765797757978579795798057981579825798357984579855798657987579885798957990579915799257993579945799557996579975799857999580005800158002580035800458005580065800758008580095801058011580125801358014580155801658017580185801958020580215802258023580245802558026580275802858029580305803158032580335803458035580365803758038580395804058041580425804358044580455804658047580485804958050580515805258053580545805558056580575805858059580605806158062580635806458065580665806758068580695807058071580725807358074580755807658077580785807958080580815808258083580845808558086580875808858089580905809158092580935809458095580965809758098580995810058101581025810358104581055810658107581085810958110581115811258113581145811558116581175811858119581205812158122581235812458125581265812758128581295813058131581325813358134581355813658137581385813958140581415814258143581445814558146581475814858149581505815158152581535815458155581565815758158581595816058161581625816358164581655816658167581685816958170581715817258173581745817558176581775817858179581805818158182581835818458185581865818758188581895819058191581925819358194581955819658197581985819958200582015820258203582045820558206582075820858209582105821158212582135821458215582165821758218582195822058221582225822358224582255822658227582285822958230582315823258233582345823558236582375823858239582405824158242582435824458245582465824758248582495825058251582525825358254582555825658257582585825958260582615826258263582645826558266582675826858269582705827158272582735827458275582765827758278582795828058281582825828358284582855828658287582885828958290582915829258293582945829558296582975829858299583005830158302583035830458305583065830758308583095831058311583125831358314583155831658317583185831958320583215832258323583245832558326583275832858329583305833158332583335833458335583365833758338583395834058341583425834358344583455834658347583485834958350583515835258353583545835558356583575835858359583605836158362583635836458365583665836758368583695837058371583725837358374583755837658377583785837958380583815838258383583845838558386583875838858389583905839158392583935839458395583965839758398583995840058401584025840358404584055840658407584085840958410584115841258413584145841558416584175841858419584205842158422584235842458425584265842758428584295843058431584325843358434584355843658437584385843958440584415844258443584445844558446584475844858449584505845158452584535845458455584565845758458584595846058461584625846358464584655846658467584685846958470584715847258473584745847558476584775847858479584805848158482584835848458485584865848758488584895849058491584925849358494584955849658497584985849958500585015850258503585045850558506585075850858509585105851158512585135851458515585165851758518585195852058521585225852358524585255852658527585285852958530585315853258533585345853558536585375853858539585405854158542585435854458545585465854758548585495855058551585525855358554585555855658557585585855958560585615856258563585645856558566585675856858569585705857158572585735857458575585765857758578585795858058581585825858358584585855858658587585885858958590585915859258593585945859558596585975859858599586005860158602586035860458605586065860758608586095861058611586125861358614586155861658617586185861958620586215862258623586245862558626586275862858629586305863158632586335863458635586365863758638586395864058641586425864358644586455864658647586485864958650586515865258653586545865558656586575865858659586605866158662586635866458665586665866758668586695867058671586725867358674586755867658677586785867958680586815868258683586845868558686586875868858689586905869158692586935869458695586965869758698586995870058701587025870358704587055870658707587085870958710587115871258713587145871558716587175871858719587205872158722587235872458725587265872758728587295873058731587325873358734587355873658737587385873958740587415874258743587445874558746587475874858749587505875158752587535875458755587565875758758587595876058761587625876358764587655876658767587685876958770587715877258773587745877558776587775877858779587805878158782587835878458785587865878758788587895879058791587925879358794587955879658797587985879958800588015880258803588045880558806588075880858809588105881158812588135881458815588165881758818588195882058821588225882358824588255882658827588285882958830588315883258833588345883558836588375883858839588405884158842588435884458845588465884758848588495885058851588525885358854588555885658857588585885958860588615886258863588645886558866588675886858869588705887158872588735887458875588765887758878588795888058881588825888358884588855888658887588885888958890588915889258893588945889558896588975889858899589005890158902589035890458905589065890758908589095891058911589125891358914589155891658917589185891958920589215892258923589245892558926589275892858929589305893158932589335893458935589365893758938589395894058941589425894358944589455894658947589485894958950589515895258953589545895558956589575895858959589605896158962589635896458965589665896758968589695897058971589725897358974589755897658977589785897958980589815898258983589845898558986589875898858989589905899158992589935899458995589965899758998589995900059001590025900359004590055900659007590085900959010590115901259013590145901559016590175901859019590205902159022590235902459025590265902759028590295903059031590325903359034590355903659037590385903959040590415904259043590445904559046590475904859049590505905159052590535905459055590565905759058590595906059061590625906359064590655906659067590685906959070590715907259073590745907559076590775907859079590805908159082590835908459085590865908759088590895909059091590925909359094590955909659097590985909959100591015910259103591045910559106591075910859109591105911159112591135911459115591165911759118591195912059121591225912359124591255912659127591285912959130591315913259133591345913559136591375913859139591405914159142591435914459145591465914759148591495915059151591525915359154591555915659157591585915959160591615916259163591645916559166591675916859169591705917159172591735917459175591765917759178591795918059181591825918359184591855918659187591885918959190591915919259193591945919559196591975919859199592005920159202592035920459205592065920759208592095921059211592125921359214592155921659217592185921959220592215922259223592245922559226592275922859229592305923159232592335923459235592365923759238592395924059241592425924359244592455924659247592485924959250592515925259253592545925559256592575925859259592605926159262592635926459265592665926759268592695927059271592725927359274592755927659277592785927959280592815928259283592845928559286592875928859289592905929159292592935929459295592965929759298592995930059301593025930359304593055930659307593085930959310593115931259313593145931559316593175931859319593205932159322593235932459325593265932759328593295933059331593325933359334593355933659337593385933959340593415934259343593445934559346593475934859349593505935159352593535935459355593565935759358593595936059361593625936359364593655936659367593685936959370593715937259373593745937559376593775937859379593805938159382593835938459385593865938759388593895939059391593925939359394593955939659397593985939959400594015940259403594045940559406594075940859409594105941159412594135941459415594165941759418594195942059421594225942359424594255942659427594285942959430594315943259433594345943559436594375943859439594405944159442594435944459445594465944759448594495945059451594525945359454594555945659457594585945959460594615946259463594645946559466594675946859469594705947159472594735947459475594765947759478594795948059481594825948359484594855948659487594885948959490594915949259493594945949559496594975949859499595005950159502595035950459505595065950759508595095951059511595125951359514595155951659517595185951959520595215952259523595245952559526595275952859529595305953159532595335953459535595365953759538595395954059541595425954359544595455954659547595485954959550595515955259553595545955559556595575955859559595605956159562595635956459565595665956759568595695957059571595725957359574595755957659577595785957959580595815958259583595845958559586595875958859589595905959159592595935959459595595965959759598595995960059601596025960359604596055960659607596085960959610596115961259613596145961559616596175961859619596205962159622596235962459625596265962759628596295963059631596325963359634596355963659637596385963959640596415964259643596445964559646596475964859649596505965159652596535965459655596565965759658596595966059661596625966359664596655966659667596685966959670596715967259673596745967559676596775967859679596805968159682596835968459685596865968759688596895969059691596925969359694596955969659697596985969959700597015970259703597045970559706597075970859709597105971159712597135971459715597165971759718597195972059721597225972359724597255972659727597285972959730597315973259733597345973559736597375973859739597405974159742597435974459745597465974759748597495975059751597525975359754597555975659757597585975959760597615976259763597645976559766597675976859769597705977159772597735977459775597765977759778597795978059781597825978359784597855978659787597885978959790597915979259793597945979559796597975979859799598005980159802598035980459805598065980759808598095981059811598125981359814598155981659817598185981959820598215982259823598245982559826598275982859829598305983159832598335983459835598365983759838598395984059841598425984359844598455984659847598485984959850598515985259853598545985559856598575985859859598605986159862598635986459865598665986759868598695987059871598725987359874598755987659877598785987959880598815988259883598845988559886598875988859889598905989159892598935989459895598965989759898598995990059901599025990359904599055990659907599085990959910599115991259913599145991559916599175991859919599205992159922599235992459925599265992759928599295993059931599325993359934599355993659937599385993959940599415994259943599445994559946599475994859949599505995159952599535995459955599565995759958599595996059961599625996359964599655996659967599685996959970599715997259973599745997559976599775997859979599805998159982599835998459985599865998759988599895999059991599925999359994599955999659997599985999960000600016000260003600046000560006600076000860009600106001160012600136001460015600166001760018600196002060021600226002360024600256002660027600286002960030600316003260033600346003560036600376003860039600406004160042600436004460045600466004760048600496005060051600526005360054600556005660057600586005960060600616006260063600646006560066600676006860069600706007160072600736007460075600766007760078600796008060081600826008360084600856008660087600886008960090600916009260093600946009560096600976009860099601006010160102601036010460105601066010760108601096011060111601126011360114601156011660117601186011960120601216012260123601246012560126601276012860129601306013160132601336013460135601366013760138601396014060141601426014360144601456014660147601486014960150601516015260153601546015560156601576015860159601606016160162601636016460165601666016760168601696017060171601726017360174601756017660177601786017960180601816018260183601846018560186601876018860189601906019160192601936019460195601966019760198601996020060201602026020360204602056020660207602086020960210602116021260213602146021560216602176021860219602206022160222602236022460225602266022760228602296023060231602326023360234602356023660237602386023960240602416024260243602446024560246602476024860249602506025160252602536025460255602566025760258602596026060261602626026360264602656026660267602686026960270602716027260273602746027560276602776027860279602806028160282602836028460285602866028760288602896029060291602926029360294602956029660297602986029960300603016030260303603046030560306603076030860309603106031160312603136031460315603166031760318603196032060321603226032360324603256032660327603286032960330603316033260333603346033560336603376033860339603406034160342603436034460345603466034760348603496035060351603526035360354603556035660357603586035960360603616036260363603646036560366603676036860369603706037160372603736037460375603766037760378603796038060381603826038360384603856038660387603886038960390603916039260393603946039560396603976039860399604006040160402604036040460405604066040760408604096041060411604126041360414604156041660417604186041960420604216042260423604246042560426604276042860429604306043160432604336043460435604366043760438604396044060441604426044360444604456044660447604486044960450604516045260453604546045560456604576045860459604606046160462604636046460465604666046760468604696047060471604726047360474604756047660477604786047960480604816048260483604846048560486604876048860489604906049160492604936049460495604966049760498604996050060501605026050360504605056050660507605086050960510605116051260513605146051560516605176051860519605206052160522605236052460525605266052760528605296053060531605326053360534605356053660537605386053960540605416054260543605446054560546605476054860549605506055160552605536055460555605566055760558605596056060561605626056360564605656056660567605686056960570605716057260573605746057560576605776057860579605806058160582605836058460585605866058760588605896059060591605926059360594605956059660597605986059960600606016060260603606046060560606606076060860609606106061160612606136061460615606166061760618606196062060621606226062360624606256062660627606286062960630606316063260633606346063560636606376063860639606406064160642606436064460645606466064760648606496065060651606526065360654606556065660657606586065960660606616066260663606646066560666606676066860669606706067160672606736067460675606766067760678606796068060681606826068360684606856068660687606886068960690606916069260693606946069560696606976069860699607006070160702607036070460705607066070760708607096071060711607126071360714607156071660717607186071960720607216072260723607246072560726607276072860729607306073160732607336073460735607366073760738607396074060741607426074360744607456074660747607486074960750607516075260753607546075560756607576075860759607606076160762607636076460765607666076760768607696077060771607726077360774607756077660777607786077960780607816078260783607846078560786607876078860789607906079160792607936079460795607966079760798607996080060801608026080360804608056080660807608086080960810608116081260813608146081560816608176081860819608206082160822608236082460825608266082760828608296083060831608326083360834608356083660837608386083960840608416084260843608446084560846608476084860849608506085160852608536085460855608566085760858608596086060861608626086360864608656086660867608686086960870608716087260873608746087560876608776087860879608806088160882608836088460885608866088760888608896089060891608926089360894608956089660897608986089960900609016090260903609046090560906609076090860909609106091160912609136091460915609166091760918609196092060921609226092360924609256092660927609286092960930609316093260933609346093560936609376093860939609406094160942609436094460945609466094760948609496095060951609526095360954609556095660957609586095960960609616096260963609646096560966609676096860969609706097160972609736097460975609766097760978609796098060981609826098360984609856098660987609886098960990609916099260993609946099560996609976099860999610006100161002610036100461005610066100761008610096101061011610126101361014610156101661017610186101961020610216102261023610246102561026610276102861029610306103161032610336103461035610366103761038610396104061041610426104361044610456104661047610486104961050610516105261053610546105561056610576105861059610606106161062610636106461065610666106761068610696107061071610726107361074610756107661077610786107961080610816108261083610846108561086610876108861089610906109161092610936109461095610966109761098610996110061101611026110361104611056110661107611086110961110611116111261113611146111561116611176111861119611206112161122611236112461125611266112761128611296113061131611326113361134611356113661137611386113961140611416114261143611446114561146611476114861149611506115161152611536115461155611566115761158611596116061161611626116361164611656116661167611686116961170611716117261173611746117561176611776117861179611806118161182611836118461185611866118761188611896119061191611926119361194611956119661197611986119961200612016120261203612046120561206612076120861209612106121161212612136121461215612166121761218612196122061221612226122361224612256122661227612286122961230612316123261233612346123561236612376123861239612406124161242612436124461245612466124761248612496125061251612526125361254612556125661257612586125961260612616126261263612646126561266612676126861269612706127161272612736127461275612766127761278612796128061281612826128361284612856128661287612886128961290612916129261293612946129561296612976129861299613006130161302613036130461305613066130761308613096131061311613126131361314613156131661317613186131961320613216132261323613246132561326613276132861329613306133161332613336133461335613366133761338613396134061341613426134361344613456134661347613486134961350613516135261353613546135561356613576135861359613606136161362613636136461365613666136761368613696137061371613726137361374613756137661377613786137961380613816138261383613846138561386613876138861389613906139161392613936139461395613966139761398613996140061401614026140361404614056140661407614086140961410614116141261413614146141561416614176141861419614206142161422614236142461425614266142761428614296143061431614326143361434614356143661437614386143961440614416144261443614446144561446614476144861449614506145161452614536145461455614566145761458614596146061461614626146361464614656146661467614686146961470614716147261473614746147561476614776147861479614806148161482614836148461485614866148761488614896149061491614926149361494614956149661497614986149961500615016150261503615046150561506615076150861509615106151161512615136151461515615166151761518615196152061521615226152361524615256152661527615286152961530615316153261533615346153561536615376153861539615406154161542615436154461545615466154761548615496155061551615526155361554615556155661557615586155961560615616156261563615646156561566615676156861569615706157161572615736157461575615766157761578615796158061581615826158361584615856158661587615886158961590615916159261593615946159561596615976159861599616006160161602616036160461605616066160761608616096161061611616126161361614616156161661617616186161961620616216162261623616246162561626616276162861629616306163161632616336163461635616366163761638616396164061641616426164361644616456164661647616486164961650616516165261653616546165561656616576165861659616606166161662616636166461665616666166761668616696167061671616726167361674616756167661677616786167961680616816168261683616846168561686616876168861689616906169161692616936169461695616966169761698616996170061701617026170361704617056170661707617086170961710617116171261713617146171561716617176171861719617206172161722617236172461725617266172761728617296173061731617326173361734617356173661737617386173961740617416174261743617446174561746617476174861749617506175161752617536175461755617566175761758617596176061761617626176361764617656176661767617686176961770617716177261773617746177561776617776177861779617806178161782617836178461785617866178761788617896179061791617926179361794617956179661797617986179961800618016180261803618046180561806618076180861809618106181161812618136181461815618166181761818618196182061821618226182361824618256182661827618286182961830618316183261833618346183561836618376183861839618406184161842618436184461845618466184761848618496185061851618526185361854618556185661857618586185961860618616186261863618646186561866618676186861869618706187161872618736187461875618766187761878618796188061881618826188361884618856188661887618886188961890618916189261893618946189561896618976189861899619006190161902619036190461905619066190761908619096191061911619126191361914619156191661917619186191961920619216192261923619246192561926619276192861929619306193161932619336193461935619366193761938619396194061941619426194361944619456194661947619486194961950619516195261953619546195561956619576195861959619606196161962619636196461965619666196761968619696197061971619726197361974619756197661977619786197961980619816198261983619846198561986619876198861989619906199161992619936199461995619966199761998619996200062001620026200362004620056200662007620086200962010620116201262013620146201562016620176201862019620206202162022620236202462025620266202762028620296203062031620326203362034620356203662037620386203962040620416204262043620446204562046620476204862049620506205162052620536205462055620566205762058620596206062061620626206362064620656206662067620686206962070620716207262073620746207562076620776207862079620806208162082620836208462085620866208762088620896209062091620926209362094620956209662097620986209962100621016210262103621046210562106621076210862109621106211162112621136211462115621166211762118621196212062121621226212362124621256212662127621286212962130621316213262133621346213562136621376213862139621406214162142621436214462145621466214762148621496215062151621526215362154621556215662157621586215962160621616216262163621646216562166621676216862169621706217162172621736217462175621766217762178621796218062181621826218362184621856218662187621886218962190621916219262193621946219562196621976219862199622006220162202622036220462205622066220762208622096221062211622126221362214622156221662217622186221962220622216222262223622246222562226622276222862229622306223162232622336223462235622366223762238622396224062241622426224362244622456224662247622486224962250622516225262253622546225562256622576225862259622606226162262622636226462265622666226762268622696227062271622726227362274622756227662277622786227962280622816228262283622846228562286622876228862289622906229162292622936229462295622966229762298622996230062301623026230362304623056230662307623086230962310623116231262313623146231562316623176231862319623206232162322623236232462325623266232762328623296233062331623326233362334623356233662337623386233962340623416234262343623446234562346623476234862349623506235162352623536235462355623566235762358623596236062361623626236362364623656236662367623686236962370623716237262373623746237562376623776237862379623806238162382623836238462385623866238762388623896239062391623926239362394623956239662397623986239962400624016240262403624046240562406624076240862409624106241162412624136241462415624166241762418624196242062421624226242362424624256242662427624286242962430624316243262433624346243562436624376243862439624406244162442624436244462445624466244762448624496245062451624526245362454624556245662457624586245962460624616246262463624646246562466624676246862469624706247162472624736247462475624766247762478624796248062481624826248362484624856248662487624886248962490624916249262493624946249562496624976249862499625006250162502625036250462505625066250762508625096251062511625126251362514625156251662517625186251962520625216252262523625246252562526625276252862529625306253162532625336253462535625366253762538625396254062541625426254362544625456254662547625486254962550625516255262553625546255562556625576255862559625606256162562625636256462565625666256762568625696257062571625726257362574625756257662577625786257962580625816258262583625846258562586625876258862589625906259162592625936259462595625966259762598625996260062601626026260362604626056260662607626086260962610626116261262613626146261562616626176261862619626206262162622626236262462625626266262762628626296263062631626326263362634626356263662637626386263962640626416264262643626446264562646626476264862649626506265162652626536265462655626566265762658626596266062661626626266362664626656266662667626686266962670626716267262673626746267562676626776267862679626806268162682626836268462685626866268762688626896269062691626926269362694626956269662697626986269962700627016270262703627046270562706627076270862709627106271162712627136271462715627166271762718627196272062721627226272362724627256272662727627286272962730627316273262733627346273562736627376273862739627406274162742627436274462745627466274762748627496275062751627526275362754627556275662757627586275962760627616276262763627646276562766627676276862769627706277162772627736277462775627766277762778627796278062781627826278362784627856278662787627886278962790627916279262793627946279562796627976279862799628006280162802628036280462805628066280762808628096281062811628126281362814628156281662817628186281962820628216282262823628246282562826628276282862829628306283162832628336283462835628366283762838628396284062841628426284362844628456284662847628486284962850628516285262853628546285562856628576285862859628606286162862628636286462865628666286762868628696287062871628726287362874628756287662877628786287962880628816288262883628846288562886628876288862889628906289162892628936289462895628966289762898628996290062901629026290362904629056290662907629086290962910629116291262913629146291562916629176291862919629206292162922629236292462925629266292762928629296293062931629326293362934629356293662937629386293962940629416294262943629446294562946629476294862949629506295162952629536295462955629566295762958629596296062961629626296362964629656296662967629686296962970629716297262973629746297562976629776297862979629806298162982629836298462985629866298762988629896299062991629926299362994629956299662997629986299963000630016300263003630046300563006630076300863009630106301163012630136301463015630166301763018630196302063021630226302363024630256302663027630286302963030630316303263033630346303563036630376303863039630406304163042630436304463045630466304763048630496305063051630526305363054630556305663057630586305963060630616306263063630646306563066630676306863069630706307163072630736307463075630766307763078630796308063081630826308363084630856308663087630886308963090630916309263093630946309563096630976309863099631006310163102631036310463105631066310763108631096311063111631126311363114631156311663117631186311963120631216312263123631246312563126631276312863129631306313163132631336313463135631366313763138631396314063141631426314363144631456314663147631486314963150631516315263153631546315563156631576315863159631606316163162631636316463165631666316763168631696317063171631726317363174631756317663177631786317963180631816318263183631846318563186631876318863189631906319163192631936319463195631966319763198631996320063201632026320363204632056320663207632086320963210632116321263213632146321563216632176321863219632206322163222632236322463225632266322763228632296323063231632326323363234632356323663237632386323963240632416324263243632446324563246632476324863249632506325163252632536325463255632566325763258632596326063261632626326363264632656326663267632686326963270632716327263273632746327563276632776327863279632806328163282632836328463285632866328763288632896329063291632926329363294632956329663297632986329963300633016330263303633046330563306633076330863309633106331163312633136331463315633166331763318633196332063321633226332363324633256332663327633286332963330633316333263333633346333563336633376333863339633406334163342633436334463345633466334763348633496335063351633526335363354633556335663357633586335963360633616336263363633646336563366633676336863369633706337163372633736337463375633766337763378633796338063381633826338363384633856338663387633886338963390633916339263393633946339563396633976339863399634006340163402634036340463405634066340763408634096341063411634126341363414634156341663417634186341963420634216342263423634246342563426634276342863429634306343163432634336343463435634366343763438634396344063441634426344363444634456344663447634486344963450634516345263453634546345563456634576345863459634606346163462634636346463465634666346763468634696347063471634726347363474634756347663477634786347963480634816348263483634846348563486634876348863489634906349163492634936349463495634966349763498634996350063501635026350363504635056350663507635086350963510635116351263513635146351563516635176351863519635206352163522635236352463525635266352763528635296353063531635326353363534635356353663537635386353963540635416354263543635446354563546635476354863549635506355163552635536355463555635566355763558635596356063561635626356363564635656356663567635686356963570635716357263573635746357563576635776357863579635806358163582635836358463585635866358763588635896359063591635926359363594635956359663597635986359963600636016360263603636046360563606636076360863609636106361163612636136361463615636166361763618636196362063621636226362363624636256362663627636286362963630636316363263633636346363563636636376363863639636406364163642636436364463645636466364763648636496365063651636526365363654636556365663657636586365963660636616366263663636646366563666636676366863669636706367163672636736367463675636766367763678636796368063681636826368363684636856368663687636886368963690636916369263693636946369563696636976369863699637006370163702637036370463705637066370763708637096371063711637126371363714637156371663717637186371963720637216372263723637246372563726637276372863729637306373163732637336373463735637366373763738637396374063741637426374363744637456374663747637486374963750637516375263753637546375563756637576375863759637606376163762637636376463765637666376763768637696377063771637726377363774637756377663777637786377963780637816378263783637846378563786637876378863789637906379163792637936379463795637966379763798637996380063801638026380363804638056380663807638086380963810638116381263813638146381563816638176381863819638206382163822638236382463825638266382763828638296383063831638326383363834638356383663837638386383963840638416384263843638446384563846638476384863849638506385163852638536385463855638566385763858638596386063861638626386363864638656386663867638686386963870638716387263873638746387563876638776387863879638806388163882638836388463885638866388763888638896389063891638926389363894638956389663897638986389963900639016390263903639046390563906639076390863909639106391163912639136391463915639166391763918639196392063921639226392363924639256392663927639286392963930639316393263933639346393563936639376393863939639406394163942639436394463945639466394763948639496395063951639526395363954639556395663957639586395963960639616396263963639646396563966639676396863969639706397163972639736397463975639766397763978639796398063981639826398363984639856398663987639886398963990639916399263993639946399563996639976399863999640006400164002640036400464005640066400764008640096401064011640126401364014640156401664017640186401964020640216402264023640246402564026640276402864029640306403164032640336403464035640366403764038640396404064041640426404364044640456404664047640486404964050640516405264053640546405564056640576405864059640606406164062640636406464065640666406764068640696407064071640726407364074640756407664077640786407964080640816408264083640846408564086640876408864089640906409164092640936409464095640966409764098640996410064101641026410364104641056410664107641086410964110641116411264113641146411564116641176411864119641206412164122641236412464125641266412764128641296413064131641326413364134641356413664137641386413964140641416414264143641446414564146641476414864149641506415164152641536415464155641566415764158641596416064161641626416364164641656416664167641686416964170641716417264173641746417564176641776417864179641806418164182641836418464185641866418764188641896419064191641926419364194641956419664197641986419964200642016420264203642046420564206642076420864209642106421164212642136421464215642166421764218642196422064221642226422364224642256422664227642286422964230642316423264233642346423564236642376423864239642406424164242642436424464245642466424764248642496425064251642526425364254642556425664257642586425964260642616426264263642646426564266642676426864269642706427164272642736427464275642766427764278642796428064281642826428364284642856428664287642886428964290642916429264293642946429564296642976429864299643006430164302643036430464305643066430764308643096431064311643126431364314643156431664317643186431964320643216432264323643246432564326643276432864329643306433164332643336433464335643366433764338643396434064341643426434364344643456434664347643486434964350643516435264353643546435564356643576435864359643606436164362643636436464365643666436764368643696437064371643726437364374643756437664377643786437964380643816438264383643846438564386643876438864389643906439164392643936439464395643966439764398643996440064401644026440364404644056440664407644086440964410644116441264413644146441564416644176441864419644206442164422644236442464425644266442764428644296443064431644326443364434644356443664437644386443964440644416444264443644446444564446644476444864449644506445164452644536445464455644566445764458644596446064461644626446364464644656446664467644686446964470644716447264473644746447564476644776447864479644806448164482644836448464485644866448764488644896449064491644926449364494644956449664497644986449964500645016450264503645046450564506645076450864509645106451164512645136451464515645166451764518645196452064521645226452364524645256452664527645286452964530645316453264533645346453564536645376453864539645406454164542645436454464545645466454764548645496455064551645526455364554645556455664557645586455964560645616456264563645646456564566645676456864569645706457164572645736457464575645766457764578645796458064581645826458364584645856458664587645886458964590645916459264593645946459564596645976459864599646006460164602646036460464605646066460764608646096461064611646126461364614646156461664617646186461964620646216462264623646246462564626646276462864629646306463164632646336463464635646366463764638646396464064641646426464364644646456464664647646486464964650646516465264653646546465564656646576465864659646606466164662646636466464665646666466764668646696467064671646726467364674646756467664677646786467964680646816468264683646846468564686646876468864689646906469164692646936469464695646966469764698646996470064701647026470364704647056470664707647086470964710647116471264713647146471564716647176471864719647206472164722647236472464725647266472764728647296473064731647326473364734647356473664737647386473964740647416474264743647446474564746647476474864749647506475164752647536475464755647566475764758647596476064761647626476364764647656476664767647686476964770647716477264773647746477564776647776477864779647806478164782647836478464785647866478764788647896479064791647926479364794647956479664797647986479964800648016480264803648046480564806648076480864809648106481164812648136481464815648166481764818648196482064821648226482364824648256482664827648286482964830648316483264833648346483564836648376483864839648406484164842648436484464845648466484764848648496485064851648526485364854648556485664857648586485964860648616486264863648646486564866648676486864869648706487164872648736487464875648766487764878648796488064881648826488364884648856488664887648886488964890648916489264893648946489564896648976489864899649006490164902649036490464905649066490764908649096491064911649126491364914649156491664917649186491964920649216492264923649246492564926649276492864929649306493164932649336493464935649366493764938649396494064941649426494364944649456494664947649486494964950649516495264953649546495564956649576495864959649606496164962649636496464965649666496764968649696497064971649726497364974649756497664977649786497964980649816498264983649846498564986649876498864989649906499164992649936499464995649966499764998649996500065001650026500365004650056500665007650086500965010650116501265013650146501565016650176501865019650206502165022650236502465025650266502765028650296503065031650326503365034650356503665037650386503965040650416504265043650446504565046650476504865049650506505165052650536505465055650566505765058650596506065061650626506365064650656506665067650686506965070650716507265073650746507565076650776507865079650806508165082650836508465085650866508765088650896509065091650926509365094650956509665097650986509965100651016510265103651046510565106651076510865109651106511165112651136511465115651166511765118651196512065121651226512365124651256512665127651286512965130651316513265133651346513565136651376513865139651406514165142651436514465145651466514765148651496515065151651526515365154651556515665157651586515965160651616516265163651646516565166651676516865169651706517165172651736517465175651766517765178651796518065181651826518365184651856518665187651886518965190651916519265193651946519565196651976519865199652006520165202652036520465205652066520765208652096521065211652126521365214652156521665217652186521965220652216522265223652246522565226652276522865229652306523165232652336523465235652366523765238652396524065241652426524365244652456524665247652486524965250652516525265253652546525565256652576525865259652606526165262652636526465265652666526765268652696527065271652726527365274652756527665277652786527965280652816528265283652846528565286652876528865289652906529165292652936529465295652966529765298652996530065301653026530365304653056530665307653086530965310653116531265313653146531565316653176531865319653206532165322653236532465325653266532765328653296533065331653326533365334653356533665337653386533965340653416534265343653446534565346653476534865349653506535165352653536535465355653566535765358653596536065361653626536365364653656536665367653686536965370653716537265373653746537565376653776537865379653806538165382653836538465385653866538765388653896539065391653926539365394653956539665397653986539965400654016540265403654046540565406654076540865409654106541165412654136541465415654166541765418654196542065421654226542365424654256542665427654286542965430654316543265433654346543565436654376543865439654406544165442654436544465445654466544765448654496545065451654526545365454654556545665457654586545965460654616546265463654646546565466654676546865469654706547165472654736547465475654766547765478654796548065481654826548365484654856548665487654886548965490654916549265493654946549565496654976549865499655006550165502655036550465505655066550765508655096551065511655126551365514655156551665517655186551965520655216552265523655246552565526655276552865529655306553165532655336553465535655366553765538655396554065541655426554365544655456554665547655486554965550655516555265553655546555565556655576555865559655606556165562655636556465565655666556765568655696557065571655726557365574655756557665577655786557965580655816558265583655846558565586655876558865589655906559165592655936559465595655966559765598655996560065601656026560365604656056560665607656086560965610656116561265613656146561565616656176561865619656206562165622656236562465625656266562765628656296563065631656326563365634656356563665637656386563965640656416564265643656446564565646656476564865649656506565165652656536565465655656566565765658656596566065661656626566365664656656566665667656686566965670656716567265673656746567565676656776567865679656806568165682656836568465685656866568765688656896569065691656926569365694656956569665697656986569965700657016570265703657046570565706657076570865709657106571165712657136571465715657166571765718657196572065721657226572365724657256572665727657286572965730657316573265733657346573565736657376573865739657406574165742657436574465745657466574765748657496575065751657526575365754657556575665757657586575965760657616576265763657646576565766657676576865769657706577165772657736577465775657766577765778657796578065781657826578365784657856578665787657886578965790657916579265793657946579565796657976579865799658006580165802658036580465805658066580765808658096581065811658126581365814658156581665817658186581965820658216582265823658246582565826658276582865829658306583165832658336583465835658366583765838658396584065841658426584365844658456584665847658486584965850658516585265853658546585565856658576585865859658606586165862658636586465865658666586765868658696587065871658726587365874658756587665877658786587965880658816588265883658846588565886658876588865889658906589165892658936589465895658966589765898658996590065901659026590365904659056590665907659086590965910659116591265913659146591565916659176591865919659206592165922659236592465925659266592765928659296593065931659326593365934659356593665937659386593965940659416594265943659446594565946659476594865949659506595165952659536595465955659566595765958659596596065961659626596365964659656596665967659686596965970659716597265973659746597565976659776597865979659806598165982659836598465985659866598765988659896599065991659926599365994659956599665997659986599966000660016600266003660046600566006660076600866009660106601166012660136601466015660166601766018660196602066021660226602366024660256602666027660286602966030660316603266033660346603566036660376603866039660406604166042660436604466045660466604766048660496605066051660526605366054660556605666057660586605966060660616606266063660646606566066660676606866069660706607166072660736607466075660766607766078660796608066081660826608366084
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
  3. typeof define === 'function' && define.amd ? define(factory) :
  4. (factory());
  5. }(this, (function () { 'use strict';
  6. QUnit.module( "Source", () => {
  7. var REVISION = '88dev';
  8. var MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2 };
  9. var CullFaceNone = 0;
  10. var CullFaceBack = 1;
  11. var CullFaceFront = 2;
  12. var CullFaceFrontBack = 3;
  13. var FrontFaceDirectionCW = 0;
  14. var FrontFaceDirectionCCW = 1;
  15. var BasicShadowMap = 0;
  16. var PCFShadowMap = 1;
  17. var PCFSoftShadowMap = 2;
  18. var FrontSide = 0;
  19. var BackSide = 1;
  20. var DoubleSide = 2;
  21. var FlatShading = 1;
  22. var SmoothShading = 2;
  23. var NoColors = 0;
  24. var FaceColors = 1;
  25. var VertexColors = 2;
  26. var NoBlending = 0;
  27. var NormalBlending = 1;
  28. var AdditiveBlending = 2;
  29. var SubtractiveBlending = 3;
  30. var MultiplyBlending = 4;
  31. var CustomBlending = 5;
  32. var AddEquation = 100;
  33. var SubtractEquation = 101;
  34. var ReverseSubtractEquation = 102;
  35. var MinEquation = 103;
  36. var MaxEquation = 104;
  37. var ZeroFactor = 200;
  38. var OneFactor = 201;
  39. var SrcColorFactor = 202;
  40. var OneMinusSrcColorFactor = 203;
  41. var SrcAlphaFactor = 204;
  42. var OneMinusSrcAlphaFactor = 205;
  43. var DstAlphaFactor = 206;
  44. var OneMinusDstAlphaFactor = 207;
  45. var DstColorFactor = 208;
  46. var OneMinusDstColorFactor = 209;
  47. var SrcAlphaSaturateFactor = 210;
  48. var NeverDepth = 0;
  49. var AlwaysDepth = 1;
  50. var LessDepth = 2;
  51. var LessEqualDepth = 3;
  52. var EqualDepth = 4;
  53. var GreaterEqualDepth = 5;
  54. var GreaterDepth = 6;
  55. var NotEqualDepth = 7;
  56. var MultiplyOperation = 0;
  57. var MixOperation = 1;
  58. var AddOperation = 2;
  59. var NoToneMapping = 0;
  60. var LinearToneMapping = 1;
  61. var ReinhardToneMapping = 2;
  62. var Uncharted2ToneMapping = 3;
  63. var CineonToneMapping = 4;
  64. var UVMapping = 300;
  65. var CubeReflectionMapping = 301;
  66. var CubeRefractionMapping = 302;
  67. var EquirectangularReflectionMapping = 303;
  68. var EquirectangularRefractionMapping = 304;
  69. var SphericalReflectionMapping = 305;
  70. var CubeUVReflectionMapping = 306;
  71. var CubeUVRefractionMapping = 307;
  72. var RepeatWrapping = 1000;
  73. var ClampToEdgeWrapping = 1001;
  74. var MirroredRepeatWrapping = 1002;
  75. var NearestFilter = 1003;
  76. var NearestMipMapNearestFilter = 1004;
  77. var NearestMipMapLinearFilter = 1005;
  78. var LinearFilter = 1006;
  79. var LinearMipMapNearestFilter = 1007;
  80. var LinearMipMapLinearFilter = 1008;
  81. var UnsignedByteType = 1009;
  82. var ByteType = 1010;
  83. var ShortType = 1011;
  84. var UnsignedShortType = 1012;
  85. var IntType = 1013;
  86. var UnsignedIntType = 1014;
  87. var FloatType = 1015;
  88. var HalfFloatType = 1016;
  89. var UnsignedShort4444Type = 1017;
  90. var UnsignedShort5551Type = 1018;
  91. var UnsignedShort565Type = 1019;
  92. var UnsignedInt248Type = 1020;
  93. var AlphaFormat = 1021;
  94. var RGBFormat = 1022;
  95. var RGBAFormat = 1023;
  96. var LuminanceFormat = 1024;
  97. var LuminanceAlphaFormat = 1025;
  98. var RGBEFormat = RGBAFormat;
  99. var DepthFormat = 1026;
  100. var DepthStencilFormat = 1027;
  101. var RGB_S3TC_DXT1_Format = 2001;
  102. var RGBA_S3TC_DXT1_Format = 2002;
  103. var RGBA_S3TC_DXT3_Format = 2003;
  104. var RGBA_S3TC_DXT5_Format = 2004;
  105. var RGB_PVRTC_4BPPV1_Format = 2100;
  106. var RGB_PVRTC_2BPPV1_Format = 2101;
  107. var RGBA_PVRTC_4BPPV1_Format = 2102;
  108. var RGBA_PVRTC_2BPPV1_Format = 2103;
  109. var RGB_ETC1_Format = 2151;
  110. var LoopOnce = 2200;
  111. var LoopRepeat = 2201;
  112. var LoopPingPong = 2202;
  113. var InterpolateDiscrete = 2300;
  114. var InterpolateLinear = 2301;
  115. var InterpolateSmooth = 2302;
  116. var ZeroCurvatureEnding = 2400;
  117. var ZeroSlopeEnding = 2401;
  118. var WrapAroundEnding = 2402;
  119. var TrianglesDrawMode = 0;
  120. var TriangleStripDrawMode = 1;
  121. var TriangleFanDrawMode = 2;
  122. var LinearEncoding = 3000;
  123. var sRGBEncoding = 3001;
  124. var GammaEncoding = 3007;
  125. var RGBEEncoding = 3002;
  126. var LogLuvEncoding = 3003;
  127. var RGBM7Encoding = 3004;
  128. var RGBM16Encoding = 3005;
  129. var RGBDEncoding = 3006;
  130. var BasicDepthPacking = 3200;
  131. var RGBADepthPacking = 3201;
  132. /**
  133. * @author TristanVALCKE / https://github.com/Itee
  134. */
  135. /* global QUnit */
  136. QUnit.module( 'Constants', () => {
  137. QUnit.test( "default values", ( assert ) => {
  138. assert.propEqual( MOUSE, { LEFT: 0, MIDDLE: 1, RIGHT: 2 }, 'MOUSE equal { LEFT: 0, MIDDLE: 1, RIGHT: 2 }' );
  139. assert.equal( CullFaceNone, 0, 'CullFaceNone equal 0' );
  140. assert.equal( CullFaceBack, 1, 'CullFaceBack equal 1' );
  141. assert.equal( CullFaceFront, 2, 'CullFaceFront is equal to 2' );
  142. assert.equal( CullFaceFrontBack, 3, 'CullFaceFrontBack is equal to 3' );
  143. assert.equal( FrontFaceDirectionCW, 0, 'FrontFaceDirectionCW is equal to 0' );
  144. assert.equal( FrontFaceDirectionCCW, 1, 'FrontFaceDirectionCCW is equal to 1' );
  145. assert.equal( BasicShadowMap, 0, 'BasicShadowMap is equal to 0' );
  146. assert.equal( PCFShadowMap, 1, 'PCFShadowMap is equal to 1' );
  147. assert.equal( PCFSoftShadowMap, 2, 'PCFSoftShadowMap is equal to 2' );
  148. assert.equal( FrontSide, 0, 'FrontSide is equal to 0' );
  149. assert.equal( BackSide, 1, 'BackSide is equal to 1' );
  150. assert.equal( DoubleSide, 2, 'DoubleSide is equal to 2' );
  151. assert.equal( FlatShading, 1, 'FlatShading is equal to 1' );
  152. assert.equal( SmoothShading, 2, 'SmoothShading is equal to 2' );
  153. assert.equal( NoColors, 0, 'NoColors is equal to 0' );
  154. assert.equal( FaceColors, 1, 'FaceColors is equal to 1' );
  155. assert.equal( VertexColors, 2, 'VertexColors is equal to 2' );
  156. assert.equal( NoBlending, 0, 'NoBlending is equal to 0' );
  157. assert.equal( NormalBlending, 1, 'NormalBlending is equal to 1' );
  158. assert.equal( AdditiveBlending, 2, 'AdditiveBlending is equal to 2' );
  159. assert.equal( SubtractiveBlending, 3, 'SubtractiveBlending is equal to 3' );
  160. assert.equal( MultiplyBlending, 4, 'MultiplyBlending is equal to 4' );
  161. assert.equal( CustomBlending, 5, 'CustomBlending is equal to 5' );
  162. assert.equal( AddEquation, 100, 'AddEquation is equal to 100' );
  163. assert.equal( SubtractEquation, 101, 'SubtractEquation is equal to 101' );
  164. assert.equal( ReverseSubtractEquation, 102, 'ReverseSubtractEquation is equal to 102' );
  165. assert.equal( MinEquation, 103, 'MinEquation is equal to 103' );
  166. assert.equal( MaxEquation, 104, 'MaxEquation is equal to 104' );
  167. assert.equal( ZeroFactor, 200, 'ZeroFactor is equal to 200' );
  168. assert.equal( OneFactor, 201, 'OneFactor is equal to 201' );
  169. assert.equal( SrcColorFactor, 202, 'SrcColorFactor is equal to 202' );
  170. assert.equal( OneMinusSrcColorFactor, 203, 'OneMinusSrcColorFactor is equal to 203' );
  171. assert.equal( SrcAlphaFactor, 204, 'SrcAlphaFactor is equal to 204' );
  172. assert.equal( OneMinusSrcAlphaFactor, 205, 'OneMinusSrcAlphaFactor is equal to 205' );
  173. assert.equal( DstAlphaFactor, 206, 'DstAlphaFactor is equal to 206' );
  174. assert.equal( OneMinusDstAlphaFactor, 207, 'OneMinusDstAlphaFactor is equal to 207' );
  175. assert.equal( DstColorFactor, 208, 'DstColorFactor is equal to 208' );
  176. assert.equal( OneMinusDstColorFactor, 209, 'OneMinusDstColorFactor is equal to 209' );
  177. assert.equal( SrcAlphaSaturateFactor, 210, 'SrcAlphaSaturateFactor is equal to 210' );
  178. assert.equal( NeverDepth, 0, 'NeverDepth is equal to 0' );
  179. assert.equal( AlwaysDepth, 1, 'AlwaysDepth is equal to 1' );
  180. assert.equal( LessDepth, 2, 'LessDepth is equal to 2' );
  181. assert.equal( LessEqualDepth, 3, 'LessEqualDepth is equal to 3' );
  182. assert.equal( EqualDepth, 4, 'EqualDepth is equal to 4' );
  183. assert.equal( GreaterEqualDepth, 5, 'GreaterEqualDepth is equal to 5' );
  184. assert.equal( GreaterDepth, 6, 'GreaterDepth is equal to 6' );
  185. assert.equal( NotEqualDepth, 7, 'NotEqualDepth is equal to 7' );
  186. assert.equal( MultiplyOperation, 0, 'MultiplyOperation is equal to 0' );
  187. assert.equal( MixOperation, 1, 'MixOperation is equal to 1' );
  188. assert.equal( AddOperation, 2, 'AddOperation is equal to 2' );
  189. assert.equal( NoToneMapping, 0, 'NoToneMapping is equal to 0' );
  190. assert.equal( LinearToneMapping, 1, 'LinearToneMapping is equal to 1' );
  191. assert.equal( ReinhardToneMapping, 2, 'ReinhardToneMapping is equal to 2' );
  192. assert.equal( Uncharted2ToneMapping, 3, 'Uncharted2ToneMapping is equal to 3' );
  193. assert.equal( CineonToneMapping, 4, 'CineonToneMapping is equal to 4' );
  194. assert.equal( UVMapping, 300, 'UVMapping is equal to 300' );
  195. assert.equal( CubeReflectionMapping, 301, 'CubeReflectionMapping is equal to 301' );
  196. assert.equal( CubeRefractionMapping, 302, 'CubeRefractionMapping is equal to 302' );
  197. assert.equal( EquirectangularReflectionMapping, 303, 'EquirectangularReflectionMapping is equal to 303' );
  198. assert.equal( EquirectangularRefractionMapping, 304, 'EquirectangularRefractionMapping is equal to 304' );
  199. assert.equal( SphericalReflectionMapping, 305, 'SphericalReflectionMapping is equal to 305' );
  200. assert.equal( CubeUVReflectionMapping, 306, 'CubeUVReflectionMapping is equal to 306' );
  201. assert.equal( CubeUVRefractionMapping, 307, 'CubeUVRefractionMapping is equal to 307' );
  202. assert.equal( RepeatWrapping, 1000, 'RepeatWrapping is equal to 1000' );
  203. assert.equal( ClampToEdgeWrapping, 1001, 'ClampToEdgeWrapping is equal to 1001' );
  204. assert.equal( MirroredRepeatWrapping, 1002, 'MirroredRepeatWrapping is equal to 1002' );
  205. assert.equal( NearestFilter, 1003, 'NearestFilter is equal to 1003' );
  206. assert.equal( NearestMipMapNearestFilter, 1004, 'NearestMipMapNearestFilter is equal to 1004' );
  207. assert.equal( NearestMipMapLinearFilter, 1005, 'NearestMipMapLinearFilter is equal to 1005' );
  208. assert.equal( LinearFilter, 1006, 'LinearFilter is equal to 1006' );
  209. assert.equal( LinearMipMapNearestFilter, 1007, 'LinearMipMapNearestFilter is equal to 1007' );
  210. assert.equal( LinearMipMapLinearFilter, 1008, 'LinearMipMapLinearFilter is equal to 1008' );
  211. assert.equal( UnsignedByteType, 1009, 'UnsignedByteType is equal to 1009' );
  212. assert.equal( ByteType, 1010, 'ByteType is equal to 1010' );
  213. assert.equal( ShortType, 1011, 'ShortType is equal to 1011' );
  214. assert.equal( UnsignedShortType, 1012, 'UnsignedShortType is equal to 1012' );
  215. assert.equal( IntType, 1013, 'IntType is equal to 1013' );
  216. assert.equal( UnsignedIntType, 1014, 'UnsignedIntType is equal to 1014' );
  217. assert.equal( FloatType, 1015, 'FloatType is equal to 1015' );
  218. assert.equal( HalfFloatType, 1016, 'HalfFloatType is equal to 1016' );
  219. assert.equal( UnsignedShort4444Type, 1017, 'UnsignedShort4444Type is equal to 1017' );
  220. assert.equal( UnsignedShort5551Type, 1018, 'UnsignedShort5551Type is equal to 1018' );
  221. assert.equal( UnsignedShort565Type, 1019, 'UnsignedShort565Type is equal to 1019' );
  222. assert.equal( UnsignedInt248Type, 1020, 'UnsignedInt248Type is equal to 1020' );
  223. assert.equal( AlphaFormat, 1021, 'AlphaFormat is equal to 1021' );
  224. assert.equal( RGBFormat, 1022, 'RGBFormat is equal to 1022' );
  225. assert.equal( RGBAFormat, 1023, 'RGBAFormat is equal to 1023' );
  226. assert.equal( LuminanceFormat, 1024, 'LuminanceFormat is equal to 1024' );
  227. assert.equal( LuminanceAlphaFormat, 1025, 'LuminanceAlphaFormat is equal to 1025' );
  228. assert.equal( RGBEFormat, RGBAFormat, 'RGBEFormat is equal to RGBAFormat' );
  229. assert.equal( DepthFormat, 1026, 'DepthFormat is equal to 1026' );
  230. assert.equal( DepthStencilFormat, 1027, 'DepthStencilFormat is equal to 1027' );
  231. assert.equal( RGB_S3TC_DXT1_Format, 2001, 'RGB_S3TC_DXT1_Format is equal to 2001' );
  232. assert.equal( RGBA_S3TC_DXT1_Format, 2002, 'RGBA_S3TC_DXT1_Format is equal to 2002' );
  233. assert.equal( RGBA_S3TC_DXT3_Format, 2003, 'RGBA_S3TC_DXT3_Format is equal to 2003' );
  234. assert.equal( RGBA_S3TC_DXT5_Format, 2004, 'RGBA_S3TC_DXT5_Format is equal to 2004' );
  235. assert.equal( RGB_PVRTC_4BPPV1_Format, 2100, 'RGB_PVRTC_4BPPV1_Format is equal to 2100' );
  236. assert.equal( RGB_PVRTC_2BPPV1_Format, 2101, 'RGB_PVRTC_2BPPV1_Format is equal to 2101' );
  237. assert.equal( RGBA_PVRTC_4BPPV1_Format, 2102, 'RGBA_PVRTC_4BPPV1_Format is equal to 2102' );
  238. assert.equal( RGBA_PVRTC_2BPPV1_Format, 2103, 'RGBA_PVRTC_2BPPV1_Format is equal to 2103' );
  239. assert.equal( RGB_ETC1_Format, 2151, 'RGB_ETC1_Format is equal to 2151' );
  240. assert.equal( LoopOnce, 2200, 'LoopOnce is equal to 2200' );
  241. assert.equal( LoopRepeat, 2201, 'LoopRepeat is equal to 2201' );
  242. assert.equal( LoopPingPong, 2202, 'LoopPingPong is equal to 2202' );
  243. assert.equal( InterpolateDiscrete, 2300, 'InterpolateDiscrete is equal to 2300' );
  244. assert.equal( InterpolateLinear, 2301, 'InterpolateLinear is equal to 2301' );
  245. assert.equal( InterpolateSmooth, 2302, 'InterpolateSmooth is equal to 2302' );
  246. assert.equal( ZeroCurvatureEnding, 2400, 'ZeroCurvatureEnding is equal to 2400' );
  247. assert.equal( ZeroSlopeEnding, 2401, 'ZeroSlopeEnding is equal to 2401' );
  248. assert.equal( WrapAroundEnding, 2402, 'WrapAroundEnding is equal to 2402' );
  249. assert.equal( TrianglesDrawMode, 0, 'TrianglesDrawMode is equal to 0' );
  250. assert.equal( TriangleStripDrawMode, 1, 'TriangleStripDrawMode is equal to 1' );
  251. assert.equal( TriangleFanDrawMode, 2, 'TriangleFanDrawMode is equal to 2' );
  252. assert.equal( LinearEncoding, 3000, 'LinearEncoding is equal to 3000' );
  253. assert.equal( sRGBEncoding, 3001, 'sRGBEncoding is equal to 3001' );
  254. assert.equal( GammaEncoding, 3007, 'GammaEncoding is equal to 3007' );
  255. assert.equal( RGBEEncoding, 3002, 'RGBEEncoding is equal to 3002' );
  256. assert.equal( LogLuvEncoding, 3003, 'LogLuvEncoding is equal to 3003' );
  257. assert.equal( RGBM7Encoding, 3004, 'RGBM7Encoding is equal to 3004' );
  258. assert.equal( RGBM16Encoding, 3005, 'RGBM16Encoding is equal to 3005' );
  259. assert.equal( RGBDEncoding, 3006, 'RGBDEncoding is equal to 3006' );
  260. assert.equal( BasicDepthPacking, 3200, 'BasicDepthPacking is equal to 3200' );
  261. assert.equal( RGBADepthPacking, 3201, 'RGBADepthPacking is equal to 3201' );
  262. } );
  263. } );
  264. // Polyfills
  265. if ( Number.EPSILON === undefined ) {
  266. Number.EPSILON = Math.pow( 2, - 52 );
  267. }
  268. if ( Number.isInteger === undefined ) {
  269. // Missing in IE
  270. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger
  271. Number.isInteger = function ( value ) {
  272. return typeof value === 'number' && isFinite( value ) && Math.floor( value ) === value;
  273. };
  274. }
  275. //
  276. if ( Math.sign === undefined ) {
  277. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  278. Math.sign = function ( x ) {
  279. return ( x < 0 ) ? - 1 : ( x > 0 ) ? 1 : + x;
  280. };
  281. }
  282. if ( 'name' in Function.prototype === false ) {
  283. // Missing in IE
  284. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
  285. Object.defineProperty( Function.prototype, 'name', {
  286. get: function () {
  287. return this.toString().match( /^\s*function\s*([^\(\s]*)/ )[ 1 ];
  288. }
  289. } );
  290. }
  291. if ( Object.assign === undefined ) {
  292. // Missing in IE
  293. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
  294. ( function () {
  295. Object.assign = function ( target ) {
  296. 'use strict';
  297. if ( target === undefined || target === null ) {
  298. throw new TypeError( 'Cannot convert undefined or null to object' );
  299. }
  300. var output = Object( target );
  301. for ( var index = 1; index < arguments.length; index ++ ) {
  302. var source = arguments[ index ];
  303. if ( source !== undefined && source !== null ) {
  304. for ( var nextKey in source ) {
  305. if ( Object.prototype.hasOwnProperty.call( source, nextKey ) ) {
  306. output[ nextKey ] = source[ nextKey ];
  307. }
  308. }
  309. }
  310. }
  311. return output;
  312. };
  313. } )();
  314. }
  315. /**
  316. * @author alteredq / http://alteredqualia.com/
  317. * @author mrdoob / http://mrdoob.com/
  318. */
  319. var _Math = {
  320. DEG2RAD: Math.PI / 180,
  321. RAD2DEG: 180 / Math.PI,
  322. generateUUID: function () {
  323. // http://www.broofa.com/Tools/Math.uuid.htm
  324. // Replaced .join with string concatenation (@takahirox)
  325. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split( '' );
  326. var rnd = 0, r;
  327. return function generateUUID() {
  328. var uuid = '';
  329. for ( var i = 0; i < 36; i ++ ) {
  330. if ( i === 8 || i === 13 || i === 18 || i === 23 ) {
  331. uuid += '-';
  332. } else if ( i === 14 ) {
  333. uuid += '4';
  334. } else {
  335. if ( rnd <= 0x02 ) rnd = 0x2000000 + ( Math.random() * 0x1000000 ) | 0;
  336. r = rnd & 0xf;
  337. rnd = rnd >> 4;
  338. uuid += chars[ ( i === 19 ) ? ( r & 0x3 ) | 0x8 : r ];
  339. }
  340. }
  341. return uuid;
  342. };
  343. }(),
  344. clamp: function ( value, min, max ) {
  345. return Math.max( min, Math.min( max, value ) );
  346. },
  347. // compute euclidian modulo of m % n
  348. // https://en.wikipedia.org/wiki/Modulo_operation
  349. euclideanModulo: function ( n, m ) {
  350. return ( ( n % m ) + m ) % m;
  351. },
  352. // Linear mapping from range <a1, a2> to range <b1, b2>
  353. mapLinear: function ( x, a1, a2, b1, b2 ) {
  354. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  355. },
  356. // https://en.wikipedia.org/wiki/Linear_interpolation
  357. lerp: function ( x, y, t ) {
  358. return ( 1 - t ) * x + t * y;
  359. },
  360. // http://en.wikipedia.org/wiki/Smoothstep
  361. smoothstep: function ( x, min, max ) {
  362. if ( x <= min ) return 0;
  363. if ( x >= max ) return 1;
  364. x = ( x - min ) / ( max - min );
  365. return x * x * ( 3 - 2 * x );
  366. },
  367. smootherstep: function ( x, min, max ) {
  368. if ( x <= min ) return 0;
  369. if ( x >= max ) return 1;
  370. x = ( x - min ) / ( max - min );
  371. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  372. },
  373. // Random integer from <low, high> interval
  374. randInt: function ( low, high ) {
  375. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  376. },
  377. // Random float from <low, high> interval
  378. randFloat: function ( low, high ) {
  379. return low + Math.random() * ( high - low );
  380. },
  381. // Random float from <-range/2, range/2> interval
  382. randFloatSpread: function ( range ) {
  383. return range * ( 0.5 - Math.random() );
  384. },
  385. degToRad: function ( degrees ) {
  386. return degrees * _Math.DEG2RAD;
  387. },
  388. radToDeg: function ( radians ) {
  389. return radians * _Math.RAD2DEG;
  390. },
  391. isPowerOfTwo: function ( value ) {
  392. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  393. },
  394. ceilPowerOfTwo: function ( value ) {
  395. return Math.pow( 2, Math.ceil( Math.log( value ) / Math.LN2 ) );
  396. },
  397. floorPowerOfTwo: function ( value ) {
  398. return Math.pow( 2, Math.floor( Math.log( value ) / Math.LN2 ) );
  399. }
  400. };
  401. function Matrix4() {
  402. this.elements = [
  403. 1, 0, 0, 0,
  404. 0, 1, 0, 0,
  405. 0, 0, 1, 0,
  406. 0, 0, 0, 1
  407. ];
  408. if ( arguments.length > 0 ) {
  409. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  410. }
  411. }
  412. Object.assign( Matrix4.prototype, {
  413. isMatrix4: true,
  414. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  415. var te = this.elements;
  416. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  417. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  418. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  419. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  420. return this;
  421. },
  422. identity: function () {
  423. this.set(
  424. 1, 0, 0, 0,
  425. 0, 1, 0, 0,
  426. 0, 0, 1, 0,
  427. 0, 0, 0, 1
  428. );
  429. return this;
  430. },
  431. clone: function () {
  432. return new Matrix4().fromArray( this.elements );
  433. },
  434. copy: function ( m ) {
  435. var te = this.elements;
  436. var me = m.elements;
  437. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ]; te[ 3 ] = me[ 3 ];
  438. te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ]; te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ];
  439. te[ 8 ] = me[ 8 ]; te[ 9 ] = me[ 9 ]; te[ 10 ] = me[ 10 ]; te[ 11 ] = me[ 11 ];
  440. te[ 12 ] = me[ 12 ]; te[ 13 ] = me[ 13 ]; te[ 14 ] = me[ 14 ]; te[ 15 ] = me[ 15 ];
  441. return this;
  442. },
  443. copyPosition: function ( m ) {
  444. var te = this.elements, me = m.elements;
  445. te[ 12 ] = me[ 12 ];
  446. te[ 13 ] = me[ 13 ];
  447. te[ 14 ] = me[ 14 ];
  448. return this;
  449. },
  450. extractBasis: function ( xAxis, yAxis, zAxis ) {
  451. xAxis.setFromMatrixColumn( this, 0 );
  452. yAxis.setFromMatrixColumn( this, 1 );
  453. zAxis.setFromMatrixColumn( this, 2 );
  454. return this;
  455. },
  456. makeBasis: function ( xAxis, yAxis, zAxis ) {
  457. this.set(
  458. xAxis.x, yAxis.x, zAxis.x, 0,
  459. xAxis.y, yAxis.y, zAxis.y, 0,
  460. xAxis.z, yAxis.z, zAxis.z, 0,
  461. 0, 0, 0, 1
  462. );
  463. return this;
  464. },
  465. extractRotation: function () {
  466. var v1 = new Vector3();
  467. return function extractRotation( m ) {
  468. var te = this.elements;
  469. var me = m.elements;
  470. var scaleX = 1 / v1.setFromMatrixColumn( m, 0 ).length();
  471. var scaleY = 1 / v1.setFromMatrixColumn( m, 1 ).length();
  472. var scaleZ = 1 / v1.setFromMatrixColumn( m, 2 ).length();
  473. te[ 0 ] = me[ 0 ] * scaleX;
  474. te[ 1 ] = me[ 1 ] * scaleX;
  475. te[ 2 ] = me[ 2 ] * scaleX;
  476. te[ 4 ] = me[ 4 ] * scaleY;
  477. te[ 5 ] = me[ 5 ] * scaleY;
  478. te[ 6 ] = me[ 6 ] * scaleY;
  479. te[ 8 ] = me[ 8 ] * scaleZ;
  480. te[ 9 ] = me[ 9 ] * scaleZ;
  481. te[ 10 ] = me[ 10 ] * scaleZ;
  482. return this;
  483. };
  484. }(),
  485. makeRotationFromEuler: function ( euler ) {
  486. if ( ! ( euler && euler.isEuler ) ) {
  487. console.error( 'THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  488. }
  489. var te = this.elements;
  490. var x = euler.x, y = euler.y, z = euler.z;
  491. var a = Math.cos( x ), b = Math.sin( x );
  492. var c = Math.cos( y ), d = Math.sin( y );
  493. var e = Math.cos( z ), f = Math.sin( z );
  494. if ( euler.order === 'XYZ' ) {
  495. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  496. te[ 0 ] = c * e;
  497. te[ 4 ] = - c * f;
  498. te[ 8 ] = d;
  499. te[ 1 ] = af + be * d;
  500. te[ 5 ] = ae - bf * d;
  501. te[ 9 ] = - b * c;
  502. te[ 2 ] = bf - ae * d;
  503. te[ 6 ] = be + af * d;
  504. te[ 10 ] = a * c;
  505. } else if ( euler.order === 'YXZ' ) {
  506. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  507. te[ 0 ] = ce + df * b;
  508. te[ 4 ] = de * b - cf;
  509. te[ 8 ] = a * d;
  510. te[ 1 ] = a * f;
  511. te[ 5 ] = a * e;
  512. te[ 9 ] = - b;
  513. te[ 2 ] = cf * b - de;
  514. te[ 6 ] = df + ce * b;
  515. te[ 10 ] = a * c;
  516. } else if ( euler.order === 'ZXY' ) {
  517. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  518. te[ 0 ] = ce - df * b;
  519. te[ 4 ] = - a * f;
  520. te[ 8 ] = de + cf * b;
  521. te[ 1 ] = cf + de * b;
  522. te[ 5 ] = a * e;
  523. te[ 9 ] = df - ce * b;
  524. te[ 2 ] = - a * d;
  525. te[ 6 ] = b;
  526. te[ 10 ] = a * c;
  527. } else if ( euler.order === 'ZYX' ) {
  528. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  529. te[ 0 ] = c * e;
  530. te[ 4 ] = be * d - af;
  531. te[ 8 ] = ae * d + bf;
  532. te[ 1 ] = c * f;
  533. te[ 5 ] = bf * d + ae;
  534. te[ 9 ] = af * d - be;
  535. te[ 2 ] = - d;
  536. te[ 6 ] = b * c;
  537. te[ 10 ] = a * c;
  538. } else if ( euler.order === 'YZX' ) {
  539. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  540. te[ 0 ] = c * e;
  541. te[ 4 ] = bd - ac * f;
  542. te[ 8 ] = bc * f + ad;
  543. te[ 1 ] = f;
  544. te[ 5 ] = a * e;
  545. te[ 9 ] = - b * e;
  546. te[ 2 ] = - d * e;
  547. te[ 6 ] = ad * f + bc;
  548. te[ 10 ] = ac - bd * f;
  549. } else if ( euler.order === 'XZY' ) {
  550. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  551. te[ 0 ] = c * e;
  552. te[ 4 ] = - f;
  553. te[ 8 ] = d * e;
  554. te[ 1 ] = ac * f + bd;
  555. te[ 5 ] = a * e;
  556. te[ 9 ] = ad * f - bc;
  557. te[ 2 ] = bc * f - ad;
  558. te[ 6 ] = b * e;
  559. te[ 10 ] = bd * f + ac;
  560. }
  561. // last column
  562. te[ 3 ] = 0;
  563. te[ 7 ] = 0;
  564. te[ 11 ] = 0;
  565. // bottom row
  566. te[ 12 ] = 0;
  567. te[ 13 ] = 0;
  568. te[ 14 ] = 0;
  569. te[ 15 ] = 1;
  570. return this;
  571. },
  572. makeRotationFromQuaternion: function ( q ) {
  573. var te = this.elements;
  574. var x = q._x, y = q._y, z = q._z, w = q._w;
  575. var x2 = x + x, y2 = y + y, z2 = z + z;
  576. var xx = x * x2, xy = x * y2, xz = x * z2;
  577. var yy = y * y2, yz = y * z2, zz = z * z2;
  578. var wx = w * x2, wy = w * y2, wz = w * z2;
  579. te[ 0 ] = 1 - ( yy + zz );
  580. te[ 4 ] = xy - wz;
  581. te[ 8 ] = xz + wy;
  582. te[ 1 ] = xy + wz;
  583. te[ 5 ] = 1 - ( xx + zz );
  584. te[ 9 ] = yz - wx;
  585. te[ 2 ] = xz - wy;
  586. te[ 6 ] = yz + wx;
  587. te[ 10 ] = 1 - ( xx + yy );
  588. // last column
  589. te[ 3 ] = 0;
  590. te[ 7 ] = 0;
  591. te[ 11 ] = 0;
  592. // bottom row
  593. te[ 12 ] = 0;
  594. te[ 13 ] = 0;
  595. te[ 14 ] = 0;
  596. te[ 15 ] = 1;
  597. return this;
  598. },
  599. lookAt: function () {
  600. var x = new Vector3();
  601. var y = new Vector3();
  602. var z = new Vector3();
  603. return function lookAt( eye, target, up ) {
  604. var te = this.elements;
  605. z.subVectors( eye, target );
  606. if ( z.lengthSq() === 0 ) {
  607. // eye and target are in the same position
  608. z.z = 1;
  609. }
  610. z.normalize();
  611. x.crossVectors( up, z );
  612. if ( x.lengthSq() === 0 ) {
  613. // up and z are parallel
  614. if ( Math.abs( up.z ) === 1 ) {
  615. z.x += 0.0001;
  616. } else {
  617. z.z += 0.0001;
  618. }
  619. z.normalize();
  620. x.crossVectors( up, z );
  621. }
  622. x.normalize();
  623. y.crossVectors( z, x );
  624. te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
  625. te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
  626. te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
  627. return this;
  628. };
  629. }(),
  630. multiply: function ( m, n ) {
  631. if ( n !== undefined ) {
  632. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  633. return this.multiplyMatrices( m, n );
  634. }
  635. return this.multiplyMatrices( this, m );
  636. },
  637. premultiply: function ( m ) {
  638. return this.multiplyMatrices( m, this );
  639. },
  640. multiplyMatrices: function ( a, b ) {
  641. var ae = a.elements;
  642. var be = b.elements;
  643. var te = this.elements;
  644. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  645. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  646. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  647. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  648. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  649. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  650. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  651. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  652. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  653. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  654. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  655. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  656. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  657. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  658. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  659. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  660. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  661. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  662. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  663. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  664. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  665. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  666. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  667. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  668. return this;
  669. },
  670. multiplyScalar: function ( s ) {
  671. var te = this.elements;
  672. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  673. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  674. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  675. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  676. return this;
  677. },
  678. applyToBufferAttribute: function () {
  679. var v1 = new Vector3();
  680. return function applyToBufferAttribute( attribute ) {
  681. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  682. v1.x = attribute.getX( i );
  683. v1.y = attribute.getY( i );
  684. v1.z = attribute.getZ( i );
  685. v1.applyMatrix4( this );
  686. attribute.setXYZ( i, v1.x, v1.y, v1.z );
  687. }
  688. return attribute;
  689. };
  690. }(),
  691. determinant: function () {
  692. var te = this.elements;
  693. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  694. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  695. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  696. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  697. //TODO: make this more efficient
  698. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  699. return (
  700. n41 * (
  701. + n14 * n23 * n32
  702. - n13 * n24 * n32
  703. - n14 * n22 * n33
  704. + n12 * n24 * n33
  705. + n13 * n22 * n34
  706. - n12 * n23 * n34
  707. ) +
  708. n42 * (
  709. + n11 * n23 * n34
  710. - n11 * n24 * n33
  711. + n14 * n21 * n33
  712. - n13 * n21 * n34
  713. + n13 * n24 * n31
  714. - n14 * n23 * n31
  715. ) +
  716. n43 * (
  717. + n11 * n24 * n32
  718. - n11 * n22 * n34
  719. - n14 * n21 * n32
  720. + n12 * n21 * n34
  721. + n14 * n22 * n31
  722. - n12 * n24 * n31
  723. ) +
  724. n44 * (
  725. - n13 * n22 * n31
  726. - n11 * n23 * n32
  727. + n11 * n22 * n33
  728. + n13 * n21 * n32
  729. - n12 * n21 * n33
  730. + n12 * n23 * n31
  731. )
  732. );
  733. },
  734. transpose: function () {
  735. var te = this.elements;
  736. var tmp;
  737. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  738. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  739. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  740. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  741. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  742. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  743. return this;
  744. },
  745. setPosition: function ( v ) {
  746. var te = this.elements;
  747. te[ 12 ] = v.x;
  748. te[ 13 ] = v.y;
  749. te[ 14 ] = v.z;
  750. return this;
  751. },
  752. getInverse: function ( m, throwOnDegenerate ) {
  753. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  754. var te = this.elements,
  755. me = m.elements,
  756. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ], n41 = me[ 3 ],
  757. n12 = me[ 4 ], n22 = me[ 5 ], n32 = me[ 6 ], n42 = me[ 7 ],
  758. n13 = me[ 8 ], n23 = me[ 9 ], n33 = me[ 10 ], n43 = me[ 11 ],
  759. n14 = me[ 12 ], n24 = me[ 13 ], n34 = me[ 14 ], n44 = me[ 15 ],
  760. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  761. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  762. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  763. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  764. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  765. if ( det === 0 ) {
  766. var msg = "THREE.Matrix4: .getInverse() can't invert matrix, determinant is 0";
  767. if ( throwOnDegenerate === true ) {
  768. throw new Error( msg );
  769. } else {
  770. console.warn( msg );
  771. }
  772. return this.identity();
  773. }
  774. var detInv = 1 / det;
  775. te[ 0 ] = t11 * detInv;
  776. te[ 1 ] = ( n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44 ) * detInv;
  777. te[ 2 ] = ( n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44 ) * detInv;
  778. te[ 3 ] = ( n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43 ) * detInv;
  779. te[ 4 ] = t12 * detInv;
  780. te[ 5 ] = ( n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44 ) * detInv;
  781. te[ 6 ] = ( n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44 ) * detInv;
  782. te[ 7 ] = ( n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43 ) * detInv;
  783. te[ 8 ] = t13 * detInv;
  784. te[ 9 ] = ( n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44 ) * detInv;
  785. te[ 10 ] = ( n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44 ) * detInv;
  786. te[ 11 ] = ( n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43 ) * detInv;
  787. te[ 12 ] = t14 * detInv;
  788. te[ 13 ] = ( n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34 ) * detInv;
  789. te[ 14 ] = ( n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34 ) * detInv;
  790. te[ 15 ] = ( n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33 ) * detInv;
  791. return this;
  792. },
  793. scale: function ( v ) {
  794. var te = this.elements;
  795. var x = v.x, y = v.y, z = v.z;
  796. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  797. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  798. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  799. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  800. return this;
  801. },
  802. getMaxScaleOnAxis: function () {
  803. var te = this.elements;
  804. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  805. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  806. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  807. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  808. },
  809. makeTranslation: function ( x, y, z ) {
  810. this.set(
  811. 1, 0, 0, x,
  812. 0, 1, 0, y,
  813. 0, 0, 1, z,
  814. 0, 0, 0, 1
  815. );
  816. return this;
  817. },
  818. makeRotationX: function ( theta ) {
  819. var c = Math.cos( theta ), s = Math.sin( theta );
  820. this.set(
  821. 1, 0, 0, 0,
  822. 0, c, - s, 0,
  823. 0, s, c, 0,
  824. 0, 0, 0, 1
  825. );
  826. return this;
  827. },
  828. makeRotationY: function ( theta ) {
  829. var c = Math.cos( theta ), s = Math.sin( theta );
  830. this.set(
  831. c, 0, s, 0,
  832. 0, 1, 0, 0,
  833. - s, 0, c, 0,
  834. 0, 0, 0, 1
  835. );
  836. return this;
  837. },
  838. makeRotationZ: function ( theta ) {
  839. var c = Math.cos( theta ), s = Math.sin( theta );
  840. this.set(
  841. c, - s, 0, 0,
  842. s, c, 0, 0,
  843. 0, 0, 1, 0,
  844. 0, 0, 0, 1
  845. );
  846. return this;
  847. },
  848. makeRotationAxis: function ( axis, angle ) {
  849. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  850. var c = Math.cos( angle );
  851. var s = Math.sin( angle );
  852. var t = 1 - c;
  853. var x = axis.x, y = axis.y, z = axis.z;
  854. var tx = t * x, ty = t * y;
  855. this.set(
  856. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  857. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  858. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  859. 0, 0, 0, 1
  860. );
  861. return this;
  862. },
  863. makeScale: function ( x, y, z ) {
  864. this.set(
  865. x, 0, 0, 0,
  866. 0, y, 0, 0,
  867. 0, 0, z, 0,
  868. 0, 0, 0, 1
  869. );
  870. return this;
  871. },
  872. makeShear: function ( x, y, z ) {
  873. this.set(
  874. 1, y, z, 0,
  875. x, 1, z, 0,
  876. x, y, 1, 0,
  877. 0, 0, 0, 1
  878. );
  879. return this;
  880. },
  881. compose: function ( position, quaternion, scale ) {
  882. this.makeRotationFromQuaternion( quaternion );
  883. this.scale( scale );
  884. this.setPosition( position );
  885. return this;
  886. },
  887. decompose: function () {
  888. var vector = new Vector3();
  889. var matrix = new Matrix4();
  890. return function decompose( position, quaternion, scale ) {
  891. var te = this.elements;
  892. var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  893. var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  894. var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  895. // if determine is negative, we need to invert one scale
  896. var det = this.determinant();
  897. if ( det < 0 ) sx = - sx;
  898. position.x = te[ 12 ];
  899. position.y = te[ 13 ];
  900. position.z = te[ 14 ];
  901. // scale the rotation part
  902. matrix.copy( this );
  903. var invSX = 1 / sx;
  904. var invSY = 1 / sy;
  905. var invSZ = 1 / sz;
  906. matrix.elements[ 0 ] *= invSX;
  907. matrix.elements[ 1 ] *= invSX;
  908. matrix.elements[ 2 ] *= invSX;
  909. matrix.elements[ 4 ] *= invSY;
  910. matrix.elements[ 5 ] *= invSY;
  911. matrix.elements[ 6 ] *= invSY;
  912. matrix.elements[ 8 ] *= invSZ;
  913. matrix.elements[ 9 ] *= invSZ;
  914. matrix.elements[ 10 ] *= invSZ;
  915. quaternion.setFromRotationMatrix( matrix );
  916. scale.x = sx;
  917. scale.y = sy;
  918. scale.z = sz;
  919. return this;
  920. };
  921. }(),
  922. makePerspective: function ( left, right, top, bottom, near, far ) {
  923. if ( far === undefined ) {
  924. console.warn( 'THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.' );
  925. }
  926. var te = this.elements;
  927. var x = 2 * near / ( right - left );
  928. var y = 2 * near / ( top - bottom );
  929. var a = ( right + left ) / ( right - left );
  930. var b = ( top + bottom ) / ( top - bottom );
  931. var c = - ( far + near ) / ( far - near );
  932. var d = - 2 * far * near / ( far - near );
  933. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  934. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  935. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  936. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  937. return this;
  938. },
  939. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  940. var te = this.elements;
  941. var w = 1.0 / ( right - left );
  942. var h = 1.0 / ( top - bottom );
  943. var p = 1.0 / ( far - near );
  944. var x = ( right + left ) * w;
  945. var y = ( top + bottom ) * h;
  946. var z = ( far + near ) * p;
  947. te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  948. te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y;
  949. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 * p; te[ 14 ] = - z;
  950. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  951. return this;
  952. },
  953. equals: function ( matrix ) {
  954. var te = this.elements;
  955. var me = matrix.elements;
  956. for ( var i = 0; i < 16; i ++ ) {
  957. if ( te[ i ] !== me[ i ] ) return false;
  958. }
  959. return true;
  960. },
  961. fromArray: function ( array, offset ) {
  962. if ( offset === undefined ) offset = 0;
  963. for ( var i = 0; i < 16; i ++ ) {
  964. this.elements[ i ] = array[ i + offset ];
  965. }
  966. return this;
  967. },
  968. toArray: function ( array, offset ) {
  969. if ( array === undefined ) array = [];
  970. if ( offset === undefined ) offset = 0;
  971. var te = this.elements;
  972. array[ offset ] = te[ 0 ];
  973. array[ offset + 1 ] = te[ 1 ];
  974. array[ offset + 2 ] = te[ 2 ];
  975. array[ offset + 3 ] = te[ 3 ];
  976. array[ offset + 4 ] = te[ 4 ];
  977. array[ offset + 5 ] = te[ 5 ];
  978. array[ offset + 6 ] = te[ 6 ];
  979. array[ offset + 7 ] = te[ 7 ];
  980. array[ offset + 8 ] = te[ 8 ];
  981. array[ offset + 9 ] = te[ 9 ];
  982. array[ offset + 10 ] = te[ 10 ];
  983. array[ offset + 11 ] = te[ 11 ];
  984. array[ offset + 12 ] = te[ 12 ];
  985. array[ offset + 13 ] = te[ 13 ];
  986. array[ offset + 14 ] = te[ 14 ];
  987. array[ offset + 15 ] = te[ 15 ];
  988. return array;
  989. }
  990. } );
  991. function Quaternion( x, y, z, w ) {
  992. this._x = x || 0;
  993. this._y = y || 0;
  994. this._z = z || 0;
  995. this._w = ( w !== undefined ) ? w : 1;
  996. }
  997. Object.assign( Quaternion, {
  998. slerp: function ( qa, qb, qm, t ) {
  999. return qm.copy( qa ).slerp( qb, t );
  1000. },
  1001. slerpFlat: function ( dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {
  1002. // fuzz-free, array-based Quaternion SLERP operation
  1003. var x0 = src0[ srcOffset0 + 0 ],
  1004. y0 = src0[ srcOffset0 + 1 ],
  1005. z0 = src0[ srcOffset0 + 2 ],
  1006. w0 = src0[ srcOffset0 + 3 ],
  1007. x1 = src1[ srcOffset1 + 0 ],
  1008. y1 = src1[ srcOffset1 + 1 ],
  1009. z1 = src1[ srcOffset1 + 2 ],
  1010. w1 = src1[ srcOffset1 + 3 ];
  1011. if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {
  1012. var s = 1 - t,
  1013. cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  1014. dir = ( cos >= 0 ? 1 : - 1 ),
  1015. sqrSin = 1 - cos * cos;
  1016. // Skip the Slerp for tiny steps to avoid numeric problems:
  1017. if ( sqrSin > Number.EPSILON ) {
  1018. var sin = Math.sqrt( sqrSin ),
  1019. len = Math.atan2( sin, cos * dir );
  1020. s = Math.sin( s * len ) / sin;
  1021. t = Math.sin( t * len ) / sin;
  1022. }
  1023. var tDir = t * dir;
  1024. x0 = x0 * s + x1 * tDir;
  1025. y0 = y0 * s + y1 * tDir;
  1026. z0 = z0 * s + z1 * tDir;
  1027. w0 = w0 * s + w1 * tDir;
  1028. // Normalize in case we just did a lerp:
  1029. if ( s === 1 - t ) {
  1030. var f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 );
  1031. x0 *= f;
  1032. y0 *= f;
  1033. z0 *= f;
  1034. w0 *= f;
  1035. }
  1036. }
  1037. dst[ dstOffset ] = x0;
  1038. dst[ dstOffset + 1 ] = y0;
  1039. dst[ dstOffset + 2 ] = z0;
  1040. dst[ dstOffset + 3 ] = w0;
  1041. }
  1042. } );
  1043. Object.defineProperties( Quaternion.prototype, {
  1044. x: {
  1045. get: function () {
  1046. return this._x;
  1047. },
  1048. set: function ( value ) {
  1049. this._x = value;
  1050. this.onChangeCallback();
  1051. }
  1052. },
  1053. y: {
  1054. get: function () {
  1055. return this._y;
  1056. },
  1057. set: function ( value ) {
  1058. this._y = value;
  1059. this.onChangeCallback();
  1060. }
  1061. },
  1062. z: {
  1063. get: function () {
  1064. return this._z;
  1065. },
  1066. set: function ( value ) {
  1067. this._z = value;
  1068. this.onChangeCallback();
  1069. }
  1070. },
  1071. w: {
  1072. get: function () {
  1073. return this._w;
  1074. },
  1075. set: function ( value ) {
  1076. this._w = value;
  1077. this.onChangeCallback();
  1078. }
  1079. }
  1080. } );
  1081. Object.assign( Quaternion.prototype, {
  1082. set: function ( x, y, z, w ) {
  1083. this._x = x;
  1084. this._y = y;
  1085. this._z = z;
  1086. this._w = w;
  1087. this.onChangeCallback();
  1088. return this;
  1089. },
  1090. clone: function () {
  1091. return new this.constructor( this._x, this._y, this._z, this._w );
  1092. },
  1093. copy: function ( quaternion ) {
  1094. this._x = quaternion.x;
  1095. this._y = quaternion.y;
  1096. this._z = quaternion.z;
  1097. this._w = quaternion.w;
  1098. this.onChangeCallback();
  1099. return this;
  1100. },
  1101. setFromEuler: function ( euler, update ) {
  1102. if ( ! ( euler && euler.isEuler ) ) {
  1103. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1104. }
  1105. var x = euler._x, y = euler._y, z = euler._z, order = euler.order;
  1106. // http://www.mathworks.com/matlabcentral/fileexchange/
  1107. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  1108. // content/SpinCalc.m
  1109. var cos = Math.cos;
  1110. var sin = Math.sin;
  1111. var c1 = cos( x / 2 );
  1112. var c2 = cos( y / 2 );
  1113. var c3 = cos( z / 2 );
  1114. var s1 = sin( x / 2 );
  1115. var s2 = sin( y / 2 );
  1116. var s3 = sin( z / 2 );
  1117. if ( order === 'XYZ' ) {
  1118. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1119. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1120. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1121. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1122. } else if ( order === 'YXZ' ) {
  1123. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1124. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1125. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1126. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1127. } else if ( order === 'ZXY' ) {
  1128. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1129. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1130. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1131. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1132. } else if ( order === 'ZYX' ) {
  1133. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1134. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1135. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1136. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1137. } else if ( order === 'YZX' ) {
  1138. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1139. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1140. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1141. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1142. } else if ( order === 'XZY' ) {
  1143. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1144. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1145. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1146. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1147. }
  1148. if ( update !== false ) this.onChangeCallback();
  1149. return this;
  1150. },
  1151. setFromAxisAngle: function ( axis, angle ) {
  1152. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  1153. // assumes axis is normalized
  1154. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  1155. this._x = axis.x * s;
  1156. this._y = axis.y * s;
  1157. this._z = axis.z * s;
  1158. this._w = Math.cos( halfAngle );
  1159. this.onChangeCallback();
  1160. return this;
  1161. },
  1162. setFromRotationMatrix: function ( m ) {
  1163. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  1164. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1165. var te = m.elements,
  1166. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1167. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1168. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  1169. trace = m11 + m22 + m33,
  1170. s;
  1171. if ( trace > 0 ) {
  1172. s = 0.5 / Math.sqrt( trace + 1.0 );
  1173. this._w = 0.25 / s;
  1174. this._x = ( m32 - m23 ) * s;
  1175. this._y = ( m13 - m31 ) * s;
  1176. this._z = ( m21 - m12 ) * s;
  1177. } else if ( m11 > m22 && m11 > m33 ) {
  1178. s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  1179. this._w = ( m32 - m23 ) / s;
  1180. this._x = 0.25 * s;
  1181. this._y = ( m12 + m21 ) / s;
  1182. this._z = ( m13 + m31 ) / s;
  1183. } else if ( m22 > m33 ) {
  1184. s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  1185. this._w = ( m13 - m31 ) / s;
  1186. this._x = ( m12 + m21 ) / s;
  1187. this._y = 0.25 * s;
  1188. this._z = ( m23 + m32 ) / s;
  1189. } else {
  1190. s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  1191. this._w = ( m21 - m12 ) / s;
  1192. this._x = ( m13 + m31 ) / s;
  1193. this._y = ( m23 + m32 ) / s;
  1194. this._z = 0.25 * s;
  1195. }
  1196. this.onChangeCallback();
  1197. return this;
  1198. },
  1199. setFromUnitVectors: function () {
  1200. // assumes direction vectors vFrom and vTo are normalized
  1201. var v1 = new Vector3();
  1202. var r;
  1203. var EPS = 0.000001;
  1204. return function setFromUnitVectors( vFrom, vTo ) {
  1205. if ( v1 === undefined ) v1 = new Vector3();
  1206. r = vFrom.dot( vTo ) + 1;
  1207. if ( r < EPS ) {
  1208. r = 0;
  1209. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  1210. v1.set( - vFrom.y, vFrom.x, 0 );
  1211. } else {
  1212. v1.set( 0, - vFrom.z, vFrom.y );
  1213. }
  1214. } else {
  1215. v1.crossVectors( vFrom, vTo );
  1216. }
  1217. this._x = v1.x;
  1218. this._y = v1.y;
  1219. this._z = v1.z;
  1220. this._w = r;
  1221. return this.normalize();
  1222. };
  1223. }(),
  1224. inverse: function () {
  1225. return this.conjugate().normalize();
  1226. },
  1227. conjugate: function () {
  1228. this._x *= - 1;
  1229. this._y *= - 1;
  1230. this._z *= - 1;
  1231. this.onChangeCallback();
  1232. return this;
  1233. },
  1234. dot: function ( v ) {
  1235. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  1236. },
  1237. lengthSq: function () {
  1238. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  1239. },
  1240. length: function () {
  1241. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  1242. },
  1243. normalize: function () {
  1244. var l = this.length();
  1245. if ( l === 0 ) {
  1246. this._x = 0;
  1247. this._y = 0;
  1248. this._z = 0;
  1249. this._w = 1;
  1250. } else {
  1251. l = 1 / l;
  1252. this._x = this._x * l;
  1253. this._y = this._y * l;
  1254. this._z = this._z * l;
  1255. this._w = this._w * l;
  1256. }
  1257. this.onChangeCallback();
  1258. return this;
  1259. },
  1260. multiply: function ( q, p ) {
  1261. if ( p !== undefined ) {
  1262. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  1263. return this.multiplyQuaternions( q, p );
  1264. }
  1265. return this.multiplyQuaternions( this, q );
  1266. },
  1267. premultiply: function ( q ) {
  1268. return this.multiplyQuaternions( q, this );
  1269. },
  1270. multiplyQuaternions: function ( a, b ) {
  1271. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  1272. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  1273. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  1274. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  1275. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  1276. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  1277. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  1278. this.onChangeCallback();
  1279. return this;
  1280. },
  1281. slerp: function ( qb, t ) {
  1282. if ( t === 0 ) return this;
  1283. if ( t === 1 ) return this.copy( qb );
  1284. var x = this._x, y = this._y, z = this._z, w = this._w;
  1285. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  1286. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  1287. if ( cosHalfTheta < 0 ) {
  1288. this._w = - qb._w;
  1289. this._x = - qb._x;
  1290. this._y = - qb._y;
  1291. this._z = - qb._z;
  1292. cosHalfTheta = - cosHalfTheta;
  1293. } else {
  1294. this.copy( qb );
  1295. }
  1296. if ( cosHalfTheta >= 1.0 ) {
  1297. this._w = w;
  1298. this._x = x;
  1299. this._y = y;
  1300. this._z = z;
  1301. return this;
  1302. }
  1303. var sinHalfTheta = Math.sqrt( 1.0 - cosHalfTheta * cosHalfTheta );
  1304. if ( Math.abs( sinHalfTheta ) < 0.001 ) {
  1305. this._w = 0.5 * ( w + this._w );
  1306. this._x = 0.5 * ( x + this._x );
  1307. this._y = 0.5 * ( y + this._y );
  1308. this._z = 0.5 * ( z + this._z );
  1309. return this;
  1310. }
  1311. var halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );
  1312. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  1313. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  1314. this._w = ( w * ratioA + this._w * ratioB );
  1315. this._x = ( x * ratioA + this._x * ratioB );
  1316. this._y = ( y * ratioA + this._y * ratioB );
  1317. this._z = ( z * ratioA + this._z * ratioB );
  1318. this.onChangeCallback();
  1319. return this;
  1320. },
  1321. equals: function ( quaternion ) {
  1322. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  1323. },
  1324. fromArray: function ( array, offset ) {
  1325. if ( offset === undefined ) offset = 0;
  1326. this._x = array[ offset ];
  1327. this._y = array[ offset + 1 ];
  1328. this._z = array[ offset + 2 ];
  1329. this._w = array[ offset + 3 ];
  1330. this.onChangeCallback();
  1331. return this;
  1332. },
  1333. toArray: function ( array, offset ) {
  1334. if ( array === undefined ) array = [];
  1335. if ( offset === undefined ) offset = 0;
  1336. array[ offset ] = this._x;
  1337. array[ offset + 1 ] = this._y;
  1338. array[ offset + 2 ] = this._z;
  1339. array[ offset + 3 ] = this._w;
  1340. return array;
  1341. },
  1342. onChange: function ( callback ) {
  1343. this.onChangeCallback = callback;
  1344. return this;
  1345. },
  1346. onChangeCallback: function () {}
  1347. } );
  1348. function Vector3( x, y, z ) {
  1349. this.x = x || 0;
  1350. this.y = y || 0;
  1351. this.z = z || 0;
  1352. }
  1353. Object.assign( Vector3.prototype, {
  1354. isVector3: true,
  1355. set: function ( x, y, z ) {
  1356. this.x = x;
  1357. this.y = y;
  1358. this.z = z;
  1359. return this;
  1360. },
  1361. setScalar: function ( scalar ) {
  1362. this.x = scalar;
  1363. this.y = scalar;
  1364. this.z = scalar;
  1365. return this;
  1366. },
  1367. setX: function ( x ) {
  1368. this.x = x;
  1369. return this;
  1370. },
  1371. setY: function ( y ) {
  1372. this.y = y;
  1373. return this;
  1374. },
  1375. setZ: function ( z ) {
  1376. this.z = z;
  1377. return this;
  1378. },
  1379. setComponent: function ( index, value ) {
  1380. switch ( index ) {
  1381. case 0: this.x = value; break;
  1382. case 1: this.y = value; break;
  1383. case 2: this.z = value; break;
  1384. default: throw new Error( 'index is out of range: ' + index );
  1385. }
  1386. return this;
  1387. },
  1388. getComponent: function ( index ) {
  1389. switch ( index ) {
  1390. case 0: return this.x;
  1391. case 1: return this.y;
  1392. case 2: return this.z;
  1393. default: throw new Error( 'index is out of range: ' + index );
  1394. }
  1395. },
  1396. clone: function () {
  1397. return new this.constructor( this.x, this.y, this.z );
  1398. },
  1399. copy: function ( v ) {
  1400. this.x = v.x;
  1401. this.y = v.y;
  1402. this.z = v.z;
  1403. return this;
  1404. },
  1405. add: function ( v, w ) {
  1406. if ( w !== undefined ) {
  1407. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1408. return this.addVectors( v, w );
  1409. }
  1410. this.x += v.x;
  1411. this.y += v.y;
  1412. this.z += v.z;
  1413. return this;
  1414. },
  1415. addScalar: function ( s ) {
  1416. this.x += s;
  1417. this.y += s;
  1418. this.z += s;
  1419. return this;
  1420. },
  1421. addVectors: function ( a, b ) {
  1422. this.x = a.x + b.x;
  1423. this.y = a.y + b.y;
  1424. this.z = a.z + b.z;
  1425. return this;
  1426. },
  1427. addScaledVector: function ( v, s ) {
  1428. this.x += v.x * s;
  1429. this.y += v.y * s;
  1430. this.z += v.z * s;
  1431. return this;
  1432. },
  1433. sub: function ( v, w ) {
  1434. if ( w !== undefined ) {
  1435. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1436. return this.subVectors( v, w );
  1437. }
  1438. this.x -= v.x;
  1439. this.y -= v.y;
  1440. this.z -= v.z;
  1441. return this;
  1442. },
  1443. subScalar: function ( s ) {
  1444. this.x -= s;
  1445. this.y -= s;
  1446. this.z -= s;
  1447. return this;
  1448. },
  1449. subVectors: function ( a, b ) {
  1450. this.x = a.x - b.x;
  1451. this.y = a.y - b.y;
  1452. this.z = a.z - b.z;
  1453. return this;
  1454. },
  1455. multiply: function ( v, w ) {
  1456. if ( w !== undefined ) {
  1457. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  1458. return this.multiplyVectors( v, w );
  1459. }
  1460. this.x *= v.x;
  1461. this.y *= v.y;
  1462. this.z *= v.z;
  1463. return this;
  1464. },
  1465. multiplyScalar: function ( scalar ) {
  1466. this.x *= scalar;
  1467. this.y *= scalar;
  1468. this.z *= scalar;
  1469. return this;
  1470. },
  1471. multiplyVectors: function ( a, b ) {
  1472. this.x = a.x * b.x;
  1473. this.y = a.y * b.y;
  1474. this.z = a.z * b.z;
  1475. return this;
  1476. },
  1477. applyEuler: function () {
  1478. var quaternion = new Quaternion();
  1479. return function applyEuler( euler ) {
  1480. if ( ! ( euler && euler.isEuler ) ) {
  1481. console.error( 'THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1482. }
  1483. return this.applyQuaternion( quaternion.setFromEuler( euler ) );
  1484. };
  1485. }(),
  1486. applyAxisAngle: function () {
  1487. var quaternion = new Quaternion();
  1488. return function applyAxisAngle( axis, angle ) {
  1489. return this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
  1490. };
  1491. }(),
  1492. applyMatrix3: function ( m ) {
  1493. var x = this.x, y = this.y, z = this.z;
  1494. var e = m.elements;
  1495. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1496. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1497. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1498. return this;
  1499. },
  1500. applyMatrix4: function ( m ) {
  1501. var x = this.x, y = this.y, z = this.z;
  1502. var e = m.elements;
  1503. var w = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] );
  1504. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * w;
  1505. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * w;
  1506. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * w;
  1507. return this;
  1508. },
  1509. applyQuaternion: function ( q ) {
  1510. var x = this.x, y = this.y, z = this.z;
  1511. var qx = q.x, qy = q.y, qz = q.z, qw = q.w;
  1512. // calculate quat * vector
  1513. var ix = qw * x + qy * z - qz * y;
  1514. var iy = qw * y + qz * x - qx * z;
  1515. var iz = qw * z + qx * y - qy * x;
  1516. var iw = - qx * x - qy * y - qz * z;
  1517. // calculate result * inverse quat
  1518. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1519. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1520. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1521. return this;
  1522. },
  1523. project: function () {
  1524. var matrix = new Matrix4();
  1525. return function project( camera ) {
  1526. matrix.multiplyMatrices( camera.projectionMatrix, matrix.getInverse( camera.matrixWorld ) );
  1527. return this.applyMatrix4( matrix );
  1528. };
  1529. }(),
  1530. unproject: function () {
  1531. var matrix = new Matrix4();
  1532. return function unproject( camera ) {
  1533. matrix.multiplyMatrices( camera.matrixWorld, matrix.getInverse( camera.projectionMatrix ) );
  1534. return this.applyMatrix4( matrix );
  1535. };
  1536. }(),
  1537. transformDirection: function ( m ) {
  1538. // input: THREE.Matrix4 affine matrix
  1539. // vector interpreted as a direction
  1540. var x = this.x, y = this.y, z = this.z;
  1541. var e = m.elements;
  1542. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1543. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1544. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1545. return this.normalize();
  1546. },
  1547. divide: function ( v ) {
  1548. this.x /= v.x;
  1549. this.y /= v.y;
  1550. this.z /= v.z;
  1551. return this;
  1552. },
  1553. divideScalar: function ( scalar ) {
  1554. return this.multiplyScalar( 1 / scalar );
  1555. },
  1556. min: function ( v ) {
  1557. this.x = Math.min( this.x, v.x );
  1558. this.y = Math.min( this.y, v.y );
  1559. this.z = Math.min( this.z, v.z );
  1560. return this;
  1561. },
  1562. max: function ( v ) {
  1563. this.x = Math.max( this.x, v.x );
  1564. this.y = Math.max( this.y, v.y );
  1565. this.z = Math.max( this.z, v.z );
  1566. return this;
  1567. },
  1568. clamp: function ( min, max ) {
  1569. // assumes min < max, componentwise
  1570. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1571. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1572. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1573. return this;
  1574. },
  1575. clampScalar: function () {
  1576. var min = new Vector3();
  1577. var max = new Vector3();
  1578. return function clampScalar( minVal, maxVal ) {
  1579. min.set( minVal, minVal, minVal );
  1580. max.set( maxVal, maxVal, maxVal );
  1581. return this.clamp( min, max );
  1582. };
  1583. }(),
  1584. clampLength: function ( min, max ) {
  1585. var length = this.length();
  1586. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  1587. },
  1588. floor: function () {
  1589. this.x = Math.floor( this.x );
  1590. this.y = Math.floor( this.y );
  1591. this.z = Math.floor( this.z );
  1592. return this;
  1593. },
  1594. ceil: function () {
  1595. this.x = Math.ceil( this.x );
  1596. this.y = Math.ceil( this.y );
  1597. this.z = Math.ceil( this.z );
  1598. return this;
  1599. },
  1600. round: function () {
  1601. this.x = Math.round( this.x );
  1602. this.y = Math.round( this.y );
  1603. this.z = Math.round( this.z );
  1604. return this;
  1605. },
  1606. roundToZero: function () {
  1607. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1608. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1609. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1610. return this;
  1611. },
  1612. negate: function () {
  1613. this.x = - this.x;
  1614. this.y = - this.y;
  1615. this.z = - this.z;
  1616. return this;
  1617. },
  1618. dot: function ( v ) {
  1619. return this.x * v.x + this.y * v.y + this.z * v.z;
  1620. },
  1621. // TODO lengthSquared?
  1622. lengthSq: function () {
  1623. return this.x * this.x + this.y * this.y + this.z * this.z;
  1624. },
  1625. length: function () {
  1626. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1627. },
  1628. manhattanLength: function () {
  1629. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1630. },
  1631. normalize: function () {
  1632. return this.divideScalar( this.length() || 1 );
  1633. },
  1634. setLength: function ( length ) {
  1635. return this.normalize().multiplyScalar( length );
  1636. },
  1637. lerp: function ( v, alpha ) {
  1638. this.x += ( v.x - this.x ) * alpha;
  1639. this.y += ( v.y - this.y ) * alpha;
  1640. this.z += ( v.z - this.z ) * alpha;
  1641. return this;
  1642. },
  1643. lerpVectors: function ( v1, v2, alpha ) {
  1644. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1645. },
  1646. cross: function ( v, w ) {
  1647. if ( w !== undefined ) {
  1648. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  1649. return this.crossVectors( v, w );
  1650. }
  1651. return this.crossVectors( this, v );
  1652. },
  1653. crossVectors: function ( a, b ) {
  1654. var ax = a.x, ay = a.y, az = a.z;
  1655. var bx = b.x, by = b.y, bz = b.z;
  1656. this.x = ay * bz - az * by;
  1657. this.y = az * bx - ax * bz;
  1658. this.z = ax * by - ay * bx;
  1659. return this;
  1660. },
  1661. projectOnVector: function ( vector ) {
  1662. var scalar = vector.dot( this ) / vector.lengthSq();
  1663. return this.copy( vector ).multiplyScalar( scalar );
  1664. },
  1665. projectOnPlane: function () {
  1666. var v1 = new Vector3();
  1667. return function projectOnPlane( planeNormal ) {
  1668. v1.copy( this ).projectOnVector( planeNormal );
  1669. return this.sub( v1 );
  1670. };
  1671. }(),
  1672. reflect: function () {
  1673. // reflect incident vector off plane orthogonal to normal
  1674. // normal is assumed to have unit length
  1675. var v1 = new Vector3();
  1676. return function reflect( normal ) {
  1677. return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1678. };
  1679. }(),
  1680. angleTo: function ( v ) {
  1681. var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) );
  1682. // clamp, to handle numerical problems
  1683. return Math.acos( _Math.clamp( theta, - 1, 1 ) );
  1684. },
  1685. distanceTo: function ( v ) {
  1686. return Math.sqrt( this.distanceToSquared( v ) );
  1687. },
  1688. distanceToSquared: function ( v ) {
  1689. var dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
  1690. return dx * dx + dy * dy + dz * dz;
  1691. },
  1692. manhattanDistanceTo: function ( v ) {
  1693. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y ) + Math.abs( this.z - v.z );
  1694. },
  1695. setFromSpherical: function ( s ) {
  1696. var sinPhiRadius = Math.sin( s.phi ) * s.radius;
  1697. this.x = sinPhiRadius * Math.sin( s.theta );
  1698. this.y = Math.cos( s.phi ) * s.radius;
  1699. this.z = sinPhiRadius * Math.cos( s.theta );
  1700. return this;
  1701. },
  1702. setFromCylindrical: function ( c ) {
  1703. this.x = c.radius * Math.sin( c.theta );
  1704. this.y = c.y;
  1705. this.z = c.radius * Math.cos( c.theta );
  1706. return this;
  1707. },
  1708. setFromMatrixPosition: function ( m ) {
  1709. var e = m.elements;
  1710. this.x = e[ 12 ];
  1711. this.y = e[ 13 ];
  1712. this.z = e[ 14 ];
  1713. return this;
  1714. },
  1715. setFromMatrixScale: function ( m ) {
  1716. var sx = this.setFromMatrixColumn( m, 0 ).length();
  1717. var sy = this.setFromMatrixColumn( m, 1 ).length();
  1718. var sz = this.setFromMatrixColumn( m, 2 ).length();
  1719. this.x = sx;
  1720. this.y = sy;
  1721. this.z = sz;
  1722. return this;
  1723. },
  1724. setFromMatrixColumn: function ( m, index ) {
  1725. return this.fromArray( m.elements, index * 4 );
  1726. },
  1727. equals: function ( v ) {
  1728. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1729. },
  1730. fromArray: function ( array, offset ) {
  1731. if ( offset === undefined ) offset = 0;
  1732. this.x = array[ offset ];
  1733. this.y = array[ offset + 1 ];
  1734. this.z = array[ offset + 2 ];
  1735. return this;
  1736. },
  1737. toArray: function ( array, offset ) {
  1738. if ( array === undefined ) array = [];
  1739. if ( offset === undefined ) offset = 0;
  1740. array[ offset ] = this.x;
  1741. array[ offset + 1 ] = this.y;
  1742. array[ offset + 2 ] = this.z;
  1743. return array;
  1744. },
  1745. fromBufferAttribute: function ( attribute, index, offset ) {
  1746. if ( offset !== undefined ) {
  1747. console.warn( 'THREE.Vector3: offset has been removed from .fromBufferAttribute().' );
  1748. }
  1749. this.x = attribute.getX( index );
  1750. this.y = attribute.getY( index );
  1751. this.z = attribute.getZ( index );
  1752. return this;
  1753. }
  1754. } );
  1755. /**
  1756. * @author TristanVALCKE / https://github.com/Itee
  1757. */
  1758. /* global QUnit */
  1759. QUnit.module.todo( 'Polyfills', () => {
  1760. // PUBLIC STUFF
  1761. QUnit.test( "Number.EPSILON", ( assert ) => {
  1762. assert.ok( false, "everything's gonna be alright" );
  1763. } );
  1764. QUnit.test( "Number.isInteger", ( assert ) => {
  1765. assert.ok( false, "everything's gonna be alright" );
  1766. } );
  1767. //https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  1768. //http://people.mozilla.org/~jorendorff/es6-draft.html#sec-math.sign
  1769. /*
  1770. 20.2.2.29 Math.sign(x)
  1771. Returns the sign of the x, indicating whether x is positive, negative or zero.
  1772. If x is NaN, the result is NaN.
  1773. If x is -0, the result is -0.
  1774. If x is +0, the result is +0.
  1775. If x is negative and not -0, the result is -1.
  1776. If x is positive and not +0, the result is +1.
  1777. */
  1778. QUnit.test( "Math.sign", ( assert ) => {
  1779. assert.ok( isNaN( Math.sign( NaN ) ), "If x is NaN<NaN>, the result is NaN." );
  1780. assert.ok( isNaN( Math.sign( new Vector3() ) ), "If x is NaN<object>, the result is NaN." );
  1781. assert.ok( isNaN( Math.sign() ), "If x is NaN<undefined>, the result is NaN." );
  1782. assert.ok( isNaN( Math.sign( '--3' ) ), "If x is NaN<'--3'>, the result is NaN." );
  1783. assert.ok( isNegativeZero( Math.sign( - 0 ) ), "If x is -0, the result is -0." );
  1784. assert.ok( Math.sign( + 0 ) === + 0, "If x is +0, the result is +0." );
  1785. assert.ok( Math.sign( - Infinity ) === - 1, "If x is negative<-Infinity> and not -0, the result is -1." );
  1786. assert.ok( Math.sign( '-3' ) === - 1, "If x is negative<'-3'> and not -0, the result is -1." );
  1787. assert.ok( Math.sign( '-1e-10' ) === - 1, "If x is negative<'-1e-10'> and not -0, the result is -1." );
  1788. assert.ok( Math.sign( + Infinity ) === + 1, "If x is positive<+Infinity> and not +0, the result is +1." );
  1789. assert.ok( Math.sign( '+3' ) === + 1, "If x is positive<'+3'> and not +0, the result is +1." );
  1790. // Comparing with -0 is tricky because 0 === -0. But
  1791. // luckily 1 / -0 === -Infinity so we can use that.
  1792. function isNegativeZero( value ) {
  1793. return value === 0 && 1 / value < 0;
  1794. }
  1795. } );
  1796. QUnit.test( "'name' in Function.prototype", ( assert ) => {
  1797. assert.ok( false, "everything's gonna be alright" );
  1798. } );
  1799. QUnit.test( "Object.assign", ( assert ) => {
  1800. assert.ok( false, "everything's gonna be alright" );
  1801. } );
  1802. } );
  1803. /**
  1804. * @author mrdoob / http://mrdoob.com/
  1805. */
  1806. function arrayMin( array ) {
  1807. if ( array.length === 0 ) return Infinity;
  1808. var min = array[ 0 ];
  1809. for ( var i = 1, l = array.length; i < l; ++ i ) {
  1810. if ( array[ i ] < min ) min = array[ i ];
  1811. }
  1812. return min;
  1813. }
  1814. function arrayMax( array ) {
  1815. if ( array.length === 0 ) return - Infinity;
  1816. var max = array[ 0 ];
  1817. for ( var i = 1, l = array.length; i < l; ++ i ) {
  1818. if ( array[ i ] > max ) max = array[ i ];
  1819. }
  1820. return max;
  1821. }
  1822. /**
  1823. * @author alemures / https://github.com/alemures
  1824. * @author TristanVALCKE / https://github.com/Itee
  1825. */
  1826. /* global QUnit */
  1827. QUnit.module( 'utils', () => {
  1828. QUnit.test( 'arrayMin', ( assert ) => {
  1829. assert.equal( arrayMin( [] ), Infinity, 'Empty array return positive infinit' );
  1830. assert.equal( arrayMin( [ 5 ] ), 5, 'Single valued array should return the unique value as minimum' );
  1831. assert.equal( arrayMin( [ 1, 5, 10 ] ), 1, 'The array [ 1, 5, 10 ] return 1' );
  1832. assert.equal( arrayMin( [ 5, 1, 10 ] ), 1, 'The array [ 5, 1, 10 ] return 1' );
  1833. assert.equal( arrayMin( [ 10, 5, 1 ] ), 1, 'The array [ 10, 5, 1 ] return 1' );
  1834. assert.equal( arrayMax( [ - 0, 0 ] ), - 0, 'The array [ - 0, 0 ] return -0' );
  1835. assert.equal( arrayMin( [ - Infinity, 0, Infinity ] ), - Infinity, 'The array [ - Infinity, 0, Infinity ] return -Infinity' );
  1836. } );
  1837. QUnit.test( 'arrayMax', ( assert ) => {
  1838. assert.equal( arrayMax( [] ), - Infinity, 'Empty array return negative infinit' );
  1839. assert.equal( arrayMax( [ 5 ] ), 5, 'Single valued array should return the unique value as maximum' );
  1840. assert.equal( arrayMax( [ 10, 5, 1 ] ), 10, 'The array [ 10, 5, 1 ] return 10' );
  1841. assert.equal( arrayMax( [ 1, 10, 5 ] ), 10, 'The array [ 1, 10, 5 ] return 10' );
  1842. assert.equal( arrayMax( [ 1, 5, 10 ] ), 10, 'The array [ 1, 5, 10 ] return 10' );
  1843. assert.equal( arrayMax( [ - 0, 0 ] ), 0, 'The array [ - 0, 0 ] return 0' );
  1844. assert.equal( arrayMax( [ - Infinity, 0, Infinity ] ), Infinity, 'The array [ - Infinity, 0, Infinity ] return Infinity' );
  1845. } );
  1846. } );
  1847. function AnimationAction( mixer, clip, localRoot ) {
  1848. this._mixer = mixer;
  1849. this._clip = clip;
  1850. this._localRoot = localRoot || null;
  1851. var tracks = clip.tracks,
  1852. nTracks = tracks.length,
  1853. interpolants = new Array( nTracks );
  1854. var interpolantSettings = {
  1855. endingStart: ZeroCurvatureEnding,
  1856. endingEnd: ZeroCurvatureEnding
  1857. };
  1858. for ( var i = 0; i !== nTracks; ++ i ) {
  1859. var interpolant = tracks[ i ].createInterpolant( null );
  1860. interpolants[ i ] = interpolant;
  1861. interpolant.settings = interpolantSettings;
  1862. }
  1863. this._interpolantSettings = interpolantSettings;
  1864. this._interpolants = interpolants; // bound by the mixer
  1865. // inside: PropertyMixer (managed by the mixer)
  1866. this._propertyBindings = new Array( nTracks );
  1867. this._cacheIndex = null; // for the memory manager
  1868. this._byClipCacheIndex = null; // for the memory manager
  1869. this._timeScaleInterpolant = null;
  1870. this._weightInterpolant = null;
  1871. this.loop = LoopRepeat;
  1872. this._loopCount = - 1;
  1873. // global mixer time when the action is to be started
  1874. // it's set back to 'null' upon start of the action
  1875. this._startTime = null;
  1876. // scaled local time of the action
  1877. // gets clamped or wrapped to 0..clip.duration according to loop
  1878. this.time = 0;
  1879. this.timeScale = 1;
  1880. this._effectiveTimeScale = 1;
  1881. this.weight = 1;
  1882. this._effectiveWeight = 1;
  1883. this.repetitions = Infinity; // no. of repetitions when looping
  1884. this.paused = false; // true -> zero effective time scale
  1885. this.enabled = true; // false -> zero effective weight
  1886. this.clampWhenFinished = false; // keep feeding the last frame?
  1887. this.zeroSlopeAtStart = true; // for smooth interpolation w/o separate
  1888. this.zeroSlopeAtEnd = true; // clips for start, loop and end
  1889. }
  1890. Object.assign( AnimationAction.prototype, {
  1891. // State & Scheduling
  1892. play: function () {
  1893. this._mixer._activateAction( this );
  1894. return this;
  1895. },
  1896. stop: function () {
  1897. this._mixer._deactivateAction( this );
  1898. return this.reset();
  1899. },
  1900. reset: function () {
  1901. this.paused = false;
  1902. this.enabled = true;
  1903. this.time = 0; // restart clip
  1904. this._loopCount = - 1; // forget previous loops
  1905. this._startTime = null; // forget scheduling
  1906. return this.stopFading().stopWarping();
  1907. },
  1908. isRunning: function () {
  1909. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  1910. this._startTime === null && this._mixer._isActiveAction( this );
  1911. },
  1912. // return true when play has been called
  1913. isScheduled: function () {
  1914. return this._mixer._isActiveAction( this );
  1915. },
  1916. startAt: function ( time ) {
  1917. this._startTime = time;
  1918. return this;
  1919. },
  1920. setLoop: function ( mode, repetitions ) {
  1921. this.loop = mode;
  1922. this.repetitions = repetitions;
  1923. return this;
  1924. },
  1925. // Weight
  1926. // set the weight stopping any scheduled fading
  1927. // although .enabled = false yields an effective weight of zero, this
  1928. // method does *not* change .enabled, because it would be confusing
  1929. setEffectiveWeight: function ( weight ) {
  1930. this.weight = weight;
  1931. // note: same logic as when updated at runtime
  1932. this._effectiveWeight = this.enabled ? weight : 0;
  1933. return this.stopFading();
  1934. },
  1935. // return the weight considering fading and .enabled
  1936. getEffectiveWeight: function () {
  1937. return this._effectiveWeight;
  1938. },
  1939. fadeIn: function ( duration ) {
  1940. return this._scheduleFading( duration, 0, 1 );
  1941. },
  1942. fadeOut: function ( duration ) {
  1943. return this._scheduleFading( duration, 1, 0 );
  1944. },
  1945. crossFadeFrom: function ( fadeOutAction, duration, warp ) {
  1946. fadeOutAction.fadeOut( duration );
  1947. this.fadeIn( duration );
  1948. if ( warp ) {
  1949. var fadeInDuration = this._clip.duration,
  1950. fadeOutDuration = fadeOutAction._clip.duration,
  1951. startEndRatio = fadeOutDuration / fadeInDuration,
  1952. endStartRatio = fadeInDuration / fadeOutDuration;
  1953. fadeOutAction.warp( 1.0, startEndRatio, duration );
  1954. this.warp( endStartRatio, 1.0, duration );
  1955. }
  1956. return this;
  1957. },
  1958. crossFadeTo: function ( fadeInAction, duration, warp ) {
  1959. return fadeInAction.crossFadeFrom( this, duration, warp );
  1960. },
  1961. stopFading: function () {
  1962. var weightInterpolant = this._weightInterpolant;
  1963. if ( weightInterpolant !== null ) {
  1964. this._weightInterpolant = null;
  1965. this._mixer._takeBackControlInterpolant( weightInterpolant );
  1966. }
  1967. return this;
  1968. },
  1969. // Time Scale Control
  1970. // set the time scale stopping any scheduled warping
  1971. // although .paused = true yields an effective time scale of zero, this
  1972. // method does *not* change .paused, because it would be confusing
  1973. setEffectiveTimeScale: function ( timeScale ) {
  1974. this.timeScale = timeScale;
  1975. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  1976. return this.stopWarping();
  1977. },
  1978. // return the time scale considering warping and .paused
  1979. getEffectiveTimeScale: function () {
  1980. return this._effectiveTimeScale;
  1981. },
  1982. setDuration: function ( duration ) {
  1983. this.timeScale = this._clip.duration / duration;
  1984. return this.stopWarping();
  1985. },
  1986. syncWith: function ( action ) {
  1987. this.time = action.time;
  1988. this.timeScale = action.timeScale;
  1989. return this.stopWarping();
  1990. },
  1991. halt: function ( duration ) {
  1992. return this.warp( this._effectiveTimeScale, 0, duration );
  1993. },
  1994. warp: function ( startTimeScale, endTimeScale, duration ) {
  1995. var mixer = this._mixer, now = mixer.time,
  1996. interpolant = this._timeScaleInterpolant,
  1997. timeScale = this.timeScale;
  1998. if ( interpolant === null ) {
  1999. interpolant = mixer._lendControlInterpolant();
  2000. this._timeScaleInterpolant = interpolant;
  2001. }
  2002. var times = interpolant.parameterPositions,
  2003. values = interpolant.sampleValues;
  2004. times[ 0 ] = now;
  2005. times[ 1 ] = now + duration;
  2006. values[ 0 ] = startTimeScale / timeScale;
  2007. values[ 1 ] = endTimeScale / timeScale;
  2008. return this;
  2009. },
  2010. stopWarping: function () {
  2011. var timeScaleInterpolant = this._timeScaleInterpolant;
  2012. if ( timeScaleInterpolant !== null ) {
  2013. this._timeScaleInterpolant = null;
  2014. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  2015. }
  2016. return this;
  2017. },
  2018. // Object Accessors
  2019. getMixer: function () {
  2020. return this._mixer;
  2021. },
  2022. getClip: function () {
  2023. return this._clip;
  2024. },
  2025. getRoot: function () {
  2026. return this._localRoot || this._mixer._root;
  2027. },
  2028. // Interna
  2029. _update: function ( time, deltaTime, timeDirection, accuIndex ) {
  2030. // called by the mixer
  2031. if ( ! this.enabled ) {
  2032. // call ._updateWeight() to update ._effectiveWeight
  2033. this._updateWeight( time );
  2034. return;
  2035. }
  2036. var startTime = this._startTime;
  2037. if ( startTime !== null ) {
  2038. // check for scheduled start of action
  2039. var timeRunning = ( time - startTime ) * timeDirection;
  2040. if ( timeRunning < 0 || timeDirection === 0 ) {
  2041. return; // yet to come / don't decide when delta = 0
  2042. }
  2043. // start
  2044. this._startTime = null; // unschedule
  2045. deltaTime = timeDirection * timeRunning;
  2046. }
  2047. // apply time scale and advance time
  2048. deltaTime *= this._updateTimeScale( time );
  2049. var clipTime = this._updateTime( deltaTime );
  2050. // note: _updateTime may disable the action resulting in
  2051. // an effective weight of 0
  2052. var weight = this._updateWeight( time );
  2053. if ( weight > 0 ) {
  2054. var interpolants = this._interpolants;
  2055. var propertyMixers = this._propertyBindings;
  2056. for ( var j = 0, m = interpolants.length; j !== m; ++ j ) {
  2057. interpolants[ j ].evaluate( clipTime );
  2058. propertyMixers[ j ].accumulate( accuIndex, weight );
  2059. }
  2060. }
  2061. },
  2062. _updateWeight: function ( time ) {
  2063. var weight = 0;
  2064. if ( this.enabled ) {
  2065. weight = this.weight;
  2066. var interpolant = this._weightInterpolant;
  2067. if ( interpolant !== null ) {
  2068. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  2069. weight *= interpolantValue;
  2070. if ( time > interpolant.parameterPositions[ 1 ] ) {
  2071. this.stopFading();
  2072. if ( interpolantValue === 0 ) {
  2073. // faded out, disable
  2074. this.enabled = false;
  2075. }
  2076. }
  2077. }
  2078. }
  2079. this._effectiveWeight = weight;
  2080. return weight;
  2081. },
  2082. _updateTimeScale: function ( time ) {
  2083. var timeScale = 0;
  2084. if ( ! this.paused ) {
  2085. timeScale = this.timeScale;
  2086. var interpolant = this._timeScaleInterpolant;
  2087. if ( interpolant !== null ) {
  2088. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  2089. timeScale *= interpolantValue;
  2090. if ( time > interpolant.parameterPositions[ 1 ] ) {
  2091. this.stopWarping();
  2092. if ( timeScale === 0 ) {
  2093. // motion has halted, pause
  2094. this.paused = true;
  2095. } else {
  2096. // warp done - apply final time scale
  2097. this.timeScale = timeScale;
  2098. }
  2099. }
  2100. }
  2101. }
  2102. this._effectiveTimeScale = timeScale;
  2103. return timeScale;
  2104. },
  2105. _updateTime: function ( deltaTime ) {
  2106. var time = this.time + deltaTime;
  2107. if ( deltaTime === 0 ) return time;
  2108. var duration = this._clip.duration,
  2109. loop = this.loop,
  2110. loopCount = this._loopCount;
  2111. if ( loop === LoopOnce ) {
  2112. if ( loopCount === - 1 ) {
  2113. // just started
  2114. this._loopCount = 0;
  2115. this._setEndings( true, true, false );
  2116. }
  2117. handle_stop: {
  2118. if ( time >= duration ) {
  2119. time = duration;
  2120. } else if ( time < 0 ) {
  2121. time = 0;
  2122. } else break handle_stop;
  2123. if ( this.clampWhenFinished ) this.paused = true;
  2124. else this.enabled = false;
  2125. this._mixer.dispatchEvent( {
  2126. type: 'finished', action: this,
  2127. direction: deltaTime < 0 ? - 1 : 1
  2128. } );
  2129. }
  2130. } else { // repetitive Repeat or PingPong
  2131. var pingPong = ( loop === LoopPingPong );
  2132. if ( loopCount === - 1 ) {
  2133. // just started
  2134. if ( deltaTime >= 0 ) {
  2135. loopCount = 0;
  2136. this._setEndings( true, this.repetitions === 0, pingPong );
  2137. } else {
  2138. // when looping in reverse direction, the initial
  2139. // transition through zero counts as a repetition,
  2140. // so leave loopCount at -1
  2141. this._setEndings( this.repetitions === 0, true, pingPong );
  2142. }
  2143. }
  2144. if ( time >= duration || time < 0 ) {
  2145. // wrap around
  2146. var loopDelta = Math.floor( time / duration ); // signed
  2147. time -= duration * loopDelta;
  2148. loopCount += Math.abs( loopDelta );
  2149. var pending = this.repetitions - loopCount;
  2150. if ( pending < 0 ) {
  2151. // have to stop (switch state, clamp time, fire event)
  2152. if ( this.clampWhenFinished ) this.paused = true;
  2153. else this.enabled = false;
  2154. time = deltaTime > 0 ? duration : 0;
  2155. this._mixer.dispatchEvent( {
  2156. type: 'finished', action: this,
  2157. direction: deltaTime > 0 ? 1 : - 1
  2158. } );
  2159. } else {
  2160. // keep running
  2161. if ( pending === 0 ) {
  2162. // entering the last round
  2163. var atStart = deltaTime < 0;
  2164. this._setEndings( atStart, ! atStart, pingPong );
  2165. } else {
  2166. this._setEndings( false, false, pingPong );
  2167. }
  2168. this._loopCount = loopCount;
  2169. this._mixer.dispatchEvent( {
  2170. type: 'loop', action: this, loopDelta: loopDelta
  2171. } );
  2172. }
  2173. }
  2174. if ( pingPong && ( loopCount & 1 ) === 1 ) {
  2175. // invert time for the "pong round"
  2176. this.time = time;
  2177. return duration - time;
  2178. }
  2179. }
  2180. this.time = time;
  2181. return time;
  2182. },
  2183. _setEndings: function ( atStart, atEnd, pingPong ) {
  2184. var settings = this._interpolantSettings;
  2185. if ( pingPong ) {
  2186. settings.endingStart = ZeroSlopeEnding;
  2187. settings.endingEnd = ZeroSlopeEnding;
  2188. } else {
  2189. // assuming for LoopOnce atStart == atEnd == true
  2190. if ( atStart ) {
  2191. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  2192. } else {
  2193. settings.endingStart = WrapAroundEnding;
  2194. }
  2195. if ( atEnd ) {
  2196. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  2197. } else {
  2198. settings.endingEnd = WrapAroundEnding;
  2199. }
  2200. }
  2201. },
  2202. _scheduleFading: function ( duration, weightNow, weightThen ) {
  2203. var mixer = this._mixer, now = mixer.time,
  2204. interpolant = this._weightInterpolant;
  2205. if ( interpolant === null ) {
  2206. interpolant = mixer._lendControlInterpolant();
  2207. this._weightInterpolant = interpolant;
  2208. }
  2209. var times = interpolant.parameterPositions,
  2210. values = interpolant.sampleValues;
  2211. times[ 0 ] = now; values[ 0 ] = weightNow;
  2212. times[ 1 ] = now + duration; values[ 1 ] = weightThen;
  2213. return this;
  2214. }
  2215. } );
  2216. /**
  2217. * https://github.com/mrdoob/eventdispatcher.js/
  2218. */
  2219. function EventDispatcher() {}
  2220. Object.assign( EventDispatcher.prototype, {
  2221. addEventListener: function ( type, listener ) {
  2222. if ( this._listeners === undefined ) this._listeners = {};
  2223. var listeners = this._listeners;
  2224. if ( listeners[ type ] === undefined ) {
  2225. listeners[ type ] = [];
  2226. }
  2227. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  2228. listeners[ type ].push( listener );
  2229. }
  2230. },
  2231. hasEventListener: function ( type, listener ) {
  2232. if ( this._listeners === undefined ) return false;
  2233. var listeners = this._listeners;
  2234. return listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1;
  2235. },
  2236. removeEventListener: function ( type, listener ) {
  2237. if ( this._listeners === undefined ) return;
  2238. var listeners = this._listeners;
  2239. var listenerArray = listeners[ type ];
  2240. if ( listenerArray !== undefined ) {
  2241. var index = listenerArray.indexOf( listener );
  2242. if ( index !== - 1 ) {
  2243. listenerArray.splice( index, 1 );
  2244. }
  2245. }
  2246. },
  2247. dispatchEvent: function ( event ) {
  2248. if ( this._listeners === undefined ) return;
  2249. var listeners = this._listeners;
  2250. var listenerArray = listeners[ event.type ];
  2251. if ( listenerArray !== undefined ) {
  2252. event.target = this;
  2253. var array = listenerArray.slice( 0 );
  2254. for ( var i = 0, l = array.length; i < l; i ++ ) {
  2255. array[ i ].call( this, event );
  2256. }
  2257. }
  2258. }
  2259. } );
  2260. /**
  2261. * Abstract base class of interpolants over parametric samples.
  2262. *
  2263. * The parameter domain is one dimensional, typically the time or a path
  2264. * along a curve defined by the data.
  2265. *
  2266. * The sample values can have any dimensionality and derived classes may
  2267. * apply special interpretations to the data.
  2268. *
  2269. * This class provides the interval seek in a Template Method, deferring
  2270. * the actual interpolation to derived classes.
  2271. *
  2272. * Time complexity is O(1) for linear access crossing at most two points
  2273. * and O(log N) for random access, where N is the number of positions.
  2274. *
  2275. * References:
  2276. *
  2277. * http://www.oodesign.com/template-method-pattern.html
  2278. *
  2279. * @author tschw
  2280. */
  2281. function Interpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  2282. this.parameterPositions = parameterPositions;
  2283. this._cachedIndex = 0;
  2284. this.resultBuffer = resultBuffer !== undefined ?
  2285. resultBuffer : new sampleValues.constructor( sampleSize );
  2286. this.sampleValues = sampleValues;
  2287. this.valueSize = sampleSize;
  2288. }
  2289. Object.assign( Interpolant.prototype, {
  2290. evaluate: function ( t ) {
  2291. var pp = this.parameterPositions,
  2292. i1 = this._cachedIndex,
  2293. t1 = pp[ i1 ],
  2294. t0 = pp[ i1 - 1 ];
  2295. validate_interval: {
  2296. seek: {
  2297. var right;
  2298. linear_scan: {
  2299. //- See http://jsperf.com/comparison-to-undefined/3
  2300. //- slower code:
  2301. //-
  2302. //- if ( t >= t1 || t1 === undefined ) {
  2303. forward_scan: if ( ! ( t < t1 ) ) {
  2304. for ( var giveUpAt = i1 + 2; ; ) {
  2305. if ( t1 === undefined ) {
  2306. if ( t < t0 ) break forward_scan;
  2307. // after end
  2308. i1 = pp.length;
  2309. this._cachedIndex = i1;
  2310. return this.afterEnd_( i1 - 1, t, t0 );
  2311. }
  2312. if ( i1 === giveUpAt ) break; // this loop
  2313. t0 = t1;
  2314. t1 = pp[ ++ i1 ];
  2315. if ( t < t1 ) {
  2316. // we have arrived at the sought interval
  2317. break seek;
  2318. }
  2319. }
  2320. // prepare binary search on the right side of the index
  2321. right = pp.length;
  2322. break linear_scan;
  2323. }
  2324. //- slower code:
  2325. //- if ( t < t0 || t0 === undefined ) {
  2326. if ( ! ( t >= t0 ) ) {
  2327. // looping?
  2328. var t1global = pp[ 1 ];
  2329. if ( t < t1global ) {
  2330. i1 = 2; // + 1, using the scan for the details
  2331. t0 = t1global;
  2332. }
  2333. // linear reverse scan
  2334. for ( var giveUpAt = i1 - 2; ; ) {
  2335. if ( t0 === undefined ) {
  2336. // before start
  2337. this._cachedIndex = 0;
  2338. return this.beforeStart_( 0, t, t1 );
  2339. }
  2340. if ( i1 === giveUpAt ) break; // this loop
  2341. t1 = t0;
  2342. t0 = pp[ -- i1 - 1 ];
  2343. if ( t >= t0 ) {
  2344. // we have arrived at the sought interval
  2345. break seek;
  2346. }
  2347. }
  2348. // prepare binary search on the left side of the index
  2349. right = i1;
  2350. i1 = 0;
  2351. break linear_scan;
  2352. }
  2353. // the interval is valid
  2354. break validate_interval;
  2355. } // linear scan
  2356. // binary search
  2357. while ( i1 < right ) {
  2358. var mid = ( i1 + right ) >>> 1;
  2359. if ( t < pp[ mid ] ) {
  2360. right = mid;
  2361. } else {
  2362. i1 = mid + 1;
  2363. }
  2364. }
  2365. t1 = pp[ i1 ];
  2366. t0 = pp[ i1 - 1 ];
  2367. // check boundary cases, again
  2368. if ( t0 === undefined ) {
  2369. this._cachedIndex = 0;
  2370. return this.beforeStart_( 0, t, t1 );
  2371. }
  2372. if ( t1 === undefined ) {
  2373. i1 = pp.length;
  2374. this._cachedIndex = i1;
  2375. return this.afterEnd_( i1 - 1, t0, t );
  2376. }
  2377. } // seek
  2378. this._cachedIndex = i1;
  2379. this.intervalChanged_( i1, t0, t1 );
  2380. } // validate_interval
  2381. return this.interpolate_( i1, t0, t, t1 );
  2382. },
  2383. settings: null, // optional, subclass-specific settings structure
  2384. // Note: The indirection allows central control of many interpolants.
  2385. // --- Protected interface
  2386. DefaultSettings_: {},
  2387. getSettings_: function () {
  2388. return this.settings || this.DefaultSettings_;
  2389. },
  2390. copySampleValue_: function ( index ) {
  2391. // copies a sample value to the result buffer
  2392. var result = this.resultBuffer,
  2393. values = this.sampleValues,
  2394. stride = this.valueSize,
  2395. offset = index * stride;
  2396. for ( var i = 0; i !== stride; ++ i ) {
  2397. result[ i ] = values[ offset + i ];
  2398. }
  2399. return result;
  2400. },
  2401. // Template methods for derived classes:
  2402. interpolate_: function ( /* i1, t0, t, t1 */ ) {
  2403. throw new Error( 'call to abstract method' );
  2404. // implementations shall return this.resultBuffer
  2405. },
  2406. intervalChanged_: function ( /* i1, t0, t1 */ ) {
  2407. // empty
  2408. }
  2409. } );
  2410. //!\ DECLARE ALIAS AFTER assign prototype !
  2411. Object.assign( Interpolant.prototype, {
  2412. //( 0, t, t0 ), returns this.resultBuffer
  2413. beforeStart_: Interpolant.prototype.copySampleValue_,
  2414. //( N-1, tN-1, t ), returns this.resultBuffer
  2415. afterEnd_: Interpolant.prototype.copySampleValue_,
  2416. } );
  2417. function LinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  2418. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  2419. }
  2420. LinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  2421. constructor: LinearInterpolant,
  2422. interpolate_: function ( i1, t0, t, t1 ) {
  2423. var result = this.resultBuffer,
  2424. values = this.sampleValues,
  2425. stride = this.valueSize,
  2426. offset1 = i1 * stride,
  2427. offset0 = offset1 - stride,
  2428. weight1 = ( t - t0 ) / ( t1 - t0 ),
  2429. weight0 = 1 - weight1;
  2430. for ( var i = 0; i !== stride; ++ i ) {
  2431. result[ i ] =
  2432. values[ offset0 + i ] * weight0 +
  2433. values[ offset1 + i ] * weight1;
  2434. }
  2435. return result;
  2436. }
  2437. } );
  2438. /**
  2439. *
  2440. * A reference to a real property in the scene graph.
  2441. *
  2442. *
  2443. * @author Ben Houston / http://clara.io/
  2444. * @author David Sarno / http://lighthaus.us/
  2445. * @author tschw
  2446. */
  2447. function Composite( targetGroup, path, optionalParsedPath ) {
  2448. var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName( path );
  2449. this._targetGroup = targetGroup;
  2450. this._bindings = targetGroup.subscribe_( path, parsedPath );
  2451. }
  2452. Object.assign( Composite.prototype, {
  2453. getValue: function ( array, offset ) {
  2454. this.bind(); // bind all binding
  2455. var firstValidIndex = this._targetGroup.nCachedObjects_,
  2456. binding = this._bindings[ firstValidIndex ];
  2457. // and only call .getValue on the first
  2458. if ( binding !== undefined ) binding.getValue( array, offset );
  2459. },
  2460. setValue: function ( array, offset ) {
  2461. var bindings = this._bindings;
  2462. for ( var i = this._targetGroup.nCachedObjects_,
  2463. n = bindings.length; i !== n; ++ i ) {
  2464. bindings[ i ].setValue( array, offset );
  2465. }
  2466. },
  2467. bind: function () {
  2468. var bindings = this._bindings;
  2469. for ( var i = this._targetGroup.nCachedObjects_,
  2470. n = bindings.length; i !== n; ++ i ) {
  2471. bindings[ i ].bind();
  2472. }
  2473. },
  2474. unbind: function () {
  2475. var bindings = this._bindings;
  2476. for ( var i = this._targetGroup.nCachedObjects_,
  2477. n = bindings.length; i !== n; ++ i ) {
  2478. bindings[ i ].unbind();
  2479. }
  2480. }
  2481. } );
  2482. function PropertyBinding( rootNode, path, parsedPath ) {
  2483. this.path = path;
  2484. this.parsedPath = parsedPath || PropertyBinding.parseTrackName( path );
  2485. this.node = PropertyBinding.findNode( rootNode, this.parsedPath.nodeName ) || rootNode;
  2486. this.rootNode = rootNode;
  2487. }
  2488. Object.assign( PropertyBinding, {
  2489. Composite: Composite,
  2490. create: function ( root, path, parsedPath ) {
  2491. if ( ! ( root && root.isAnimationObjectGroup ) ) {
  2492. return new PropertyBinding( root, path, parsedPath );
  2493. } else {
  2494. return new PropertyBinding.Composite( root, path, parsedPath );
  2495. }
  2496. },
  2497. /**
  2498. * Replaces spaces with underscores and removes unsupported characters from
  2499. * node names, to ensure compatibility with parseTrackName().
  2500. *
  2501. * @param {string} name Node name to be sanitized.
  2502. * @return {string}
  2503. */
  2504. sanitizeNodeName: function ( name ) {
  2505. return name.replace( /\s/g, '_' ).replace( /[^\w-]/g, '' );
  2506. },
  2507. parseTrackName: function () {
  2508. // Parent directories, delimited by '/' or ':'. Currently unused, but must
  2509. // be matched to parse the rest of the track name.
  2510. var directoryRe = /((?:[\w-]+[\/:])*)/;
  2511. // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  2512. var nodeRe = /([\w-\.]+)?/;
  2513. // Object on target node, and accessor. Name may contain only word
  2514. // characters. Accessor may contain any character except closing bracket.
  2515. var objectRe = /(?:\.([\w-]+)(?:\[(.+)\])?)?/;
  2516. // Property and accessor. May contain only word characters. Accessor may
  2517. // contain any non-bracket characters.
  2518. var propertyRe = /\.([\w-]+)(?:\[(.+)\])?/;
  2519. var trackRe = new RegExp( ''
  2520. + '^'
  2521. + directoryRe.source
  2522. + nodeRe.source
  2523. + objectRe.source
  2524. + propertyRe.source
  2525. + '$'
  2526. );
  2527. var supportedObjectNames = [ 'material', 'materials', 'bones' ];
  2528. return function ( trackName ) {
  2529. var matches = trackRe.exec( trackName );
  2530. if ( ! matches ) {
  2531. throw new Error( 'PropertyBinding: Cannot parse trackName: ' + trackName );
  2532. }
  2533. var results = {
  2534. // directoryName: matches[ 1 ], // (tschw) currently unused
  2535. nodeName: matches[ 2 ],
  2536. objectName: matches[ 3 ],
  2537. objectIndex: matches[ 4 ],
  2538. propertyName: matches[ 5 ], // required
  2539. propertyIndex: matches[ 6 ]
  2540. };
  2541. var lastDot = results.nodeName && results.nodeName.lastIndexOf( '.' );
  2542. if ( lastDot !== undefined && lastDot !== - 1 ) {
  2543. var objectName = results.nodeName.substring( lastDot + 1 );
  2544. // Object names must be checked against a whitelist. Otherwise, there
  2545. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  2546. // 'bar' could be the objectName, or part of a nodeName (which can
  2547. // include '.' characters).
  2548. if ( supportedObjectNames.indexOf( objectName ) !== - 1 ) {
  2549. results.nodeName = results.nodeName.substring( 0, lastDot );
  2550. results.objectName = objectName;
  2551. }
  2552. }
  2553. if ( results.propertyName === null || results.propertyName.length === 0 ) {
  2554. throw new Error( 'PropertyBinding: can not parse propertyName from trackName: ' + trackName );
  2555. }
  2556. return results;
  2557. };
  2558. }(),
  2559. findNode: function ( root, nodeName ) {
  2560. if ( ! nodeName || nodeName === "" || nodeName === "root" || nodeName === "." || nodeName === - 1 || nodeName === root.name || nodeName === root.uuid ) {
  2561. return root;
  2562. }
  2563. // search into skeleton bones.
  2564. if ( root.skeleton ) {
  2565. var searchSkeleton = function ( skeleton ) {
  2566. for ( var i = 0; i < skeleton.bones.length; i ++ ) {
  2567. var bone = skeleton.bones[ i ];
  2568. if ( bone.name === nodeName ) {
  2569. return bone;
  2570. }
  2571. }
  2572. return null;
  2573. };
  2574. var bone = searchSkeleton( root.skeleton );
  2575. if ( bone ) {
  2576. return bone;
  2577. }
  2578. }
  2579. // search into node subtree.
  2580. if ( root.children ) {
  2581. var searchNodeSubtree = function ( children ) {
  2582. for ( var i = 0; i < children.length; i ++ ) {
  2583. var childNode = children[ i ];
  2584. if ( childNode.name === nodeName || childNode.uuid === nodeName ) {
  2585. return childNode;
  2586. }
  2587. var result = searchNodeSubtree( childNode.children );
  2588. if ( result ) return result;
  2589. }
  2590. return null;
  2591. };
  2592. var subTreeNode = searchNodeSubtree( root.children );
  2593. if ( subTreeNode ) {
  2594. return subTreeNode;
  2595. }
  2596. }
  2597. return null;
  2598. }
  2599. } );
  2600. Object.assign( PropertyBinding.prototype, { // prototype, continued
  2601. // these are used to "bind" a nonexistent property
  2602. _getValue_unavailable: function () {},
  2603. _setValue_unavailable: function () {},
  2604. BindingType: {
  2605. Direct: 0,
  2606. EntireArray: 1,
  2607. ArrayElement: 2,
  2608. HasFromToArray: 3
  2609. },
  2610. Versioning: {
  2611. None: 0,
  2612. NeedsUpdate: 1,
  2613. MatrixWorldNeedsUpdate: 2
  2614. },
  2615. GetterByBindingType: [
  2616. function getValue_direct( buffer, offset ) {
  2617. buffer[ offset ] = this.node[ this.propertyName ];
  2618. },
  2619. function getValue_array( buffer, offset ) {
  2620. var source = this.resolvedProperty;
  2621. for ( var i = 0, n = source.length; i !== n; ++ i ) {
  2622. buffer[ offset ++ ] = source[ i ];
  2623. }
  2624. },
  2625. function getValue_arrayElement( buffer, offset ) {
  2626. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  2627. },
  2628. function getValue_toArray( buffer, offset ) {
  2629. this.resolvedProperty.toArray( buffer, offset );
  2630. }
  2631. ],
  2632. SetterByBindingTypeAndVersioning: [
  2633. [
  2634. // Direct
  2635. function setValue_direct( buffer, offset ) {
  2636. this.targetObject[ this.propertyName ] = buffer[ offset ];
  2637. },
  2638. function setValue_direct_setNeedsUpdate( buffer, offset ) {
  2639. this.targetObject[ this.propertyName ] = buffer[ offset ];
  2640. this.targetObject.needsUpdate = true;
  2641. },
  2642. function setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  2643. this.targetObject[ this.propertyName ] = buffer[ offset ];
  2644. this.targetObject.matrixWorldNeedsUpdate = true;
  2645. }
  2646. ], [
  2647. // EntireArray
  2648. function setValue_array( buffer, offset ) {
  2649. var dest = this.resolvedProperty;
  2650. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  2651. dest[ i ] = buffer[ offset ++ ];
  2652. }
  2653. },
  2654. function setValue_array_setNeedsUpdate( buffer, offset ) {
  2655. var dest = this.resolvedProperty;
  2656. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  2657. dest[ i ] = buffer[ offset ++ ];
  2658. }
  2659. this.targetObject.needsUpdate = true;
  2660. },
  2661. function setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  2662. var dest = this.resolvedProperty;
  2663. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  2664. dest[ i ] = buffer[ offset ++ ];
  2665. }
  2666. this.targetObject.matrixWorldNeedsUpdate = true;
  2667. }
  2668. ], [
  2669. // ArrayElement
  2670. function setValue_arrayElement( buffer, offset ) {
  2671. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  2672. },
  2673. function setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  2674. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  2675. this.targetObject.needsUpdate = true;
  2676. },
  2677. function setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  2678. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  2679. this.targetObject.matrixWorldNeedsUpdate = true;
  2680. }
  2681. ], [
  2682. // HasToFromArray
  2683. function setValue_fromArray( buffer, offset ) {
  2684. this.resolvedProperty.fromArray( buffer, offset );
  2685. },
  2686. function setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  2687. this.resolvedProperty.fromArray( buffer, offset );
  2688. this.targetObject.needsUpdate = true;
  2689. },
  2690. function setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  2691. this.resolvedProperty.fromArray( buffer, offset );
  2692. this.targetObject.matrixWorldNeedsUpdate = true;
  2693. }
  2694. ]
  2695. ],
  2696. getValue: function getValue_unbound( targetArray, offset ) {
  2697. this.bind();
  2698. this.getValue( targetArray, offset );
  2699. // Note: This class uses a State pattern on a per-method basis:
  2700. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  2701. // prototype version of these methods with one that represents
  2702. // the bound state. When the property is not found, the methods
  2703. // become no-ops.
  2704. },
  2705. setValue: function getValue_unbound( sourceArray, offset ) {
  2706. this.bind();
  2707. this.setValue( sourceArray, offset );
  2708. },
  2709. // create getter / setter pair for a property in the scene graph
  2710. bind: function () {
  2711. var targetObject = this.node,
  2712. parsedPath = this.parsedPath,
  2713. objectName = parsedPath.objectName,
  2714. propertyName = parsedPath.propertyName,
  2715. propertyIndex = parsedPath.propertyIndex;
  2716. if ( ! targetObject ) {
  2717. targetObject = PropertyBinding.findNode( this.rootNode, parsedPath.nodeName ) || this.rootNode;
  2718. this.node = targetObject;
  2719. }
  2720. // set fail state so we can just 'return' on error
  2721. this.getValue = this._getValue_unavailable;
  2722. this.setValue = this._setValue_unavailable;
  2723. // ensure there is a value node
  2724. if ( ! targetObject ) {
  2725. console.error( 'THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.' );
  2726. return;
  2727. }
  2728. if ( objectName ) {
  2729. var objectIndex = parsedPath.objectIndex;
  2730. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  2731. switch ( objectName ) {
  2732. case 'materials':
  2733. if ( ! targetObject.material ) {
  2734. console.error( 'THREE.PropertyBinding: Can not bind to material as node does not have a material.', this );
  2735. return;
  2736. }
  2737. if ( ! targetObject.material.materials ) {
  2738. console.error( 'THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this );
  2739. return;
  2740. }
  2741. targetObject = targetObject.material.materials;
  2742. break;
  2743. case 'bones':
  2744. if ( ! targetObject.skeleton ) {
  2745. console.error( 'THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this );
  2746. return;
  2747. }
  2748. // potential future optimization: skip this if propertyIndex is already an integer
  2749. // and convert the integer string to a true integer.
  2750. targetObject = targetObject.skeleton.bones;
  2751. // support resolving morphTarget names into indices.
  2752. for ( var i = 0; i < targetObject.length; i ++ ) {
  2753. if ( targetObject[ i ].name === objectIndex ) {
  2754. objectIndex = i;
  2755. break;
  2756. }
  2757. }
  2758. break;
  2759. default:
  2760. if ( targetObject[ objectName ] === undefined ) {
  2761. console.error( 'THREE.PropertyBinding: Can not bind to objectName of node undefined.', this );
  2762. return;
  2763. }
  2764. targetObject = targetObject[ objectName ];
  2765. }
  2766. if ( objectIndex !== undefined ) {
  2767. if ( targetObject[ objectIndex ] === undefined ) {
  2768. console.error( 'THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject );
  2769. return;
  2770. }
  2771. targetObject = targetObject[ objectIndex ];
  2772. }
  2773. }
  2774. // resolve property
  2775. var nodeProperty = targetObject[ propertyName ];
  2776. if ( nodeProperty === undefined ) {
  2777. var nodeName = parsedPath.nodeName;
  2778. console.error( 'THREE.PropertyBinding: Trying to update property for track: ' + nodeName +
  2779. '.' + propertyName + ' but it wasn\'t found.', targetObject );
  2780. return;
  2781. }
  2782. // determine versioning scheme
  2783. var versioning = this.Versioning.None;
  2784. if ( targetObject.needsUpdate !== undefined ) { // material
  2785. versioning = this.Versioning.NeedsUpdate;
  2786. this.targetObject = targetObject;
  2787. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  2788. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  2789. this.targetObject = targetObject;
  2790. }
  2791. // determine how the property gets bound
  2792. var bindingType = this.BindingType.Direct;
  2793. if ( propertyIndex !== undefined ) {
  2794. // access a sub element of the property array (only primitives are supported right now)
  2795. if ( propertyName === "morphTargetInfluences" ) {
  2796. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  2797. // support resolving morphTarget names into indices.
  2798. if ( ! targetObject.geometry ) {
  2799. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this );
  2800. return;
  2801. }
  2802. if ( targetObject.geometry.isBufferGeometry ) {
  2803. if ( ! targetObject.geometry.morphAttributes ) {
  2804. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this );
  2805. return;
  2806. }
  2807. for ( var i = 0; i < this.node.geometry.morphAttributes.position.length; i ++ ) {
  2808. if ( targetObject.geometry.morphAttributes.position[ i ].name === propertyIndex ) {
  2809. propertyIndex = i;
  2810. break;
  2811. }
  2812. }
  2813. } else {
  2814. if ( ! targetObject.geometry.morphTargets ) {
  2815. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphTargets.', this );
  2816. return;
  2817. }
  2818. for ( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {
  2819. if ( targetObject.geometry.morphTargets[ i ].name === propertyIndex ) {
  2820. propertyIndex = i;
  2821. break;
  2822. }
  2823. }
  2824. }
  2825. }
  2826. bindingType = this.BindingType.ArrayElement;
  2827. this.resolvedProperty = nodeProperty;
  2828. this.propertyIndex = propertyIndex;
  2829. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  2830. // must use copy for Object3D.Euler/Quaternion
  2831. bindingType = this.BindingType.HasFromToArray;
  2832. this.resolvedProperty = nodeProperty;
  2833. } else if ( Array.isArray( nodeProperty ) ) {
  2834. bindingType = this.BindingType.EntireArray;
  2835. this.resolvedProperty = nodeProperty;
  2836. } else {
  2837. this.propertyName = propertyName;
  2838. }
  2839. // select getter / setter
  2840. this.getValue = this.GetterByBindingType[ bindingType ];
  2841. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  2842. },
  2843. unbind: function () {
  2844. this.node = null;
  2845. // back to the prototype version of getValue / setValue
  2846. // note: avoiding to mutate the shape of 'this' via 'delete'
  2847. this.getValue = this._getValue_unbound;
  2848. this.setValue = this._setValue_unbound;
  2849. }
  2850. } );
  2851. //!\ DECLARE ALIAS AFTER assign prototype !
  2852. Object.assign( PropertyBinding.prototype, {
  2853. // initial state of these methods that calls 'bind'
  2854. _getValue_unbound: PropertyBinding.prototype.getValue,
  2855. _setValue_unbound: PropertyBinding.prototype.setValue,
  2856. } );
  2857. function PropertyMixer( binding, typeName, valueSize ) {
  2858. this.binding = binding;
  2859. this.valueSize = valueSize;
  2860. var bufferType = Float64Array,
  2861. mixFunction;
  2862. switch ( typeName ) {
  2863. case 'quaternion':
  2864. mixFunction = this._slerp;
  2865. break;
  2866. case 'string':
  2867. case 'bool':
  2868. bufferType = Array;
  2869. mixFunction = this._select;
  2870. break;
  2871. default:
  2872. mixFunction = this._lerp;
  2873. }
  2874. this.buffer = new bufferType( valueSize * 4 );
  2875. // layout: [ incoming | accu0 | accu1 | orig ]
  2876. //
  2877. // interpolators can use .buffer as their .result
  2878. // the data then goes to 'incoming'
  2879. //
  2880. // 'accu0' and 'accu1' are used frame-interleaved for
  2881. // the cumulative result and are compared to detect
  2882. // changes
  2883. //
  2884. // 'orig' stores the original state of the property
  2885. this._mixBufferRegion = mixFunction;
  2886. this.cumulativeWeight = 0;
  2887. this.useCount = 0;
  2888. this.referenceCount = 0;
  2889. }
  2890. Object.assign( PropertyMixer.prototype, {
  2891. // accumulate data in the 'incoming' region into 'accu<i>'
  2892. accumulate: function ( accuIndex, weight ) {
  2893. // note: happily accumulating nothing when weight = 0, the caller knows
  2894. // the weight and shouldn't have made the call in the first place
  2895. var buffer = this.buffer,
  2896. stride = this.valueSize,
  2897. offset = accuIndex * stride + stride,
  2898. currentWeight = this.cumulativeWeight;
  2899. if ( currentWeight === 0 ) {
  2900. // accuN := incoming * weight
  2901. for ( var i = 0; i !== stride; ++ i ) {
  2902. buffer[ offset + i ] = buffer[ i ];
  2903. }
  2904. currentWeight = weight;
  2905. } else {
  2906. // accuN := accuN + incoming * weight
  2907. currentWeight += weight;
  2908. var mix = weight / currentWeight;
  2909. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  2910. }
  2911. this.cumulativeWeight = currentWeight;
  2912. },
  2913. // apply the state of 'accu<i>' to the binding when accus differ
  2914. apply: function ( accuIndex ) {
  2915. var stride = this.valueSize,
  2916. buffer = this.buffer,
  2917. offset = accuIndex * stride + stride,
  2918. weight = this.cumulativeWeight,
  2919. binding = this.binding;
  2920. this.cumulativeWeight = 0;
  2921. if ( weight < 1 ) {
  2922. // accuN := accuN + original * ( 1 - cumulativeWeight )
  2923. var originalValueOffset = stride * 3;
  2924. this._mixBufferRegion(
  2925. buffer, offset, originalValueOffset, 1 - weight, stride );
  2926. }
  2927. for ( var i = stride, e = stride + stride; i !== e; ++ i ) {
  2928. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  2929. // value has changed -> update scene graph
  2930. binding.setValue( buffer, offset );
  2931. break;
  2932. }
  2933. }
  2934. },
  2935. // remember the state of the bound property and copy it to both accus
  2936. saveOriginalState: function () {
  2937. var binding = this.binding;
  2938. var buffer = this.buffer,
  2939. stride = this.valueSize,
  2940. originalValueOffset = stride * 3;
  2941. binding.getValue( buffer, originalValueOffset );
  2942. // accu[0..1] := orig -- initially detect changes against the original
  2943. for ( var i = stride, e = originalValueOffset; i !== e; ++ i ) {
  2944. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  2945. }
  2946. this.cumulativeWeight = 0;
  2947. },
  2948. // apply the state previously taken via 'saveOriginalState' to the binding
  2949. restoreOriginalState: function () {
  2950. var originalValueOffset = this.valueSize * 3;
  2951. this.binding.setValue( this.buffer, originalValueOffset );
  2952. },
  2953. // mix functions
  2954. _select: function ( buffer, dstOffset, srcOffset, t, stride ) {
  2955. if ( t >= 0.5 ) {
  2956. for ( var i = 0; i !== stride; ++ i ) {
  2957. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  2958. }
  2959. }
  2960. },
  2961. _slerp: function ( buffer, dstOffset, srcOffset, t ) {
  2962. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t );
  2963. },
  2964. _lerp: function ( buffer, dstOffset, srcOffset, t, stride ) {
  2965. var s = 1 - t;
  2966. for ( var i = 0; i !== stride; ++ i ) {
  2967. var j = dstOffset + i;
  2968. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  2969. }
  2970. }
  2971. } );
  2972. /**
  2973. * @author tschw
  2974. * @author Ben Houston / http://clara.io/
  2975. * @author David Sarno / http://lighthaus.us/
  2976. */
  2977. var AnimationUtils = {
  2978. // same as Array.prototype.slice, but also works on typed arrays
  2979. arraySlice: function ( array, from, to ) {
  2980. if ( AnimationUtils.isTypedArray( array ) ) {
  2981. // in ios9 array.subarray(from, undefined) will return empty array
  2982. // but array.subarray(from) or array.subarray(from, len) is correct
  2983. return new array.constructor( array.subarray( from, to !== undefined ? to : array.length ) );
  2984. }
  2985. return array.slice( from, to );
  2986. },
  2987. // converts an array to a specific type
  2988. convertArray: function ( array, type, forceClone ) {
  2989. if ( ! array || // let 'undefined' and 'null' pass
  2990. ! forceClone && array.constructor === type ) return array;
  2991. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  2992. return new type( array ); // create typed array
  2993. }
  2994. return Array.prototype.slice.call( array ); // create Array
  2995. },
  2996. isTypedArray: function ( object ) {
  2997. return ArrayBuffer.isView( object ) &&
  2998. ! ( object instanceof DataView );
  2999. },
  3000. // returns an array by which times and values can be sorted
  3001. getKeyframeOrder: function ( times ) {
  3002. function compareTime( i, j ) {
  3003. return times[ i ] - times[ j ];
  3004. }
  3005. var n = times.length;
  3006. var result = new Array( n );
  3007. for ( var i = 0; i !== n; ++ i ) result[ i ] = i;
  3008. result.sort( compareTime );
  3009. return result;
  3010. },
  3011. // uses the array previously returned by 'getKeyframeOrder' to sort data
  3012. sortedArray: function ( values, stride, order ) {
  3013. var nValues = values.length;
  3014. var result = new values.constructor( nValues );
  3015. for ( var i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  3016. var srcOffset = order[ i ] * stride;
  3017. for ( var j = 0; j !== stride; ++ j ) {
  3018. result[ dstOffset ++ ] = values[ srcOffset + j ];
  3019. }
  3020. }
  3021. return result;
  3022. },
  3023. // function for parsing AOS keyframe formats
  3024. flattenJSON: function ( jsonKeys, times, values, valuePropertyName ) {
  3025. var i = 1, key = jsonKeys[ 0 ];
  3026. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  3027. key = jsonKeys[ i ++ ];
  3028. }
  3029. if ( key === undefined ) return; // no data
  3030. var value = key[ valuePropertyName ];
  3031. if ( value === undefined ) return; // no data
  3032. if ( Array.isArray( value ) ) {
  3033. do {
  3034. value = key[ valuePropertyName ];
  3035. if ( value !== undefined ) {
  3036. times.push( key.time );
  3037. values.push.apply( values, value ); // push all elements
  3038. }
  3039. key = jsonKeys[ i ++ ];
  3040. } while ( key !== undefined );
  3041. } else if ( value.toArray !== undefined ) {
  3042. // ...assume THREE.Math-ish
  3043. do {
  3044. value = key[ valuePropertyName ];
  3045. if ( value !== undefined ) {
  3046. times.push( key.time );
  3047. value.toArray( values, values.length );
  3048. }
  3049. key = jsonKeys[ i ++ ];
  3050. } while ( key !== undefined );
  3051. } else {
  3052. // otherwise push as-is
  3053. do {
  3054. value = key[ valuePropertyName ];
  3055. if ( value !== undefined ) {
  3056. times.push( key.time );
  3057. values.push( value );
  3058. }
  3059. key = jsonKeys[ i ++ ];
  3060. } while ( key !== undefined );
  3061. }
  3062. }
  3063. };
  3064. function CubicInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  3065. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  3066. this._weightPrev = - 0;
  3067. this._offsetPrev = - 0;
  3068. this._weightNext = - 0;
  3069. this._offsetNext = - 0;
  3070. }
  3071. CubicInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  3072. constructor: CubicInterpolant,
  3073. DefaultSettings_: {
  3074. endingStart: ZeroCurvatureEnding,
  3075. endingEnd: ZeroCurvatureEnding
  3076. },
  3077. intervalChanged_: function ( i1, t0, t1 ) {
  3078. var pp = this.parameterPositions,
  3079. iPrev = i1 - 2,
  3080. iNext = i1 + 1,
  3081. tPrev = pp[ iPrev ],
  3082. tNext = pp[ iNext ];
  3083. if ( tPrev === undefined ) {
  3084. switch ( this.getSettings_().endingStart ) {
  3085. case ZeroSlopeEnding:
  3086. // f'(t0) = 0
  3087. iPrev = i1;
  3088. tPrev = 2 * t0 - t1;
  3089. break;
  3090. case WrapAroundEnding:
  3091. // use the other end of the curve
  3092. iPrev = pp.length - 2;
  3093. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  3094. break;
  3095. default: // ZeroCurvatureEnding
  3096. // f''(t0) = 0 a.k.a. Natural Spline
  3097. iPrev = i1;
  3098. tPrev = t1;
  3099. }
  3100. }
  3101. if ( tNext === undefined ) {
  3102. switch ( this.getSettings_().endingEnd ) {
  3103. case ZeroSlopeEnding:
  3104. // f'(tN) = 0
  3105. iNext = i1;
  3106. tNext = 2 * t1 - t0;
  3107. break;
  3108. case WrapAroundEnding:
  3109. // use the other end of the curve
  3110. iNext = 1;
  3111. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  3112. break;
  3113. default: // ZeroCurvatureEnding
  3114. // f''(tN) = 0, a.k.a. Natural Spline
  3115. iNext = i1 - 1;
  3116. tNext = t0;
  3117. }
  3118. }
  3119. var halfDt = ( t1 - t0 ) * 0.5,
  3120. stride = this.valueSize;
  3121. this._weightPrev = halfDt / ( t0 - tPrev );
  3122. this._weightNext = halfDt / ( tNext - t1 );
  3123. this._offsetPrev = iPrev * stride;
  3124. this._offsetNext = iNext * stride;
  3125. },
  3126. interpolate_: function ( i1, t0, t, t1 ) {
  3127. var result = this.resultBuffer,
  3128. values = this.sampleValues,
  3129. stride = this.valueSize,
  3130. o1 = i1 * stride, o0 = o1 - stride,
  3131. oP = this._offsetPrev, oN = this._offsetNext,
  3132. wP = this._weightPrev, wN = this._weightNext,
  3133. p = ( t - t0 ) / ( t1 - t0 ),
  3134. pp = p * p,
  3135. ppp = pp * p;
  3136. // evaluate polynomials
  3137. var sP = - wP * ppp + 2 * wP * pp - wP * p;
  3138. var s0 = ( 1 + wP ) * ppp + ( - 1.5 - 2 * wP ) * pp + ( - 0.5 + wP ) * p + 1;
  3139. var s1 = ( - 1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  3140. var sN = wN * ppp - wN * pp;
  3141. // combine data linearly
  3142. for ( var i = 0; i !== stride; ++ i ) {
  3143. result[ i ] =
  3144. sP * values[ oP + i ] +
  3145. s0 * values[ o0 + i ] +
  3146. s1 * values[ o1 + i ] +
  3147. sN * values[ oN + i ];
  3148. }
  3149. return result;
  3150. }
  3151. } );
  3152. function DiscreteInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  3153. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  3154. }
  3155. DiscreteInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  3156. constructor: DiscreteInterpolant,
  3157. interpolate_: function ( i1 /*, t0, t, t1 */ ) {
  3158. return this.copySampleValue_( i1 - 1 );
  3159. }
  3160. } );
  3161. var KeyframeTrackPrototype;
  3162. KeyframeTrackPrototype = {
  3163. TimeBufferType: Float32Array,
  3164. ValueBufferType: Float32Array,
  3165. DefaultInterpolation: InterpolateLinear,
  3166. InterpolantFactoryMethodDiscrete: function ( result ) {
  3167. return new DiscreteInterpolant( this.times, this.values, this.getValueSize(), result );
  3168. },
  3169. InterpolantFactoryMethodLinear: function ( result ) {
  3170. return new LinearInterpolant( this.times, this.values, this.getValueSize(), result );
  3171. },
  3172. InterpolantFactoryMethodSmooth: function ( result ) {
  3173. return new CubicInterpolant( this.times, this.values, this.getValueSize(), result );
  3174. },
  3175. setInterpolation: function ( interpolation ) {
  3176. var factoryMethod;
  3177. switch ( interpolation ) {
  3178. case InterpolateDiscrete:
  3179. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  3180. break;
  3181. case InterpolateLinear:
  3182. factoryMethod = this.InterpolantFactoryMethodLinear;
  3183. break;
  3184. case InterpolateSmooth:
  3185. factoryMethod = this.InterpolantFactoryMethodSmooth;
  3186. break;
  3187. }
  3188. if ( factoryMethod === undefined ) {
  3189. var message = "unsupported interpolation for " +
  3190. this.ValueTypeName + " keyframe track named " + this.name;
  3191. if ( this.createInterpolant === undefined ) {
  3192. // fall back to default, unless the default itself is messed up
  3193. if ( interpolation !== this.DefaultInterpolation ) {
  3194. this.setInterpolation( this.DefaultInterpolation );
  3195. } else {
  3196. throw new Error( message ); // fatal, in this case
  3197. }
  3198. }
  3199. console.warn( 'THREE.KeyframeTrackPrototype:', message );
  3200. return;
  3201. }
  3202. this.createInterpolant = factoryMethod;
  3203. },
  3204. getInterpolation: function () {
  3205. switch ( this.createInterpolant ) {
  3206. case this.InterpolantFactoryMethodDiscrete:
  3207. return InterpolateDiscrete;
  3208. case this.InterpolantFactoryMethodLinear:
  3209. return InterpolateLinear;
  3210. case this.InterpolantFactoryMethodSmooth:
  3211. return InterpolateSmooth;
  3212. }
  3213. },
  3214. getValueSize: function () {
  3215. return this.values.length / this.times.length;
  3216. },
  3217. // move all keyframes either forwards or backwards in time
  3218. shift: function ( timeOffset ) {
  3219. if ( timeOffset !== 0.0 ) {
  3220. var times = this.times;
  3221. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  3222. times[ i ] += timeOffset;
  3223. }
  3224. }
  3225. return this;
  3226. },
  3227. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  3228. scale: function ( timeScale ) {
  3229. if ( timeScale !== 1.0 ) {
  3230. var times = this.times;
  3231. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  3232. times[ i ] *= timeScale;
  3233. }
  3234. }
  3235. return this;
  3236. },
  3237. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  3238. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  3239. trim: function ( startTime, endTime ) {
  3240. var times = this.times,
  3241. nKeys = times.length,
  3242. from = 0,
  3243. to = nKeys - 1;
  3244. while ( from !== nKeys && times[ from ] < startTime ) ++ from;
  3245. while ( to !== - 1 && times[ to ] > endTime ) -- to;
  3246. ++ to; // inclusive -> exclusive bound
  3247. if ( from !== 0 || to !== nKeys ) {
  3248. // empty tracks are forbidden, so keep at least one keyframe
  3249. if ( from >= to ) to = Math.max( to, 1 ), from = to - 1;
  3250. var stride = this.getValueSize();
  3251. this.times = AnimationUtils.arraySlice( times, from, to );
  3252. this.values = AnimationUtils.arraySlice( this.values, from * stride, to * stride );
  3253. }
  3254. return this;
  3255. },
  3256. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  3257. validate: function () {
  3258. var valid = true;
  3259. var valueSize = this.getValueSize();
  3260. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  3261. console.error( 'THREE.KeyframeTrackPrototype: Invalid value size in track.', this );
  3262. valid = false;
  3263. }
  3264. var times = this.times,
  3265. values = this.values,
  3266. nKeys = times.length;
  3267. if ( nKeys === 0 ) {
  3268. console.error( 'THREE.KeyframeTrackPrototype: Track is empty.', this );
  3269. valid = false;
  3270. }
  3271. var prevTime = null;
  3272. for ( var i = 0; i !== nKeys; i ++ ) {
  3273. var currTime = times[ i ];
  3274. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  3275. console.error( 'THREE.KeyframeTrackPrototype: Time is not a valid number.', this, i, currTime );
  3276. valid = false;
  3277. break;
  3278. }
  3279. if ( prevTime !== null && prevTime > currTime ) {
  3280. console.error( 'THREE.KeyframeTrackPrototype: Out of order keys.', this, i, currTime, prevTime );
  3281. valid = false;
  3282. break;
  3283. }
  3284. prevTime = currTime;
  3285. }
  3286. if ( values !== undefined ) {
  3287. if ( AnimationUtils.isTypedArray( values ) ) {
  3288. for ( var i = 0, n = values.length; i !== n; ++ i ) {
  3289. var value = values[ i ];
  3290. if ( isNaN( value ) ) {
  3291. console.error( 'THREE.KeyframeTrackPrototype: Value is not a valid number.', this, i, value );
  3292. valid = false;
  3293. break;
  3294. }
  3295. }
  3296. }
  3297. }
  3298. return valid;
  3299. },
  3300. // removes equivalent sequential keys as common in morph target sequences
  3301. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  3302. optimize: function () {
  3303. var times = this.times,
  3304. values = this.values,
  3305. stride = this.getValueSize(),
  3306. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  3307. writeIndex = 1,
  3308. lastIndex = times.length - 1;
  3309. for ( var i = 1; i < lastIndex; ++ i ) {
  3310. var keep = false;
  3311. var time = times[ i ];
  3312. var timeNext = times[ i + 1 ];
  3313. // remove adjacent keyframes scheduled at the same time
  3314. if ( time !== timeNext && ( i !== 1 || time !== time[ 0 ] ) ) {
  3315. if ( ! smoothInterpolation ) {
  3316. // remove unnecessary keyframes same as their neighbors
  3317. var offset = i * stride,
  3318. offsetP = offset - stride,
  3319. offsetN = offset + stride;
  3320. for ( var j = 0; j !== stride; ++ j ) {
  3321. var value = values[ offset + j ];
  3322. if ( value !== values[ offsetP + j ] ||
  3323. value !== values[ offsetN + j ] ) {
  3324. keep = true;
  3325. break;
  3326. }
  3327. }
  3328. } else keep = true;
  3329. }
  3330. // in-place compaction
  3331. if ( keep ) {
  3332. if ( i !== writeIndex ) {
  3333. times[ writeIndex ] = times[ i ];
  3334. var readOffset = i * stride,
  3335. writeOffset = writeIndex * stride;
  3336. for ( var j = 0; j !== stride; ++ j )
  3337. values[ writeOffset + j ] = values[ readOffset + j ];
  3338. }
  3339. ++ writeIndex;
  3340. }
  3341. }
  3342. // flush last keyframe (compaction looks ahead)
  3343. if ( lastIndex > 0 ) {
  3344. times[ writeIndex ] = times[ lastIndex ];
  3345. for ( var readOffset = lastIndex * stride, writeOffset = writeIndex * stride, j = 0; j !== stride; ++ j )
  3346. values[ writeOffset + j ] = values[ readOffset + j ];
  3347. ++ writeIndex;
  3348. }
  3349. if ( writeIndex !== times.length ) {
  3350. this.times = AnimationUtils.arraySlice( times, 0, writeIndex );
  3351. this.values = AnimationUtils.arraySlice( values, 0, writeIndex * stride );
  3352. }
  3353. return this;
  3354. }
  3355. };
  3356. function KeyframeTrackConstructor( name, times, values, interpolation ) {
  3357. if ( name === undefined ) throw new Error( 'track name is undefined' );
  3358. if ( times === undefined || times.length === 0 ) {
  3359. throw new Error( 'no keyframes in track named ' + name );
  3360. }
  3361. this.name = name;
  3362. this.times = AnimationUtils.convertArray( times, this.TimeBufferType );
  3363. this.values = AnimationUtils.convertArray( values, this.ValueBufferType );
  3364. this.setInterpolation( interpolation || this.DefaultInterpolation );
  3365. this.validate();
  3366. this.optimize();
  3367. }
  3368. function VectorKeyframeTrack( name, times, values, interpolation ) {
  3369. KeyframeTrackConstructor.call( this, name, times, values, interpolation );
  3370. }
  3371. VectorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrackPrototype ), {
  3372. constructor: VectorKeyframeTrack,
  3373. ValueTypeName: 'vector'
  3374. // ValueBufferType is inherited
  3375. // DefaultInterpolation is inherited
  3376. } );
  3377. function QuaternionLinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  3378. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  3379. }
  3380. QuaternionLinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  3381. constructor: QuaternionLinearInterpolant,
  3382. interpolate_: function ( i1, t0, t, t1 ) {
  3383. var result = this.resultBuffer,
  3384. values = this.sampleValues,
  3385. stride = this.valueSize,
  3386. offset = i1 * stride,
  3387. alpha = ( t - t0 ) / ( t1 - t0 );
  3388. for ( var end = offset + stride; offset !== end; offset += 4 ) {
  3389. Quaternion.slerpFlat( result, 0, values, offset - stride, values, offset, alpha );
  3390. }
  3391. return result;
  3392. }
  3393. } );
  3394. function QuaternionKeyframeTrack( name, times, values, interpolation ) {
  3395. KeyframeTrackConstructor.call( this, name, times, values, interpolation );
  3396. }
  3397. QuaternionKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrackPrototype ), {
  3398. constructor: QuaternionKeyframeTrack,
  3399. ValueTypeName: 'quaternion',
  3400. // ValueBufferType is inherited
  3401. DefaultInterpolation: InterpolateLinear,
  3402. InterpolantFactoryMethodLinear: function ( result ) {
  3403. return new QuaternionLinearInterpolant( this.times, this.values, this.getValueSize(), result );
  3404. },
  3405. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  3406. } );
  3407. function NumberKeyframeTrack( name, times, values, interpolation ) {
  3408. KeyframeTrackConstructor.call( this, name, times, values, interpolation );
  3409. }
  3410. NumberKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrackPrototype ), {
  3411. constructor: NumberKeyframeTrack,
  3412. ValueTypeName: 'number'
  3413. // ValueBufferType is inherited
  3414. // DefaultInterpolation is inherited
  3415. } );
  3416. function StringKeyframeTrack( name, times, values, interpolation ) {
  3417. KeyframeTrackConstructor.call( this, name, times, values, interpolation );
  3418. }
  3419. StringKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrackPrototype ), {
  3420. constructor: StringKeyframeTrack,
  3421. ValueTypeName: 'string',
  3422. ValueBufferType: Array,
  3423. DefaultInterpolation: InterpolateDiscrete,
  3424. InterpolantFactoryMethodLinear: undefined,
  3425. InterpolantFactoryMethodSmooth: undefined
  3426. } );
  3427. function BooleanKeyframeTrack( name, times, values ) {
  3428. KeyframeTrackConstructor.call( this, name, times, values );
  3429. }
  3430. BooleanKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrackPrototype ), {
  3431. constructor: BooleanKeyframeTrack,
  3432. ValueTypeName: 'bool',
  3433. ValueBufferType: Array,
  3434. DefaultInterpolation: InterpolateDiscrete,
  3435. InterpolantFactoryMethodLinear: undefined,
  3436. InterpolantFactoryMethodSmooth: undefined
  3437. // Note: Actually this track could have a optimized / compressed
  3438. // representation of a single value and a custom interpolant that
  3439. // computes "firstValue ^ isOdd( index )".
  3440. } );
  3441. function ColorKeyframeTrack( name, times, values, interpolation ) {
  3442. KeyframeTrackConstructor.call( this, name, times, values, interpolation );
  3443. }
  3444. ColorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrackPrototype ), {
  3445. constructor: ColorKeyframeTrack,
  3446. ValueTypeName: 'color'
  3447. // ValueBufferType is inherited
  3448. // DefaultInterpolation is inherited
  3449. // Note: Very basic implementation and nothing special yet.
  3450. // However, this is the place for color space parameterization.
  3451. } );
  3452. function KeyframeTrack( name, times, values, interpolation ) {
  3453. KeyframeTrackConstructor.apply( this, name, times, values, interpolation );
  3454. }
  3455. KeyframeTrack.prototype = KeyframeTrackPrototype;
  3456. KeyframeTrackPrototype.constructor = KeyframeTrack;
  3457. // Static methods:
  3458. Object.assign( KeyframeTrack, {
  3459. // Serialization (in static context, because of constructor invocation
  3460. // and automatic invocation of .toJSON):
  3461. parse: function ( json ) {
  3462. if ( json.type === undefined ) {
  3463. throw new Error( 'track type undefined, can not parse' );
  3464. }
  3465. var trackType = KeyframeTrack._getTrackTypeForValueTypeName( json.type );
  3466. if ( json.times === undefined ) {
  3467. var times = [], values = [];
  3468. AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
  3469. json.times = times;
  3470. json.values = values;
  3471. }
  3472. // derived classes can define a static parse method
  3473. if ( trackType.parse !== undefined ) {
  3474. return trackType.parse( json );
  3475. } else {
  3476. // by default, we assume a constructor compatible with the base
  3477. return new trackType( json.name, json.times, json.values, json.interpolation );
  3478. }
  3479. },
  3480. toJSON: function ( track ) {
  3481. var trackType = track.constructor;
  3482. var json;
  3483. // derived classes can define a static toJSON method
  3484. if ( trackType.toJSON !== undefined ) {
  3485. json = trackType.toJSON( track );
  3486. } else {
  3487. // by default, we assume the data can be serialized as-is
  3488. json = {
  3489. 'name': track.name,
  3490. 'times': AnimationUtils.convertArray( track.times, Array ),
  3491. 'values': AnimationUtils.convertArray( track.values, Array )
  3492. };
  3493. var interpolation = track.getInterpolation();
  3494. if ( interpolation !== track.DefaultInterpolation ) {
  3495. json.interpolation = interpolation;
  3496. }
  3497. }
  3498. json.type = track.ValueTypeName; // mandatory
  3499. return json;
  3500. },
  3501. _getTrackTypeForValueTypeName: function ( typeName ) {
  3502. switch ( typeName.toLowerCase() ) {
  3503. case 'scalar':
  3504. case 'double':
  3505. case 'float':
  3506. case 'number':
  3507. case 'integer':
  3508. return NumberKeyframeTrack;
  3509. case 'vector':
  3510. case 'vector2':
  3511. case 'vector3':
  3512. case 'vector4':
  3513. return VectorKeyframeTrack;
  3514. case 'color':
  3515. return ColorKeyframeTrack;
  3516. case 'quaternion':
  3517. return QuaternionKeyframeTrack;
  3518. case 'bool':
  3519. case 'boolean':
  3520. return BooleanKeyframeTrack;
  3521. case 'string':
  3522. return StringKeyframeTrack;
  3523. }
  3524. throw new Error( 'Unsupported typeName: ' + typeName );
  3525. }
  3526. } );
  3527. function AnimationClip( name, duration, tracks ) {
  3528. this.name = name;
  3529. this.tracks = tracks;
  3530. this.duration = ( duration !== undefined ) ? duration : - 1;
  3531. this.uuid = _Math.generateUUID();
  3532. // this means it should figure out its duration by scanning the tracks
  3533. if ( this.duration < 0 ) {
  3534. this.resetDuration();
  3535. }
  3536. this.optimize();
  3537. }
  3538. Object.assign( AnimationClip, {
  3539. parse: function ( json ) {
  3540. var tracks = [],
  3541. jsonTracks = json.tracks,
  3542. frameTime = 1.0 / ( json.fps || 1.0 );
  3543. for ( var i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  3544. tracks.push( KeyframeTrack.parse( jsonTracks[ i ] ).scale( frameTime ) );
  3545. }
  3546. return new AnimationClip( json.name, json.duration, tracks );
  3547. },
  3548. toJSON: function ( clip ) {
  3549. var tracks = [],
  3550. clipTracks = clip.tracks;
  3551. var json = {
  3552. 'name': clip.name,
  3553. 'duration': clip.duration,
  3554. 'tracks': tracks
  3555. };
  3556. for ( var i = 0, n = clipTracks.length; i !== n; ++ i ) {
  3557. tracks.push( KeyframeTrack.toJSON( clipTracks[ i ] ) );
  3558. }
  3559. return json;
  3560. },
  3561. CreateFromMorphTargetSequence: function ( name, morphTargetSequence, fps, noLoop ) {
  3562. var numMorphTargets = morphTargetSequence.length;
  3563. var tracks = [];
  3564. for ( var i = 0; i < numMorphTargets; i ++ ) {
  3565. var times = [];
  3566. var values = [];
  3567. times.push(
  3568. ( i + numMorphTargets - 1 ) % numMorphTargets,
  3569. i,
  3570. ( i + 1 ) % numMorphTargets );
  3571. values.push( 0, 1, 0 );
  3572. var order = AnimationUtils.getKeyframeOrder( times );
  3573. times = AnimationUtils.sortedArray( times, 1, order );
  3574. values = AnimationUtils.sortedArray( values, 1, order );
  3575. // if there is a key at the first frame, duplicate it as the
  3576. // last frame as well for perfect loop.
  3577. if ( ! noLoop && times[ 0 ] === 0 ) {
  3578. times.push( numMorphTargets );
  3579. values.push( values[ 0 ] );
  3580. }
  3581. tracks.push(
  3582. new NumberKeyframeTrack(
  3583. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  3584. times, values
  3585. ).scale( 1.0 / fps ) );
  3586. }
  3587. return new AnimationClip( name, - 1, tracks );
  3588. },
  3589. findByName: function ( objectOrClipArray, name ) {
  3590. var clipArray = objectOrClipArray;
  3591. if ( ! Array.isArray( objectOrClipArray ) ) {
  3592. var o = objectOrClipArray;
  3593. clipArray = o.geometry && o.geometry.animations || o.animations;
  3594. }
  3595. for ( var i = 0; i < clipArray.length; i ++ ) {
  3596. if ( clipArray[ i ].name === name ) {
  3597. return clipArray[ i ];
  3598. }
  3599. }
  3600. return null;
  3601. },
  3602. CreateClipsFromMorphTargetSequences: function ( morphTargets, fps, noLoop ) {
  3603. var animationToMorphTargets = {};
  3604. // tested with https://regex101.com/ on trick sequences
  3605. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  3606. var pattern = /^([\w-]*?)([\d]+)$/;
  3607. // sort morph target names into animation groups based
  3608. // patterns like Walk_001, Walk_002, Run_001, Run_002
  3609. for ( var i = 0, il = morphTargets.length; i < il; i ++ ) {
  3610. var morphTarget = morphTargets[ i ];
  3611. var parts = morphTarget.name.match( pattern );
  3612. if ( parts && parts.length > 1 ) {
  3613. var name = parts[ 1 ];
  3614. var animationMorphTargets = animationToMorphTargets[ name ];
  3615. if ( ! animationMorphTargets ) {
  3616. animationToMorphTargets[ name ] = animationMorphTargets = [];
  3617. }
  3618. animationMorphTargets.push( morphTarget );
  3619. }
  3620. }
  3621. var clips = [];
  3622. for ( var name in animationToMorphTargets ) {
  3623. clips.push( AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps, noLoop ) );
  3624. }
  3625. return clips;
  3626. },
  3627. // parse the animation.hierarchy format
  3628. parseAnimation: function ( animation, bones ) {
  3629. if ( ! animation ) {
  3630. console.error( 'THREE.AnimationClip: No animation in JSONLoader data.' );
  3631. return null;
  3632. }
  3633. var addNonemptyTrack = function ( trackType, trackName, animationKeys, propertyName, destTracks ) {
  3634. // only return track if there are actually keys.
  3635. if ( animationKeys.length !== 0 ) {
  3636. var times = [];
  3637. var values = [];
  3638. AnimationUtils.flattenJSON( animationKeys, times, values, propertyName );
  3639. // empty keys are filtered out, so check again
  3640. if ( times.length !== 0 ) {
  3641. destTracks.push( new trackType( trackName, times, values ) );
  3642. }
  3643. }
  3644. };
  3645. var tracks = [];
  3646. var clipName = animation.name || 'default';
  3647. // automatic length determination in AnimationClip.
  3648. var duration = animation.length || - 1;
  3649. var fps = animation.fps || 30;
  3650. var hierarchyTracks = animation.hierarchy || [];
  3651. for ( var h = 0; h < hierarchyTracks.length; h ++ ) {
  3652. var animationKeys = hierarchyTracks[ h ].keys;
  3653. // skip empty tracks
  3654. if ( ! animationKeys || animationKeys.length === 0 ) continue;
  3655. // process morph targets
  3656. if ( animationKeys[ 0 ].morphTargets ) {
  3657. // figure out all morph targets used in this track
  3658. var morphTargetNames = {};
  3659. for ( var k = 0; k < animationKeys.length; k ++ ) {
  3660. if ( animationKeys[ k ].morphTargets ) {
  3661. for ( var m = 0; m < animationKeys[ k ].morphTargets.length; m ++ ) {
  3662. morphTargetNames[ animationKeys[ k ].morphTargets[ m ] ] = - 1;
  3663. }
  3664. }
  3665. }
  3666. // create a track for each morph target with all zero
  3667. // morphTargetInfluences except for the keys in which
  3668. // the morphTarget is named.
  3669. for ( var morphTargetName in morphTargetNames ) {
  3670. var times = [];
  3671. var values = [];
  3672. for ( var m = 0; m !== animationKeys[ k ].morphTargets.length; ++ m ) {
  3673. var animationKey = animationKeys[ k ];
  3674. times.push( animationKey.time );
  3675. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 );
  3676. }
  3677. tracks.push( new NumberKeyframeTrack( '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  3678. }
  3679. duration = morphTargetNames.length * ( fps || 1.0 );
  3680. } else {
  3681. // ...assume skeletal animation
  3682. var boneName = '.bones[' + bones[ h ].name + ']';
  3683. addNonemptyTrack(
  3684. VectorKeyframeTrack, boneName + '.position',
  3685. animationKeys, 'pos', tracks );
  3686. addNonemptyTrack(
  3687. QuaternionKeyframeTrack, boneName + '.quaternion',
  3688. animationKeys, 'rot', tracks );
  3689. addNonemptyTrack(
  3690. VectorKeyframeTrack, boneName + '.scale',
  3691. animationKeys, 'scl', tracks );
  3692. }
  3693. }
  3694. if ( tracks.length === 0 ) {
  3695. return null;
  3696. }
  3697. var clip = new AnimationClip( clipName, duration, tracks );
  3698. return clip;
  3699. }
  3700. } );
  3701. Object.assign( AnimationClip.prototype, {
  3702. resetDuration: function () {
  3703. var tracks = this.tracks, duration = 0;
  3704. for ( var i = 0, n = tracks.length; i !== n; ++ i ) {
  3705. var track = this.tracks[ i ];
  3706. duration = Math.max( duration, track.times[ track.times.length - 1 ] );
  3707. }
  3708. this.duration = duration;
  3709. },
  3710. trim: function () {
  3711. for ( var i = 0; i < this.tracks.length; i ++ ) {
  3712. this.tracks[ i ].trim( 0, this.duration );
  3713. }
  3714. return this;
  3715. },
  3716. optimize: function () {
  3717. for ( var i = 0; i < this.tracks.length; i ++ ) {
  3718. this.tracks[ i ].optimize();
  3719. }
  3720. return this;
  3721. }
  3722. } );
  3723. function AnimationMixer( root ) {
  3724. this._root = root;
  3725. this._initMemoryManager();
  3726. this._accuIndex = 0;
  3727. this.time = 0;
  3728. this.timeScale = 1.0;
  3729. }
  3730. Object.assign( AnimationMixer.prototype, EventDispatcher.prototype, {
  3731. _bindAction: function ( action, prototypeAction ) {
  3732. var root = action._localRoot || this._root,
  3733. tracks = action._clip.tracks,
  3734. nTracks = tracks.length,
  3735. bindings = action._propertyBindings,
  3736. interpolants = action._interpolants,
  3737. rootUuid = root.uuid,
  3738. bindingsByRoot = this._bindingsByRootAndName,
  3739. bindingsByName = bindingsByRoot[ rootUuid ];
  3740. if ( bindingsByName === undefined ) {
  3741. bindingsByName = {};
  3742. bindingsByRoot[ rootUuid ] = bindingsByName;
  3743. }
  3744. for ( var i = 0; i !== nTracks; ++ i ) {
  3745. var track = tracks[ i ],
  3746. trackName = track.name,
  3747. binding = bindingsByName[ trackName ];
  3748. if ( binding !== undefined ) {
  3749. bindings[ i ] = binding;
  3750. } else {
  3751. binding = bindings[ i ];
  3752. if ( binding !== undefined ) {
  3753. // existing binding, make sure the cache knows
  3754. if ( binding._cacheIndex === null ) {
  3755. ++ binding.referenceCount;
  3756. this._addInactiveBinding( binding, rootUuid, trackName );
  3757. }
  3758. continue;
  3759. }
  3760. var path = prototypeAction && prototypeAction.
  3761. _propertyBindings[ i ].binding.parsedPath;
  3762. binding = new PropertyMixer(
  3763. PropertyBinding.create( root, trackName, path ),
  3764. track.ValueTypeName, track.getValueSize() );
  3765. ++ binding.referenceCount;
  3766. this._addInactiveBinding( binding, rootUuid, trackName );
  3767. bindings[ i ] = binding;
  3768. }
  3769. interpolants[ i ].resultBuffer = binding.buffer;
  3770. }
  3771. },
  3772. _activateAction: function ( action ) {
  3773. if ( ! this._isActiveAction( action ) ) {
  3774. if ( action._cacheIndex === null ) {
  3775. // this action has been forgotten by the cache, but the user
  3776. // appears to be still using it -> rebind
  3777. var rootUuid = ( action._localRoot || this._root ).uuid,
  3778. clipUuid = action._clip.uuid,
  3779. actionsForClip = this._actionsByClip[ clipUuid ];
  3780. this._bindAction( action,
  3781. actionsForClip && actionsForClip.knownActions[ 0 ] );
  3782. this._addInactiveAction( action, clipUuid, rootUuid );
  3783. }
  3784. var bindings = action._propertyBindings;
  3785. // increment reference counts / sort out state
  3786. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  3787. var binding = bindings[ i ];
  3788. if ( binding.useCount ++ === 0 ) {
  3789. this._lendBinding( binding );
  3790. binding.saveOriginalState();
  3791. }
  3792. }
  3793. this._lendAction( action );
  3794. }
  3795. },
  3796. _deactivateAction: function ( action ) {
  3797. if ( this._isActiveAction( action ) ) {
  3798. var bindings = action._propertyBindings;
  3799. // decrement reference counts / sort out state
  3800. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  3801. var binding = bindings[ i ];
  3802. if ( -- binding.useCount === 0 ) {
  3803. binding.restoreOriginalState();
  3804. this._takeBackBinding( binding );
  3805. }
  3806. }
  3807. this._takeBackAction( action );
  3808. }
  3809. },
  3810. // Memory manager
  3811. _initMemoryManager: function () {
  3812. this._actions = []; // 'nActiveActions' followed by inactive ones
  3813. this._nActiveActions = 0;
  3814. this._actionsByClip = {};
  3815. // inside:
  3816. // {
  3817. // knownActions: Array< AnimationAction > - used as prototypes
  3818. // actionByRoot: AnimationAction - lookup
  3819. // }
  3820. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  3821. this._nActiveBindings = 0;
  3822. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  3823. this._controlInterpolants = []; // same game as above
  3824. this._nActiveControlInterpolants = 0;
  3825. var scope = this;
  3826. this.stats = {
  3827. actions: {
  3828. get total() {
  3829. return scope._actions.length;
  3830. },
  3831. get inUse() {
  3832. return scope._nActiveActions;
  3833. }
  3834. },
  3835. bindings: {
  3836. get total() {
  3837. return scope._bindings.length;
  3838. },
  3839. get inUse() {
  3840. return scope._nActiveBindings;
  3841. }
  3842. },
  3843. controlInterpolants: {
  3844. get total() {
  3845. return scope._controlInterpolants.length;
  3846. },
  3847. get inUse() {
  3848. return scope._nActiveControlInterpolants;
  3849. }
  3850. }
  3851. };
  3852. },
  3853. // Memory management for AnimationAction objects
  3854. _isActiveAction: function ( action ) {
  3855. var index = action._cacheIndex;
  3856. return index !== null && index < this._nActiveActions;
  3857. },
  3858. _addInactiveAction: function ( action, clipUuid, rootUuid ) {
  3859. var actions = this._actions,
  3860. actionsByClip = this._actionsByClip,
  3861. actionsForClip = actionsByClip[ clipUuid ];
  3862. if ( actionsForClip === undefined ) {
  3863. actionsForClip = {
  3864. knownActions: [ action ],
  3865. actionByRoot: {}
  3866. };
  3867. action._byClipCacheIndex = 0;
  3868. actionsByClip[ clipUuid ] = actionsForClip;
  3869. } else {
  3870. var knownActions = actionsForClip.knownActions;
  3871. action._byClipCacheIndex = knownActions.length;
  3872. knownActions.push( action );
  3873. }
  3874. action._cacheIndex = actions.length;
  3875. actions.push( action );
  3876. actionsForClip.actionByRoot[ rootUuid ] = action;
  3877. },
  3878. _removeInactiveAction: function ( action ) {
  3879. var actions = this._actions,
  3880. lastInactiveAction = actions[ actions.length - 1 ],
  3881. cacheIndex = action._cacheIndex;
  3882. lastInactiveAction._cacheIndex = cacheIndex;
  3883. actions[ cacheIndex ] = lastInactiveAction;
  3884. actions.pop();
  3885. action._cacheIndex = null;
  3886. var clipUuid = action._clip.uuid,
  3887. actionsByClip = this._actionsByClip,
  3888. actionsForClip = actionsByClip[ clipUuid ],
  3889. knownActionsForClip = actionsForClip.knownActions,
  3890. lastKnownAction =
  3891. knownActionsForClip[ knownActionsForClip.length - 1 ],
  3892. byClipCacheIndex = action._byClipCacheIndex;
  3893. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  3894. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  3895. knownActionsForClip.pop();
  3896. action._byClipCacheIndex = null;
  3897. var actionByRoot = actionsForClip.actionByRoot,
  3898. rootUuid = ( action._localRoot || this._root ).uuid;
  3899. delete actionByRoot[ rootUuid ];
  3900. if ( knownActionsForClip.length === 0 ) {
  3901. delete actionsByClip[ clipUuid ];
  3902. }
  3903. this._removeInactiveBindingsForAction( action );
  3904. },
  3905. _removeInactiveBindingsForAction: function ( action ) {
  3906. var bindings = action._propertyBindings;
  3907. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  3908. var binding = bindings[ i ];
  3909. if ( -- binding.referenceCount === 0 ) {
  3910. this._removeInactiveBinding( binding );
  3911. }
  3912. }
  3913. },
  3914. _lendAction: function ( action ) {
  3915. // [ active actions | inactive actions ]
  3916. // [ active actions >| inactive actions ]
  3917. // s a
  3918. // <-swap->
  3919. // a s
  3920. var actions = this._actions,
  3921. prevIndex = action._cacheIndex,
  3922. lastActiveIndex = this._nActiveActions ++,
  3923. firstInactiveAction = actions[ lastActiveIndex ];
  3924. action._cacheIndex = lastActiveIndex;
  3925. actions[ lastActiveIndex ] = action;
  3926. firstInactiveAction._cacheIndex = prevIndex;
  3927. actions[ prevIndex ] = firstInactiveAction;
  3928. },
  3929. _takeBackAction: function ( action ) {
  3930. // [ active actions | inactive actions ]
  3931. // [ active actions |< inactive actions ]
  3932. // a s
  3933. // <-swap->
  3934. // s a
  3935. var actions = this._actions,
  3936. prevIndex = action._cacheIndex,
  3937. firstInactiveIndex = -- this._nActiveActions,
  3938. lastActiveAction = actions[ firstInactiveIndex ];
  3939. action._cacheIndex = firstInactiveIndex;
  3940. actions[ firstInactiveIndex ] = action;
  3941. lastActiveAction._cacheIndex = prevIndex;
  3942. actions[ prevIndex ] = lastActiveAction;
  3943. },
  3944. // Memory management for PropertyMixer objects
  3945. _addInactiveBinding: function ( binding, rootUuid, trackName ) {
  3946. var bindingsByRoot = this._bindingsByRootAndName,
  3947. bindingByName = bindingsByRoot[ rootUuid ],
  3948. bindings = this._bindings;
  3949. if ( bindingByName === undefined ) {
  3950. bindingByName = {};
  3951. bindingsByRoot[ rootUuid ] = bindingByName;
  3952. }
  3953. bindingByName[ trackName ] = binding;
  3954. binding._cacheIndex = bindings.length;
  3955. bindings.push( binding );
  3956. },
  3957. _removeInactiveBinding: function ( binding ) {
  3958. var bindings = this._bindings,
  3959. propBinding = binding.binding,
  3960. rootUuid = propBinding.rootNode.uuid,
  3961. trackName = propBinding.path,
  3962. bindingsByRoot = this._bindingsByRootAndName,
  3963. bindingByName = bindingsByRoot[ rootUuid ],
  3964. lastInactiveBinding = bindings[ bindings.length - 1 ],
  3965. cacheIndex = binding._cacheIndex;
  3966. lastInactiveBinding._cacheIndex = cacheIndex;
  3967. bindings[ cacheIndex ] = lastInactiveBinding;
  3968. bindings.pop();
  3969. delete bindingByName[ trackName ];
  3970. remove_empty_map: {
  3971. for ( var _ in bindingByName ) break remove_empty_map; // eslint-disable-line no-unused-vars
  3972. delete bindingsByRoot[ rootUuid ];
  3973. }
  3974. },
  3975. _lendBinding: function ( binding ) {
  3976. var bindings = this._bindings,
  3977. prevIndex = binding._cacheIndex,
  3978. lastActiveIndex = this._nActiveBindings ++,
  3979. firstInactiveBinding = bindings[ lastActiveIndex ];
  3980. binding._cacheIndex = lastActiveIndex;
  3981. bindings[ lastActiveIndex ] = binding;
  3982. firstInactiveBinding._cacheIndex = prevIndex;
  3983. bindings[ prevIndex ] = firstInactiveBinding;
  3984. },
  3985. _takeBackBinding: function ( binding ) {
  3986. var bindings = this._bindings,
  3987. prevIndex = binding._cacheIndex,
  3988. firstInactiveIndex = -- this._nActiveBindings,
  3989. lastActiveBinding = bindings[ firstInactiveIndex ];
  3990. binding._cacheIndex = firstInactiveIndex;
  3991. bindings[ firstInactiveIndex ] = binding;
  3992. lastActiveBinding._cacheIndex = prevIndex;
  3993. bindings[ prevIndex ] = lastActiveBinding;
  3994. },
  3995. // Memory management of Interpolants for weight and time scale
  3996. _lendControlInterpolant: function () {
  3997. var interpolants = this._controlInterpolants,
  3998. lastActiveIndex = this._nActiveControlInterpolants ++,
  3999. interpolant = interpolants[ lastActiveIndex ];
  4000. if ( interpolant === undefined ) {
  4001. interpolant = new LinearInterpolant(
  4002. new Float32Array( 2 ), new Float32Array( 2 ),
  4003. 1, this._controlInterpolantsResultBuffer );
  4004. interpolant.__cacheIndex = lastActiveIndex;
  4005. interpolants[ lastActiveIndex ] = interpolant;
  4006. }
  4007. return interpolant;
  4008. },
  4009. _takeBackControlInterpolant: function ( interpolant ) {
  4010. var interpolants = this._controlInterpolants,
  4011. prevIndex = interpolant.__cacheIndex,
  4012. firstInactiveIndex = -- this._nActiveControlInterpolants,
  4013. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  4014. interpolant.__cacheIndex = firstInactiveIndex;
  4015. interpolants[ firstInactiveIndex ] = interpolant;
  4016. lastActiveInterpolant.__cacheIndex = prevIndex;
  4017. interpolants[ prevIndex ] = lastActiveInterpolant;
  4018. },
  4019. _controlInterpolantsResultBuffer: new Float32Array( 1 ),
  4020. // return an action for a clip optionally using a custom root target
  4021. // object (this method allocates a lot of dynamic memory in case a
  4022. // previously unknown clip/root combination is specified)
  4023. clipAction: function ( clip, optionalRoot ) {
  4024. var root = optionalRoot || this._root,
  4025. rootUuid = root.uuid,
  4026. clipObject = typeof clip === 'string' ?
  4027. AnimationClip.findByName( root, clip ) : clip,
  4028. clipUuid = clipObject !== null ? clipObject.uuid : clip,
  4029. actionsForClip = this._actionsByClip[ clipUuid ],
  4030. prototypeAction = null;
  4031. if ( actionsForClip !== undefined ) {
  4032. var existingAction =
  4033. actionsForClip.actionByRoot[ rootUuid ];
  4034. if ( existingAction !== undefined ) {
  4035. return existingAction;
  4036. }
  4037. // we know the clip, so we don't have to parse all
  4038. // the bindings again but can just copy
  4039. prototypeAction = actionsForClip.knownActions[ 0 ];
  4040. // also, take the clip from the prototype action
  4041. if ( clipObject === null )
  4042. clipObject = prototypeAction._clip;
  4043. }
  4044. // clip must be known when specified via string
  4045. if ( clipObject === null ) return null;
  4046. // allocate all resources required to run it
  4047. var newAction = new AnimationAction( this, clipObject, optionalRoot );
  4048. this._bindAction( newAction, prototypeAction );
  4049. // and make the action known to the memory manager
  4050. this._addInactiveAction( newAction, clipUuid, rootUuid );
  4051. return newAction;
  4052. },
  4053. // get an existing action
  4054. existingAction: function ( clip, optionalRoot ) {
  4055. var root = optionalRoot || this._root,
  4056. rootUuid = root.uuid,
  4057. clipObject = typeof clip === 'string' ?
  4058. AnimationClip.findByName( root, clip ) : clip,
  4059. clipUuid = clipObject ? clipObject.uuid : clip,
  4060. actionsForClip = this._actionsByClip[ clipUuid ];
  4061. if ( actionsForClip !== undefined ) {
  4062. return actionsForClip.actionByRoot[ rootUuid ] || null;
  4063. }
  4064. return null;
  4065. },
  4066. // deactivates all previously scheduled actions
  4067. stopAllAction: function () {
  4068. var actions = this._actions,
  4069. nActions = this._nActiveActions,
  4070. bindings = this._bindings,
  4071. nBindings = this._nActiveBindings;
  4072. this._nActiveActions = 0;
  4073. this._nActiveBindings = 0;
  4074. for ( var i = 0; i !== nActions; ++ i ) {
  4075. actions[ i ].reset();
  4076. }
  4077. for ( var i = 0; i !== nBindings; ++ i ) {
  4078. bindings[ i ].useCount = 0;
  4079. }
  4080. return this;
  4081. },
  4082. // advance the time and update apply the animation
  4083. update: function ( deltaTime ) {
  4084. deltaTime *= this.timeScale;
  4085. var actions = this._actions,
  4086. nActions = this._nActiveActions,
  4087. time = this.time += deltaTime,
  4088. timeDirection = Math.sign( deltaTime ),
  4089. accuIndex = this._accuIndex ^= 1;
  4090. // run active actions
  4091. for ( var i = 0; i !== nActions; ++ i ) {
  4092. var action = actions[ i ];
  4093. action._update( time, deltaTime, timeDirection, accuIndex );
  4094. }
  4095. // update scene graph
  4096. var bindings = this._bindings,
  4097. nBindings = this._nActiveBindings;
  4098. for ( var i = 0; i !== nBindings; ++ i ) {
  4099. bindings[ i ].apply( accuIndex );
  4100. }
  4101. return this;
  4102. },
  4103. // return this mixer's root target object
  4104. getRoot: function () {
  4105. return this._root;
  4106. },
  4107. // free all resources specific to a particular clip
  4108. uncacheClip: function ( clip ) {
  4109. var actions = this._actions,
  4110. clipUuid = clip.uuid,
  4111. actionsByClip = this._actionsByClip,
  4112. actionsForClip = actionsByClip[ clipUuid ];
  4113. if ( actionsForClip !== undefined ) {
  4114. // note: just calling _removeInactiveAction would mess up the
  4115. // iteration state and also require updating the state we can
  4116. // just throw away
  4117. var actionsToRemove = actionsForClip.knownActions;
  4118. for ( var i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  4119. var action = actionsToRemove[ i ];
  4120. this._deactivateAction( action );
  4121. var cacheIndex = action._cacheIndex,
  4122. lastInactiveAction = actions[ actions.length - 1 ];
  4123. action._cacheIndex = null;
  4124. action._byClipCacheIndex = null;
  4125. lastInactiveAction._cacheIndex = cacheIndex;
  4126. actions[ cacheIndex ] = lastInactiveAction;
  4127. actions.pop();
  4128. this._removeInactiveBindingsForAction( action );
  4129. }
  4130. delete actionsByClip[ clipUuid ];
  4131. }
  4132. },
  4133. // free all resources specific to a particular root target object
  4134. uncacheRoot: function ( root ) {
  4135. var rootUuid = root.uuid,
  4136. actionsByClip = this._actionsByClip;
  4137. for ( var clipUuid in actionsByClip ) {
  4138. var actionByRoot = actionsByClip[ clipUuid ].actionByRoot,
  4139. action = actionByRoot[ rootUuid ];
  4140. if ( action !== undefined ) {
  4141. this._deactivateAction( action );
  4142. this._removeInactiveAction( action );
  4143. }
  4144. }
  4145. var bindingsByRoot = this._bindingsByRootAndName,
  4146. bindingByName = bindingsByRoot[ rootUuid ];
  4147. if ( bindingByName !== undefined ) {
  4148. for ( var trackName in bindingByName ) {
  4149. var binding = bindingByName[ trackName ];
  4150. binding.restoreOriginalState();
  4151. this._removeInactiveBinding( binding );
  4152. }
  4153. }
  4154. },
  4155. // remove a targeted clip from the cache
  4156. uncacheAction: function ( clip, optionalRoot ) {
  4157. var action = this.existingAction( clip, optionalRoot );
  4158. if ( action !== null ) {
  4159. this._deactivateAction( action );
  4160. this._removeInactiveAction( action );
  4161. }
  4162. }
  4163. } );
  4164. /**
  4165. * @author TristanVALCKE / https://github.com/Itee
  4166. */
  4167. /* global QUnit */
  4168. QUnit.module( 'Animation', () => {
  4169. QUnit.module.todo( 'AnimationAction', () => {
  4170. // INSTANCING
  4171. QUnit.test( "Instancing", ( assert ) => {
  4172. var mixer = new AnimationMixer();
  4173. var clip = new AnimationClip();
  4174. assert.throws(
  4175. function () {
  4176. new AnimationAction();
  4177. },
  4178. new Error( "Mixer can't be null or undefined !" ),
  4179. "raised error instance about undefined or null mixer"
  4180. );
  4181. assert.throws(
  4182. function () {
  4183. new AnimationAction( mixer );
  4184. },
  4185. new Error( "Clip can't be null or undefined !" ),
  4186. "raised error instance about undefined or null clip"
  4187. );
  4188. var animationAction = new AnimationAction( mixer, clip );
  4189. assert.ok( animationAction, "animationAction instanciated" );
  4190. } );
  4191. // PRIVATE STUFF
  4192. QUnit.test( "_update", ( assert ) => {
  4193. assert.ok( false, "everything's gonna be alright" );
  4194. } );
  4195. QUnit.test( "_updateWeight", ( assert ) => {
  4196. assert.ok( false, "everything's gonna be alright" );
  4197. } );
  4198. QUnit.test( "_updateTimeScale", ( assert ) => {
  4199. assert.ok( false, "everything's gonna be alright" );
  4200. } );
  4201. QUnit.test( "_updateTime", ( assert ) => {
  4202. assert.ok( false, "everything's gonna be alright" );
  4203. } );
  4204. QUnit.test( "_setEndings", ( assert ) => {
  4205. assert.ok( false, "everything's gonna be alright" );
  4206. } );
  4207. QUnit.test( "_scheduleFading", ( assert ) => {
  4208. assert.ok( false, "everything's gonna be alright" );
  4209. } );
  4210. // PUBLIC STUFF
  4211. QUnit.test( "play", ( assert ) => {
  4212. assert.ok( false, "everything's gonna be alright" );
  4213. } );
  4214. QUnit.test( "stop", ( assert ) => {
  4215. assert.ok( false, "everything's gonna be alright" );
  4216. } );
  4217. QUnit.test( "reset", ( assert ) => {
  4218. assert.ok( false, "everything's gonna be alright" );
  4219. } );
  4220. QUnit.test( "isRunning", ( assert ) => {
  4221. assert.ok( false, "everything's gonna be alright" );
  4222. } );
  4223. QUnit.test( "isScheduled", ( assert ) => {
  4224. assert.ok( false, "everything's gonna be alright" );
  4225. } );
  4226. QUnit.test( "startAt", ( assert ) => {
  4227. assert.ok( false, "everything's gonna be alright" );
  4228. } );
  4229. QUnit.test( "setLoop", ( assert ) => {
  4230. assert.ok( false, "everything's gonna be alright" );
  4231. } );
  4232. QUnit.test( "setEffectiveWeight", ( assert ) => {
  4233. assert.ok( false, "everything's gonna be alright" );
  4234. } );
  4235. QUnit.test( "getEffectiveWeight", ( assert ) => {
  4236. assert.ok( false, "everything's gonna be alright" );
  4237. } );
  4238. QUnit.test( "fadeIn", ( assert ) => {
  4239. assert.ok( false, "everything's gonna be alright" );
  4240. } );
  4241. QUnit.test( "fadeOut", ( assert ) => {
  4242. assert.ok( false, "everything's gonna be alright" );
  4243. } );
  4244. QUnit.test( "crossFadeFrom", ( assert ) => {
  4245. assert.ok( false, "everything's gonna be alright" );
  4246. } );
  4247. QUnit.test( "crossFadeTo", ( assert ) => {
  4248. assert.ok( false, "everything's gonna be alright" );
  4249. } );
  4250. QUnit.test( "stopFading", ( assert ) => {
  4251. assert.ok( false, "everything's gonna be alright" );
  4252. } );
  4253. QUnit.test( "setEffectiveTimeScale", ( assert ) => {
  4254. assert.ok( false, "everything's gonna be alright" );
  4255. } );
  4256. QUnit.test( "getEffectiveTimeScale", ( assert ) => {
  4257. assert.ok( false, "everything's gonna be alright" );
  4258. } );
  4259. QUnit.test( "setDuration", ( assert ) => {
  4260. assert.ok( false, "everything's gonna be alright" );
  4261. } );
  4262. QUnit.test( "syncWith", ( assert ) => {
  4263. assert.ok( false, "everything's gonna be alright" );
  4264. } );
  4265. QUnit.test( "halt", ( assert ) => {
  4266. assert.ok( false, "everything's gonna be alright" );
  4267. } );
  4268. QUnit.test( "warp", ( assert ) => {
  4269. assert.ok( false, "everything's gonna be alright" );
  4270. } );
  4271. QUnit.test( "stopWarping", ( assert ) => {
  4272. assert.ok( false, "everything's gonna be alright" );
  4273. } );
  4274. QUnit.test( "getMixer", ( assert ) => {
  4275. assert.ok( false, "everything's gonna be alright" );
  4276. } );
  4277. QUnit.test( "getClip", ( assert ) => {
  4278. assert.ok( false, "everything's gonna be alright" );
  4279. } );
  4280. QUnit.test( "getRoot", ( assert ) => {
  4281. assert.ok( false, "everything's gonna be alright" );
  4282. } );
  4283. } );
  4284. } );
  4285. /**
  4286. * @author TristanVALCKE / https://github.com/Itee
  4287. */
  4288. /* global QUnit */
  4289. QUnit.module( 'Animation', () => {
  4290. QUnit.module.todo( 'AnimationClip', () => {
  4291. // INSTANCING
  4292. QUnit.test( "Instancing", ( assert ) => {
  4293. assert.ok( false, "everything's gonna be alright" );
  4294. } );
  4295. // STATIC STUFF
  4296. QUnit.test( "parse", ( assert ) => {
  4297. assert.ok( false, "everything's gonna be alright" );
  4298. } );
  4299. QUnit.test( "toJSON", ( assert ) => {
  4300. assert.ok( false, "everything's gonna be alright" );
  4301. } );
  4302. QUnit.test( "CreateFromMorphTargetSequence", ( assert ) => {
  4303. assert.ok( false, "everything's gonna be alright" );
  4304. } );
  4305. QUnit.test( "findByName", ( assert ) => {
  4306. assert.ok( false, "everything's gonna be alright" );
  4307. } );
  4308. QUnit.test( "CreateClipsFromMorphTargetSequences", ( assert ) => {
  4309. assert.ok( false, "everything's gonna be alright" );
  4310. } );
  4311. QUnit.test( "parseAnimation", ( assert ) => {
  4312. assert.ok( false, "everything's gonna be alright" );
  4313. } );
  4314. // PUBLIC STUFF
  4315. QUnit.test( "resetDuration", ( assert ) => {
  4316. assert.ok( false, "everything's gonna be alright" );
  4317. } );
  4318. QUnit.test( "trim", ( assert ) => {
  4319. assert.ok( false, "everything's gonna be alright" );
  4320. } );
  4321. QUnit.test( "optimize", ( assert ) => {
  4322. assert.ok( false, "everything's gonna be alright" );
  4323. } );
  4324. } );
  4325. } );
  4326. /**
  4327. * @author TristanVALCKE / https://github.com/Itee
  4328. */
  4329. /* global QUnit */
  4330. QUnit.module( 'Animation', () => {
  4331. QUnit.module.todo( 'AnimationMixer', () => {
  4332. // INHERITANCE
  4333. QUnit.test( "Extending", ( assert ) => {
  4334. assert.ok( false, "everything's gonna be alright" );
  4335. } );
  4336. // INSTANCING
  4337. QUnit.test( "Instancing", ( assert ) => {
  4338. assert.ok( false, "everything's gonna be alright" );
  4339. } );
  4340. // PRIVATE STUFF
  4341. QUnit.test( "_bindAction", ( assert ) => {
  4342. assert.ok( false, "everything's gonna be alright" );
  4343. } );
  4344. QUnit.test( "_activateAction", ( assert ) => {
  4345. assert.ok( false, "everything's gonna be alright" );
  4346. } );
  4347. QUnit.test( "_deactivateAction", ( assert ) => {
  4348. assert.ok( false, "everything's gonna be alright" );
  4349. } );
  4350. QUnit.test( "_initMemoryManager", ( assert ) => {
  4351. assert.ok( false, "everything's gonna be alright" );
  4352. } );
  4353. QUnit.test( "_isActiveAction", ( assert ) => {
  4354. assert.ok( false, "everything's gonna be alright" );
  4355. } );
  4356. QUnit.test( "_addInactiveAction", ( assert ) => {
  4357. assert.ok( false, "everything's gonna be alright" );
  4358. } );
  4359. QUnit.test( "_removeInactiveAction", ( assert ) => {
  4360. assert.ok( false, "everything's gonna be alright" );
  4361. } );
  4362. QUnit.test( "_removeInactiveBindingsForAction", ( assert ) => {
  4363. assert.ok( false, "everything's gonna be alright" );
  4364. } );
  4365. QUnit.test( "_lendAction", ( assert ) => {
  4366. assert.ok( false, "everything's gonna be alright" );
  4367. } );
  4368. QUnit.test( "_takeBackAction", ( assert ) => {
  4369. assert.ok( false, "everything's gonna be alright" );
  4370. } );
  4371. QUnit.test( "_addInactiveBinding", ( assert ) => {
  4372. assert.ok( false, "everything's gonna be alright" );
  4373. } );
  4374. QUnit.test( "_removeInactiveBinding", ( assert ) => {
  4375. assert.ok( false, "everything's gonna be alright" );
  4376. } );
  4377. QUnit.test( "_lendBinding", ( assert ) => {
  4378. assert.ok( false, "everything's gonna be alright" );
  4379. } );
  4380. QUnit.test( "_takeBackBinding", ( assert ) => {
  4381. assert.ok( false, "everything's gonna be alright" );
  4382. } );
  4383. QUnit.test( "_lendControlInterpolant", ( assert ) => {
  4384. assert.ok( false, "everything's gonna be alright" );
  4385. } );
  4386. QUnit.test( "_takeBackControlInterpolant", ( assert ) => {
  4387. assert.ok( false, "everything's gonna be alright" );
  4388. } );
  4389. QUnit.test( "_controlInterpolantsResultBuffer", ( assert ) => {
  4390. assert.ok( false, "everything's gonna be alright" );
  4391. } );
  4392. // PUBLIC STUFF
  4393. QUnit.test( "clipAction", ( assert ) => {
  4394. assert.ok( false, "everything's gonna be alright" );
  4395. } );
  4396. QUnit.test( "existingAction", ( assert ) => {
  4397. assert.ok( false, "everything's gonna be alright" );
  4398. } );
  4399. QUnit.test( "stopAllAction", ( assert ) => {
  4400. assert.ok( false, "everything's gonna be alright" );
  4401. } );
  4402. QUnit.test( "update", ( assert ) => {
  4403. assert.ok( false, "everything's gonna be alright" );
  4404. } );
  4405. QUnit.test( "getRoot", ( assert ) => {
  4406. assert.ok( false, "everything's gonna be alright" );
  4407. } );
  4408. QUnit.test( "uncacheClip", ( assert ) => {
  4409. assert.ok( false, "everything's gonna be alright" );
  4410. } );
  4411. QUnit.test( "uncacheRoot", ( assert ) => {
  4412. assert.ok( false, "everything's gonna be alright" );
  4413. } );
  4414. QUnit.test( "uncacheAction", ( assert ) => {
  4415. assert.ok( false, "everything's gonna be alright" );
  4416. } );
  4417. } );
  4418. } );
  4419. function AnimationObjectGroup() {
  4420. this.uuid = _Math.generateUUID();
  4421. // cached objects followed by the active ones
  4422. this._objects = Array.prototype.slice.call( arguments );
  4423. this.nCachedObjects_ = 0; // threshold
  4424. // note: read by PropertyBinding.Composite
  4425. var indices = {};
  4426. this._indicesByUUID = indices; // for bookkeeping
  4427. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  4428. indices[ arguments[ i ].uuid ] = i;
  4429. }
  4430. this._paths = []; // inside: string
  4431. this._parsedPaths = []; // inside: { we don't care, here }
  4432. this._bindings = []; // inside: Array< PropertyBinding >
  4433. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  4434. var scope = this;
  4435. this.stats = {
  4436. objects: {
  4437. get total() {
  4438. return scope._objects.length;
  4439. },
  4440. get inUse() {
  4441. return this.total - scope.nCachedObjects_;
  4442. }
  4443. },
  4444. get bindingsPerObject() {
  4445. return scope._bindings.length;
  4446. }
  4447. };
  4448. }
  4449. Object.assign( AnimationObjectGroup.prototype, {
  4450. isAnimationObjectGroup: true,
  4451. add: function () {
  4452. var objects = this._objects,
  4453. nObjects = objects.length,
  4454. nCachedObjects = this.nCachedObjects_,
  4455. indicesByUUID = this._indicesByUUID,
  4456. paths = this._paths,
  4457. parsedPaths = this._parsedPaths,
  4458. bindings = this._bindings,
  4459. nBindings = bindings.length;
  4460. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  4461. var object = arguments[ i ],
  4462. uuid = object.uuid,
  4463. index = indicesByUUID[ uuid ],
  4464. knownObject = undefined;
  4465. if ( index === undefined ) {
  4466. // unknown object -> add it to the ACTIVE region
  4467. index = nObjects ++;
  4468. indicesByUUID[ uuid ] = index;
  4469. objects.push( object );
  4470. // accounting is done, now do the same for all bindings
  4471. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  4472. bindings[ j ].push( new PropertyBinding( object, paths[ j ], parsedPaths[ j ] ) );
  4473. }
  4474. } else if ( index < nCachedObjects ) {
  4475. knownObject = objects[ index ];
  4476. // move existing object to the ACTIVE region
  4477. var firstActiveIndex = -- nCachedObjects,
  4478. lastCachedObject = objects[ firstActiveIndex ];
  4479. indicesByUUID[ lastCachedObject.uuid ] = index;
  4480. objects[ index ] = lastCachedObject;
  4481. indicesByUUID[ uuid ] = firstActiveIndex;
  4482. objects[ firstActiveIndex ] = object;
  4483. // accounting is done, now do the same for all bindings
  4484. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  4485. var bindingsForPath = bindings[ j ],
  4486. lastCached = bindingsForPath[ firstActiveIndex ],
  4487. binding = bindingsForPath[ index ];
  4488. bindingsForPath[ index ] = lastCached;
  4489. if ( binding === undefined ) {
  4490. // since we do not bother to create new bindings
  4491. // for objects that are cached, the binding may
  4492. // or may not exist
  4493. binding = new PropertyBinding( object, paths[ j ], parsedPaths[ j ] );
  4494. }
  4495. bindingsForPath[ firstActiveIndex ] = binding;
  4496. }
  4497. } else if ( objects[ index ] !== knownObject ) {
  4498. console.error( 'THREE.AnimationObjectGroup: Different objects with the same UUID ' +
  4499. 'detected. Clean the caches or recreate your infrastructure when reloading scenes.' );
  4500. } // else the object is already where we want it to be
  4501. } // for arguments
  4502. this.nCachedObjects_ = nCachedObjects;
  4503. },
  4504. remove: function () {
  4505. var objects = this._objects,
  4506. nCachedObjects = this.nCachedObjects_,
  4507. indicesByUUID = this._indicesByUUID,
  4508. bindings = this._bindings,
  4509. nBindings = bindings.length;
  4510. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  4511. var object = arguments[ i ],
  4512. uuid = object.uuid,
  4513. index = indicesByUUID[ uuid ];
  4514. if ( index !== undefined && index >= nCachedObjects ) {
  4515. // move existing object into the CACHED region
  4516. var lastCachedIndex = nCachedObjects ++,
  4517. firstActiveObject = objects[ lastCachedIndex ];
  4518. indicesByUUID[ firstActiveObject.uuid ] = index;
  4519. objects[ index ] = firstActiveObject;
  4520. indicesByUUID[ uuid ] = lastCachedIndex;
  4521. objects[ lastCachedIndex ] = object;
  4522. // accounting is done, now do the same for all bindings
  4523. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  4524. var bindingsForPath = bindings[ j ],
  4525. firstActive = bindingsForPath[ lastCachedIndex ],
  4526. binding = bindingsForPath[ index ];
  4527. bindingsForPath[ index ] = firstActive;
  4528. bindingsForPath[ lastCachedIndex ] = binding;
  4529. }
  4530. }
  4531. } // for arguments
  4532. this.nCachedObjects_ = nCachedObjects;
  4533. },
  4534. // remove & forget
  4535. uncache: function () {
  4536. var objects = this._objects,
  4537. nObjects = objects.length,
  4538. nCachedObjects = this.nCachedObjects_,
  4539. indicesByUUID = this._indicesByUUID,
  4540. bindings = this._bindings,
  4541. nBindings = bindings.length;
  4542. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  4543. var object = arguments[ i ],
  4544. uuid = object.uuid,
  4545. index = indicesByUUID[ uuid ];
  4546. if ( index !== undefined ) {
  4547. delete indicesByUUID[ uuid ];
  4548. if ( index < nCachedObjects ) {
  4549. // object is cached, shrink the CACHED region
  4550. var firstActiveIndex = -- nCachedObjects,
  4551. lastCachedObject = objects[ firstActiveIndex ],
  4552. lastIndex = -- nObjects,
  4553. lastObject = objects[ lastIndex ];
  4554. // last cached object takes this object's place
  4555. indicesByUUID[ lastCachedObject.uuid ] = index;
  4556. objects[ index ] = lastCachedObject;
  4557. // last object goes to the activated slot and pop
  4558. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  4559. objects[ firstActiveIndex ] = lastObject;
  4560. objects.pop();
  4561. // accounting is done, now do the same for all bindings
  4562. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  4563. var bindingsForPath = bindings[ j ],
  4564. lastCached = bindingsForPath[ firstActiveIndex ],
  4565. last = bindingsForPath[ lastIndex ];
  4566. bindingsForPath[ index ] = lastCached;
  4567. bindingsForPath[ firstActiveIndex ] = last;
  4568. bindingsForPath.pop();
  4569. }
  4570. } else {
  4571. // object is active, just swap with the last and pop
  4572. var lastIndex = -- nObjects,
  4573. lastObject = objects[ lastIndex ];
  4574. indicesByUUID[ lastObject.uuid ] = index;
  4575. objects[ index ] = lastObject;
  4576. objects.pop();
  4577. // accounting is done, now do the same for all bindings
  4578. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  4579. var bindingsForPath = bindings[ j ];
  4580. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  4581. bindingsForPath.pop();
  4582. }
  4583. } // cached or active
  4584. } // if object is known
  4585. } // for arguments
  4586. this.nCachedObjects_ = nCachedObjects;
  4587. },
  4588. // Internal interface used by befriended PropertyBinding.Composite:
  4589. subscribe_: function ( path, parsedPath ) {
  4590. // returns an array of bindings for the given path that is changed
  4591. // according to the contained objects in the group
  4592. var indicesByPath = this._bindingsIndicesByPath,
  4593. index = indicesByPath[ path ],
  4594. bindings = this._bindings;
  4595. if ( index !== undefined ) return bindings[ index ];
  4596. var paths = this._paths,
  4597. parsedPaths = this._parsedPaths,
  4598. objects = this._objects,
  4599. nObjects = objects.length,
  4600. nCachedObjects = this.nCachedObjects_,
  4601. bindingsForPath = new Array( nObjects );
  4602. index = bindings.length;
  4603. indicesByPath[ path ] = index;
  4604. paths.push( path );
  4605. parsedPaths.push( parsedPath );
  4606. bindings.push( bindingsForPath );
  4607. for ( var i = nCachedObjects, n = objects.length; i !== n; ++ i ) {
  4608. var object = objects[ i ];
  4609. bindingsForPath[ i ] = new PropertyBinding( object, path, parsedPath );
  4610. }
  4611. return bindingsForPath;
  4612. },
  4613. unsubscribe_: function ( path ) {
  4614. // tells the group to forget about a property path and no longer
  4615. // update the array previously obtained with 'subscribe_'
  4616. var indicesByPath = this._bindingsIndicesByPath,
  4617. index = indicesByPath[ path ];
  4618. if ( index !== undefined ) {
  4619. var paths = this._paths,
  4620. parsedPaths = this._parsedPaths,
  4621. bindings = this._bindings,
  4622. lastBindingsIndex = bindings.length - 1,
  4623. lastBindings = bindings[ lastBindingsIndex ],
  4624. lastBindingsPath = path[ lastBindingsIndex ];
  4625. indicesByPath[ lastBindingsPath ] = index;
  4626. bindings[ index ] = lastBindings;
  4627. bindings.pop();
  4628. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  4629. parsedPaths.pop();
  4630. paths[ index ] = paths[ lastBindingsIndex ];
  4631. paths.pop();
  4632. }
  4633. }
  4634. } );
  4635. function Euler( x, y, z, order ) {
  4636. this._x = x || 0;
  4637. this._y = y || 0;
  4638. this._z = z || 0;
  4639. this._order = order || Euler.DefaultOrder;
  4640. }
  4641. Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  4642. Euler.DefaultOrder = 'XYZ';
  4643. Object.defineProperties( Euler.prototype, {
  4644. x: {
  4645. get: function () {
  4646. return this._x;
  4647. },
  4648. set: function ( value ) {
  4649. this._x = value;
  4650. this.onChangeCallback();
  4651. }
  4652. },
  4653. y: {
  4654. get: function () {
  4655. return this._y;
  4656. },
  4657. set: function ( value ) {
  4658. this._y = value;
  4659. this.onChangeCallback();
  4660. }
  4661. },
  4662. z: {
  4663. get: function () {
  4664. return this._z;
  4665. },
  4666. set: function ( value ) {
  4667. this._z = value;
  4668. this.onChangeCallback();
  4669. }
  4670. },
  4671. order: {
  4672. get: function () {
  4673. return this._order;
  4674. },
  4675. set: function ( value ) {
  4676. this._order = value;
  4677. this.onChangeCallback();
  4678. }
  4679. }
  4680. } );
  4681. Object.assign( Euler.prototype, {
  4682. isEuler: true,
  4683. set: function ( x, y, z, order ) {
  4684. this._x = x;
  4685. this._y = y;
  4686. this._z = z;
  4687. this._order = order || this._order;
  4688. this.onChangeCallback();
  4689. return this;
  4690. },
  4691. clone: function () {
  4692. return new this.constructor( this._x, this._y, this._z, this._order );
  4693. },
  4694. copy: function ( euler ) {
  4695. this._x = euler._x;
  4696. this._y = euler._y;
  4697. this._z = euler._z;
  4698. this._order = euler._order;
  4699. this.onChangeCallback();
  4700. return this;
  4701. },
  4702. setFromRotationMatrix: function ( m, order, update ) {
  4703. var clamp = _Math.clamp;
  4704. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4705. var te = m.elements;
  4706. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  4707. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  4708. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  4709. order = order || this._order;
  4710. if ( order === 'XYZ' ) {
  4711. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  4712. if ( Math.abs( m13 ) < 0.99999 ) {
  4713. this._x = Math.atan2( - m23, m33 );
  4714. this._z = Math.atan2( - m12, m11 );
  4715. } else {
  4716. this._x = Math.atan2( m32, m22 );
  4717. this._z = 0;
  4718. }
  4719. } else if ( order === 'YXZ' ) {
  4720. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  4721. if ( Math.abs( m23 ) < 0.99999 ) {
  4722. this._y = Math.atan2( m13, m33 );
  4723. this._z = Math.atan2( m21, m22 );
  4724. } else {
  4725. this._y = Math.atan2( - m31, m11 );
  4726. this._z = 0;
  4727. }
  4728. } else if ( order === 'ZXY' ) {
  4729. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  4730. if ( Math.abs( m32 ) < 0.99999 ) {
  4731. this._y = Math.atan2( - m31, m33 );
  4732. this._z = Math.atan2( - m12, m22 );
  4733. } else {
  4734. this._y = 0;
  4735. this._z = Math.atan2( m21, m11 );
  4736. }
  4737. } else if ( order === 'ZYX' ) {
  4738. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  4739. if ( Math.abs( m31 ) < 0.99999 ) {
  4740. this._x = Math.atan2( m32, m33 );
  4741. this._z = Math.atan2( m21, m11 );
  4742. } else {
  4743. this._x = 0;
  4744. this._z = Math.atan2( - m12, m22 );
  4745. }
  4746. } else if ( order === 'YZX' ) {
  4747. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  4748. if ( Math.abs( m21 ) < 0.99999 ) {
  4749. this._x = Math.atan2( - m23, m22 );
  4750. this._y = Math.atan2( - m31, m11 );
  4751. } else {
  4752. this._x = 0;
  4753. this._y = Math.atan2( m13, m33 );
  4754. }
  4755. } else if ( order === 'XZY' ) {
  4756. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  4757. if ( Math.abs( m12 ) < 0.99999 ) {
  4758. this._x = Math.atan2( m32, m22 );
  4759. this._y = Math.atan2( m13, m11 );
  4760. } else {
  4761. this._x = Math.atan2( - m23, m33 );
  4762. this._y = 0;
  4763. }
  4764. } else {
  4765. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order );
  4766. }
  4767. this._order = order;
  4768. if ( update !== false ) this.onChangeCallback();
  4769. return this;
  4770. },
  4771. setFromQuaternion: function () {
  4772. var matrix = new Matrix4();
  4773. return function setFromQuaternion( q, order, update ) {
  4774. matrix.makeRotationFromQuaternion( q );
  4775. return this.setFromRotationMatrix( matrix, order, update );
  4776. };
  4777. }(),
  4778. setFromVector3: function ( v, order ) {
  4779. return this.set( v.x, v.y, v.z, order || this._order );
  4780. },
  4781. reorder: function () {
  4782. // WARNING: this discards revolution information -bhouston
  4783. var q = new Quaternion();
  4784. return function reorder( newOrder ) {
  4785. q.setFromEuler( this );
  4786. return this.setFromQuaternion( q, newOrder );
  4787. };
  4788. }(),
  4789. equals: function ( euler ) {
  4790. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  4791. },
  4792. fromArray: function ( array ) {
  4793. this._x = array[ 0 ];
  4794. this._y = array[ 1 ];
  4795. this._z = array[ 2 ];
  4796. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  4797. this.onChangeCallback();
  4798. return this;
  4799. },
  4800. toArray: function ( array, offset ) {
  4801. if ( array === undefined ) array = [];
  4802. if ( offset === undefined ) offset = 0;
  4803. array[ offset ] = this._x;
  4804. array[ offset + 1 ] = this._y;
  4805. array[ offset + 2 ] = this._z;
  4806. array[ offset + 3 ] = this._order;
  4807. return array;
  4808. },
  4809. toVector3: function ( optionalResult ) {
  4810. if ( optionalResult ) {
  4811. return optionalResult.set( this._x, this._y, this._z );
  4812. } else {
  4813. return new Vector3( this._x, this._y, this._z );
  4814. }
  4815. },
  4816. onChange: function ( callback ) {
  4817. this.onChangeCallback = callback;
  4818. return this;
  4819. },
  4820. onChangeCallback: function () {}
  4821. } );
  4822. /**
  4823. * @author mrdoob / http://mrdoob.com/
  4824. */
  4825. function Layers() {
  4826. this.mask = 1 | 0;
  4827. }
  4828. Object.assign( Layers.prototype, {
  4829. set: function ( channel ) {
  4830. this.mask = 1 << channel | 0;
  4831. },
  4832. enable: function ( channel ) {
  4833. this.mask |= 1 << channel | 0;
  4834. },
  4835. toggle: function ( channel ) {
  4836. this.mask ^= 1 << channel | 0;
  4837. },
  4838. disable: function ( channel ) {
  4839. this.mask &= ~ ( 1 << channel | 0 );
  4840. },
  4841. test: function ( layers ) {
  4842. return ( this.mask & layers.mask ) !== 0;
  4843. }
  4844. } );
  4845. function Matrix3() {
  4846. this.elements = [
  4847. 1, 0, 0,
  4848. 0, 1, 0,
  4849. 0, 0, 1
  4850. ];
  4851. if ( arguments.length > 0 ) {
  4852. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  4853. }
  4854. }
  4855. Object.assign( Matrix3.prototype, {
  4856. isMatrix3: true,
  4857. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  4858. var te = this.elements;
  4859. te[ 0 ] = n11; te[ 1 ] = n21; te[ 2 ] = n31;
  4860. te[ 3 ] = n12; te[ 4 ] = n22; te[ 5 ] = n32;
  4861. te[ 6 ] = n13; te[ 7 ] = n23; te[ 8 ] = n33;
  4862. return this;
  4863. },
  4864. identity: function () {
  4865. this.set(
  4866. 1, 0, 0,
  4867. 0, 1, 0,
  4868. 0, 0, 1
  4869. );
  4870. return this;
  4871. },
  4872. clone: function () {
  4873. return new this.constructor().fromArray( this.elements );
  4874. },
  4875. copy: function ( m ) {
  4876. var te = this.elements;
  4877. var me = m.elements;
  4878. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ];
  4879. te[ 3 ] = me[ 3 ]; te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ];
  4880. te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ]; te[ 8 ] = me[ 8 ];
  4881. return this;
  4882. },
  4883. setFromMatrix4: function ( m ) {
  4884. var me = m.elements;
  4885. this.set(
  4886. me[ 0 ], me[ 4 ], me[ 8 ],
  4887. me[ 1 ], me[ 5 ], me[ 9 ],
  4888. me[ 2 ], me[ 6 ], me[ 10 ]
  4889. );
  4890. return this;
  4891. },
  4892. applyToBufferAttribute: function () {
  4893. var v1 = new Vector3();
  4894. return function applyToBufferAttribute( attribute ) {
  4895. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  4896. v1.x = attribute.getX( i );
  4897. v1.y = attribute.getY( i );
  4898. v1.z = attribute.getZ( i );
  4899. v1.applyMatrix3( this );
  4900. attribute.setXYZ( i, v1.x, v1.y, v1.z );
  4901. }
  4902. return attribute;
  4903. };
  4904. }(),
  4905. multiply: function ( m ) {
  4906. return this.multiplyMatrices( this, m );
  4907. },
  4908. premultiply: function ( m ) {
  4909. return this.multiplyMatrices( m, this );
  4910. },
  4911. multiplyMatrices: function ( a, b ) {
  4912. var ae = a.elements;
  4913. var be = b.elements;
  4914. var te = this.elements;
  4915. var a11 = ae[ 0 ], a12 = ae[ 3 ], a13 = ae[ 6 ];
  4916. var a21 = ae[ 1 ], a22 = ae[ 4 ], a23 = ae[ 7 ];
  4917. var a31 = ae[ 2 ], a32 = ae[ 5 ], a33 = ae[ 8 ];
  4918. var b11 = be[ 0 ], b12 = be[ 3 ], b13 = be[ 6 ];
  4919. var b21 = be[ 1 ], b22 = be[ 4 ], b23 = be[ 7 ];
  4920. var b31 = be[ 2 ], b32 = be[ 5 ], b33 = be[ 8 ];
  4921. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31;
  4922. te[ 3 ] = a11 * b12 + a12 * b22 + a13 * b32;
  4923. te[ 6 ] = a11 * b13 + a12 * b23 + a13 * b33;
  4924. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31;
  4925. te[ 4 ] = a21 * b12 + a22 * b22 + a23 * b32;
  4926. te[ 7 ] = a21 * b13 + a22 * b23 + a23 * b33;
  4927. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31;
  4928. te[ 5 ] = a31 * b12 + a32 * b22 + a33 * b32;
  4929. te[ 8 ] = a31 * b13 + a32 * b23 + a33 * b33;
  4930. return this;
  4931. },
  4932. multiplyScalar: function ( s ) {
  4933. var te = this.elements;
  4934. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  4935. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  4936. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  4937. return this;
  4938. },
  4939. determinant: function () {
  4940. var te = this.elements;
  4941. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  4942. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  4943. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  4944. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  4945. },
  4946. getInverse: function ( matrix, throwOnDegenerate ) {
  4947. if ( matrix && matrix.isMatrix4 ) {
  4948. console.error( "THREE.Matrix3: .getInverse() no longer takes a Matrix4 argument." );
  4949. }
  4950. var me = matrix.elements,
  4951. te = this.elements,
  4952. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ],
  4953. n12 = me[ 3 ], n22 = me[ 4 ], n32 = me[ 5 ],
  4954. n13 = me[ 6 ], n23 = me[ 7 ], n33 = me[ 8 ],
  4955. t11 = n33 * n22 - n32 * n23,
  4956. t12 = n32 * n13 - n33 * n12,
  4957. t13 = n23 * n12 - n22 * n13,
  4958. det = n11 * t11 + n21 * t12 + n31 * t13;
  4959. if ( det === 0 ) {
  4960. var msg = "THREE.Matrix3: .getInverse() can't invert matrix, determinant is 0";
  4961. if ( throwOnDegenerate === true ) {
  4962. throw new Error( msg );
  4963. } else {
  4964. console.warn( msg );
  4965. }
  4966. return this.identity();
  4967. }
  4968. var detInv = 1 / det;
  4969. te[ 0 ] = t11 * detInv;
  4970. te[ 1 ] = ( n31 * n23 - n33 * n21 ) * detInv;
  4971. te[ 2 ] = ( n32 * n21 - n31 * n22 ) * detInv;
  4972. te[ 3 ] = t12 * detInv;
  4973. te[ 4 ] = ( n33 * n11 - n31 * n13 ) * detInv;
  4974. te[ 5 ] = ( n31 * n12 - n32 * n11 ) * detInv;
  4975. te[ 6 ] = t13 * detInv;
  4976. te[ 7 ] = ( n21 * n13 - n23 * n11 ) * detInv;
  4977. te[ 8 ] = ( n22 * n11 - n21 * n12 ) * detInv;
  4978. return this;
  4979. },
  4980. transpose: function () {
  4981. var tmp, m = this.elements;
  4982. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  4983. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  4984. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  4985. return this;
  4986. },
  4987. getNormalMatrix: function ( matrix4 ) {
  4988. return this.setFromMatrix4( matrix4 ).getInverse( this ).transpose();
  4989. },
  4990. transposeIntoArray: function ( r ) {
  4991. var m = this.elements;
  4992. r[ 0 ] = m[ 0 ];
  4993. r[ 1 ] = m[ 3 ];
  4994. r[ 2 ] = m[ 6 ];
  4995. r[ 3 ] = m[ 1 ];
  4996. r[ 4 ] = m[ 4 ];
  4997. r[ 5 ] = m[ 7 ];
  4998. r[ 6 ] = m[ 2 ];
  4999. r[ 7 ] = m[ 5 ];
  5000. r[ 8 ] = m[ 8 ];
  5001. return this;
  5002. },
  5003. setUvTransform: function ( tx, ty, sx, sy, rotation, cx, cy ) {
  5004. var c = Math.cos( rotation );
  5005. var s = Math.sin( rotation );
  5006. this.set(
  5007. sx * c, sx * s, - sx * ( c * cx + s * cy ) + cx + tx,
  5008. - sy * s, sy * c, - sy * ( - s * cx + c * cy ) + cy + ty,
  5009. 0, 0, 1
  5010. );
  5011. },
  5012. scale: function ( sx, sy ) {
  5013. var te = this.elements;
  5014. te[ 0 ] *= sx; te[ 3 ] *= sx; te[ 6 ] *= sx;
  5015. te[ 1 ] *= sy; te[ 4 ] *= sy; te[ 7 ] *= sy;
  5016. return this;
  5017. },
  5018. rotate: function ( theta ) {
  5019. var c = Math.cos( theta );
  5020. var s = Math.sin( theta );
  5021. var te = this.elements;
  5022. var a11 = te[ 0 ], a12 = te[ 3 ], a13 = te[ 6 ];
  5023. var a21 = te[ 1 ], a22 = te[ 4 ], a23 = te[ 7 ];
  5024. te[ 0 ] = c * a11 + s * a21;
  5025. te[ 3 ] = c * a12 + s * a22;
  5026. te[ 6 ] = c * a13 + s * a23;
  5027. te[ 1 ] = - s * a11 + c * a21;
  5028. te[ 4 ] = - s * a12 + c * a22;
  5029. te[ 7 ] = - s * a13 + c * a23;
  5030. return this;
  5031. },
  5032. translate: function ( tx, ty ) {
  5033. var te = this.elements;
  5034. te[ 0 ] += tx * te[ 2 ]; te[ 3 ] += tx * te[ 5 ]; te[ 6 ] += tx * te[ 8 ];
  5035. te[ 1 ] += ty * te[ 2 ]; te[ 4 ] += ty * te[ 5 ]; te[ 7 ] += ty * te[ 8 ];
  5036. return this;
  5037. },
  5038. equals: function ( matrix ) {
  5039. var te = this.elements;
  5040. var me = matrix.elements;
  5041. for ( var i = 0; i < 9; i ++ ) {
  5042. if ( te[ i ] !== me[ i ] ) return false;
  5043. }
  5044. return true;
  5045. },
  5046. fromArray: function ( array, offset ) {
  5047. if ( offset === undefined ) offset = 0;
  5048. for ( var i = 0; i < 9; i ++ ) {
  5049. this.elements[ i ] = array[ i + offset ];
  5050. }
  5051. return this;
  5052. },
  5053. toArray: function ( array, offset ) {
  5054. if ( array === undefined ) array = [];
  5055. if ( offset === undefined ) offset = 0;
  5056. var te = this.elements;
  5057. array[ offset ] = te[ 0 ];
  5058. array[ offset + 1 ] = te[ 1 ];
  5059. array[ offset + 2 ] = te[ 2 ];
  5060. array[ offset + 3 ] = te[ 3 ];
  5061. array[ offset + 4 ] = te[ 4 ];
  5062. array[ offset + 5 ] = te[ 5 ];
  5063. array[ offset + 6 ] = te[ 6 ];
  5064. array[ offset + 7 ] = te[ 7 ];
  5065. array[ offset + 8 ] = te[ 8 ];
  5066. return array;
  5067. }
  5068. } );
  5069. var object3DId = 0;
  5070. function Object3D() {
  5071. Object.defineProperty( this, 'id', { value: object3DId ++ } );
  5072. this.uuid = _Math.generateUUID();
  5073. this.name = '';
  5074. this.type = 'Object3D';
  5075. this.parent = null;
  5076. this.children = [];
  5077. this.up = Object3D.DefaultUp.clone();
  5078. var position = new Vector3();
  5079. var rotation = new Euler();
  5080. var quaternion = new Quaternion();
  5081. var scale = new Vector3( 1, 1, 1 );
  5082. function onRotationChange() {
  5083. quaternion.setFromEuler( rotation, false );
  5084. }
  5085. function onQuaternionChange() {
  5086. rotation.setFromQuaternion( quaternion, undefined, false );
  5087. }
  5088. rotation.onChange( onRotationChange );
  5089. quaternion.onChange( onQuaternionChange );
  5090. Object.defineProperties( this, {
  5091. position: {
  5092. enumerable: true,
  5093. value: position
  5094. },
  5095. rotation: {
  5096. enumerable: true,
  5097. value: rotation
  5098. },
  5099. quaternion: {
  5100. enumerable: true,
  5101. value: quaternion
  5102. },
  5103. scale: {
  5104. enumerable: true,
  5105. value: scale
  5106. },
  5107. modelViewMatrix: {
  5108. value: new Matrix4()
  5109. },
  5110. normalMatrix: {
  5111. value: new Matrix3()
  5112. }
  5113. } );
  5114. this.matrix = new Matrix4();
  5115. this.matrixWorld = new Matrix4();
  5116. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  5117. this.matrixWorldNeedsUpdate = false;
  5118. this.layers = new Layers();
  5119. this.visible = true;
  5120. this.castShadow = false;
  5121. this.receiveShadow = false;
  5122. this.frustumCulled = true;
  5123. this.renderOrder = 0;
  5124. this.userData = {};
  5125. }
  5126. Object3D.DefaultUp = new Vector3( 0, 1, 0 );
  5127. Object3D.DefaultMatrixAutoUpdate = true;
  5128. Object.assign( Object3D.prototype, EventDispatcher.prototype, {
  5129. isObject3D: true,
  5130. onBeforeRender: function () {},
  5131. onAfterRender: function () {},
  5132. applyMatrix: function ( matrix ) {
  5133. this.matrix.multiplyMatrices( matrix, this.matrix );
  5134. this.matrix.decompose( this.position, this.quaternion, this.scale );
  5135. },
  5136. applyQuaternion: function ( q ) {
  5137. this.quaternion.premultiply( q );
  5138. return this;
  5139. },
  5140. setRotationFromAxisAngle: function ( axis, angle ) {
  5141. // assumes axis is normalized
  5142. this.quaternion.setFromAxisAngle( axis, angle );
  5143. },
  5144. setRotationFromEuler: function ( euler ) {
  5145. this.quaternion.setFromEuler( euler, true );
  5146. },
  5147. setRotationFromMatrix: function ( m ) {
  5148. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  5149. this.quaternion.setFromRotationMatrix( m );
  5150. },
  5151. setRotationFromQuaternion: function ( q ) {
  5152. // assumes q is normalized
  5153. this.quaternion.copy( q );
  5154. },
  5155. rotateOnAxis: function () {
  5156. // rotate object on axis in object space
  5157. // axis is assumed to be normalized
  5158. var q1 = new Quaternion();
  5159. return function rotateOnAxis( axis, angle ) {
  5160. q1.setFromAxisAngle( axis, angle );
  5161. this.quaternion.multiply( q1 );
  5162. return this;
  5163. };
  5164. }(),
  5165. rotateOnWorldAxis: function () {
  5166. // rotate object on axis in world space
  5167. // axis is assumed to be normalized
  5168. // method assumes no rotated parent
  5169. var q1 = new Quaternion();
  5170. return function rotateOnWorldAxis( axis, angle ) {
  5171. q1.setFromAxisAngle( axis, angle );
  5172. this.quaternion.premultiply( q1 );
  5173. return this;
  5174. };
  5175. }(),
  5176. rotateX: function () {
  5177. var v1 = new Vector3( 1, 0, 0 );
  5178. return function rotateX( angle ) {
  5179. return this.rotateOnAxis( v1, angle );
  5180. };
  5181. }(),
  5182. rotateY: function () {
  5183. var v1 = new Vector3( 0, 1, 0 );
  5184. return function rotateY( angle ) {
  5185. return this.rotateOnAxis( v1, angle );
  5186. };
  5187. }(),
  5188. rotateZ: function () {
  5189. var v1 = new Vector3( 0, 0, 1 );
  5190. return function rotateZ( angle ) {
  5191. return this.rotateOnAxis( v1, angle );
  5192. };
  5193. }(),
  5194. translateOnAxis: function () {
  5195. // translate object by distance along axis in object space
  5196. // axis is assumed to be normalized
  5197. var v1 = new Vector3();
  5198. return function translateOnAxis( axis, distance ) {
  5199. v1.copy( axis ).applyQuaternion( this.quaternion );
  5200. this.position.add( v1.multiplyScalar( distance ) );
  5201. return this;
  5202. };
  5203. }(),
  5204. translateX: function () {
  5205. var v1 = new Vector3( 1, 0, 0 );
  5206. return function translateX( distance ) {
  5207. return this.translateOnAxis( v1, distance );
  5208. };
  5209. }(),
  5210. translateY: function () {
  5211. var v1 = new Vector3( 0, 1, 0 );
  5212. return function translateY( distance ) {
  5213. return this.translateOnAxis( v1, distance );
  5214. };
  5215. }(),
  5216. translateZ: function () {
  5217. var v1 = new Vector3( 0, 0, 1 );
  5218. return function translateZ( distance ) {
  5219. return this.translateOnAxis( v1, distance );
  5220. };
  5221. }(),
  5222. localToWorld: function ( vector ) {
  5223. return vector.applyMatrix4( this.matrixWorld );
  5224. },
  5225. worldToLocal: function () {
  5226. var m1 = new Matrix4();
  5227. return function worldToLocal( vector ) {
  5228. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  5229. };
  5230. }(),
  5231. lookAt: function () {
  5232. // This method does not support objects with rotated and/or translated parent(s)
  5233. var m1 = new Matrix4();
  5234. var vector = new Vector3();
  5235. return function lookAt( x, y, z ) {
  5236. if ( x.isVector3 ) {
  5237. vector.copy( x );
  5238. } else {
  5239. vector.set( x, y, z );
  5240. }
  5241. if ( this.isCamera ) {
  5242. m1.lookAt( this.position, vector, this.up );
  5243. } else {
  5244. m1.lookAt( vector, this.position, this.up );
  5245. }
  5246. this.quaternion.setFromRotationMatrix( m1 );
  5247. };
  5248. }(),
  5249. add: function ( object ) {
  5250. if ( arguments.length > 1 ) {
  5251. for ( var i = 0; i < arguments.length; i ++ ) {
  5252. this.add( arguments[ i ] );
  5253. }
  5254. return this;
  5255. }
  5256. if ( object === this ) {
  5257. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  5258. return this;
  5259. }
  5260. if ( ( object && object.isObject3D ) ) {
  5261. if ( object.parent !== null ) {
  5262. object.parent.remove( object );
  5263. }
  5264. object.parent = this;
  5265. object.dispatchEvent( { type: 'added' } );
  5266. this.children.push( object );
  5267. } else {
  5268. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  5269. }
  5270. return this;
  5271. },
  5272. remove: function ( object ) {
  5273. if ( arguments.length > 1 ) {
  5274. for ( var i = 0; i < arguments.length; i ++ ) {
  5275. this.remove( arguments[ i ] );
  5276. }
  5277. return this;
  5278. }
  5279. var index = this.children.indexOf( object );
  5280. if ( index !== - 1 ) {
  5281. object.parent = null;
  5282. object.dispatchEvent( { type: 'removed' } );
  5283. this.children.splice( index, 1 );
  5284. }
  5285. return this;
  5286. },
  5287. getObjectById: function ( id ) {
  5288. return this.getObjectByProperty( 'id', id );
  5289. },
  5290. getObjectByName: function ( name ) {
  5291. return this.getObjectByProperty( 'name', name );
  5292. },
  5293. getObjectByProperty: function ( name, value ) {
  5294. if ( this[ name ] === value ) return this;
  5295. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  5296. var child = this.children[ i ];
  5297. var object = child.getObjectByProperty( name, value );
  5298. if ( object !== undefined ) {
  5299. return object;
  5300. }
  5301. }
  5302. return undefined;
  5303. },
  5304. getWorldPosition: function ( optionalTarget ) {
  5305. var result = optionalTarget || new Vector3();
  5306. this.updateMatrixWorld( true );
  5307. return result.setFromMatrixPosition( this.matrixWorld );
  5308. },
  5309. getWorldQuaternion: function () {
  5310. var position = new Vector3();
  5311. var scale = new Vector3();
  5312. return function getWorldQuaternion( optionalTarget ) {
  5313. var result = optionalTarget || new Quaternion();
  5314. this.updateMatrixWorld( true );
  5315. this.matrixWorld.decompose( position, result, scale );
  5316. return result;
  5317. };
  5318. }(),
  5319. getWorldRotation: function () {
  5320. var quaternion = new Quaternion();
  5321. return function getWorldRotation( optionalTarget ) {
  5322. var result = optionalTarget || new Euler();
  5323. this.getWorldQuaternion( quaternion );
  5324. return result.setFromQuaternion( quaternion, this.rotation.order, false );
  5325. };
  5326. }(),
  5327. getWorldScale: function () {
  5328. var position = new Vector3();
  5329. var quaternion = new Quaternion();
  5330. return function getWorldScale( optionalTarget ) {
  5331. var result = optionalTarget || new Vector3();
  5332. this.updateMatrixWorld( true );
  5333. this.matrixWorld.decompose( position, quaternion, result );
  5334. return result;
  5335. };
  5336. }(),
  5337. getWorldDirection: function () {
  5338. var quaternion = new Quaternion();
  5339. return function getWorldDirection( optionalTarget ) {
  5340. var result = optionalTarget || new Vector3();
  5341. this.getWorldQuaternion( quaternion );
  5342. return result.set( 0, 0, 1 ).applyQuaternion( quaternion );
  5343. };
  5344. }(),
  5345. raycast: function () {},
  5346. traverse: function ( callback ) {
  5347. callback( this );
  5348. var children = this.children;
  5349. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5350. children[ i ].traverse( callback );
  5351. }
  5352. },
  5353. traverseVisible: function ( callback ) {
  5354. if ( this.visible === false ) return;
  5355. callback( this );
  5356. var children = this.children;
  5357. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5358. children[ i ].traverseVisible( callback );
  5359. }
  5360. },
  5361. traverseAncestors: function ( callback ) {
  5362. var parent = this.parent;
  5363. if ( parent !== null ) {
  5364. callback( parent );
  5365. parent.traverseAncestors( callback );
  5366. }
  5367. },
  5368. updateMatrix: function () {
  5369. this.matrix.compose( this.position, this.quaternion, this.scale );
  5370. this.matrixWorldNeedsUpdate = true;
  5371. },
  5372. updateMatrixWorld: function ( force ) {
  5373. if ( this.matrixAutoUpdate ) this.updateMatrix();
  5374. if ( this.matrixWorldNeedsUpdate || force ) {
  5375. if ( this.parent === null ) {
  5376. this.matrixWorld.copy( this.matrix );
  5377. } else {
  5378. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  5379. }
  5380. this.matrixWorldNeedsUpdate = false;
  5381. force = true;
  5382. }
  5383. // update children
  5384. var children = this.children;
  5385. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5386. children[ i ].updateMatrixWorld( force );
  5387. }
  5388. },
  5389. toJSON: function ( meta ) {
  5390. // meta is a string when called from JSON.stringify
  5391. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  5392. var output = {};
  5393. // meta is a hash used to collect geometries, materials.
  5394. // not providing it implies that this is the root object
  5395. // being serialized.
  5396. if ( isRootObject ) {
  5397. // initialize meta obj
  5398. meta = {
  5399. geometries: {},
  5400. materials: {},
  5401. textures: {},
  5402. images: {}
  5403. };
  5404. output.metadata = {
  5405. version: 4.5,
  5406. type: 'Object',
  5407. generator: 'Object3D.toJSON'
  5408. };
  5409. }
  5410. // standard Object3D serialization
  5411. var object = {};
  5412. object.uuid = this.uuid;
  5413. object.type = this.type;
  5414. if ( this.name !== '' ) object.name = this.name;
  5415. if ( this.castShadow === true ) object.castShadow = true;
  5416. if ( this.receiveShadow === true ) object.receiveShadow = true;
  5417. if ( this.visible === false ) object.visible = false;
  5418. if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
  5419. object.matrix = this.matrix.toArray();
  5420. //
  5421. function serialize( library, element ) {
  5422. if ( library[ element.uuid ] === undefined ) {
  5423. library[ element.uuid ] = element.toJSON( meta );
  5424. }
  5425. return element.uuid;
  5426. }
  5427. if ( this.geometry !== undefined ) {
  5428. object.geometry = serialize( meta.geometries, this.geometry );
  5429. }
  5430. if ( this.material !== undefined ) {
  5431. if ( Array.isArray( this.material ) ) {
  5432. var uuids = [];
  5433. for ( var i = 0, l = this.material.length; i < l; i ++ ) {
  5434. uuids.push( serialize( meta.materials, this.material[ i ] ) );
  5435. }
  5436. object.material = uuids;
  5437. } else {
  5438. object.material = serialize( meta.materials, this.material );
  5439. }
  5440. }
  5441. //
  5442. if ( this.children.length > 0 ) {
  5443. object.children = [];
  5444. for ( var i = 0; i < this.children.length; i ++ ) {
  5445. object.children.push( this.children[ i ].toJSON( meta ).object );
  5446. }
  5447. }
  5448. if ( isRootObject ) {
  5449. var geometries = extractFromCache( meta.geometries );
  5450. var materials = extractFromCache( meta.materials );
  5451. var textures = extractFromCache( meta.textures );
  5452. var images = extractFromCache( meta.images );
  5453. if ( geometries.length > 0 ) output.geometries = geometries;
  5454. if ( materials.length > 0 ) output.materials = materials;
  5455. if ( textures.length > 0 ) output.textures = textures;
  5456. if ( images.length > 0 ) output.images = images;
  5457. }
  5458. output.object = object;
  5459. return output;
  5460. // extract data from the cache hash
  5461. // remove metadata on each item
  5462. // and return as array
  5463. function extractFromCache( cache ) {
  5464. var values = [];
  5465. for ( var key in cache ) {
  5466. var data = cache[ key ];
  5467. delete data.metadata;
  5468. values.push( data );
  5469. }
  5470. return values;
  5471. }
  5472. },
  5473. clone: function ( recursive ) {
  5474. return new this.constructor().copy( this, recursive );
  5475. },
  5476. copy: function ( source, recursive ) {
  5477. if ( recursive === undefined ) recursive = true;
  5478. this.name = source.name;
  5479. this.up.copy( source.up );
  5480. this.position.copy( source.position );
  5481. this.quaternion.copy( source.quaternion );
  5482. this.scale.copy( source.scale );
  5483. this.matrix.copy( source.matrix );
  5484. this.matrixWorld.copy( source.matrixWorld );
  5485. this.matrixAutoUpdate = source.matrixAutoUpdate;
  5486. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  5487. this.layers.mask = source.layers.mask;
  5488. this.visible = source.visible;
  5489. this.castShadow = source.castShadow;
  5490. this.receiveShadow = source.receiveShadow;
  5491. this.frustumCulled = source.frustumCulled;
  5492. this.renderOrder = source.renderOrder;
  5493. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  5494. if ( recursive === true ) {
  5495. for ( var i = 0; i < source.children.length; i ++ ) {
  5496. var child = source.children[ i ];
  5497. this.add( child.clone() );
  5498. }
  5499. }
  5500. return this;
  5501. }
  5502. } );
  5503. /**
  5504. * @author tschw
  5505. * @author TristanVALCKE / https://github.com/Itee
  5506. */
  5507. /* global QUnit */
  5508. QUnit.module( "Animation", () => {
  5509. QUnit.module.todo( "AnimationObjectGroup", () => {
  5510. var ObjectA = new Object3D(),
  5511. ObjectB = new Object3D(),
  5512. ObjectC = new Object3D(),
  5513. PathA = 'object.position',
  5514. PathB = 'object.rotation',
  5515. PathC = 'object.scale',
  5516. ParsedPathA = PropertyBinding.parseTrackName( PathA ),
  5517. ParsedPathB = PropertyBinding.parseTrackName( PathB ),
  5518. ParsedPathC = PropertyBinding.parseTrackName( PathC );
  5519. // INSTANCING
  5520. QUnit.test( "Instancing", ( assert ) => {
  5521. assert.ok( false, "everything's gonna be alright" );
  5522. } );
  5523. // PRIVATE STUFF
  5524. QUnit.test( "subscribe_", ( assert ) => {
  5525. assert.ok( false, "everything's gonna be alright" );
  5526. } ); // Todo: Naming guys -_-'
  5527. QUnit.test( "unsubscribe_", ( assert ) => {
  5528. assert.ok( false, "everything's gonna be alright" );
  5529. } ); // Todo: Naming guys -_-'
  5530. // PUBLIC STUFF
  5531. QUnit.test( "isAnimationObjectGroup", ( assert ) => {
  5532. assert.ok( false, "everything's gonna be alright" );
  5533. } );
  5534. QUnit.test( "add", ( assert ) => {
  5535. assert.ok( false, "everything's gonna be alright" );
  5536. } );
  5537. QUnit.test( "remove", ( assert ) => {
  5538. assert.ok( false, "everything's gonna be alright" );
  5539. } );
  5540. QUnit.test( "uncache", ( assert ) => {
  5541. assert.ok( false, "everything's gonna be alright" );
  5542. } );
  5543. // OTHERS
  5544. QUnit.test( "smoke test", ( assert ) => {
  5545. var expect = function expect( testIndex, group, bindings, path, cached, roots ) {
  5546. var rootNodes = [], pathsOk = true, nodesOk = true;
  5547. for ( var i = group.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  5548. if ( bindings[ i ].path !== path ) pathsOk = false;
  5549. rootNodes.push( bindings[ i ].rootNode );
  5550. }
  5551. for ( var i = 0, n = roots.length; i !== n; ++ i ) {
  5552. if ( rootNodes.indexOf( roots[ i ] ) === - 1 ) nodesOk = false;
  5553. }
  5554. assert.ok( pathsOk, QUnit.testIndex + " paths" );
  5555. assert.ok( nodesOk, QUnit.testIndex + " nodes" );
  5556. assert.ok( group.nCachedObjects_ === cached, QUnit.testIndex + " cache size" );
  5557. assert.ok( bindings.length - group.nCachedObjects_ === roots.length, QUnit.testIndex + " object count" );
  5558. };
  5559. // initial state
  5560. var groupA = new AnimationObjectGroup();
  5561. assert.ok( groupA instanceof AnimationObjectGroup, "constructor (w/o args)" );
  5562. var bindingsAA = groupA.subscribe_( PathA, ParsedPathA );
  5563. expect( 0, groupA, bindingsAA, PathA, 0, [] );
  5564. var groupB = new AnimationObjectGroup( ObjectA, ObjectB );
  5565. assert.ok( groupB instanceof AnimationObjectGroup, "constructor (with args)" );
  5566. var bindingsBB = groupB.subscribe_( PathB, ParsedPathB );
  5567. expect( 1, groupB, bindingsBB, PathB, 0, [ ObjectA, ObjectB ] );
  5568. // add
  5569. groupA.add( ObjectA, ObjectB );
  5570. expect( 2, groupA, bindingsAA, PathA, 0, [ ObjectA, ObjectB ] );
  5571. groupB.add( ObjectC );
  5572. expect( 3, groupB, bindingsBB, PathB, 0, [ ObjectA, ObjectB, ObjectC ] );
  5573. // remove
  5574. groupA.remove( ObjectA, ObjectC );
  5575. expect( 4, groupA, bindingsAA, PathA, 1, [ ObjectB ] );
  5576. groupB.remove( ObjectA, ObjectB, ObjectC );
  5577. expect( 5, groupB, bindingsBB, PathB, 3, [] );
  5578. // subscribe after re-add
  5579. groupA.add( ObjectC );
  5580. expect( 6, groupA, bindingsAA, PathA, 1, [ ObjectB, ObjectC ] );
  5581. var bindingsAC = groupA.subscribe_( PathC, ParsedPathC );
  5582. expect( 7, groupA, bindingsAC, PathC, 1, [ ObjectB, ObjectC ] );
  5583. // re-add after subscribe
  5584. var bindingsBC = groupB.subscribe_( PathC, ParsedPathC );
  5585. groupB.add( ObjectA, ObjectB );
  5586. expect( 8, groupB, bindingsBB, PathB, 1, [ ObjectA, ObjectB ] );
  5587. // unsubscribe
  5588. var copyOfBindingsBC = bindingsBC.slice();
  5589. groupB.unsubscribe_( PathC );
  5590. groupB.add( ObjectC );
  5591. assert.deepEqual( bindingsBC, copyOfBindingsBC, "no more update after unsubscribe" );
  5592. // uncache active
  5593. groupB.uncache( ObjectA );
  5594. expect( 9, groupB, bindingsBB, PathB, 0, [ ObjectB, ObjectC ] );
  5595. // uncache cached
  5596. groupA.uncache( ObjectA );
  5597. expect( 10, groupA, bindingsAC, PathC, 0, [ ObjectB, ObjectC ] );
  5598. } );
  5599. } );
  5600. } );
  5601. /**
  5602. * @author TristanVALCKE / https://github.com/Itee
  5603. */
  5604. /* global QUnit */
  5605. QUnit.module( 'Animation', () => {
  5606. QUnit.module.todo( 'AnimationUtils', () => {
  5607. // PUBLIC STUFF
  5608. QUnit.test( "arraySlice", ( assert ) => {
  5609. assert.ok( false, "everything's gonna be alright" );
  5610. } );
  5611. QUnit.test( "convertArray", ( assert ) => {
  5612. assert.ok( false, "everything's gonna be alright" );
  5613. } );
  5614. QUnit.test( "isTypedArray", ( assert ) => {
  5615. assert.ok( false, "everything's gonna be alright" );
  5616. } );
  5617. QUnit.test( "getKeyframeOrder", ( assert ) => {
  5618. assert.ok( false, "everything's gonna be alright" );
  5619. } );
  5620. QUnit.test( "sortedArray", ( assert ) => {
  5621. assert.ok( false, "everything's gonna be alright" );
  5622. } );
  5623. QUnit.test( "flattenJSON", ( assert ) => {
  5624. assert.ok( false, "everything's gonna be alright" );
  5625. } );
  5626. } );
  5627. } );
  5628. /**
  5629. * @author TristanVALCKE / https://github.com/Itee
  5630. */
  5631. /* global QUnit */
  5632. QUnit.module( 'Animation', () => {
  5633. QUnit.module.todo( 'KeyframeTrack', () => {
  5634. // INSTANCING
  5635. QUnit.test( "Instancing", ( assert ) => {
  5636. assert.ok( false, "everything's gonna be alright" );
  5637. } );
  5638. // STATIC STUFF
  5639. QUnit.test( "parse", ( assert ) => {
  5640. assert.ok( false, "everything's gonna be alright" );
  5641. } );
  5642. QUnit.test( "toJSON", ( assert ) => {
  5643. assert.ok( false, "everything's gonna be alright" );
  5644. } );
  5645. QUnit.test( "_getTrackTypeForValueTypeName", ( assert ) => {
  5646. assert.ok( false, "everything's gonna be alright" );
  5647. } );
  5648. // PUBLIC STUFF
  5649. QUnit.test( "TimeBufferType", ( assert ) => {
  5650. assert.ok( false, "everything's gonna be alright" );
  5651. } );
  5652. QUnit.test( "ValueBufferType", ( assert ) => {
  5653. assert.ok( false, "everything's gonna be alright" );
  5654. } );
  5655. QUnit.test( "DefaultInterpolation", ( assert ) => {
  5656. assert.ok( false, "everything's gonna be alright" );
  5657. } );
  5658. QUnit.test( "InterpolantFactoryMethodDiscrete", ( assert ) => {
  5659. assert.ok( false, "everything's gonna be alright" );
  5660. } );
  5661. QUnit.test( "InterpolantFactoryMethodLinear", ( assert ) => {
  5662. assert.ok( false, "everything's gonna be alright" );
  5663. } );
  5664. QUnit.test( "InterpolantFactoryMethodSmooth", ( assert ) => {
  5665. assert.ok( false, "everything's gonna be alright" );
  5666. } );
  5667. QUnit.test( "setInterpolation", ( assert ) => {
  5668. assert.ok( false, "everything's gonna be alright" );
  5669. } );
  5670. QUnit.test( "getInterpolation", ( assert ) => {
  5671. assert.ok( false, "everything's gonna be alright" );
  5672. } );
  5673. QUnit.test( "getValueSize", ( assert ) => {
  5674. assert.ok( false, "everything's gonna be alright" );
  5675. } );
  5676. QUnit.test( "shift", ( assert ) => {
  5677. assert.ok( false, "everything's gonna be alright" );
  5678. } );
  5679. QUnit.test( "scale", ( assert ) => {
  5680. assert.ok( false, "everything's gonna be alright" );
  5681. } );
  5682. QUnit.test( "trim", ( assert ) => {
  5683. assert.ok( false, "everything's gonna be alright" );
  5684. } );
  5685. QUnit.test( "validate", ( assert ) => {
  5686. assert.ok( false, "everything's gonna be alright" );
  5687. } );
  5688. QUnit.test( "optimize", ( assert ) => {
  5689. assert.ok( false, "everything's gonna be alright" );
  5690. } );
  5691. } );
  5692. } );
  5693. var ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  5694. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  5695. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  5696. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  5697. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  5698. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  5699. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  5700. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  5701. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  5702. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  5703. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  5704. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  5705. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  5706. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  5707. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  5708. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  5709. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  5710. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  5711. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  5712. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'rebeccapurple': 0x663399, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  5713. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  5714. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  5715. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  5716. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  5717. function Color( r, g, b ) {
  5718. if ( g === undefined && b === undefined ) {
  5719. // r is THREE.Color, hex or string
  5720. return this.set( r );
  5721. }
  5722. return this.setRGB( r, g, b );
  5723. }
  5724. Object.assign( Color.prototype, {
  5725. isColor: true,
  5726. r: 1, g: 1, b: 1,
  5727. set: function ( value ) {
  5728. if ( value && value.isColor ) {
  5729. this.copy( value );
  5730. } else if ( typeof value === 'number' ) {
  5731. this.setHex( value );
  5732. } else if ( typeof value === 'string' ) {
  5733. this.setStyle( value );
  5734. }
  5735. return this;
  5736. },
  5737. setScalar: function ( scalar ) {
  5738. this.r = scalar;
  5739. this.g = scalar;
  5740. this.b = scalar;
  5741. return this;
  5742. },
  5743. setHex: function ( hex ) {
  5744. hex = Math.floor( hex );
  5745. this.r = ( hex >> 16 & 255 ) / 255;
  5746. this.g = ( hex >> 8 & 255 ) / 255;
  5747. this.b = ( hex & 255 ) / 255;
  5748. return this;
  5749. },
  5750. setRGB: function ( r, g, b ) {
  5751. this.r = r;
  5752. this.g = g;
  5753. this.b = b;
  5754. return this;
  5755. },
  5756. setHSL: function () {
  5757. function hue2rgb( p, q, t ) {
  5758. if ( t < 0 ) t += 1;
  5759. if ( t > 1 ) t -= 1;
  5760. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  5761. if ( t < 1 / 2 ) return q;
  5762. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  5763. return p;
  5764. }
  5765. return function setHSL( h, s, l ) {
  5766. // h,s,l ranges are in 0.0 - 1.0
  5767. h = _Math.euclideanModulo( h, 1 );
  5768. s = _Math.clamp( s, 0, 1 );
  5769. l = _Math.clamp( l, 0, 1 );
  5770. if ( s === 0 ) {
  5771. this.r = this.g = this.b = l;
  5772. } else {
  5773. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  5774. var q = ( 2 * l ) - p;
  5775. this.r = hue2rgb( q, p, h + 1 / 3 );
  5776. this.g = hue2rgb( q, p, h );
  5777. this.b = hue2rgb( q, p, h - 1 / 3 );
  5778. }
  5779. return this;
  5780. };
  5781. }(),
  5782. setStyle: function ( style ) {
  5783. function handleAlpha( string ) {
  5784. if ( string === undefined ) return;
  5785. if ( parseFloat( string ) < 1 ) {
  5786. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  5787. }
  5788. }
  5789. var m;
  5790. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  5791. // rgb / hsl
  5792. var color;
  5793. var name = m[ 1 ];
  5794. var components = m[ 2 ];
  5795. switch ( name ) {
  5796. case 'rgb':
  5797. case 'rgba':
  5798. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  5799. // rgb(255,0,0) rgba(255,0,0,0.5)
  5800. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  5801. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  5802. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  5803. handleAlpha( color[ 5 ] );
  5804. return this;
  5805. }
  5806. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  5807. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  5808. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  5809. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  5810. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  5811. handleAlpha( color[ 5 ] );
  5812. return this;
  5813. }
  5814. break;
  5815. case 'hsl':
  5816. case 'hsla':
  5817. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  5818. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  5819. var h = parseFloat( color[ 1 ] ) / 360;
  5820. var s = parseInt( color[ 2 ], 10 ) / 100;
  5821. var l = parseInt( color[ 3 ], 10 ) / 100;
  5822. handleAlpha( color[ 5 ] );
  5823. return this.setHSL( h, s, l );
  5824. }
  5825. break;
  5826. }
  5827. } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  5828. // hex color
  5829. var hex = m[ 1 ];
  5830. var size = hex.length;
  5831. if ( size === 3 ) {
  5832. // #ff0
  5833. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  5834. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  5835. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  5836. return this;
  5837. } else if ( size === 6 ) {
  5838. // #ff0000
  5839. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  5840. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  5841. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  5842. return this;
  5843. }
  5844. }
  5845. if ( style && style.length > 0 ) {
  5846. // color keywords
  5847. var hex = ColorKeywords[ style ];
  5848. if ( hex !== undefined ) {
  5849. // red
  5850. this.setHex( hex );
  5851. } else {
  5852. // unknown color
  5853. console.warn( 'THREE.Color: Unknown color ' + style );
  5854. }
  5855. }
  5856. return this;
  5857. },
  5858. clone: function () {
  5859. return new this.constructor( this.r, this.g, this.b );
  5860. },
  5861. copy: function ( color ) {
  5862. this.r = color.r;
  5863. this.g = color.g;
  5864. this.b = color.b;
  5865. return this;
  5866. },
  5867. copyGammaToLinear: function ( color, gammaFactor ) {
  5868. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  5869. this.r = Math.pow( color.r, gammaFactor );
  5870. this.g = Math.pow( color.g, gammaFactor );
  5871. this.b = Math.pow( color.b, gammaFactor );
  5872. return this;
  5873. },
  5874. copyLinearToGamma: function ( color, gammaFactor ) {
  5875. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  5876. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  5877. this.r = Math.pow( color.r, safeInverse );
  5878. this.g = Math.pow( color.g, safeInverse );
  5879. this.b = Math.pow( color.b, safeInverse );
  5880. return this;
  5881. },
  5882. convertGammaToLinear: function () {
  5883. var r = this.r, g = this.g, b = this.b;
  5884. this.r = r * r;
  5885. this.g = g * g;
  5886. this.b = b * b;
  5887. return this;
  5888. },
  5889. convertLinearToGamma: function () {
  5890. this.r = Math.sqrt( this.r );
  5891. this.g = Math.sqrt( this.g );
  5892. this.b = Math.sqrt( this.b );
  5893. return this;
  5894. },
  5895. getHex: function () {
  5896. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  5897. },
  5898. getHexString: function () {
  5899. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  5900. },
  5901. getHSL: function ( optionalTarget ) {
  5902. // h,s,l ranges are in 0.0 - 1.0
  5903. var hsl = optionalTarget || { h: 0, s: 0, l: 0 };
  5904. var r = this.r, g = this.g, b = this.b;
  5905. var max = Math.max( r, g, b );
  5906. var min = Math.min( r, g, b );
  5907. var hue, saturation;
  5908. var lightness = ( min + max ) / 2.0;
  5909. if ( min === max ) {
  5910. hue = 0;
  5911. saturation = 0;
  5912. } else {
  5913. var delta = max - min;
  5914. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  5915. switch ( max ) {
  5916. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  5917. case g: hue = ( b - r ) / delta + 2; break;
  5918. case b: hue = ( r - g ) / delta + 4; break;
  5919. }
  5920. hue /= 6;
  5921. }
  5922. hsl.h = hue;
  5923. hsl.s = saturation;
  5924. hsl.l = lightness;
  5925. return hsl;
  5926. },
  5927. getStyle: function () {
  5928. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  5929. },
  5930. offsetHSL: function ( h, s, l ) {
  5931. var hsl = this.getHSL();
  5932. hsl.h += h; hsl.s += s; hsl.l += l;
  5933. this.setHSL( hsl.h, hsl.s, hsl.l );
  5934. return this;
  5935. },
  5936. add: function ( color ) {
  5937. this.r += color.r;
  5938. this.g += color.g;
  5939. this.b += color.b;
  5940. return this;
  5941. },
  5942. addColors: function ( color1, color2 ) {
  5943. this.r = color1.r + color2.r;
  5944. this.g = color1.g + color2.g;
  5945. this.b = color1.b + color2.b;
  5946. return this;
  5947. },
  5948. addScalar: function ( s ) {
  5949. this.r += s;
  5950. this.g += s;
  5951. this.b += s;
  5952. return this;
  5953. },
  5954. sub: function ( color ) {
  5955. this.r = Math.max( 0, this.r - color.r );
  5956. this.g = Math.max( 0, this.g - color.g );
  5957. this.b = Math.max( 0, this.b - color.b );
  5958. return this;
  5959. },
  5960. multiply: function ( color ) {
  5961. this.r *= color.r;
  5962. this.g *= color.g;
  5963. this.b *= color.b;
  5964. return this;
  5965. },
  5966. multiplyScalar: function ( s ) {
  5967. this.r *= s;
  5968. this.g *= s;
  5969. this.b *= s;
  5970. return this;
  5971. },
  5972. lerp: function ( color, alpha ) {
  5973. this.r += ( color.r - this.r ) * alpha;
  5974. this.g += ( color.g - this.g ) * alpha;
  5975. this.b += ( color.b - this.b ) * alpha;
  5976. return this;
  5977. },
  5978. equals: function ( c ) {
  5979. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  5980. },
  5981. fromArray: function ( array, offset ) {
  5982. if ( offset === undefined ) offset = 0;
  5983. this.r = array[ offset ];
  5984. this.g = array[ offset + 1 ];
  5985. this.b = array[ offset + 2 ];
  5986. return this;
  5987. },
  5988. toArray: function ( array, offset ) {
  5989. if ( array === undefined ) array = [];
  5990. if ( offset === undefined ) offset = 0;
  5991. array[ offset ] = this.r;
  5992. array[ offset + 1 ] = this.g;
  5993. array[ offset + 2 ] = this.b;
  5994. return array;
  5995. },
  5996. toJSON: function () {
  5997. return this.getHex();
  5998. }
  5999. } );
  6000. function Face3( a, b, c, normal, color, materialIndex ) {
  6001. this.a = a;
  6002. this.b = b;
  6003. this.c = c;
  6004. this.normal = ( normal && normal.isVector3 ) ? normal : new Vector3();
  6005. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  6006. this.color = ( color && color.isColor ) ? color : new Color();
  6007. this.vertexColors = Array.isArray( color ) ? color : [];
  6008. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  6009. }
  6010. Object.assign( Face3.prototype, {
  6011. clone: function () {
  6012. return new this.constructor().copy( this );
  6013. },
  6014. copy: function ( source ) {
  6015. this.a = source.a;
  6016. this.b = source.b;
  6017. this.c = source.c;
  6018. this.normal.copy( source.normal );
  6019. this.color.copy( source.color );
  6020. this.materialIndex = source.materialIndex;
  6021. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  6022. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  6023. }
  6024. for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  6025. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  6026. }
  6027. return this;
  6028. }
  6029. } );
  6030. function Box3( min, max ) {
  6031. this.min = ( min !== undefined ) ? min : new Vector3( + Infinity, + Infinity, + Infinity );
  6032. this.max = ( max !== undefined ) ? max : new Vector3( - Infinity, - Infinity, - Infinity );
  6033. }
  6034. Object.assign( Box3.prototype, {
  6035. isBox3: true,
  6036. set: function ( min, max ) {
  6037. this.min.copy( min );
  6038. this.max.copy( max );
  6039. return this;
  6040. },
  6041. setFromArray: function ( array ) {
  6042. var minX = + Infinity;
  6043. var minY = + Infinity;
  6044. var minZ = + Infinity;
  6045. var maxX = - Infinity;
  6046. var maxY = - Infinity;
  6047. var maxZ = - Infinity;
  6048. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  6049. var x = array[ i ];
  6050. var y = array[ i + 1 ];
  6051. var z = array[ i + 2 ];
  6052. if ( x < minX ) minX = x;
  6053. if ( y < minY ) minY = y;
  6054. if ( z < minZ ) minZ = z;
  6055. if ( x > maxX ) maxX = x;
  6056. if ( y > maxY ) maxY = y;
  6057. if ( z > maxZ ) maxZ = z;
  6058. }
  6059. this.min.set( minX, minY, minZ );
  6060. this.max.set( maxX, maxY, maxZ );
  6061. return this;
  6062. },
  6063. setFromBufferAttribute: function ( attribute ) {
  6064. var minX = + Infinity;
  6065. var minY = + Infinity;
  6066. var minZ = + Infinity;
  6067. var maxX = - Infinity;
  6068. var maxY = - Infinity;
  6069. var maxZ = - Infinity;
  6070. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  6071. var x = attribute.getX( i );
  6072. var y = attribute.getY( i );
  6073. var z = attribute.getZ( i );
  6074. if ( x < minX ) minX = x;
  6075. if ( y < minY ) minY = y;
  6076. if ( z < minZ ) minZ = z;
  6077. if ( x > maxX ) maxX = x;
  6078. if ( y > maxY ) maxY = y;
  6079. if ( z > maxZ ) maxZ = z;
  6080. }
  6081. this.min.set( minX, minY, minZ );
  6082. this.max.set( maxX, maxY, maxZ );
  6083. return this;
  6084. },
  6085. setFromPoints: function ( points ) {
  6086. this.makeEmpty();
  6087. for ( var i = 0, il = points.length; i < il; i ++ ) {
  6088. this.expandByPoint( points[ i ] );
  6089. }
  6090. return this;
  6091. },
  6092. setFromCenterAndSize: function () {
  6093. var v1 = new Vector3();
  6094. return function setFromCenterAndSize( center, size ) {
  6095. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  6096. this.min.copy( center ).sub( halfSize );
  6097. this.max.copy( center ).add( halfSize );
  6098. return this;
  6099. };
  6100. }(),
  6101. setFromObject: function ( object ) {
  6102. this.makeEmpty();
  6103. return this.expandByObject( object );
  6104. },
  6105. clone: function () {
  6106. return new this.constructor().copy( this );
  6107. },
  6108. copy: function ( box ) {
  6109. this.min.copy( box.min );
  6110. this.max.copy( box.max );
  6111. return this;
  6112. },
  6113. makeEmpty: function () {
  6114. this.min.x = this.min.y = this.min.z = + Infinity;
  6115. this.max.x = this.max.y = this.max.z = - Infinity;
  6116. return this;
  6117. },
  6118. isEmpty: function () {
  6119. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  6120. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  6121. },
  6122. getCenter: function ( optionalTarget ) {
  6123. var result = optionalTarget || new Vector3();
  6124. return this.isEmpty() ? result.set( 0, 0, 0 ) : result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  6125. },
  6126. getSize: function ( optionalTarget ) {
  6127. var result = optionalTarget || new Vector3();
  6128. return this.isEmpty() ? result.set( 0, 0, 0 ) : result.subVectors( this.max, this.min );
  6129. },
  6130. expandByPoint: function ( point ) {
  6131. this.min.min( point );
  6132. this.max.max( point );
  6133. return this;
  6134. },
  6135. expandByVector: function ( vector ) {
  6136. this.min.sub( vector );
  6137. this.max.add( vector );
  6138. return this;
  6139. },
  6140. expandByScalar: function ( scalar ) {
  6141. this.min.addScalar( - scalar );
  6142. this.max.addScalar( scalar );
  6143. return this;
  6144. },
  6145. expandByObject: function () {
  6146. // Computes the world-axis-aligned bounding box of an object (including its children),
  6147. // accounting for both the object's, and children's, world transforms
  6148. var scope, i, l;
  6149. var v1 = new Vector3();
  6150. function traverse( node ) {
  6151. var geometry = node.geometry;
  6152. if ( geometry !== undefined ) {
  6153. if ( geometry.isGeometry ) {
  6154. var vertices = geometry.vertices;
  6155. for ( i = 0, l = vertices.length; i < l; i ++ ) {
  6156. v1.copy( vertices[ i ] );
  6157. v1.applyMatrix4( node.matrixWorld );
  6158. scope.expandByPoint( v1 );
  6159. }
  6160. } else if ( geometry.isBufferGeometry ) {
  6161. var attribute = geometry.attributes.position;
  6162. if ( attribute !== undefined ) {
  6163. for ( i = 0, l = attribute.count; i < l; i ++ ) {
  6164. v1.fromBufferAttribute( attribute, i ).applyMatrix4( node.matrixWorld );
  6165. scope.expandByPoint( v1 );
  6166. }
  6167. }
  6168. }
  6169. }
  6170. }
  6171. return function expandByObject( object ) {
  6172. scope = this;
  6173. object.updateMatrixWorld( true );
  6174. object.traverse( traverse );
  6175. return this;
  6176. };
  6177. }(),
  6178. containsPoint: function ( point ) {
  6179. return point.x < this.min.x || point.x > this.max.x ||
  6180. point.y < this.min.y || point.y > this.max.y ||
  6181. point.z < this.min.z || point.z > this.max.z ? false : true;
  6182. },
  6183. containsBox: function ( box ) {
  6184. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  6185. this.min.y <= box.min.y && box.max.y <= this.max.y &&
  6186. this.min.z <= box.min.z && box.max.z <= this.max.z;
  6187. },
  6188. getParameter: function ( point, optionalTarget ) {
  6189. // This can potentially have a divide by zero if the box
  6190. // has a size dimension of 0.
  6191. var result = optionalTarget || new Vector3();
  6192. return result.set(
  6193. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  6194. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  6195. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  6196. );
  6197. },
  6198. intersectsBox: function ( box ) {
  6199. // using 6 splitting planes to rule out intersections.
  6200. return box.max.x < this.min.x || box.min.x > this.max.x ||
  6201. box.max.y < this.min.y || box.min.y > this.max.y ||
  6202. box.max.z < this.min.z || box.min.z > this.max.z ? false : true;
  6203. },
  6204. intersectsSphere: ( function () {
  6205. var closestPoint = new Vector3();
  6206. return function intersectsSphere( sphere ) {
  6207. // Find the point on the AABB closest to the sphere center.
  6208. this.clampPoint( sphere.center, closestPoint );
  6209. // If that point is inside the sphere, the AABB and sphere intersect.
  6210. return closestPoint.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  6211. };
  6212. } )(),
  6213. intersectsPlane: function ( plane ) {
  6214. // We compute the minimum and maximum dot product values. If those values
  6215. // are on the same side (back or front) of the plane, then there is no intersection.
  6216. var min, max;
  6217. if ( plane.normal.x > 0 ) {
  6218. min = plane.normal.x * this.min.x;
  6219. max = plane.normal.x * this.max.x;
  6220. } else {
  6221. min = plane.normal.x * this.max.x;
  6222. max = plane.normal.x * this.min.x;
  6223. }
  6224. if ( plane.normal.y > 0 ) {
  6225. min += plane.normal.y * this.min.y;
  6226. max += plane.normal.y * this.max.y;
  6227. } else {
  6228. min += plane.normal.y * this.max.y;
  6229. max += plane.normal.y * this.min.y;
  6230. }
  6231. if ( plane.normal.z > 0 ) {
  6232. min += plane.normal.z * this.min.z;
  6233. max += plane.normal.z * this.max.z;
  6234. } else {
  6235. min += plane.normal.z * this.max.z;
  6236. max += plane.normal.z * this.min.z;
  6237. }
  6238. return ( min <= plane.constant && max >= plane.constant );
  6239. },
  6240. clampPoint: function ( point, optionalTarget ) {
  6241. var result = optionalTarget || new Vector3();
  6242. return result.copy( point ).clamp( this.min, this.max );
  6243. },
  6244. distanceToPoint: function () {
  6245. var v1 = new Vector3();
  6246. return function distanceToPoint( point ) {
  6247. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  6248. return clampedPoint.sub( point ).length();
  6249. };
  6250. }(),
  6251. getBoundingSphere: function () {
  6252. var v1 = new Vector3();
  6253. return function getBoundingSphere( optionalTarget ) {
  6254. var result = optionalTarget || new Sphere();
  6255. this.getCenter( result.center );
  6256. result.radius = this.getSize( v1 ).length() * 0.5;
  6257. return result;
  6258. };
  6259. }(),
  6260. intersect: function ( box ) {
  6261. this.min.max( box.min );
  6262. this.max.min( box.max );
  6263. // ensure that if there is no overlap, the result is fully empty, not slightly empty with non-inf/+inf values that will cause subsequence intersects to erroneously return valid values.
  6264. if ( this.isEmpty() ) this.makeEmpty();
  6265. return this;
  6266. },
  6267. union: function ( box ) {
  6268. this.min.min( box.min );
  6269. this.max.max( box.max );
  6270. return this;
  6271. },
  6272. applyMatrix4: function () {
  6273. var points = [
  6274. new Vector3(),
  6275. new Vector3(),
  6276. new Vector3(),
  6277. new Vector3(),
  6278. new Vector3(),
  6279. new Vector3(),
  6280. new Vector3(),
  6281. new Vector3()
  6282. ];
  6283. return function applyMatrix4( matrix ) {
  6284. // transform of empty box is an empty box.
  6285. if ( this.isEmpty() ) return this;
  6286. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  6287. points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  6288. points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  6289. points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  6290. points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  6291. points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  6292. points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  6293. points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  6294. points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  6295. this.setFromPoints( points );
  6296. return this;
  6297. };
  6298. }(),
  6299. translate: function ( offset ) {
  6300. this.min.add( offset );
  6301. this.max.add( offset );
  6302. return this;
  6303. },
  6304. equals: function ( box ) {
  6305. return box.min.equals( this.min ) && box.max.equals( this.max );
  6306. }
  6307. } );
  6308. function Sphere( center, radius ) {
  6309. this.center = ( center !== undefined ) ? center : new Vector3();
  6310. this.radius = ( radius !== undefined ) ? radius : 0;
  6311. }
  6312. Object.assign( Sphere.prototype, {
  6313. set: function ( center, radius ) {
  6314. this.center.copy( center );
  6315. this.radius = radius;
  6316. return this;
  6317. },
  6318. setFromPoints: function () {
  6319. var box = new Box3();
  6320. return function setFromPoints( points, optionalCenter ) {
  6321. var center = this.center;
  6322. if ( optionalCenter !== undefined ) {
  6323. center.copy( optionalCenter );
  6324. } else {
  6325. box.setFromPoints( points ).getCenter( center );
  6326. }
  6327. var maxRadiusSq = 0;
  6328. for ( var i = 0, il = points.length; i < il; i ++ ) {
  6329. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  6330. }
  6331. this.radius = Math.sqrt( maxRadiusSq );
  6332. return this;
  6333. };
  6334. }(),
  6335. clone: function () {
  6336. return new this.constructor().copy( this );
  6337. },
  6338. copy: function ( sphere ) {
  6339. this.center.copy( sphere.center );
  6340. this.radius = sphere.radius;
  6341. return this;
  6342. },
  6343. empty: function () {
  6344. return ( this.radius <= 0 );
  6345. },
  6346. containsPoint: function ( point ) {
  6347. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  6348. },
  6349. distanceToPoint: function ( point ) {
  6350. return ( point.distanceTo( this.center ) - this.radius );
  6351. },
  6352. intersectsSphere: function ( sphere ) {
  6353. var radiusSum = this.radius + sphere.radius;
  6354. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  6355. },
  6356. intersectsBox: function ( box ) {
  6357. return box.intersectsSphere( this );
  6358. },
  6359. intersectsPlane: function ( plane ) {
  6360. return Math.abs( plane.distanceToPoint( this.center ) ) <= this.radius;
  6361. },
  6362. clampPoint: function ( point, optionalTarget ) {
  6363. var deltaLengthSq = this.center.distanceToSquared( point );
  6364. var result = optionalTarget || new Vector3();
  6365. result.copy( point );
  6366. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  6367. result.sub( this.center ).normalize();
  6368. result.multiplyScalar( this.radius ).add( this.center );
  6369. }
  6370. return result;
  6371. },
  6372. getBoundingBox: function ( optionalTarget ) {
  6373. var box = optionalTarget || new Box3();
  6374. box.set( this.center, this.center );
  6375. box.expandByScalar( this.radius );
  6376. return box;
  6377. },
  6378. applyMatrix4: function ( matrix ) {
  6379. this.center.applyMatrix4( matrix );
  6380. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  6381. return this;
  6382. },
  6383. translate: function ( offset ) {
  6384. this.center.add( offset );
  6385. return this;
  6386. },
  6387. equals: function ( sphere ) {
  6388. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  6389. }
  6390. } );
  6391. /**
  6392. * @author mrdoob / http://mrdoob.com/
  6393. * @author philogb / http://blog.thejit.org/
  6394. * @author egraether / http://egraether.com/
  6395. * @author zz85 / http://www.lab4games.net/zz85/blog
  6396. */
  6397. function Vector2( x, y ) {
  6398. this.x = x || 0;
  6399. this.y = y || 0;
  6400. }
  6401. Object.defineProperties( Vector2.prototype, {
  6402. "width": {
  6403. get: function () {
  6404. return this.x;
  6405. },
  6406. set: function ( value ) {
  6407. this.x = value;
  6408. }
  6409. },
  6410. "height": {
  6411. get: function () {
  6412. return this.y;
  6413. },
  6414. set: function ( value ) {
  6415. this.y = value;
  6416. }
  6417. }
  6418. } );
  6419. Object.assign( Vector2.prototype, {
  6420. isVector2: true,
  6421. set: function ( x, y ) {
  6422. this.x = x;
  6423. this.y = y;
  6424. return this;
  6425. },
  6426. setScalar: function ( scalar ) {
  6427. this.x = scalar;
  6428. this.y = scalar;
  6429. return this;
  6430. },
  6431. setX: function ( x ) {
  6432. this.x = x;
  6433. return this;
  6434. },
  6435. setY: function ( y ) {
  6436. this.y = y;
  6437. return this;
  6438. },
  6439. setComponent: function ( index, value ) {
  6440. switch ( index ) {
  6441. case 0: this.x = value; break;
  6442. case 1: this.y = value; break;
  6443. default: throw new Error( 'index is out of range: ' + index );
  6444. }
  6445. return this;
  6446. },
  6447. getComponent: function ( index ) {
  6448. switch ( index ) {
  6449. case 0: return this.x;
  6450. case 1: return this.y;
  6451. default: throw new Error( 'index is out of range: ' + index );
  6452. }
  6453. },
  6454. clone: function () {
  6455. return new this.constructor( this.x, this.y );
  6456. },
  6457. copy: function ( v ) {
  6458. this.x = v.x;
  6459. this.y = v.y;
  6460. return this;
  6461. },
  6462. add: function ( v, w ) {
  6463. if ( w !== undefined ) {
  6464. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  6465. return this.addVectors( v, w );
  6466. }
  6467. this.x += v.x;
  6468. this.y += v.y;
  6469. return this;
  6470. },
  6471. addScalar: function ( s ) {
  6472. this.x += s;
  6473. this.y += s;
  6474. return this;
  6475. },
  6476. addVectors: function ( a, b ) {
  6477. this.x = a.x + b.x;
  6478. this.y = a.y + b.y;
  6479. return this;
  6480. },
  6481. addScaledVector: function ( v, s ) {
  6482. this.x += v.x * s;
  6483. this.y += v.y * s;
  6484. return this;
  6485. },
  6486. sub: function ( v, w ) {
  6487. if ( w !== undefined ) {
  6488. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  6489. return this.subVectors( v, w );
  6490. }
  6491. this.x -= v.x;
  6492. this.y -= v.y;
  6493. return this;
  6494. },
  6495. subScalar: function ( s ) {
  6496. this.x -= s;
  6497. this.y -= s;
  6498. return this;
  6499. },
  6500. subVectors: function ( a, b ) {
  6501. this.x = a.x - b.x;
  6502. this.y = a.y - b.y;
  6503. return this;
  6504. },
  6505. multiply: function ( v ) {
  6506. this.x *= v.x;
  6507. this.y *= v.y;
  6508. return this;
  6509. },
  6510. multiplyScalar: function ( scalar ) {
  6511. this.x *= scalar;
  6512. this.y *= scalar;
  6513. return this;
  6514. },
  6515. divide: function ( v ) {
  6516. this.x /= v.x;
  6517. this.y /= v.y;
  6518. return this;
  6519. },
  6520. divideScalar: function ( scalar ) {
  6521. return this.multiplyScalar( 1 / scalar );
  6522. },
  6523. applyMatrix3: function ( m ) {
  6524. var x = this.x, y = this.y;
  6525. var e = m.elements;
  6526. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ];
  6527. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ];
  6528. return this;
  6529. },
  6530. min: function ( v ) {
  6531. this.x = Math.min( this.x, v.x );
  6532. this.y = Math.min( this.y, v.y );
  6533. return this;
  6534. },
  6535. max: function ( v ) {
  6536. this.x = Math.max( this.x, v.x );
  6537. this.y = Math.max( this.y, v.y );
  6538. return this;
  6539. },
  6540. clamp: function ( min, max ) {
  6541. // assumes min < max, componentwise
  6542. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  6543. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  6544. return this;
  6545. },
  6546. clampScalar: function () {
  6547. var min = new Vector2();
  6548. var max = new Vector2();
  6549. return function clampScalar( minVal, maxVal ) {
  6550. min.set( minVal, minVal );
  6551. max.set( maxVal, maxVal );
  6552. return this.clamp( min, max );
  6553. };
  6554. }(),
  6555. clampLength: function ( min, max ) {
  6556. var length = this.length();
  6557. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  6558. },
  6559. floor: function () {
  6560. this.x = Math.floor( this.x );
  6561. this.y = Math.floor( this.y );
  6562. return this;
  6563. },
  6564. ceil: function () {
  6565. this.x = Math.ceil( this.x );
  6566. this.y = Math.ceil( this.y );
  6567. return this;
  6568. },
  6569. round: function () {
  6570. this.x = Math.round( this.x );
  6571. this.y = Math.round( this.y );
  6572. return this;
  6573. },
  6574. roundToZero: function () {
  6575. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  6576. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  6577. return this;
  6578. },
  6579. negate: function () {
  6580. this.x = - this.x;
  6581. this.y = - this.y;
  6582. return this;
  6583. },
  6584. dot: function ( v ) {
  6585. return this.x * v.x + this.y * v.y;
  6586. },
  6587. lengthSq: function () {
  6588. return this.x * this.x + this.y * this.y;
  6589. },
  6590. length: function () {
  6591. return Math.sqrt( this.x * this.x + this.y * this.y );
  6592. },
  6593. manhattanLength: function () {
  6594. return Math.abs( this.x ) + Math.abs( this.y );
  6595. },
  6596. normalize: function () {
  6597. return this.divideScalar( this.length() || 1 );
  6598. },
  6599. angle: function () {
  6600. // computes the angle in radians with respect to the positive x-axis
  6601. var angle = Math.atan2( this.y, this.x );
  6602. if ( angle < 0 ) angle += 2 * Math.PI;
  6603. return angle;
  6604. },
  6605. distanceTo: function ( v ) {
  6606. return Math.sqrt( this.distanceToSquared( v ) );
  6607. },
  6608. distanceToSquared: function ( v ) {
  6609. var dx = this.x - v.x, dy = this.y - v.y;
  6610. return dx * dx + dy * dy;
  6611. },
  6612. manhattanDistanceTo: function ( v ) {
  6613. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y );
  6614. },
  6615. setLength: function ( length ) {
  6616. return this.normalize().multiplyScalar( length );
  6617. },
  6618. lerp: function ( v, alpha ) {
  6619. this.x += ( v.x - this.x ) * alpha;
  6620. this.y += ( v.y - this.y ) * alpha;
  6621. return this;
  6622. },
  6623. lerpVectors: function ( v1, v2, alpha ) {
  6624. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  6625. },
  6626. equals: function ( v ) {
  6627. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  6628. },
  6629. fromArray: function ( array, offset ) {
  6630. if ( offset === undefined ) offset = 0;
  6631. this.x = array[ offset ];
  6632. this.y = array[ offset + 1 ];
  6633. return this;
  6634. },
  6635. toArray: function ( array, offset ) {
  6636. if ( array === undefined ) array = [];
  6637. if ( offset === undefined ) offset = 0;
  6638. array[ offset ] = this.x;
  6639. array[ offset + 1 ] = this.y;
  6640. return array;
  6641. },
  6642. fromBufferAttribute: function ( attribute, index, offset ) {
  6643. if ( offset !== undefined ) {
  6644. console.warn( 'THREE.Vector2: offset has been removed from .fromBufferAttribute().' );
  6645. }
  6646. this.x = attribute.getX( index );
  6647. this.y = attribute.getY( index );
  6648. return this;
  6649. },
  6650. rotateAround: function ( center, angle ) {
  6651. var c = Math.cos( angle ), s = Math.sin( angle );
  6652. var x = this.x - center.x;
  6653. var y = this.y - center.y;
  6654. this.x = x * c - y * s + center.x;
  6655. this.y = x * s + y * c + center.y;
  6656. return this;
  6657. }
  6658. } );
  6659. var geometryId = 0; // Geometry uses even numbers as Id
  6660. function Geometry() {
  6661. Object.defineProperty( this, 'id', { value: geometryId += 2 } );
  6662. this.uuid = _Math.generateUUID();
  6663. this.name = '';
  6664. this.type = 'Geometry';
  6665. this.vertices = [];
  6666. this.colors = [];
  6667. this.faces = [];
  6668. this.faceVertexUvs = [[]];
  6669. this.morphTargets = [];
  6670. this.morphNormals = [];
  6671. this.skinWeights = [];
  6672. this.skinIndices = [];
  6673. this.lineDistances = [];
  6674. this.boundingBox = null;
  6675. this.boundingSphere = null;
  6676. // update flags
  6677. this.elementsNeedUpdate = false;
  6678. this.verticesNeedUpdate = false;
  6679. this.uvsNeedUpdate = false;
  6680. this.normalsNeedUpdate = false;
  6681. this.colorsNeedUpdate = false;
  6682. this.lineDistancesNeedUpdate = false;
  6683. this.groupsNeedUpdate = false;
  6684. }
  6685. Object.assign( Geometry.prototype, EventDispatcher.prototype, {
  6686. isGeometry: true,
  6687. applyMatrix: function ( matrix ) {
  6688. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  6689. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  6690. var vertex = this.vertices[ i ];
  6691. vertex.applyMatrix4( matrix );
  6692. }
  6693. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  6694. var face = this.faces[ i ];
  6695. face.normal.applyMatrix3( normalMatrix ).normalize();
  6696. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  6697. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  6698. }
  6699. }
  6700. if ( this.boundingBox !== null ) {
  6701. this.computeBoundingBox();
  6702. }
  6703. if ( this.boundingSphere !== null ) {
  6704. this.computeBoundingSphere();
  6705. }
  6706. this.verticesNeedUpdate = true;
  6707. this.normalsNeedUpdate = true;
  6708. return this;
  6709. },
  6710. rotateX: function () {
  6711. // rotate geometry around world x-axis
  6712. var m1 = new Matrix4();
  6713. return function rotateX( angle ) {
  6714. m1.makeRotationX( angle );
  6715. this.applyMatrix( m1 );
  6716. return this;
  6717. };
  6718. }(),
  6719. rotateY: function () {
  6720. // rotate geometry around world y-axis
  6721. var m1 = new Matrix4();
  6722. return function rotateY( angle ) {
  6723. m1.makeRotationY( angle );
  6724. this.applyMatrix( m1 );
  6725. return this;
  6726. };
  6727. }(),
  6728. rotateZ: function () {
  6729. // rotate geometry around world z-axis
  6730. var m1 = new Matrix4();
  6731. return function rotateZ( angle ) {
  6732. m1.makeRotationZ( angle );
  6733. this.applyMatrix( m1 );
  6734. return this;
  6735. };
  6736. }(),
  6737. translate: function () {
  6738. // translate geometry
  6739. var m1 = new Matrix4();
  6740. return function translate( x, y, z ) {
  6741. m1.makeTranslation( x, y, z );
  6742. this.applyMatrix( m1 );
  6743. return this;
  6744. };
  6745. }(),
  6746. scale: function () {
  6747. // scale geometry
  6748. var m1 = new Matrix4();
  6749. return function scale( x, y, z ) {
  6750. m1.makeScale( x, y, z );
  6751. this.applyMatrix( m1 );
  6752. return this;
  6753. };
  6754. }(),
  6755. lookAt: function () {
  6756. var obj = new Object3D();
  6757. return function lookAt( vector ) {
  6758. obj.lookAt( vector );
  6759. obj.updateMatrix();
  6760. this.applyMatrix( obj.matrix );
  6761. };
  6762. }(),
  6763. fromBufferGeometry: function ( geometry ) {
  6764. var scope = this;
  6765. var indices = geometry.index !== null ? geometry.index.array : undefined;
  6766. var attributes = geometry.attributes;
  6767. var positions = attributes.position.array;
  6768. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  6769. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  6770. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  6771. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  6772. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  6773. var tempNormals = [];
  6774. var tempUVs = [];
  6775. var tempUVs2 = [];
  6776. for ( var i = 0, j = 0; i < positions.length; i += 3, j += 2 ) {
  6777. scope.vertices.push( new Vector3( positions[ i ], positions[ i + 1 ], positions[ i + 2 ] ) );
  6778. if ( normals !== undefined ) {
  6779. tempNormals.push( new Vector3( normals[ i ], normals[ i + 1 ], normals[ i + 2 ] ) );
  6780. }
  6781. if ( colors !== undefined ) {
  6782. scope.colors.push( new Color( colors[ i ], colors[ i + 1 ], colors[ i + 2 ] ) );
  6783. }
  6784. if ( uvs !== undefined ) {
  6785. tempUVs.push( new Vector2( uvs[ j ], uvs[ j + 1 ] ) );
  6786. }
  6787. if ( uvs2 !== undefined ) {
  6788. tempUVs2.push( new Vector2( uvs2[ j ], uvs2[ j + 1 ] ) );
  6789. }
  6790. }
  6791. function addFace( a, b, c, materialIndex ) {
  6792. var vertexNormals = normals !== undefined ? [ tempNormals[ a ].clone(), tempNormals[ b ].clone(), tempNormals[ c ].clone() ] : [];
  6793. var vertexColors = colors !== undefined ? [ scope.colors[ a ].clone(), scope.colors[ b ].clone(), scope.colors[ c ].clone() ] : [];
  6794. var face = new Face3( a, b, c, vertexNormals, vertexColors, materialIndex );
  6795. scope.faces.push( face );
  6796. if ( uvs !== undefined ) {
  6797. scope.faceVertexUvs[ 0 ].push( [ tempUVs[ a ].clone(), tempUVs[ b ].clone(), tempUVs[ c ].clone() ] );
  6798. }
  6799. if ( uvs2 !== undefined ) {
  6800. scope.faceVertexUvs[ 1 ].push( [ tempUVs2[ a ].clone(), tempUVs2[ b ].clone(), tempUVs2[ c ].clone() ] );
  6801. }
  6802. }
  6803. var groups = geometry.groups;
  6804. if ( groups.length > 0 ) {
  6805. for ( var i = 0; i < groups.length; i ++ ) {
  6806. var group = groups[ i ];
  6807. var start = group.start;
  6808. var count = group.count;
  6809. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  6810. if ( indices !== undefined ) {
  6811. addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ], group.materialIndex );
  6812. } else {
  6813. addFace( j, j + 1, j + 2, group.materialIndex );
  6814. }
  6815. }
  6816. }
  6817. } else {
  6818. if ( indices !== undefined ) {
  6819. for ( var i = 0; i < indices.length; i += 3 ) {
  6820. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  6821. }
  6822. } else {
  6823. for ( var i = 0; i < positions.length / 3; i += 3 ) {
  6824. addFace( i, i + 1, i + 2 );
  6825. }
  6826. }
  6827. }
  6828. this.computeFaceNormals();
  6829. if ( geometry.boundingBox !== null ) {
  6830. this.boundingBox = geometry.boundingBox.clone();
  6831. }
  6832. if ( geometry.boundingSphere !== null ) {
  6833. this.boundingSphere = geometry.boundingSphere.clone();
  6834. }
  6835. return this;
  6836. },
  6837. center: function () {
  6838. this.computeBoundingBox();
  6839. var offset = this.boundingBox.getCenter().negate();
  6840. this.translate( offset.x, offset.y, offset.z );
  6841. return offset;
  6842. },
  6843. normalize: function () {
  6844. this.computeBoundingSphere();
  6845. var center = this.boundingSphere.center;
  6846. var radius = this.boundingSphere.radius;
  6847. var s = radius === 0 ? 1 : 1.0 / radius;
  6848. var matrix = new Matrix4();
  6849. matrix.set(
  6850. s, 0, 0, - s * center.x,
  6851. 0, s, 0, - s * center.y,
  6852. 0, 0, s, - s * center.z,
  6853. 0, 0, 0, 1
  6854. );
  6855. this.applyMatrix( matrix );
  6856. return this;
  6857. },
  6858. computeFaceNormals: function () {
  6859. var cb = new Vector3(), ab = new Vector3();
  6860. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6861. var face = this.faces[ f ];
  6862. var vA = this.vertices[ face.a ];
  6863. var vB = this.vertices[ face.b ];
  6864. var vC = this.vertices[ face.c ];
  6865. cb.subVectors( vC, vB );
  6866. ab.subVectors( vA, vB );
  6867. cb.cross( ab );
  6868. cb.normalize();
  6869. face.normal.copy( cb );
  6870. }
  6871. },
  6872. computeVertexNormals: function ( areaWeighted ) {
  6873. if ( areaWeighted === undefined ) areaWeighted = true;
  6874. var v, vl, f, fl, face, vertices;
  6875. vertices = new Array( this.vertices.length );
  6876. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  6877. vertices[ v ] = new Vector3();
  6878. }
  6879. if ( areaWeighted ) {
  6880. // vertex normals weighted by triangle areas
  6881. // http://www.iquilezles.org/www/articles/normals/normals.htm
  6882. var vA, vB, vC;
  6883. var cb = new Vector3(), ab = new Vector3();
  6884. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6885. face = this.faces[ f ];
  6886. vA = this.vertices[ face.a ];
  6887. vB = this.vertices[ face.b ];
  6888. vC = this.vertices[ face.c ];
  6889. cb.subVectors( vC, vB );
  6890. ab.subVectors( vA, vB );
  6891. cb.cross( ab );
  6892. vertices[ face.a ].add( cb );
  6893. vertices[ face.b ].add( cb );
  6894. vertices[ face.c ].add( cb );
  6895. }
  6896. } else {
  6897. this.computeFaceNormals();
  6898. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6899. face = this.faces[ f ];
  6900. vertices[ face.a ].add( face.normal );
  6901. vertices[ face.b ].add( face.normal );
  6902. vertices[ face.c ].add( face.normal );
  6903. }
  6904. }
  6905. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  6906. vertices[ v ].normalize();
  6907. }
  6908. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6909. face = this.faces[ f ];
  6910. var vertexNormals = face.vertexNormals;
  6911. if ( vertexNormals.length === 3 ) {
  6912. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  6913. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  6914. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  6915. } else {
  6916. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  6917. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  6918. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  6919. }
  6920. }
  6921. if ( this.faces.length > 0 ) {
  6922. this.normalsNeedUpdate = true;
  6923. }
  6924. },
  6925. computeFlatVertexNormals: function () {
  6926. var f, fl, face;
  6927. this.computeFaceNormals();
  6928. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6929. face = this.faces[ f ];
  6930. var vertexNormals = face.vertexNormals;
  6931. if ( vertexNormals.length === 3 ) {
  6932. vertexNormals[ 0 ].copy( face.normal );
  6933. vertexNormals[ 1 ].copy( face.normal );
  6934. vertexNormals[ 2 ].copy( face.normal );
  6935. } else {
  6936. vertexNormals[ 0 ] = face.normal.clone();
  6937. vertexNormals[ 1 ] = face.normal.clone();
  6938. vertexNormals[ 2 ] = face.normal.clone();
  6939. }
  6940. }
  6941. if ( this.faces.length > 0 ) {
  6942. this.normalsNeedUpdate = true;
  6943. }
  6944. },
  6945. computeMorphNormals: function () {
  6946. var i, il, f, fl, face;
  6947. // save original normals
  6948. // - create temp variables on first access
  6949. // otherwise just copy (for faster repeated calls)
  6950. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6951. face = this.faces[ f ];
  6952. if ( ! face.__originalFaceNormal ) {
  6953. face.__originalFaceNormal = face.normal.clone();
  6954. } else {
  6955. face.__originalFaceNormal.copy( face.normal );
  6956. }
  6957. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  6958. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  6959. if ( ! face.__originalVertexNormals[ i ] ) {
  6960. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  6961. } else {
  6962. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  6963. }
  6964. }
  6965. }
  6966. // use temp geometry to compute face and vertex normals for each morph
  6967. var tmpGeo = new Geometry();
  6968. tmpGeo.faces = this.faces;
  6969. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  6970. // create on first access
  6971. if ( ! this.morphNormals[ i ] ) {
  6972. this.morphNormals[ i ] = {};
  6973. this.morphNormals[ i ].faceNormals = [];
  6974. this.morphNormals[ i ].vertexNormals = [];
  6975. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  6976. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  6977. var faceNormal, vertexNormals;
  6978. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6979. faceNormal = new Vector3();
  6980. vertexNormals = { a: new Vector3(), b: new Vector3(), c: new Vector3() };
  6981. dstNormalsFace.push( faceNormal );
  6982. dstNormalsVertex.push( vertexNormals );
  6983. }
  6984. }
  6985. var morphNormals = this.morphNormals[ i ];
  6986. // set vertices to morph target
  6987. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  6988. // compute morph normals
  6989. tmpGeo.computeFaceNormals();
  6990. tmpGeo.computeVertexNormals();
  6991. // store morph normals
  6992. var faceNormal, vertexNormals;
  6993. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6994. face = this.faces[ f ];
  6995. faceNormal = morphNormals.faceNormals[ f ];
  6996. vertexNormals = morphNormals.vertexNormals[ f ];
  6997. faceNormal.copy( face.normal );
  6998. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  6999. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  7000. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  7001. }
  7002. }
  7003. // restore original normals
  7004. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7005. face = this.faces[ f ];
  7006. face.normal = face.__originalFaceNormal;
  7007. face.vertexNormals = face.__originalVertexNormals;
  7008. }
  7009. },
  7010. computeLineDistances: function () {
  7011. var d = 0;
  7012. var vertices = this.vertices;
  7013. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  7014. if ( i > 0 ) {
  7015. d += vertices[ i ].distanceTo( vertices[ i - 1 ] );
  7016. }
  7017. this.lineDistances[ i ] = d;
  7018. }
  7019. },
  7020. computeBoundingBox: function () {
  7021. if ( this.boundingBox === null ) {
  7022. this.boundingBox = new Box3();
  7023. }
  7024. this.boundingBox.setFromPoints( this.vertices );
  7025. },
  7026. computeBoundingSphere: function () {
  7027. if ( this.boundingSphere === null ) {
  7028. this.boundingSphere = new Sphere();
  7029. }
  7030. this.boundingSphere.setFromPoints( this.vertices );
  7031. },
  7032. merge: function ( geometry, matrix, materialIndexOffset ) {
  7033. if ( ! ( geometry && geometry.isGeometry ) ) {
  7034. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  7035. return;
  7036. }
  7037. var normalMatrix,
  7038. vertexOffset = this.vertices.length,
  7039. vertices1 = this.vertices,
  7040. vertices2 = geometry.vertices,
  7041. faces1 = this.faces,
  7042. faces2 = geometry.faces,
  7043. uvs1 = this.faceVertexUvs[ 0 ],
  7044. uvs2 = geometry.faceVertexUvs[ 0 ],
  7045. colors1 = this.colors,
  7046. colors2 = geometry.colors;
  7047. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  7048. if ( matrix !== undefined ) {
  7049. normalMatrix = new Matrix3().getNormalMatrix( matrix );
  7050. }
  7051. // vertices
  7052. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  7053. var vertex = vertices2[ i ];
  7054. var vertexCopy = vertex.clone();
  7055. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  7056. vertices1.push( vertexCopy );
  7057. }
  7058. // colors
  7059. for ( var i = 0, il = colors2.length; i < il; i ++ ) {
  7060. colors1.push( colors2[ i ].clone() );
  7061. }
  7062. // faces
  7063. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  7064. var face = faces2[ i ], faceCopy, normal, color,
  7065. faceVertexNormals = face.vertexNormals,
  7066. faceVertexColors = face.vertexColors;
  7067. faceCopy = new Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  7068. faceCopy.normal.copy( face.normal );
  7069. if ( normalMatrix !== undefined ) {
  7070. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  7071. }
  7072. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  7073. normal = faceVertexNormals[ j ].clone();
  7074. if ( normalMatrix !== undefined ) {
  7075. normal.applyMatrix3( normalMatrix ).normalize();
  7076. }
  7077. faceCopy.vertexNormals.push( normal );
  7078. }
  7079. faceCopy.color.copy( face.color );
  7080. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  7081. color = faceVertexColors[ j ];
  7082. faceCopy.vertexColors.push( color.clone() );
  7083. }
  7084. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  7085. faces1.push( faceCopy );
  7086. }
  7087. // uvs
  7088. for ( i = 0, il = uvs2.length; i < il; i ++ ) {
  7089. var uv = uvs2[ i ], uvCopy = [];
  7090. if ( uv === undefined ) {
  7091. continue;
  7092. }
  7093. for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
  7094. uvCopy.push( uv[ j ].clone() );
  7095. }
  7096. uvs1.push( uvCopy );
  7097. }
  7098. },
  7099. mergeMesh: function ( mesh ) {
  7100. if ( ! ( mesh && mesh.isMesh ) ) {
  7101. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  7102. return;
  7103. }
  7104. mesh.matrixAutoUpdate && mesh.updateMatrix();
  7105. this.merge( mesh.geometry, mesh.matrix );
  7106. },
  7107. /*
  7108. * Checks for duplicate vertices with hashmap.
  7109. * Duplicated vertices are removed
  7110. * and faces' vertices are updated.
  7111. */
  7112. mergeVertices: function () {
  7113. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  7114. var unique = [], changes = [];
  7115. var v, key;
  7116. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  7117. var precision = Math.pow( 10, precisionPoints );
  7118. var i, il, face;
  7119. var indices, j, jl;
  7120. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  7121. v = this.vertices[ i ];
  7122. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  7123. if ( verticesMap[ key ] === undefined ) {
  7124. verticesMap[ key ] = i;
  7125. unique.push( this.vertices[ i ] );
  7126. changes[ i ] = unique.length - 1;
  7127. } else {
  7128. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  7129. changes[ i ] = changes[ verticesMap[ key ] ];
  7130. }
  7131. }
  7132. // if faces are completely degenerate after merging vertices, we
  7133. // have to remove them from the geometry.
  7134. var faceIndicesToRemove = [];
  7135. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  7136. face = this.faces[ i ];
  7137. face.a = changes[ face.a ];
  7138. face.b = changes[ face.b ];
  7139. face.c = changes[ face.c ];
  7140. indices = [ face.a, face.b, face.c ];
  7141. // if any duplicate vertices are found in a Face3
  7142. // we have to remove the face as nothing can be saved
  7143. for ( var n = 0; n < 3; n ++ ) {
  7144. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  7145. faceIndicesToRemove.push( i );
  7146. break;
  7147. }
  7148. }
  7149. }
  7150. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  7151. var idx = faceIndicesToRemove[ i ];
  7152. this.faces.splice( idx, 1 );
  7153. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  7154. this.faceVertexUvs[ j ].splice( idx, 1 );
  7155. }
  7156. }
  7157. // Use unique set of vertices
  7158. var diff = this.vertices.length - unique.length;
  7159. this.vertices = unique;
  7160. return diff;
  7161. },
  7162. setFromPoints: function ( points ) {
  7163. this.vertices = [];
  7164. for ( var i = 0, l = points.length; i < l; i ++ ) {
  7165. var point = points[ i ];
  7166. this.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  7167. }
  7168. return this;
  7169. },
  7170. sortFacesByMaterialIndex: function () {
  7171. var faces = this.faces;
  7172. var length = faces.length;
  7173. // tag faces
  7174. for ( var i = 0; i < length; i ++ ) {
  7175. faces[ i ]._id = i;
  7176. }
  7177. // sort faces
  7178. function materialIndexSort( a, b ) {
  7179. return a.materialIndex - b.materialIndex;
  7180. }
  7181. faces.sort( materialIndexSort );
  7182. // sort uvs
  7183. var uvs1 = this.faceVertexUvs[ 0 ];
  7184. var uvs2 = this.faceVertexUvs[ 1 ];
  7185. var newUvs1, newUvs2;
  7186. if ( uvs1 && uvs1.length === length ) newUvs1 = [];
  7187. if ( uvs2 && uvs2.length === length ) newUvs2 = [];
  7188. for ( var i = 0; i < length; i ++ ) {
  7189. var id = faces[ i ]._id;
  7190. if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
  7191. if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
  7192. }
  7193. if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
  7194. if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
  7195. },
  7196. toJSON: function () {
  7197. var data = {
  7198. metadata: {
  7199. version: 4.5,
  7200. type: 'Geometry',
  7201. generator: 'Geometry.toJSON'
  7202. }
  7203. };
  7204. // standard Geometry serialization
  7205. data.uuid = this.uuid;
  7206. data.type = this.type;
  7207. if ( this.name !== '' ) data.name = this.name;
  7208. if ( this.parameters !== undefined ) {
  7209. var parameters = this.parameters;
  7210. for ( var key in parameters ) {
  7211. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  7212. }
  7213. return data;
  7214. }
  7215. var vertices = [];
  7216. for ( var i = 0; i < this.vertices.length; i ++ ) {
  7217. var vertex = this.vertices[ i ];
  7218. vertices.push( vertex.x, vertex.y, vertex.z );
  7219. }
  7220. var faces = [];
  7221. var normals = [];
  7222. var normalsHash = {};
  7223. var colors = [];
  7224. var colorsHash = {};
  7225. var uvs = [];
  7226. var uvsHash = {};
  7227. for ( var i = 0; i < this.faces.length; i ++ ) {
  7228. var face = this.faces[ i ];
  7229. var hasMaterial = true;
  7230. var hasFaceUv = false; // deprecated
  7231. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  7232. var hasFaceNormal = face.normal.length() > 0;
  7233. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  7234. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  7235. var hasFaceVertexColor = face.vertexColors.length > 0;
  7236. var faceType = 0;
  7237. faceType = setBit( faceType, 0, 0 ); // isQuad
  7238. faceType = setBit( faceType, 1, hasMaterial );
  7239. faceType = setBit( faceType, 2, hasFaceUv );
  7240. faceType = setBit( faceType, 3, hasFaceVertexUv );
  7241. faceType = setBit( faceType, 4, hasFaceNormal );
  7242. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  7243. faceType = setBit( faceType, 6, hasFaceColor );
  7244. faceType = setBit( faceType, 7, hasFaceVertexColor );
  7245. faces.push( faceType );
  7246. faces.push( face.a, face.b, face.c );
  7247. faces.push( face.materialIndex );
  7248. if ( hasFaceVertexUv ) {
  7249. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  7250. faces.push(
  7251. getUvIndex( faceVertexUvs[ 0 ] ),
  7252. getUvIndex( faceVertexUvs[ 1 ] ),
  7253. getUvIndex( faceVertexUvs[ 2 ] )
  7254. );
  7255. }
  7256. if ( hasFaceNormal ) {
  7257. faces.push( getNormalIndex( face.normal ) );
  7258. }
  7259. if ( hasFaceVertexNormal ) {
  7260. var vertexNormals = face.vertexNormals;
  7261. faces.push(
  7262. getNormalIndex( vertexNormals[ 0 ] ),
  7263. getNormalIndex( vertexNormals[ 1 ] ),
  7264. getNormalIndex( vertexNormals[ 2 ] )
  7265. );
  7266. }
  7267. if ( hasFaceColor ) {
  7268. faces.push( getColorIndex( face.color ) );
  7269. }
  7270. if ( hasFaceVertexColor ) {
  7271. var vertexColors = face.vertexColors;
  7272. faces.push(
  7273. getColorIndex( vertexColors[ 0 ] ),
  7274. getColorIndex( vertexColors[ 1 ] ),
  7275. getColorIndex( vertexColors[ 2 ] )
  7276. );
  7277. }
  7278. }
  7279. function setBit( value, position, enabled ) {
  7280. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  7281. }
  7282. function getNormalIndex( normal ) {
  7283. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  7284. if ( normalsHash[ hash ] !== undefined ) {
  7285. return normalsHash[ hash ];
  7286. }
  7287. normalsHash[ hash ] = normals.length / 3;
  7288. normals.push( normal.x, normal.y, normal.z );
  7289. return normalsHash[ hash ];
  7290. }
  7291. function getColorIndex( color ) {
  7292. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  7293. if ( colorsHash[ hash ] !== undefined ) {
  7294. return colorsHash[ hash ];
  7295. }
  7296. colorsHash[ hash ] = colors.length;
  7297. colors.push( color.getHex() );
  7298. return colorsHash[ hash ];
  7299. }
  7300. function getUvIndex( uv ) {
  7301. var hash = uv.x.toString() + uv.y.toString();
  7302. if ( uvsHash[ hash ] !== undefined ) {
  7303. return uvsHash[ hash ];
  7304. }
  7305. uvsHash[ hash ] = uvs.length / 2;
  7306. uvs.push( uv.x, uv.y );
  7307. return uvsHash[ hash ];
  7308. }
  7309. data.data = {};
  7310. data.data.vertices = vertices;
  7311. data.data.normals = normals;
  7312. if ( colors.length > 0 ) data.data.colors = colors;
  7313. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  7314. data.data.faces = faces;
  7315. return data;
  7316. },
  7317. clone: function () {
  7318. /*
  7319. // Handle primitives
  7320. var parameters = this.parameters;
  7321. if ( parameters !== undefined ) {
  7322. var values = [];
  7323. for ( var key in parameters ) {
  7324. values.push( parameters[ key ] );
  7325. }
  7326. var geometry = Object.create( this.constructor.prototype );
  7327. this.constructor.apply( geometry, values );
  7328. return geometry;
  7329. }
  7330. return new this.constructor().copy( this );
  7331. */
  7332. return new Geometry().copy( this );
  7333. },
  7334. copy: function ( source ) {
  7335. var i, il, j, jl, k, kl;
  7336. // reset
  7337. this.vertices = [];
  7338. this.colors = [];
  7339. this.faces = [];
  7340. this.faceVertexUvs = [[]];
  7341. this.morphTargets = [];
  7342. this.morphNormals = [];
  7343. this.skinWeights = [];
  7344. this.skinIndices = [];
  7345. this.lineDistances = [];
  7346. this.boundingBox = null;
  7347. this.boundingSphere = null;
  7348. // name
  7349. this.name = source.name;
  7350. // vertices
  7351. var vertices = source.vertices;
  7352. for ( i = 0, il = vertices.length; i < il; i ++ ) {
  7353. this.vertices.push( vertices[ i ].clone() );
  7354. }
  7355. // colors
  7356. var colors = source.colors;
  7357. for ( i = 0, il = colors.length; i < il; i ++ ) {
  7358. this.colors.push( colors[ i ].clone() );
  7359. }
  7360. // faces
  7361. var faces = source.faces;
  7362. for ( i = 0, il = faces.length; i < il; i ++ ) {
  7363. this.faces.push( faces[ i ].clone() );
  7364. }
  7365. // face vertex uvs
  7366. for ( i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  7367. var faceVertexUvs = source.faceVertexUvs[ i ];
  7368. if ( this.faceVertexUvs[ i ] === undefined ) {
  7369. this.faceVertexUvs[ i ] = [];
  7370. }
  7371. for ( j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  7372. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  7373. for ( k = 0, kl = uvs.length; k < kl; k ++ ) {
  7374. var uv = uvs[ k ];
  7375. uvsCopy.push( uv.clone() );
  7376. }
  7377. this.faceVertexUvs[ i ].push( uvsCopy );
  7378. }
  7379. }
  7380. // morph targets
  7381. var morphTargets = source.morphTargets;
  7382. for ( i = 0, il = morphTargets.length; i < il; i ++ ) {
  7383. var morphTarget = {};
  7384. morphTarget.name = morphTargets[ i ].name;
  7385. // vertices
  7386. if ( morphTargets[ i ].vertices !== undefined ) {
  7387. morphTarget.vertices = [];
  7388. for ( j = 0, jl = morphTargets[ i ].vertices.length; j < jl; j ++ ) {
  7389. morphTarget.vertices.push( morphTargets[ i ].vertices[ j ].clone() );
  7390. }
  7391. }
  7392. // normals
  7393. if ( morphTargets[ i ].normals !== undefined ) {
  7394. morphTarget.normals = [];
  7395. for ( j = 0, jl = morphTargets[ i ].normals.length; j < jl; j ++ ) {
  7396. morphTarget.normals.push( morphTargets[ i ].normals[ j ].clone() );
  7397. }
  7398. }
  7399. this.morphTargets.push( morphTarget );
  7400. }
  7401. // morph normals
  7402. var morphNormals = source.morphNormals;
  7403. for ( i = 0, il = morphNormals.length; i < il; i ++ ) {
  7404. var morphNormal = {};
  7405. // vertex normals
  7406. if ( morphNormals[ i ].vertexNormals !== undefined ) {
  7407. morphNormal.vertexNormals = [];
  7408. for ( j = 0, jl = morphNormals[ i ].vertexNormals.length; j < jl; j ++ ) {
  7409. var srcVertexNormal = morphNormals[ i ].vertexNormals[ j ];
  7410. var destVertexNormal = {};
  7411. destVertexNormal.a = srcVertexNormal.a.clone();
  7412. destVertexNormal.b = srcVertexNormal.b.clone();
  7413. destVertexNormal.c = srcVertexNormal.c.clone();
  7414. morphNormal.vertexNormals.push( destVertexNormal );
  7415. }
  7416. }
  7417. // face normals
  7418. if ( morphNormals[ i ].faceNormals !== undefined ) {
  7419. morphNormal.faceNormals = [];
  7420. for ( j = 0, jl = morphNormals[ i ].faceNormals.length; j < jl; j ++ ) {
  7421. morphNormal.faceNormals.push( morphNormals[ i ].faceNormals[ j ].clone() );
  7422. }
  7423. }
  7424. this.morphNormals.push( morphNormal );
  7425. }
  7426. // skin weights
  7427. var skinWeights = source.skinWeights;
  7428. for ( i = 0, il = skinWeights.length; i < il; i ++ ) {
  7429. this.skinWeights.push( skinWeights[ i ].clone() );
  7430. }
  7431. // skin indices
  7432. var skinIndices = source.skinIndices;
  7433. for ( i = 0, il = skinIndices.length; i < il; i ++ ) {
  7434. this.skinIndices.push( skinIndices[ i ].clone() );
  7435. }
  7436. // line distances
  7437. var lineDistances = source.lineDistances;
  7438. for ( i = 0, il = lineDistances.length; i < il; i ++ ) {
  7439. this.lineDistances.push( lineDistances[ i ] );
  7440. }
  7441. // bounding box
  7442. var boundingBox = source.boundingBox;
  7443. if ( boundingBox !== null ) {
  7444. this.boundingBox = boundingBox.clone();
  7445. }
  7446. // bounding sphere
  7447. var boundingSphere = source.boundingSphere;
  7448. if ( boundingSphere !== null ) {
  7449. this.boundingSphere = boundingSphere.clone();
  7450. }
  7451. // update flags
  7452. this.elementsNeedUpdate = source.elementsNeedUpdate;
  7453. this.verticesNeedUpdate = source.verticesNeedUpdate;
  7454. this.uvsNeedUpdate = source.uvsNeedUpdate;
  7455. this.normalsNeedUpdate = source.normalsNeedUpdate;
  7456. this.colorsNeedUpdate = source.colorsNeedUpdate;
  7457. this.lineDistancesNeedUpdate = source.lineDistancesNeedUpdate;
  7458. this.groupsNeedUpdate = source.groupsNeedUpdate;
  7459. return this;
  7460. },
  7461. dispose: function () {
  7462. this.dispatchEvent( { type: 'dispose' } );
  7463. }
  7464. } );
  7465. /**
  7466. * @author supereggbert / http://www.paulbrunt.co.uk/
  7467. * @author philogb / http://blog.thejit.org/
  7468. * @author mikael emtinger / http://gomo.se/
  7469. * @author egraether / http://egraether.com/
  7470. * @author WestLangley / http://github.com/WestLangley
  7471. */
  7472. function Vector4( x, y, z, w ) {
  7473. this.x = x || 0;
  7474. this.y = y || 0;
  7475. this.z = z || 0;
  7476. this.w = ( w !== undefined ) ? w : 1;
  7477. }
  7478. Object.assign( Vector4.prototype, {
  7479. isVector4: true,
  7480. set: function ( x, y, z, w ) {
  7481. this.x = x;
  7482. this.y = y;
  7483. this.z = z;
  7484. this.w = w;
  7485. return this;
  7486. },
  7487. setScalar: function ( scalar ) {
  7488. this.x = scalar;
  7489. this.y = scalar;
  7490. this.z = scalar;
  7491. this.w = scalar;
  7492. return this;
  7493. },
  7494. setX: function ( x ) {
  7495. this.x = x;
  7496. return this;
  7497. },
  7498. setY: function ( y ) {
  7499. this.y = y;
  7500. return this;
  7501. },
  7502. setZ: function ( z ) {
  7503. this.z = z;
  7504. return this;
  7505. },
  7506. setW: function ( w ) {
  7507. this.w = w;
  7508. return this;
  7509. },
  7510. setComponent: function ( index, value ) {
  7511. switch ( index ) {
  7512. case 0: this.x = value; break;
  7513. case 1: this.y = value; break;
  7514. case 2: this.z = value; break;
  7515. case 3: this.w = value; break;
  7516. default: throw new Error( 'index is out of range: ' + index );
  7517. }
  7518. return this;
  7519. },
  7520. getComponent: function ( index ) {
  7521. switch ( index ) {
  7522. case 0: return this.x;
  7523. case 1: return this.y;
  7524. case 2: return this.z;
  7525. case 3: return this.w;
  7526. default: throw new Error( 'index is out of range: ' + index );
  7527. }
  7528. },
  7529. clone: function () {
  7530. return new this.constructor( this.x, this.y, this.z, this.w );
  7531. },
  7532. copy: function ( v ) {
  7533. this.x = v.x;
  7534. this.y = v.y;
  7535. this.z = v.z;
  7536. this.w = ( v.w !== undefined ) ? v.w : 1;
  7537. return this;
  7538. },
  7539. add: function ( v, w ) {
  7540. if ( w !== undefined ) {
  7541. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  7542. return this.addVectors( v, w );
  7543. }
  7544. this.x += v.x;
  7545. this.y += v.y;
  7546. this.z += v.z;
  7547. this.w += v.w;
  7548. return this;
  7549. },
  7550. addScalar: function ( s ) {
  7551. this.x += s;
  7552. this.y += s;
  7553. this.z += s;
  7554. this.w += s;
  7555. return this;
  7556. },
  7557. addVectors: function ( a, b ) {
  7558. this.x = a.x + b.x;
  7559. this.y = a.y + b.y;
  7560. this.z = a.z + b.z;
  7561. this.w = a.w + b.w;
  7562. return this;
  7563. },
  7564. addScaledVector: function ( v, s ) {
  7565. this.x += v.x * s;
  7566. this.y += v.y * s;
  7567. this.z += v.z * s;
  7568. this.w += v.w * s;
  7569. return this;
  7570. },
  7571. sub: function ( v, w ) {
  7572. if ( w !== undefined ) {
  7573. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  7574. return this.subVectors( v, w );
  7575. }
  7576. this.x -= v.x;
  7577. this.y -= v.y;
  7578. this.z -= v.z;
  7579. this.w -= v.w;
  7580. return this;
  7581. },
  7582. subScalar: function ( s ) {
  7583. this.x -= s;
  7584. this.y -= s;
  7585. this.z -= s;
  7586. this.w -= s;
  7587. return this;
  7588. },
  7589. subVectors: function ( a, b ) {
  7590. this.x = a.x - b.x;
  7591. this.y = a.y - b.y;
  7592. this.z = a.z - b.z;
  7593. this.w = a.w - b.w;
  7594. return this;
  7595. },
  7596. multiplyScalar: function ( scalar ) {
  7597. this.x *= scalar;
  7598. this.y *= scalar;
  7599. this.z *= scalar;
  7600. this.w *= scalar;
  7601. return this;
  7602. },
  7603. applyMatrix4: function ( m ) {
  7604. var x = this.x, y = this.y, z = this.z, w = this.w;
  7605. var e = m.elements;
  7606. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  7607. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  7608. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  7609. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  7610. return this;
  7611. },
  7612. divideScalar: function ( scalar ) {
  7613. return this.multiplyScalar( 1 / scalar );
  7614. },
  7615. setAxisAngleFromQuaternion: function ( q ) {
  7616. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  7617. // q is assumed to be normalized
  7618. this.w = 2 * Math.acos( q.w );
  7619. var s = Math.sqrt( 1 - q.w * q.w );
  7620. if ( s < 0.0001 ) {
  7621. this.x = 1;
  7622. this.y = 0;
  7623. this.z = 0;
  7624. } else {
  7625. this.x = q.x / s;
  7626. this.y = q.y / s;
  7627. this.z = q.z / s;
  7628. }
  7629. return this;
  7630. },
  7631. setAxisAngleFromRotationMatrix: function ( m ) {
  7632. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  7633. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  7634. var angle, x, y, z, // variables for result
  7635. epsilon = 0.01, // margin to allow for rounding errors
  7636. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  7637. te = m.elements,
  7638. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  7639. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  7640. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  7641. if ( ( Math.abs( m12 - m21 ) < epsilon ) &&
  7642. ( Math.abs( m13 - m31 ) < epsilon ) &&
  7643. ( Math.abs( m23 - m32 ) < epsilon ) ) {
  7644. // singularity found
  7645. // first check for identity matrix which must have +1 for all terms
  7646. // in leading diagonal and zero in other terms
  7647. if ( ( Math.abs( m12 + m21 ) < epsilon2 ) &&
  7648. ( Math.abs( m13 + m31 ) < epsilon2 ) &&
  7649. ( Math.abs( m23 + m32 ) < epsilon2 ) &&
  7650. ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  7651. // this singularity is identity matrix so angle = 0
  7652. this.set( 1, 0, 0, 0 );
  7653. return this; // zero angle, arbitrary axis
  7654. }
  7655. // otherwise this singularity is angle = 180
  7656. angle = Math.PI;
  7657. var xx = ( m11 + 1 ) / 2;
  7658. var yy = ( m22 + 1 ) / 2;
  7659. var zz = ( m33 + 1 ) / 2;
  7660. var xy = ( m12 + m21 ) / 4;
  7661. var xz = ( m13 + m31 ) / 4;
  7662. var yz = ( m23 + m32 ) / 4;
  7663. if ( ( xx > yy ) && ( xx > zz ) ) {
  7664. // m11 is the largest diagonal term
  7665. if ( xx < epsilon ) {
  7666. x = 0;
  7667. y = 0.707106781;
  7668. z = 0.707106781;
  7669. } else {
  7670. x = Math.sqrt( xx );
  7671. y = xy / x;
  7672. z = xz / x;
  7673. }
  7674. } else if ( yy > zz ) {
  7675. // m22 is the largest diagonal term
  7676. if ( yy < epsilon ) {
  7677. x = 0.707106781;
  7678. y = 0;
  7679. z = 0.707106781;
  7680. } else {
  7681. y = Math.sqrt( yy );
  7682. x = xy / y;
  7683. z = yz / y;
  7684. }
  7685. } else {
  7686. // m33 is the largest diagonal term so base result on this
  7687. if ( zz < epsilon ) {
  7688. x = 0.707106781;
  7689. y = 0.707106781;
  7690. z = 0;
  7691. } else {
  7692. z = Math.sqrt( zz );
  7693. x = xz / z;
  7694. y = yz / z;
  7695. }
  7696. }
  7697. this.set( x, y, z, angle );
  7698. return this; // return 180 deg rotation
  7699. }
  7700. // as we have reached here there are no singularities so we can handle normally
  7701. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 ) +
  7702. ( m13 - m31 ) * ( m13 - m31 ) +
  7703. ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  7704. if ( Math.abs( s ) < 0.001 ) s = 1;
  7705. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  7706. // caught by singularity test above, but I've left it in just in case
  7707. this.x = ( m32 - m23 ) / s;
  7708. this.y = ( m13 - m31 ) / s;
  7709. this.z = ( m21 - m12 ) / s;
  7710. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  7711. return this;
  7712. },
  7713. min: function ( v ) {
  7714. this.x = Math.min( this.x, v.x );
  7715. this.y = Math.min( this.y, v.y );
  7716. this.z = Math.min( this.z, v.z );
  7717. this.w = Math.min( this.w, v.w );
  7718. return this;
  7719. },
  7720. max: function ( v ) {
  7721. this.x = Math.max( this.x, v.x );
  7722. this.y = Math.max( this.y, v.y );
  7723. this.z = Math.max( this.z, v.z );
  7724. this.w = Math.max( this.w, v.w );
  7725. return this;
  7726. },
  7727. clamp: function ( min, max ) {
  7728. // assumes min < max, componentwise
  7729. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  7730. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  7731. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  7732. this.w = Math.max( min.w, Math.min( max.w, this.w ) );
  7733. return this;
  7734. },
  7735. clampScalar: function () {
  7736. var min, max;
  7737. return function clampScalar( minVal, maxVal ) {
  7738. if ( min === undefined ) {
  7739. min = new Vector4();
  7740. max = new Vector4();
  7741. }
  7742. min.set( minVal, minVal, minVal, minVal );
  7743. max.set( maxVal, maxVal, maxVal, maxVal );
  7744. return this.clamp( min, max );
  7745. };
  7746. }(),
  7747. clampLength: function ( min, max ) {
  7748. var length = this.length();
  7749. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  7750. },
  7751. floor: function () {
  7752. this.x = Math.floor( this.x );
  7753. this.y = Math.floor( this.y );
  7754. this.z = Math.floor( this.z );
  7755. this.w = Math.floor( this.w );
  7756. return this;
  7757. },
  7758. ceil: function () {
  7759. this.x = Math.ceil( this.x );
  7760. this.y = Math.ceil( this.y );
  7761. this.z = Math.ceil( this.z );
  7762. this.w = Math.ceil( this.w );
  7763. return this;
  7764. },
  7765. round: function () {
  7766. this.x = Math.round( this.x );
  7767. this.y = Math.round( this.y );
  7768. this.z = Math.round( this.z );
  7769. this.w = Math.round( this.w );
  7770. return this;
  7771. },
  7772. roundToZero: function () {
  7773. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  7774. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  7775. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  7776. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  7777. return this;
  7778. },
  7779. negate: function () {
  7780. this.x = - this.x;
  7781. this.y = - this.y;
  7782. this.z = - this.z;
  7783. this.w = - this.w;
  7784. return this;
  7785. },
  7786. dot: function ( v ) {
  7787. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  7788. },
  7789. lengthSq: function () {
  7790. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  7791. },
  7792. length: function () {
  7793. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  7794. },
  7795. manhattanLength: function () {
  7796. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  7797. },
  7798. normalize: function () {
  7799. return this.divideScalar( this.length() || 1 );
  7800. },
  7801. setLength: function ( length ) {
  7802. return this.normalize().multiplyScalar( length );
  7803. },
  7804. lerp: function ( v, alpha ) {
  7805. this.x += ( v.x - this.x ) * alpha;
  7806. this.y += ( v.y - this.y ) * alpha;
  7807. this.z += ( v.z - this.z ) * alpha;
  7808. this.w += ( v.w - this.w ) * alpha;
  7809. return this;
  7810. },
  7811. lerpVectors: function ( v1, v2, alpha ) {
  7812. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  7813. },
  7814. equals: function ( v ) {
  7815. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  7816. },
  7817. fromArray: function ( array, offset ) {
  7818. if ( offset === undefined ) offset = 0;
  7819. this.x = array[ offset ];
  7820. this.y = array[ offset + 1 ];
  7821. this.z = array[ offset + 2 ];
  7822. this.w = array[ offset + 3 ];
  7823. return this;
  7824. },
  7825. toArray: function ( array, offset ) {
  7826. if ( array === undefined ) array = [];
  7827. if ( offset === undefined ) offset = 0;
  7828. array[ offset ] = this.x;
  7829. array[ offset + 1 ] = this.y;
  7830. array[ offset + 2 ] = this.z;
  7831. array[ offset + 3 ] = this.w;
  7832. return array;
  7833. },
  7834. fromBufferAttribute: function ( attribute, index, offset ) {
  7835. if ( offset !== undefined ) {
  7836. console.warn( 'THREE.Vector4: offset has been removed from .fromBufferAttribute().' );
  7837. }
  7838. this.x = attribute.getX( index );
  7839. this.y = attribute.getY( index );
  7840. this.z = attribute.getZ( index );
  7841. this.w = attribute.getW( index );
  7842. return this;
  7843. }
  7844. } );
  7845. function BufferAttribute( array, itemSize, normalized ) {
  7846. if ( Array.isArray( array ) ) {
  7847. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  7848. }
  7849. this.uuid = _Math.generateUUID();
  7850. this.name = '';
  7851. this.array = array;
  7852. this.itemSize = itemSize;
  7853. this.count = array !== undefined ? array.length / itemSize : 0;
  7854. this.normalized = normalized === true;
  7855. this.dynamic = false;
  7856. this.updateRange = { offset: 0, count: - 1 };
  7857. this.onUploadCallback = function () {};
  7858. this.version = 0;
  7859. }
  7860. Object.defineProperty( BufferAttribute.prototype, 'needsUpdate', {
  7861. set: function ( value ) {
  7862. if ( value === true ) this.version ++;
  7863. }
  7864. } );
  7865. Object.assign( BufferAttribute.prototype, {
  7866. isBufferAttribute: true,
  7867. setArray: function ( array ) {
  7868. if ( Array.isArray( array ) ) {
  7869. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  7870. }
  7871. this.count = array !== undefined ? array.length / this.itemSize : 0;
  7872. this.array = array;
  7873. },
  7874. setDynamic: function ( value ) {
  7875. this.dynamic = value;
  7876. return this;
  7877. },
  7878. copy: function ( source ) {
  7879. this.array = new source.array.constructor( source.array );
  7880. this.itemSize = source.itemSize;
  7881. this.count = source.count;
  7882. this.normalized = source.normalized;
  7883. this.dynamic = source.dynamic;
  7884. return this;
  7885. },
  7886. copyAt: function ( index1, attribute, index2 ) {
  7887. index1 *= this.itemSize;
  7888. index2 *= attribute.itemSize;
  7889. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  7890. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  7891. }
  7892. return this;
  7893. },
  7894. copyArray: function ( array ) {
  7895. this.array.set( array );
  7896. return this;
  7897. },
  7898. copyColorsArray: function ( colors ) {
  7899. var array = this.array, offset = 0;
  7900. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  7901. var color = colors[ i ];
  7902. if ( color === undefined ) {
  7903. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  7904. color = new Color();
  7905. }
  7906. array[ offset ++ ] = color.r;
  7907. array[ offset ++ ] = color.g;
  7908. array[ offset ++ ] = color.b;
  7909. }
  7910. return this;
  7911. },
  7912. copyIndicesArray: function ( indices ) {
  7913. var array = this.array, offset = 0;
  7914. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  7915. var index = indices[ i ];
  7916. array[ offset ++ ] = index.a;
  7917. array[ offset ++ ] = index.b;
  7918. array[ offset ++ ] = index.c;
  7919. }
  7920. return this;
  7921. },
  7922. copyVector2sArray: function ( vectors ) {
  7923. var array = this.array, offset = 0;
  7924. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  7925. var vector = vectors[ i ];
  7926. if ( vector === undefined ) {
  7927. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  7928. vector = new Vector2();
  7929. }
  7930. array[ offset ++ ] = vector.x;
  7931. array[ offset ++ ] = vector.y;
  7932. }
  7933. return this;
  7934. },
  7935. copyVector3sArray: function ( vectors ) {
  7936. var array = this.array, offset = 0;
  7937. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  7938. var vector = vectors[ i ];
  7939. if ( vector === undefined ) {
  7940. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  7941. vector = new Vector3();
  7942. }
  7943. array[ offset ++ ] = vector.x;
  7944. array[ offset ++ ] = vector.y;
  7945. array[ offset ++ ] = vector.z;
  7946. }
  7947. return this;
  7948. },
  7949. copyVector4sArray: function ( vectors ) {
  7950. var array = this.array, offset = 0;
  7951. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  7952. var vector = vectors[ i ];
  7953. if ( vector === undefined ) {
  7954. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  7955. vector = new Vector4();
  7956. }
  7957. array[ offset ++ ] = vector.x;
  7958. array[ offset ++ ] = vector.y;
  7959. array[ offset ++ ] = vector.z;
  7960. array[ offset ++ ] = vector.w;
  7961. }
  7962. return this;
  7963. },
  7964. set: function ( value, offset ) {
  7965. if ( offset === undefined ) offset = 0;
  7966. this.array.set( value, offset );
  7967. return this;
  7968. },
  7969. getX: function ( index ) {
  7970. return this.array[ index * this.itemSize ];
  7971. },
  7972. setX: function ( index, x ) {
  7973. this.array[ index * this.itemSize ] = x;
  7974. return this;
  7975. },
  7976. getY: function ( index ) {
  7977. return this.array[ index * this.itemSize + 1 ];
  7978. },
  7979. setY: function ( index, y ) {
  7980. this.array[ index * this.itemSize + 1 ] = y;
  7981. return this;
  7982. },
  7983. getZ: function ( index ) {
  7984. return this.array[ index * this.itemSize + 2 ];
  7985. },
  7986. setZ: function ( index, z ) {
  7987. this.array[ index * this.itemSize + 2 ] = z;
  7988. return this;
  7989. },
  7990. getW: function ( index ) {
  7991. return this.array[ index * this.itemSize + 3 ];
  7992. },
  7993. setW: function ( index, w ) {
  7994. this.array[ index * this.itemSize + 3 ] = w;
  7995. return this;
  7996. },
  7997. setXY: function ( index, x, y ) {
  7998. index *= this.itemSize;
  7999. this.array[ index + 0 ] = x;
  8000. this.array[ index + 1 ] = y;
  8001. return this;
  8002. },
  8003. setXYZ: function ( index, x, y, z ) {
  8004. index *= this.itemSize;
  8005. this.array[ index + 0 ] = x;
  8006. this.array[ index + 1 ] = y;
  8007. this.array[ index + 2 ] = z;
  8008. return this;
  8009. },
  8010. setXYZW: function ( index, x, y, z, w ) {
  8011. index *= this.itemSize;
  8012. this.array[ index + 0 ] = x;
  8013. this.array[ index + 1 ] = y;
  8014. this.array[ index + 2 ] = z;
  8015. this.array[ index + 3 ] = w;
  8016. return this;
  8017. },
  8018. onUpload: function ( callback ) {
  8019. this.onUploadCallback = callback;
  8020. return this;
  8021. },
  8022. clone: function () {
  8023. return new this.constructor( this.array, this.itemSize ).copy( this );
  8024. }
  8025. } );
  8026. //
  8027. function Uint16BufferAttribute( array, itemSize, normalized ) {
  8028. BufferAttribute.call( this, new Uint16Array( array ), itemSize, normalized );
  8029. }
  8030. Uint16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  8031. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  8032. function Uint32BufferAttribute( array, itemSize, normalized ) {
  8033. BufferAttribute.call( this, new Uint32Array( array ), itemSize, normalized );
  8034. }
  8035. Uint32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  8036. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  8037. function Float32BufferAttribute( array, itemSize, normalized ) {
  8038. BufferAttribute.call( this, new Float32Array( array ), itemSize, normalized );
  8039. }
  8040. Float32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  8041. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  8042. /**
  8043. * @author mrdoob / http://mrdoob.com/
  8044. */
  8045. function DirectGeometry() {
  8046. this.indices = [];
  8047. this.vertices = [];
  8048. this.normals = [];
  8049. this.colors = [];
  8050. this.uvs = [];
  8051. this.uvs2 = [];
  8052. this.groups = [];
  8053. this.morphTargets = {};
  8054. this.skinWeights = [];
  8055. this.skinIndices = [];
  8056. // this.lineDistances = [];
  8057. this.boundingBox = null;
  8058. this.boundingSphere = null;
  8059. // update flags
  8060. this.verticesNeedUpdate = false;
  8061. this.normalsNeedUpdate = false;
  8062. this.colorsNeedUpdate = false;
  8063. this.uvsNeedUpdate = false;
  8064. this.groupsNeedUpdate = false;
  8065. }
  8066. Object.assign( DirectGeometry.prototype, {
  8067. computeGroups: function ( geometry ) {
  8068. var group;
  8069. var groups = [];
  8070. var materialIndex = undefined;
  8071. var faces = geometry.faces;
  8072. for ( var i = 0; i < faces.length; i ++ ) {
  8073. var face = faces[ i ];
  8074. // materials
  8075. if ( face.materialIndex !== materialIndex ) {
  8076. materialIndex = face.materialIndex;
  8077. if ( group !== undefined ) {
  8078. group.count = ( i * 3 ) - group.start;
  8079. groups.push( group );
  8080. }
  8081. group = {
  8082. start: i * 3,
  8083. materialIndex: materialIndex
  8084. };
  8085. }
  8086. }
  8087. if ( group !== undefined ) {
  8088. group.count = ( i * 3 ) - group.start;
  8089. groups.push( group );
  8090. }
  8091. this.groups = groups;
  8092. },
  8093. fromGeometry: function ( geometry ) {
  8094. var faces = geometry.faces;
  8095. var vertices = geometry.vertices;
  8096. var faceVertexUvs = geometry.faceVertexUvs;
  8097. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  8098. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  8099. // morphs
  8100. var morphTargets = geometry.morphTargets;
  8101. var morphTargetsLength = morphTargets.length;
  8102. var morphTargetsPosition;
  8103. if ( morphTargetsLength > 0 ) {
  8104. morphTargetsPosition = [];
  8105. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  8106. morphTargetsPosition[ i ] = [];
  8107. }
  8108. this.morphTargets.position = morphTargetsPosition;
  8109. }
  8110. var morphNormals = geometry.morphNormals;
  8111. var morphNormalsLength = morphNormals.length;
  8112. var morphTargetsNormal;
  8113. if ( morphNormalsLength > 0 ) {
  8114. morphTargetsNormal = [];
  8115. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  8116. morphTargetsNormal[ i ] = [];
  8117. }
  8118. this.morphTargets.normal = morphTargetsNormal;
  8119. }
  8120. // skins
  8121. var skinIndices = geometry.skinIndices;
  8122. var skinWeights = geometry.skinWeights;
  8123. var hasSkinIndices = skinIndices.length === vertices.length;
  8124. var hasSkinWeights = skinWeights.length === vertices.length;
  8125. //
  8126. for ( var i = 0; i < faces.length; i ++ ) {
  8127. var face = faces[ i ];
  8128. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  8129. var vertexNormals = face.vertexNormals;
  8130. if ( vertexNormals.length === 3 ) {
  8131. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  8132. } else {
  8133. var normal = face.normal;
  8134. this.normals.push( normal, normal, normal );
  8135. }
  8136. var vertexColors = face.vertexColors;
  8137. if ( vertexColors.length === 3 ) {
  8138. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  8139. } else {
  8140. var color = face.color;
  8141. this.colors.push( color, color, color );
  8142. }
  8143. if ( hasFaceVertexUv === true ) {
  8144. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  8145. if ( vertexUvs !== undefined ) {
  8146. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  8147. } else {
  8148. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  8149. this.uvs.push( new Vector2(), new Vector2(), new Vector2() );
  8150. }
  8151. }
  8152. if ( hasFaceVertexUv2 === true ) {
  8153. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  8154. if ( vertexUvs !== undefined ) {
  8155. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  8156. } else {
  8157. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  8158. this.uvs2.push( new Vector2(), new Vector2(), new Vector2() );
  8159. }
  8160. }
  8161. // morphs
  8162. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  8163. var morphTarget = morphTargets[ j ].vertices;
  8164. morphTargetsPosition[ j ].push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  8165. }
  8166. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  8167. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  8168. morphTargetsNormal[ j ].push( morphNormal.a, morphNormal.b, morphNormal.c );
  8169. }
  8170. // skins
  8171. if ( hasSkinIndices ) {
  8172. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  8173. }
  8174. if ( hasSkinWeights ) {
  8175. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  8176. }
  8177. }
  8178. this.computeGroups( geometry );
  8179. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  8180. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  8181. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  8182. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  8183. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  8184. return this;
  8185. }
  8186. } );
  8187. var bufferGeometryId = 1; // BufferGeometry uses odd numbers as Id
  8188. function BufferGeometry() {
  8189. Object.defineProperty( this, 'id', { value: bufferGeometryId += 2 } );
  8190. this.uuid = _Math.generateUUID();
  8191. this.name = '';
  8192. this.type = 'BufferGeometry';
  8193. this.index = null;
  8194. this.attributes = {};
  8195. this.morphAttributes = {};
  8196. this.groups = [];
  8197. this.boundingBox = null;
  8198. this.boundingSphere = null;
  8199. this.drawRange = { start: 0, count: Infinity };
  8200. }
  8201. Object.assign( BufferGeometry.prototype, EventDispatcher.prototype, {
  8202. isBufferGeometry: true,
  8203. getIndex: function () {
  8204. return this.index;
  8205. },
  8206. setIndex: function ( index ) {
  8207. if ( Array.isArray( index ) ) {
  8208. this.index = new ( arrayMax( index ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( index, 1 );
  8209. } else {
  8210. this.index = index;
  8211. }
  8212. },
  8213. addAttribute: function ( name, attribute ) {
  8214. if ( ! ( attribute && attribute.isBufferAttribute ) && ! ( attribute && attribute.isInterleavedBufferAttribute ) ) {
  8215. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  8216. this.addAttribute( name, new BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  8217. return;
  8218. }
  8219. if ( name === 'index' ) {
  8220. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  8221. this.setIndex( attribute );
  8222. return;
  8223. }
  8224. this.attributes[ name ] = attribute;
  8225. return this;
  8226. },
  8227. getAttribute: function ( name ) {
  8228. return this.attributes[ name ];
  8229. },
  8230. removeAttribute: function ( name ) {
  8231. delete this.attributes[ name ];
  8232. return this;
  8233. },
  8234. addGroup: function ( start, count, materialIndex ) {
  8235. this.groups.push( {
  8236. start: start,
  8237. count: count,
  8238. materialIndex: materialIndex !== undefined ? materialIndex : 0
  8239. } );
  8240. },
  8241. clearGroups: function () {
  8242. this.groups = [];
  8243. },
  8244. setDrawRange: function ( start, count ) {
  8245. this.drawRange.start = start;
  8246. this.drawRange.count = count;
  8247. },
  8248. applyMatrix: function ( matrix ) {
  8249. var position = this.attributes.position;
  8250. if ( position !== undefined ) {
  8251. matrix.applyToBufferAttribute( position );
  8252. position.needsUpdate = true;
  8253. }
  8254. var normal = this.attributes.normal;
  8255. if ( normal !== undefined ) {
  8256. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  8257. normalMatrix.applyToBufferAttribute( normal );
  8258. normal.needsUpdate = true;
  8259. }
  8260. if ( this.boundingBox !== null ) {
  8261. this.computeBoundingBox();
  8262. }
  8263. if ( this.boundingSphere !== null ) {
  8264. this.computeBoundingSphere();
  8265. }
  8266. return this;
  8267. },
  8268. rotateX: function () {
  8269. // rotate geometry around world x-axis
  8270. var m1 = new Matrix4();
  8271. return function rotateX( angle ) {
  8272. m1.makeRotationX( angle );
  8273. this.applyMatrix( m1 );
  8274. return this;
  8275. };
  8276. }(),
  8277. rotateY: function () {
  8278. // rotate geometry around world y-axis
  8279. var m1 = new Matrix4();
  8280. return function rotateY( angle ) {
  8281. m1.makeRotationY( angle );
  8282. this.applyMatrix( m1 );
  8283. return this;
  8284. };
  8285. }(),
  8286. rotateZ: function () {
  8287. // rotate geometry around world z-axis
  8288. var m1 = new Matrix4();
  8289. return function rotateZ( angle ) {
  8290. m1.makeRotationZ( angle );
  8291. this.applyMatrix( m1 );
  8292. return this;
  8293. };
  8294. }(),
  8295. translate: function () {
  8296. // translate geometry
  8297. var m1 = new Matrix4();
  8298. return function translate( x, y, z ) {
  8299. m1.makeTranslation( x, y, z );
  8300. this.applyMatrix( m1 );
  8301. return this;
  8302. };
  8303. }(),
  8304. scale: function () {
  8305. // scale geometry
  8306. var m1 = new Matrix4();
  8307. return function scale( x, y, z ) {
  8308. m1.makeScale( x, y, z );
  8309. this.applyMatrix( m1 );
  8310. return this;
  8311. };
  8312. }(),
  8313. lookAt: function () {
  8314. var obj = new Object3D();
  8315. return function lookAt( vector ) {
  8316. obj.lookAt( vector );
  8317. obj.updateMatrix();
  8318. this.applyMatrix( obj.matrix );
  8319. };
  8320. }(),
  8321. center: function () {
  8322. this.computeBoundingBox();
  8323. var offset = this.boundingBox.getCenter().negate();
  8324. this.translate( offset.x, offset.y, offset.z );
  8325. return offset;
  8326. },
  8327. setFromObject: function ( object ) {
  8328. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  8329. var geometry = object.geometry;
  8330. if ( object.isPoints || object.isLine ) {
  8331. var positions = new Float32BufferAttribute( geometry.vertices.length * 3, 3 );
  8332. var colors = new Float32BufferAttribute( geometry.colors.length * 3, 3 );
  8333. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  8334. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  8335. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  8336. var lineDistances = new Float32BufferAttribute( geometry.lineDistances.length, 1 );
  8337. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  8338. }
  8339. if ( geometry.boundingSphere !== null ) {
  8340. this.boundingSphere = geometry.boundingSphere.clone();
  8341. }
  8342. if ( geometry.boundingBox !== null ) {
  8343. this.boundingBox = geometry.boundingBox.clone();
  8344. }
  8345. } else if ( object.isMesh ) {
  8346. if ( geometry && geometry.isGeometry ) {
  8347. this.fromGeometry( geometry );
  8348. }
  8349. }
  8350. return this;
  8351. },
  8352. setFromPoints: function ( points ) {
  8353. var position = [];
  8354. for ( var i = 0, l = points.length; i < l; i ++ ) {
  8355. var point = points[ i ];
  8356. position.push( point.x, point.y, point.z || 0 );
  8357. }
  8358. this.addAttribute( 'position', new Float32BufferAttribute( position, 3 ) );
  8359. return this;
  8360. },
  8361. updateFromObject: function ( object ) {
  8362. var geometry = object.geometry;
  8363. if ( object.isMesh ) {
  8364. var direct = geometry.__directGeometry;
  8365. if ( geometry.elementsNeedUpdate === true ) {
  8366. direct = undefined;
  8367. geometry.elementsNeedUpdate = false;
  8368. }
  8369. if ( direct === undefined ) {
  8370. return this.fromGeometry( geometry );
  8371. }
  8372. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  8373. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  8374. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  8375. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  8376. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  8377. geometry.verticesNeedUpdate = false;
  8378. geometry.normalsNeedUpdate = false;
  8379. geometry.colorsNeedUpdate = false;
  8380. geometry.uvsNeedUpdate = false;
  8381. geometry.groupsNeedUpdate = false;
  8382. geometry = direct;
  8383. }
  8384. var attribute;
  8385. if ( geometry.verticesNeedUpdate === true ) {
  8386. attribute = this.attributes.position;
  8387. if ( attribute !== undefined ) {
  8388. attribute.copyVector3sArray( geometry.vertices );
  8389. attribute.needsUpdate = true;
  8390. }
  8391. geometry.verticesNeedUpdate = false;
  8392. }
  8393. if ( geometry.normalsNeedUpdate === true ) {
  8394. attribute = this.attributes.normal;
  8395. if ( attribute !== undefined ) {
  8396. attribute.copyVector3sArray( geometry.normals );
  8397. attribute.needsUpdate = true;
  8398. }
  8399. geometry.normalsNeedUpdate = false;
  8400. }
  8401. if ( geometry.colorsNeedUpdate === true ) {
  8402. attribute = this.attributes.color;
  8403. if ( attribute !== undefined ) {
  8404. attribute.copyColorsArray( geometry.colors );
  8405. attribute.needsUpdate = true;
  8406. }
  8407. geometry.colorsNeedUpdate = false;
  8408. }
  8409. if ( geometry.uvsNeedUpdate ) {
  8410. attribute = this.attributes.uv;
  8411. if ( attribute !== undefined ) {
  8412. attribute.copyVector2sArray( geometry.uvs );
  8413. attribute.needsUpdate = true;
  8414. }
  8415. geometry.uvsNeedUpdate = false;
  8416. }
  8417. if ( geometry.lineDistancesNeedUpdate ) {
  8418. attribute = this.attributes.lineDistance;
  8419. if ( attribute !== undefined ) {
  8420. attribute.copyArray( geometry.lineDistances );
  8421. attribute.needsUpdate = true;
  8422. }
  8423. geometry.lineDistancesNeedUpdate = false;
  8424. }
  8425. if ( geometry.groupsNeedUpdate ) {
  8426. geometry.computeGroups( object.geometry );
  8427. this.groups = geometry.groups;
  8428. geometry.groupsNeedUpdate = false;
  8429. }
  8430. return this;
  8431. },
  8432. fromGeometry: function ( geometry ) {
  8433. geometry.__directGeometry = new DirectGeometry().fromGeometry( geometry );
  8434. return this.fromDirectGeometry( geometry.__directGeometry );
  8435. },
  8436. fromDirectGeometry: function ( geometry ) {
  8437. var positions = new Float32Array( geometry.vertices.length * 3 );
  8438. this.addAttribute( 'position', new BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  8439. if ( geometry.normals.length > 0 ) {
  8440. var normals = new Float32Array( geometry.normals.length * 3 );
  8441. this.addAttribute( 'normal', new BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  8442. }
  8443. if ( geometry.colors.length > 0 ) {
  8444. var colors = new Float32Array( geometry.colors.length * 3 );
  8445. this.addAttribute( 'color', new BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  8446. }
  8447. if ( geometry.uvs.length > 0 ) {
  8448. var uvs = new Float32Array( geometry.uvs.length * 2 );
  8449. this.addAttribute( 'uv', new BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  8450. }
  8451. if ( geometry.uvs2.length > 0 ) {
  8452. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  8453. this.addAttribute( 'uv2', new BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  8454. }
  8455. if ( geometry.indices.length > 0 ) {
  8456. var TypeArray = arrayMax( geometry.indices ) > 65535 ? Uint32Array : Uint16Array;
  8457. var indices = new TypeArray( geometry.indices.length * 3 );
  8458. this.setIndex( new BufferAttribute( indices, 1 ).copyIndicesArray( geometry.indices ) );
  8459. }
  8460. // groups
  8461. this.groups = geometry.groups;
  8462. // morphs
  8463. for ( var name in geometry.morphTargets ) {
  8464. var array = [];
  8465. var morphTargets = geometry.morphTargets[ name ];
  8466. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  8467. var morphTarget = morphTargets[ i ];
  8468. var attribute = new Float32BufferAttribute( morphTarget.length * 3, 3 );
  8469. array.push( attribute.copyVector3sArray( morphTarget ) );
  8470. }
  8471. this.morphAttributes[ name ] = array;
  8472. }
  8473. // skinning
  8474. if ( geometry.skinIndices.length > 0 ) {
  8475. var skinIndices = new Float32BufferAttribute( geometry.skinIndices.length * 4, 4 );
  8476. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  8477. }
  8478. if ( geometry.skinWeights.length > 0 ) {
  8479. var skinWeights = new Float32BufferAttribute( geometry.skinWeights.length * 4, 4 );
  8480. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  8481. }
  8482. //
  8483. if ( geometry.boundingSphere !== null ) {
  8484. this.boundingSphere = geometry.boundingSphere.clone();
  8485. }
  8486. if ( geometry.boundingBox !== null ) {
  8487. this.boundingBox = geometry.boundingBox.clone();
  8488. }
  8489. return this;
  8490. },
  8491. computeBoundingBox: function () {
  8492. if ( this.boundingBox === null ) {
  8493. this.boundingBox = new Box3();
  8494. }
  8495. var position = this.attributes.position;
  8496. if ( position !== undefined ) {
  8497. this.boundingBox.setFromBufferAttribute( position );
  8498. } else {
  8499. this.boundingBox.makeEmpty();
  8500. }
  8501. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  8502. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  8503. }
  8504. },
  8505. computeBoundingSphere: function () {
  8506. var box = new Box3();
  8507. var vector = new Vector3();
  8508. return function computeBoundingSphere() {
  8509. if ( this.boundingSphere === null ) {
  8510. this.boundingSphere = new Sphere();
  8511. }
  8512. var position = this.attributes.position;
  8513. if ( position ) {
  8514. var center = this.boundingSphere.center;
  8515. box.setFromBufferAttribute( position );
  8516. box.getCenter( center );
  8517. // hoping to find a boundingSphere with a radius smaller than the
  8518. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  8519. var maxRadiusSq = 0;
  8520. for ( var i = 0, il = position.count; i < il; i ++ ) {
  8521. vector.x = position.getX( i );
  8522. vector.y = position.getY( i );
  8523. vector.z = position.getZ( i );
  8524. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  8525. }
  8526. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  8527. if ( isNaN( this.boundingSphere.radius ) ) {
  8528. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  8529. }
  8530. }
  8531. };
  8532. }(),
  8533. computeFaceNormals: function () {
  8534. // backwards compatibility
  8535. },
  8536. computeVertexNormals: function () {
  8537. var index = this.index;
  8538. var attributes = this.attributes;
  8539. var groups = this.groups;
  8540. if ( attributes.position ) {
  8541. var positions = attributes.position.array;
  8542. if ( attributes.normal === undefined ) {
  8543. this.addAttribute( 'normal', new BufferAttribute( new Float32Array( positions.length ), 3 ) );
  8544. } else {
  8545. // reset existing normals to zero
  8546. var array = attributes.normal.array;
  8547. for ( var i = 0, il = array.length; i < il; i ++ ) {
  8548. array[ i ] = 0;
  8549. }
  8550. }
  8551. var normals = attributes.normal.array;
  8552. var vA, vB, vC;
  8553. var pA = new Vector3(), pB = new Vector3(), pC = new Vector3();
  8554. var cb = new Vector3(), ab = new Vector3();
  8555. // indexed elements
  8556. if ( index ) {
  8557. var indices = index.array;
  8558. if ( groups.length === 0 ) {
  8559. this.addGroup( 0, indices.length );
  8560. }
  8561. for ( var j = 0, jl = groups.length; j < jl; ++ j ) {
  8562. var group = groups[ j ];
  8563. var start = group.start;
  8564. var count = group.count;
  8565. for ( var i = start, il = start + count; i < il; i += 3 ) {
  8566. vA = indices[ i + 0 ] * 3;
  8567. vB = indices[ i + 1 ] * 3;
  8568. vC = indices[ i + 2 ] * 3;
  8569. pA.fromArray( positions, vA );
  8570. pB.fromArray( positions, vB );
  8571. pC.fromArray( positions, vC );
  8572. cb.subVectors( pC, pB );
  8573. ab.subVectors( pA, pB );
  8574. cb.cross( ab );
  8575. normals[ vA ] += cb.x;
  8576. normals[ vA + 1 ] += cb.y;
  8577. normals[ vA + 2 ] += cb.z;
  8578. normals[ vB ] += cb.x;
  8579. normals[ vB + 1 ] += cb.y;
  8580. normals[ vB + 2 ] += cb.z;
  8581. normals[ vC ] += cb.x;
  8582. normals[ vC + 1 ] += cb.y;
  8583. normals[ vC + 2 ] += cb.z;
  8584. }
  8585. }
  8586. } else {
  8587. // non-indexed elements (unconnected triangle soup)
  8588. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  8589. pA.fromArray( positions, i );
  8590. pB.fromArray( positions, i + 3 );
  8591. pC.fromArray( positions, i + 6 );
  8592. cb.subVectors( pC, pB );
  8593. ab.subVectors( pA, pB );
  8594. cb.cross( ab );
  8595. normals[ i ] = cb.x;
  8596. normals[ i + 1 ] = cb.y;
  8597. normals[ i + 2 ] = cb.z;
  8598. normals[ i + 3 ] = cb.x;
  8599. normals[ i + 4 ] = cb.y;
  8600. normals[ i + 5 ] = cb.z;
  8601. normals[ i + 6 ] = cb.x;
  8602. normals[ i + 7 ] = cb.y;
  8603. normals[ i + 8 ] = cb.z;
  8604. }
  8605. }
  8606. this.normalizeNormals();
  8607. attributes.normal.needsUpdate = true;
  8608. }
  8609. },
  8610. merge: function ( geometry, offset ) {
  8611. if ( ! ( geometry && geometry.isBufferGeometry ) ) {
  8612. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  8613. return;
  8614. }
  8615. if ( offset === undefined ) offset = 0;
  8616. var attributes = this.attributes;
  8617. for ( var key in attributes ) {
  8618. if ( geometry.attributes[ key ] === undefined ) continue;
  8619. var attribute1 = attributes[ key ];
  8620. var attributeArray1 = attribute1.array;
  8621. var attribute2 = geometry.attributes[ key ];
  8622. var attributeArray2 = attribute2.array;
  8623. var attributeSize = attribute2.itemSize;
  8624. for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length; i ++, j ++ ) {
  8625. attributeArray1[ j ] = attributeArray2[ i ];
  8626. }
  8627. }
  8628. return this;
  8629. },
  8630. normalizeNormals: function () {
  8631. var vector = new Vector3();
  8632. return function normalizeNormals() {
  8633. var normals = this.attributes.normal;
  8634. for ( var i = 0, il = normals.count; i < il; i ++ ) {
  8635. vector.x = normals.getX( i );
  8636. vector.y = normals.getY( i );
  8637. vector.z = normals.getZ( i );
  8638. vector.normalize();
  8639. normals.setXYZ( i, vector.x, vector.y, vector.z );
  8640. }
  8641. };
  8642. }(),
  8643. toNonIndexed: function () {
  8644. if ( this.index === null ) {
  8645. console.warn( 'THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.' );
  8646. return this;
  8647. }
  8648. var geometry2 = new BufferGeometry();
  8649. var indices = this.index.array;
  8650. var attributes = this.attributes;
  8651. for ( var name in attributes ) {
  8652. var attribute = attributes[ name ];
  8653. var array = attribute.array;
  8654. var itemSize = attribute.itemSize;
  8655. var array2 = new array.constructor( indices.length * itemSize );
  8656. var index = 0, index2 = 0;
  8657. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  8658. index = indices[ i ] * itemSize;
  8659. for ( var j = 0; j < itemSize; j ++ ) {
  8660. array2[ index2 ++ ] = array[ index ++ ];
  8661. }
  8662. }
  8663. geometry2.addAttribute( name, new BufferAttribute( array2, itemSize ) );
  8664. }
  8665. return geometry2;
  8666. },
  8667. toJSON: function () {
  8668. var data = {
  8669. metadata: {
  8670. version: 4.5,
  8671. type: 'BufferGeometry',
  8672. generator: 'BufferGeometry.toJSON'
  8673. }
  8674. };
  8675. // standard BufferGeometry serialization
  8676. data.uuid = this.uuid;
  8677. data.type = this.type;
  8678. if ( this.name !== '' ) data.name = this.name;
  8679. if ( this.parameters !== undefined ) {
  8680. var parameters = this.parameters;
  8681. for ( var key in parameters ) {
  8682. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  8683. }
  8684. return data;
  8685. }
  8686. data.data = { attributes: {} };
  8687. var index = this.index;
  8688. if ( index !== null ) {
  8689. var array = Array.prototype.slice.call( index.array );
  8690. data.data.index = {
  8691. type: index.array.constructor.name,
  8692. array: array
  8693. };
  8694. }
  8695. var attributes = this.attributes;
  8696. for ( var key in attributes ) {
  8697. var attribute = attributes[ key ];
  8698. var array = Array.prototype.slice.call( attribute.array );
  8699. data.data.attributes[ key ] = {
  8700. itemSize: attribute.itemSize,
  8701. type: attribute.array.constructor.name,
  8702. array: array,
  8703. normalized: attribute.normalized
  8704. };
  8705. }
  8706. var groups = this.groups;
  8707. if ( groups.length > 0 ) {
  8708. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  8709. }
  8710. var boundingSphere = this.boundingSphere;
  8711. if ( boundingSphere !== null ) {
  8712. data.data.boundingSphere = {
  8713. center: boundingSphere.center.toArray(),
  8714. radius: boundingSphere.radius
  8715. };
  8716. }
  8717. return data;
  8718. },
  8719. clone: function () {
  8720. /*
  8721. // Handle primitives
  8722. var parameters = this.parameters;
  8723. if ( parameters !== undefined ) {
  8724. var values = [];
  8725. for ( var key in parameters ) {
  8726. values.push( parameters[ key ] );
  8727. }
  8728. var geometry = Object.create( this.constructor.prototype );
  8729. this.constructor.apply( geometry, values );
  8730. return geometry;
  8731. }
  8732. return new this.constructor().copy( this );
  8733. */
  8734. return new BufferGeometry().copy( this );
  8735. },
  8736. copy: function ( source ) {
  8737. var name, i, l;
  8738. // reset
  8739. this.index = null;
  8740. this.attributes = {};
  8741. this.morphAttributes = {};
  8742. this.groups = [];
  8743. this.boundingBox = null;
  8744. this.boundingSphere = null;
  8745. // name
  8746. this.name = source.name;
  8747. // index
  8748. var index = source.index;
  8749. if ( index !== null ) {
  8750. this.setIndex( index.clone() );
  8751. }
  8752. // attributes
  8753. var attributes = source.attributes;
  8754. for ( name in attributes ) {
  8755. var attribute = attributes[ name ];
  8756. this.addAttribute( name, attribute.clone() );
  8757. }
  8758. // morph attributes
  8759. var morphAttributes = source.morphAttributes;
  8760. for ( name in morphAttributes ) {
  8761. var array = [];
  8762. var morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  8763. for ( i = 0, l = morphAttribute.length; i < l; i ++ ) {
  8764. array.push( morphAttribute[ i ].clone() );
  8765. }
  8766. this.morphAttributes[ name ] = array;
  8767. }
  8768. // groups
  8769. var groups = source.groups;
  8770. for ( i = 0, l = groups.length; i < l; i ++ ) {
  8771. var group = groups[ i ];
  8772. this.addGroup( group.start, group.count, group.materialIndex );
  8773. }
  8774. // bounding box
  8775. var boundingBox = source.boundingBox;
  8776. if ( boundingBox !== null ) {
  8777. this.boundingBox = boundingBox.clone();
  8778. }
  8779. // bounding sphere
  8780. var boundingSphere = source.boundingSphere;
  8781. if ( boundingSphere !== null ) {
  8782. this.boundingSphere = boundingSphere.clone();
  8783. }
  8784. // draw range
  8785. this.drawRange.start = source.drawRange.start;
  8786. this.drawRange.count = source.drawRange.count;
  8787. return this;
  8788. },
  8789. dispose: function () {
  8790. this.dispatchEvent( { type: 'dispose' } );
  8791. }
  8792. } );
  8793. /**
  8794. * @author mrdoob / http://mrdoob.com/
  8795. * @author Mugen87 / https://github.com/Mugen87
  8796. */
  8797. function BoxGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  8798. Geometry.call( this );
  8799. this.type = 'BoxGeometry';
  8800. this.parameters = {
  8801. width: width,
  8802. height: height,
  8803. depth: depth,
  8804. widthSegments: widthSegments,
  8805. heightSegments: heightSegments,
  8806. depthSegments: depthSegments
  8807. };
  8808. this.fromBufferGeometry( new BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) );
  8809. this.mergeVertices();
  8810. }
  8811. BoxGeometry.prototype = Object.create( Geometry.prototype );
  8812. BoxGeometry.prototype.constructor = BoxGeometry;
  8813. // BoxBufferGeometry
  8814. function BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  8815. BufferGeometry.call( this );
  8816. this.type = 'BoxBufferGeometry';
  8817. this.parameters = {
  8818. width: width,
  8819. height: height,
  8820. depth: depth,
  8821. widthSegments: widthSegments,
  8822. heightSegments: heightSegments,
  8823. depthSegments: depthSegments
  8824. };
  8825. var scope = this;
  8826. width = width || 1;
  8827. height = height || 1;
  8828. depth = depth || 1;
  8829. // segments
  8830. widthSegments = Math.floor( widthSegments ) || 1;
  8831. heightSegments = Math.floor( heightSegments ) || 1;
  8832. depthSegments = Math.floor( depthSegments ) || 1;
  8833. // buffers
  8834. var indices = [];
  8835. var vertices = [];
  8836. var normals = [];
  8837. var uvs = [];
  8838. // helper variables
  8839. var numberOfVertices = 0;
  8840. var groupStart = 0;
  8841. // build each side of the box geometry
  8842. buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px
  8843. buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
  8844. buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
  8845. buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
  8846. buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
  8847. buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
  8848. // build geometry
  8849. this.setIndex( indices );
  8850. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  8851. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  8852. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  8853. function buildPlane( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
  8854. var segmentWidth = width / gridX;
  8855. var segmentHeight = height / gridY;
  8856. var widthHalf = width / 2;
  8857. var heightHalf = height / 2;
  8858. var depthHalf = depth / 2;
  8859. var gridX1 = gridX + 1;
  8860. var gridY1 = gridY + 1;
  8861. var vertexCounter = 0;
  8862. var groupCount = 0;
  8863. var ix, iy;
  8864. var vector = new Vector3();
  8865. // generate vertices, normals and uvs
  8866. for ( iy = 0; iy < gridY1; iy ++ ) {
  8867. var y = iy * segmentHeight - heightHalf;
  8868. for ( ix = 0; ix < gridX1; ix ++ ) {
  8869. var x = ix * segmentWidth - widthHalf;
  8870. // set values to correct vector component
  8871. vector[ u ] = x * udir;
  8872. vector[ v ] = y * vdir;
  8873. vector[ w ] = depthHalf;
  8874. // now apply vector to vertex buffer
  8875. vertices.push( vector.x, vector.y, vector.z );
  8876. // set values to correct vector component
  8877. vector[ u ] = 0;
  8878. vector[ v ] = 0;
  8879. vector[ w ] = depth > 0 ? 1 : - 1;
  8880. // now apply vector to normal buffer
  8881. normals.push( vector.x, vector.y, vector.z );
  8882. // uvs
  8883. uvs.push( ix / gridX );
  8884. uvs.push( 1 - ( iy / gridY ) );
  8885. // counters
  8886. vertexCounter += 1;
  8887. }
  8888. }
  8889. // indices
  8890. // 1. you need three indices to draw a single face
  8891. // 2. a single segment consists of two faces
  8892. // 3. so we need to generate six (2*3) indices per segment
  8893. for ( iy = 0; iy < gridY; iy ++ ) {
  8894. for ( ix = 0; ix < gridX; ix ++ ) {
  8895. var a = numberOfVertices + ix + gridX1 * iy;
  8896. var b = numberOfVertices + ix + gridX1 * ( iy + 1 );
  8897. var c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
  8898. var d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
  8899. // faces
  8900. indices.push( a, b, d );
  8901. indices.push( b, c, d );
  8902. // increase counter
  8903. groupCount += 6;
  8904. }
  8905. }
  8906. // add a group to the geometry. this will ensure multi material support
  8907. scope.addGroup( groupStart, groupCount, materialIndex );
  8908. // calculate new start value for groups
  8909. groupStart += groupCount;
  8910. // update total number of vertices
  8911. numberOfVertices += vertexCounter;
  8912. }
  8913. }
  8914. BoxBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  8915. BoxBufferGeometry.prototype.constructor = BoxBufferGeometry;
  8916. function Ray( origin, direction ) {
  8917. this.origin = ( origin !== undefined ) ? origin : new Vector3();
  8918. this.direction = ( direction !== undefined ) ? direction : new Vector3();
  8919. }
  8920. Object.assign( Ray.prototype, {
  8921. set: function ( origin, direction ) {
  8922. this.origin.copy( origin );
  8923. this.direction.copy( direction );
  8924. return this;
  8925. },
  8926. clone: function () {
  8927. return new this.constructor().copy( this );
  8928. },
  8929. copy: function ( ray ) {
  8930. this.origin.copy( ray.origin );
  8931. this.direction.copy( ray.direction );
  8932. return this;
  8933. },
  8934. at: function ( t, optionalTarget ) {
  8935. var result = optionalTarget || new Vector3();
  8936. return result.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  8937. },
  8938. lookAt: function ( v ) {
  8939. this.direction.copy( v ).sub( this.origin ).normalize();
  8940. return this;
  8941. },
  8942. recast: function () {
  8943. var v1 = new Vector3();
  8944. return function recast( t ) {
  8945. this.origin.copy( this.at( t, v1 ) );
  8946. return this;
  8947. };
  8948. }(),
  8949. closestPointToPoint: function ( point, optionalTarget ) {
  8950. var result = optionalTarget || new Vector3();
  8951. result.subVectors( point, this.origin );
  8952. var directionDistance = result.dot( this.direction );
  8953. if ( directionDistance < 0 ) {
  8954. return result.copy( this.origin );
  8955. }
  8956. return result.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  8957. },
  8958. distanceToPoint: function ( point ) {
  8959. return Math.sqrt( this.distanceSqToPoint( point ) );
  8960. },
  8961. distanceSqToPoint: function () {
  8962. var v1 = new Vector3();
  8963. return function distanceSqToPoint( point ) {
  8964. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  8965. // point behind the ray
  8966. if ( directionDistance < 0 ) {
  8967. return this.origin.distanceToSquared( point );
  8968. }
  8969. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  8970. return v1.distanceToSquared( point );
  8971. };
  8972. }(),
  8973. distanceSqToSegment: function () {
  8974. var segCenter = new Vector3();
  8975. var segDir = new Vector3();
  8976. var diff = new Vector3();
  8977. return function distanceSqToSegment( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  8978. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  8979. // It returns the min distance between the ray and the segment
  8980. // defined by v0 and v1
  8981. // It can also set two optional targets :
  8982. // - The closest point on the ray
  8983. // - The closest point on the segment
  8984. segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  8985. segDir.copy( v1 ).sub( v0 ).normalize();
  8986. diff.copy( this.origin ).sub( segCenter );
  8987. var segExtent = v0.distanceTo( v1 ) * 0.5;
  8988. var a01 = - this.direction.dot( segDir );
  8989. var b0 = diff.dot( this.direction );
  8990. var b1 = - diff.dot( segDir );
  8991. var c = diff.lengthSq();
  8992. var det = Math.abs( 1 - a01 * a01 );
  8993. var s0, s1, sqrDist, extDet;
  8994. if ( det > 0 ) {
  8995. // The ray and segment are not parallel.
  8996. s0 = a01 * b1 - b0;
  8997. s1 = a01 * b0 - b1;
  8998. extDet = segExtent * det;
  8999. if ( s0 >= 0 ) {
  9000. if ( s1 >= - extDet ) {
  9001. if ( s1 <= extDet ) {
  9002. // region 0
  9003. // Minimum at interior points of ray and segment.
  9004. var invDet = 1 / det;
  9005. s0 *= invDet;
  9006. s1 *= invDet;
  9007. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  9008. } else {
  9009. // region 1
  9010. s1 = segExtent;
  9011. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  9012. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  9013. }
  9014. } else {
  9015. // region 5
  9016. s1 = - segExtent;
  9017. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  9018. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  9019. }
  9020. } else {
  9021. if ( s1 <= - extDet ) {
  9022. // region 4
  9023. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  9024. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  9025. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  9026. } else if ( s1 <= extDet ) {
  9027. // region 3
  9028. s0 = 0;
  9029. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  9030. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  9031. } else {
  9032. // region 2
  9033. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  9034. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  9035. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  9036. }
  9037. }
  9038. } else {
  9039. // Ray and segment are parallel.
  9040. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  9041. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  9042. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  9043. }
  9044. if ( optionalPointOnRay ) {
  9045. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  9046. }
  9047. if ( optionalPointOnSegment ) {
  9048. optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
  9049. }
  9050. return sqrDist;
  9051. };
  9052. }(),
  9053. intersectSphere: function () {
  9054. var v1 = new Vector3();
  9055. return function intersectSphere( sphere, optionalTarget ) {
  9056. v1.subVectors( sphere.center, this.origin );
  9057. var tca = v1.dot( this.direction );
  9058. var d2 = v1.dot( v1 ) - tca * tca;
  9059. var radius2 = sphere.radius * sphere.radius;
  9060. if ( d2 > radius2 ) return null;
  9061. var thc = Math.sqrt( radius2 - d2 );
  9062. // t0 = first intersect point - entrance on front of sphere
  9063. var t0 = tca - thc;
  9064. // t1 = second intersect point - exit point on back of sphere
  9065. var t1 = tca + thc;
  9066. // test to see if both t0 and t1 are behind the ray - if so, return null
  9067. if ( t0 < 0 && t1 < 0 ) return null;
  9068. // test to see if t0 is behind the ray:
  9069. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  9070. // in order to always return an intersect point that is in front of the ray.
  9071. if ( t0 < 0 ) return this.at( t1, optionalTarget );
  9072. // else t0 is in front of the ray, so return the first collision point scaled by t0
  9073. return this.at( t0, optionalTarget );
  9074. };
  9075. }(),
  9076. intersectsSphere: function ( sphere ) {
  9077. return this.distanceToPoint( sphere.center ) <= sphere.radius;
  9078. },
  9079. distanceToPlane: function ( plane ) {
  9080. var denominator = plane.normal.dot( this.direction );
  9081. if ( denominator === 0 ) {
  9082. // line is coplanar, return origin
  9083. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  9084. return 0;
  9085. }
  9086. // Null is preferable to undefined since undefined means.... it is undefined
  9087. return null;
  9088. }
  9089. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  9090. // Return if the ray never intersects the plane
  9091. return t >= 0 ? t : null;
  9092. },
  9093. intersectPlane: function ( plane, optionalTarget ) {
  9094. var t = this.distanceToPlane( plane );
  9095. if ( t === null ) {
  9096. return null;
  9097. }
  9098. return this.at( t, optionalTarget );
  9099. },
  9100. intersectsPlane: function ( plane ) {
  9101. // check if the ray lies on the plane first
  9102. var distToPoint = plane.distanceToPoint( this.origin );
  9103. if ( distToPoint === 0 ) {
  9104. return true;
  9105. }
  9106. var denominator = plane.normal.dot( this.direction );
  9107. if ( denominator * distToPoint < 0 ) {
  9108. return true;
  9109. }
  9110. // ray origin is behind the plane (and is pointing behind it)
  9111. return false;
  9112. },
  9113. intersectBox: function ( box, optionalTarget ) {
  9114. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  9115. var invdirx = 1 / this.direction.x,
  9116. invdiry = 1 / this.direction.y,
  9117. invdirz = 1 / this.direction.z;
  9118. var origin = this.origin;
  9119. if ( invdirx >= 0 ) {
  9120. tmin = ( box.min.x - origin.x ) * invdirx;
  9121. tmax = ( box.max.x - origin.x ) * invdirx;
  9122. } else {
  9123. tmin = ( box.max.x - origin.x ) * invdirx;
  9124. tmax = ( box.min.x - origin.x ) * invdirx;
  9125. }
  9126. if ( invdiry >= 0 ) {
  9127. tymin = ( box.min.y - origin.y ) * invdiry;
  9128. tymax = ( box.max.y - origin.y ) * invdiry;
  9129. } else {
  9130. tymin = ( box.max.y - origin.y ) * invdiry;
  9131. tymax = ( box.min.y - origin.y ) * invdiry;
  9132. }
  9133. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  9134. // These lines also handle the case where tmin or tmax is NaN
  9135. // (result of 0 * Infinity). x !== x returns true if x is NaN
  9136. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  9137. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  9138. if ( invdirz >= 0 ) {
  9139. tzmin = ( box.min.z - origin.z ) * invdirz;
  9140. tzmax = ( box.max.z - origin.z ) * invdirz;
  9141. } else {
  9142. tzmin = ( box.max.z - origin.z ) * invdirz;
  9143. tzmax = ( box.min.z - origin.z ) * invdirz;
  9144. }
  9145. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  9146. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  9147. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  9148. //return point closest to the ray (positive side)
  9149. if ( tmax < 0 ) return null;
  9150. return this.at( tmin >= 0 ? tmin : tmax, optionalTarget );
  9151. },
  9152. intersectsBox: ( function () {
  9153. var v = new Vector3();
  9154. return function intersectsBox( box ) {
  9155. return this.intersectBox( box, v ) !== null;
  9156. };
  9157. } )(),
  9158. intersectTriangle: function () {
  9159. // Compute the offset origin, edges, and normal.
  9160. var diff = new Vector3();
  9161. var edge1 = new Vector3();
  9162. var edge2 = new Vector3();
  9163. var normal = new Vector3();
  9164. return function intersectTriangle( a, b, c, backfaceCulling, optionalTarget ) {
  9165. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  9166. edge1.subVectors( b, a );
  9167. edge2.subVectors( c, a );
  9168. normal.crossVectors( edge1, edge2 );
  9169. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  9170. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  9171. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  9172. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  9173. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  9174. var DdN = this.direction.dot( normal );
  9175. var sign;
  9176. if ( DdN > 0 ) {
  9177. if ( backfaceCulling ) return null;
  9178. sign = 1;
  9179. } else if ( DdN < 0 ) {
  9180. sign = - 1;
  9181. DdN = - DdN;
  9182. } else {
  9183. return null;
  9184. }
  9185. diff.subVectors( this.origin, a );
  9186. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  9187. // b1 < 0, no intersection
  9188. if ( DdQxE2 < 0 ) {
  9189. return null;
  9190. }
  9191. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  9192. // b2 < 0, no intersection
  9193. if ( DdE1xQ < 0 ) {
  9194. return null;
  9195. }
  9196. // b1+b2 > 1, no intersection
  9197. if ( DdQxE2 + DdE1xQ > DdN ) {
  9198. return null;
  9199. }
  9200. // Line intersects triangle, check if ray does.
  9201. var QdN = - sign * diff.dot( normal );
  9202. // t < 0, no intersection
  9203. if ( QdN < 0 ) {
  9204. return null;
  9205. }
  9206. // Ray intersects triangle.
  9207. return this.at( QdN / DdN, optionalTarget );
  9208. };
  9209. }(),
  9210. applyMatrix4: function ( matrix4 ) {
  9211. this.origin.applyMatrix4( matrix4 );
  9212. this.direction.transformDirection( matrix4 );
  9213. return this;
  9214. },
  9215. equals: function ( ray ) {
  9216. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  9217. }
  9218. } );
  9219. function Line3( start, end ) {
  9220. this.start = ( start !== undefined ) ? start : new Vector3();
  9221. this.end = ( end !== undefined ) ? end : new Vector3();
  9222. }
  9223. Object.assign( Line3.prototype, {
  9224. set: function ( start, end ) {
  9225. this.start.copy( start );
  9226. this.end.copy( end );
  9227. return this;
  9228. },
  9229. clone: function () {
  9230. return new this.constructor().copy( this );
  9231. },
  9232. copy: function ( line ) {
  9233. this.start.copy( line.start );
  9234. this.end.copy( line.end );
  9235. return this;
  9236. },
  9237. getCenter: function ( optionalTarget ) {
  9238. var result = optionalTarget || new Vector3();
  9239. return result.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  9240. },
  9241. delta: function ( optionalTarget ) {
  9242. var result = optionalTarget || new Vector3();
  9243. return result.subVectors( this.end, this.start );
  9244. },
  9245. distanceSq: function () {
  9246. return this.start.distanceToSquared( this.end );
  9247. },
  9248. distance: function () {
  9249. return this.start.distanceTo( this.end );
  9250. },
  9251. at: function ( t, optionalTarget ) {
  9252. var result = optionalTarget || new Vector3();
  9253. return this.delta( result ).multiplyScalar( t ).add( this.start );
  9254. },
  9255. closestPointToPointParameter: function () {
  9256. var startP = new Vector3();
  9257. var startEnd = new Vector3();
  9258. return function closestPointToPointParameter( point, clampToLine ) {
  9259. startP.subVectors( point, this.start );
  9260. startEnd.subVectors( this.end, this.start );
  9261. var startEnd2 = startEnd.dot( startEnd );
  9262. var startEnd_startP = startEnd.dot( startP );
  9263. var t = startEnd_startP / startEnd2;
  9264. if ( clampToLine ) {
  9265. t = _Math.clamp( t, 0, 1 );
  9266. }
  9267. return t;
  9268. };
  9269. }(),
  9270. closestPointToPoint: function ( point, clampToLine, optionalTarget ) {
  9271. var t = this.closestPointToPointParameter( point, clampToLine );
  9272. var result = optionalTarget || new Vector3();
  9273. return this.delta( result ).multiplyScalar( t ).add( this.start );
  9274. },
  9275. applyMatrix4: function ( matrix ) {
  9276. this.start.applyMatrix4( matrix );
  9277. this.end.applyMatrix4( matrix );
  9278. return this;
  9279. },
  9280. equals: function ( line ) {
  9281. return line.start.equals( this.start ) && line.end.equals( this.end );
  9282. }
  9283. } );
  9284. function Plane( normal, constant ) {
  9285. // normal is assumed to be normalized
  9286. this.normal = ( normal !== undefined ) ? normal : new Vector3( 1, 0, 0 );
  9287. this.constant = ( constant !== undefined ) ? constant : 0;
  9288. }
  9289. Object.assign( Plane.prototype, {
  9290. set: function ( normal, constant ) {
  9291. this.normal.copy( normal );
  9292. this.constant = constant;
  9293. return this;
  9294. },
  9295. setComponents: function ( x, y, z, w ) {
  9296. this.normal.set( x, y, z );
  9297. this.constant = w;
  9298. return this;
  9299. },
  9300. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  9301. this.normal.copy( normal );
  9302. this.constant = - point.dot( this.normal );
  9303. return this;
  9304. },
  9305. setFromCoplanarPoints: function () {
  9306. var v1 = new Vector3();
  9307. var v2 = new Vector3();
  9308. return function setFromCoplanarPoints( a, b, c ) {
  9309. var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
  9310. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  9311. this.setFromNormalAndCoplanarPoint( normal, a );
  9312. return this;
  9313. };
  9314. }(),
  9315. clone: function () {
  9316. return new this.constructor().copy( this );
  9317. },
  9318. copy: function ( plane ) {
  9319. this.normal.copy( plane.normal );
  9320. this.constant = plane.constant;
  9321. return this;
  9322. },
  9323. normalize: function () {
  9324. // Note: will lead to a divide by zero if the plane is invalid.
  9325. var inverseNormalLength = 1.0 / this.normal.length();
  9326. this.normal.multiplyScalar( inverseNormalLength );
  9327. this.constant *= inverseNormalLength;
  9328. return this;
  9329. },
  9330. negate: function () {
  9331. this.constant *= - 1;
  9332. this.normal.negate();
  9333. return this;
  9334. },
  9335. distanceToPoint: function ( point ) {
  9336. return this.normal.dot( point ) + this.constant;
  9337. },
  9338. distanceToSphere: function ( sphere ) {
  9339. return this.distanceToPoint( sphere.center ) - sphere.radius;
  9340. },
  9341. projectPoint: function ( point, optionalTarget ) {
  9342. var result = optionalTarget || new Vector3();
  9343. return result.copy( this.normal ).multiplyScalar( - this.distanceToPoint( point ) ).add( point );
  9344. },
  9345. intersectLine: function () {
  9346. var v1 = new Vector3();
  9347. return function intersectLine( line, optionalTarget ) {
  9348. var result = optionalTarget || new Vector3();
  9349. var direction = line.delta( v1 );
  9350. var denominator = this.normal.dot( direction );
  9351. if ( denominator === 0 ) {
  9352. // line is coplanar, return origin
  9353. if ( this.distanceToPoint( line.start ) === 0 ) {
  9354. return result.copy( line.start );
  9355. }
  9356. // Unsure if this is the correct method to handle this case.
  9357. return undefined;
  9358. }
  9359. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  9360. if ( t < 0 || t > 1 ) {
  9361. return undefined;
  9362. }
  9363. return result.copy( direction ).multiplyScalar( t ).add( line.start );
  9364. };
  9365. }(),
  9366. intersectsLine: function ( line ) {
  9367. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  9368. var startSign = this.distanceToPoint( line.start );
  9369. var endSign = this.distanceToPoint( line.end );
  9370. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  9371. },
  9372. intersectsBox: function ( box ) {
  9373. return box.intersectsPlane( this );
  9374. },
  9375. intersectsSphere: function ( sphere ) {
  9376. return sphere.intersectsPlane( this );
  9377. },
  9378. coplanarPoint: function ( optionalTarget ) {
  9379. var result = optionalTarget || new Vector3();
  9380. return result.copy( this.normal ).multiplyScalar( - this.constant );
  9381. },
  9382. applyMatrix4: function () {
  9383. var v1 = new Vector3();
  9384. var m1 = new Matrix3();
  9385. return function applyMatrix4( matrix, optionalNormalMatrix ) {
  9386. var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
  9387. var referencePoint = this.coplanarPoint( v1 ).applyMatrix4( matrix );
  9388. var normal = this.normal.applyMatrix3( normalMatrix ).normalize();
  9389. this.constant = - referencePoint.dot( normal );
  9390. return this;
  9391. };
  9392. }(),
  9393. translate: function ( offset ) {
  9394. this.constant -= offset.dot( this.normal );
  9395. return this;
  9396. },
  9397. equals: function ( plane ) {
  9398. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  9399. }
  9400. } );
  9401. function Triangle( a, b, c ) {
  9402. this.a = ( a !== undefined ) ? a : new Vector3();
  9403. this.b = ( b !== undefined ) ? b : new Vector3();
  9404. this.c = ( c !== undefined ) ? c : new Vector3();
  9405. }
  9406. Object.assign( Triangle, {
  9407. normal: function () {
  9408. var v0 = new Vector3();
  9409. return function normal( a, b, c, optionalTarget ) {
  9410. var result = optionalTarget || new Vector3();
  9411. result.subVectors( c, b );
  9412. v0.subVectors( a, b );
  9413. result.cross( v0 );
  9414. var resultLengthSq = result.lengthSq();
  9415. if ( resultLengthSq > 0 ) {
  9416. return result.multiplyScalar( 1 / Math.sqrt( resultLengthSq ) );
  9417. }
  9418. return result.set( 0, 0, 0 );
  9419. };
  9420. }(),
  9421. // static/instance method to calculate barycentric coordinates
  9422. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  9423. barycoordFromPoint: function () {
  9424. var v0 = new Vector3();
  9425. var v1 = new Vector3();
  9426. var v2 = new Vector3();
  9427. return function barycoordFromPoint( point, a, b, c, optionalTarget ) {
  9428. v0.subVectors( c, a );
  9429. v1.subVectors( b, a );
  9430. v2.subVectors( point, a );
  9431. var dot00 = v0.dot( v0 );
  9432. var dot01 = v0.dot( v1 );
  9433. var dot02 = v0.dot( v2 );
  9434. var dot11 = v1.dot( v1 );
  9435. var dot12 = v1.dot( v2 );
  9436. var denom = ( dot00 * dot11 - dot01 * dot01 );
  9437. var result = optionalTarget || new Vector3();
  9438. // collinear or singular triangle
  9439. if ( denom === 0 ) {
  9440. // arbitrary location outside of triangle?
  9441. // not sure if this is the best idea, maybe should be returning undefined
  9442. return result.set( - 2, - 1, - 1 );
  9443. }
  9444. var invDenom = 1 / denom;
  9445. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  9446. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  9447. // barycentric coordinates must always sum to 1
  9448. return result.set( 1 - u - v, v, u );
  9449. };
  9450. }(),
  9451. containsPoint: function () {
  9452. var v1 = new Vector3();
  9453. return function containsPoint( point, a, b, c ) {
  9454. var result = Triangle.barycoordFromPoint( point, a, b, c, v1 );
  9455. return ( result.x >= 0 ) && ( result.y >= 0 ) && ( ( result.x + result.y ) <= 1 );
  9456. };
  9457. }()
  9458. } );
  9459. Object.assign( Triangle.prototype, {
  9460. set: function ( a, b, c ) {
  9461. this.a.copy( a );
  9462. this.b.copy( b );
  9463. this.c.copy( c );
  9464. return this;
  9465. },
  9466. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  9467. this.a.copy( points[ i0 ] );
  9468. this.b.copy( points[ i1 ] );
  9469. this.c.copy( points[ i2 ] );
  9470. return this;
  9471. },
  9472. clone: function () {
  9473. return new this.constructor().copy( this );
  9474. },
  9475. copy: function ( triangle ) {
  9476. this.a.copy( triangle.a );
  9477. this.b.copy( triangle.b );
  9478. this.c.copy( triangle.c );
  9479. return this;
  9480. },
  9481. area: function () {
  9482. var v0 = new Vector3();
  9483. var v1 = new Vector3();
  9484. return function area() {
  9485. v0.subVectors( this.c, this.b );
  9486. v1.subVectors( this.a, this.b );
  9487. return v0.cross( v1 ).length() * 0.5;
  9488. };
  9489. }(),
  9490. midpoint: function ( optionalTarget ) {
  9491. var result = optionalTarget || new Vector3();
  9492. return result.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  9493. },
  9494. normal: function ( optionalTarget ) {
  9495. return Triangle.normal( this.a, this.b, this.c, optionalTarget );
  9496. },
  9497. plane: function ( optionalTarget ) {
  9498. var result = optionalTarget || new Plane();
  9499. return result.setFromCoplanarPoints( this.a, this.b, this.c );
  9500. },
  9501. barycoordFromPoint: function ( point, optionalTarget ) {
  9502. return Triangle.barycoordFromPoint( point, this.a, this.b, this.c, optionalTarget );
  9503. },
  9504. containsPoint: function ( point ) {
  9505. return Triangle.containsPoint( point, this.a, this.b, this.c );
  9506. },
  9507. closestPointToPoint: function () {
  9508. var plane = new Plane();
  9509. var edgeList = [ new Line3(), new Line3(), new Line3() ];
  9510. var projectedPoint = new Vector3();
  9511. var closestPoint = new Vector3();
  9512. return function closestPointToPoint( point, optionalTarget ) {
  9513. var result = optionalTarget || new Vector3();
  9514. var minDistance = Infinity;
  9515. // project the point onto the plane of the triangle
  9516. plane.setFromCoplanarPoints( this.a, this.b, this.c );
  9517. plane.projectPoint( point, projectedPoint );
  9518. // check if the projection lies within the triangle
  9519. if ( this.containsPoint( projectedPoint ) === true ) {
  9520. // if so, this is the closest point
  9521. result.copy( projectedPoint );
  9522. } else {
  9523. // if not, the point falls outside the triangle. the result is the closest point to the triangle's edges or vertices
  9524. edgeList[ 0 ].set( this.a, this.b );
  9525. edgeList[ 1 ].set( this.b, this.c );
  9526. edgeList[ 2 ].set( this.c, this.a );
  9527. for ( var i = 0; i < edgeList.length; i ++ ) {
  9528. edgeList[ i ].closestPointToPoint( projectedPoint, true, closestPoint );
  9529. var distance = projectedPoint.distanceToSquared( closestPoint );
  9530. if ( distance < minDistance ) {
  9531. minDistance = distance;
  9532. result.copy( closestPoint );
  9533. }
  9534. }
  9535. }
  9536. return result;
  9537. };
  9538. }(),
  9539. equals: function ( triangle ) {
  9540. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  9541. }
  9542. } );
  9543. var materialId = 0;
  9544. function Material() {
  9545. Object.defineProperty( this, 'id', { value: materialId ++ } );
  9546. this.uuid = _Math.generateUUID();
  9547. this.name = '';
  9548. this.type = 'Material';
  9549. this.fog = true;
  9550. this.lights = true;
  9551. this.blending = NormalBlending;
  9552. this.side = FrontSide;
  9553. this.flatShading = false;
  9554. this.vertexColors = NoColors; // THREE.NoColors, THREE.VertexColors, THREE.FaceColors
  9555. this.opacity = 1;
  9556. this.transparent = false;
  9557. this.blendSrc = SrcAlphaFactor;
  9558. this.blendDst = OneMinusSrcAlphaFactor;
  9559. this.blendEquation = AddEquation;
  9560. this.blendSrcAlpha = null;
  9561. this.blendDstAlpha = null;
  9562. this.blendEquationAlpha = null;
  9563. this.depthFunc = LessEqualDepth;
  9564. this.depthTest = true;
  9565. this.depthWrite = true;
  9566. this.clippingPlanes = null;
  9567. this.clipIntersection = false;
  9568. this.clipShadows = false;
  9569. this.colorWrite = true;
  9570. this.precision = null; // override the renderer's default precision for this material
  9571. this.polygonOffset = false;
  9572. this.polygonOffsetFactor = 0;
  9573. this.polygonOffsetUnits = 0;
  9574. this.dithering = false;
  9575. this.alphaTest = 0;
  9576. this.premultipliedAlpha = false;
  9577. this.overdraw = 0; // Overdrawn pixels (typically between 0 and 1) for fixing antialiasing gaps in CanvasRenderer
  9578. this.visible = true;
  9579. this.userData = {};
  9580. this.needsUpdate = true;
  9581. }
  9582. Object.assign( Material.prototype, EventDispatcher.prototype, {
  9583. isMaterial: true,
  9584. onBeforeCompile: function () {},
  9585. setValues: function ( values ) {
  9586. if ( values === undefined ) return;
  9587. for ( var key in values ) {
  9588. var newValue = values[ key ];
  9589. if ( newValue === undefined ) {
  9590. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  9591. continue;
  9592. }
  9593. // for backward compatability if shading is set in the constructor
  9594. if ( key === 'shading' ) {
  9595. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  9596. this.flatShading = ( newValue === FlatShading ) ? true : false;
  9597. continue;
  9598. }
  9599. var currentValue = this[ key ];
  9600. if ( currentValue === undefined ) {
  9601. console.warn( "THREE." + this.type + ": '" + key + "' is not a property of this material." );
  9602. continue;
  9603. }
  9604. if ( currentValue && currentValue.isColor ) {
  9605. currentValue.set( newValue );
  9606. } else if ( ( currentValue && currentValue.isVector3 ) && ( newValue && newValue.isVector3 ) ) {
  9607. currentValue.copy( newValue );
  9608. } else if ( key === 'overdraw' ) {
  9609. // ensure overdraw is backwards-compatible with legacy boolean type
  9610. this[ key ] = Number( newValue );
  9611. } else {
  9612. this[ key ] = newValue;
  9613. }
  9614. }
  9615. },
  9616. toJSON: function ( meta ) {
  9617. var isRoot = ( meta === undefined || typeof meta === 'string' );
  9618. if ( isRoot ) {
  9619. meta = {
  9620. textures: {},
  9621. images: {}
  9622. };
  9623. }
  9624. var data = {
  9625. metadata: {
  9626. version: 4.5,
  9627. type: 'Material',
  9628. generator: 'Material.toJSON'
  9629. }
  9630. };
  9631. // standard Material serialization
  9632. data.uuid = this.uuid;
  9633. data.type = this.type;
  9634. if ( this.name !== '' ) data.name = this.name;
  9635. if ( this.color && this.color.isColor ) data.color = this.color.getHex();
  9636. if ( this.roughness !== undefined ) data.roughness = this.roughness;
  9637. if ( this.metalness !== undefined ) data.metalness = this.metalness;
  9638. if ( this.emissive && this.emissive.isColor ) data.emissive = this.emissive.getHex();
  9639. if ( this.emissiveIntensity !== 1 ) data.emissiveIntensity = this.emissiveIntensity;
  9640. if ( this.specular && this.specular.isColor ) data.specular = this.specular.getHex();
  9641. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  9642. if ( this.clearCoat !== undefined ) data.clearCoat = this.clearCoat;
  9643. if ( this.clearCoatRoughness !== undefined ) data.clearCoatRoughness = this.clearCoatRoughness;
  9644. if ( this.map && this.map.isTexture ) data.map = this.map.toJSON( meta ).uuid;
  9645. if ( this.alphaMap && this.alphaMap.isTexture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  9646. if ( this.lightMap && this.lightMap.isTexture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  9647. if ( this.bumpMap && this.bumpMap.isTexture ) {
  9648. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  9649. data.bumpScale = this.bumpScale;
  9650. }
  9651. if ( this.normalMap && this.normalMap.isTexture ) {
  9652. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  9653. data.normalScale = this.normalScale.toArray();
  9654. }
  9655. if ( this.displacementMap && this.displacementMap.isTexture ) {
  9656. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  9657. data.displacementScale = this.displacementScale;
  9658. data.displacementBias = this.displacementBias;
  9659. }
  9660. if ( this.roughnessMap && this.roughnessMap.isTexture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;
  9661. if ( this.metalnessMap && this.metalnessMap.isTexture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;
  9662. if ( this.emissiveMap && this.emissiveMap.isTexture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid;
  9663. if ( this.specularMap && this.specularMap.isTexture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  9664. if ( this.envMap && this.envMap.isTexture ) {
  9665. data.envMap = this.envMap.toJSON( meta ).uuid;
  9666. data.reflectivity = this.reflectivity; // Scale behind envMap
  9667. }
  9668. if ( this.gradientMap && this.gradientMap.isTexture ) {
  9669. data.gradientMap = this.gradientMap.toJSON( meta ).uuid;
  9670. }
  9671. if ( this.size !== undefined ) data.size = this.size;
  9672. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  9673. if ( this.blending !== NormalBlending ) data.blending = this.blending;
  9674. if ( this.flatShading === true ) data.flatShading = this.flatShading;
  9675. if ( this.side !== FrontSide ) data.side = this.side;
  9676. if ( this.vertexColors !== NoColors ) data.vertexColors = this.vertexColors;
  9677. if ( this.opacity < 1 ) data.opacity = this.opacity;
  9678. if ( this.transparent === true ) data.transparent = this.transparent;
  9679. data.depthFunc = this.depthFunc;
  9680. data.depthTest = this.depthTest;
  9681. data.depthWrite = this.depthWrite;
  9682. // rotation (SpriteMaterial)
  9683. if ( this.rotation !== 0 ) data.rotation = this.rotation;
  9684. if ( this.linewidth !== 1 ) data.linewidth = this.linewidth;
  9685. if ( this.dashSize !== undefined ) data.dashSize = this.dashSize;
  9686. if ( this.gapSize !== undefined ) data.gapSize = this.gapSize;
  9687. if ( this.scale !== undefined ) data.scale = this.scale;
  9688. if ( this.dithering === true ) data.dithering = true;
  9689. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  9690. if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = this.premultipliedAlpha;
  9691. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  9692. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  9693. if ( this.wireframeLinecap !== 'round' ) data.wireframeLinecap = this.wireframeLinecap;
  9694. if ( this.wireframeLinejoin !== 'round' ) data.wireframeLinejoin = this.wireframeLinejoin;
  9695. if ( this.morphTargets === true ) data.morphTargets = true;
  9696. if ( this.skinning === true ) data.skinning = true;
  9697. if ( this.visible === false ) data.visible = false;
  9698. if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
  9699. // TODO: Copied from Object3D.toJSON
  9700. function extractFromCache( cache ) {
  9701. var values = [];
  9702. for ( var key in cache ) {
  9703. var data = cache[ key ];
  9704. delete data.metadata;
  9705. values.push( data );
  9706. }
  9707. return values;
  9708. }
  9709. if ( isRoot ) {
  9710. var textures = extractFromCache( meta.textures );
  9711. var images = extractFromCache( meta.images );
  9712. if ( textures.length > 0 ) data.textures = textures;
  9713. if ( images.length > 0 ) data.images = images;
  9714. }
  9715. return data;
  9716. },
  9717. clone: function () {
  9718. return new this.constructor().copy( this );
  9719. },
  9720. copy: function ( source ) {
  9721. this.name = source.name;
  9722. this.fog = source.fog;
  9723. this.lights = source.lights;
  9724. this.blending = source.blending;
  9725. this.side = source.side;
  9726. this.flatShading = source.flatShading;
  9727. this.vertexColors = source.vertexColors;
  9728. this.opacity = source.opacity;
  9729. this.transparent = source.transparent;
  9730. this.blendSrc = source.blendSrc;
  9731. this.blendDst = source.blendDst;
  9732. this.blendEquation = source.blendEquation;
  9733. this.blendSrcAlpha = source.blendSrcAlpha;
  9734. this.blendDstAlpha = source.blendDstAlpha;
  9735. this.blendEquationAlpha = source.blendEquationAlpha;
  9736. this.depthFunc = source.depthFunc;
  9737. this.depthTest = source.depthTest;
  9738. this.depthWrite = source.depthWrite;
  9739. this.colorWrite = source.colorWrite;
  9740. this.precision = source.precision;
  9741. this.polygonOffset = source.polygonOffset;
  9742. this.polygonOffsetFactor = source.polygonOffsetFactor;
  9743. this.polygonOffsetUnits = source.polygonOffsetUnits;
  9744. this.dithering = source.dithering;
  9745. this.alphaTest = source.alphaTest;
  9746. this.premultipliedAlpha = source.premultipliedAlpha;
  9747. this.overdraw = source.overdraw;
  9748. this.visible = source.visible;
  9749. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  9750. this.clipShadows = source.clipShadows;
  9751. this.clipIntersection = source.clipIntersection;
  9752. var srcPlanes = source.clippingPlanes,
  9753. dstPlanes = null;
  9754. if ( srcPlanes !== null ) {
  9755. var n = srcPlanes.length;
  9756. dstPlanes = new Array( n );
  9757. for ( var i = 0; i !== n; ++ i )
  9758. dstPlanes[ i ] = srcPlanes[ i ].clone();
  9759. }
  9760. this.clippingPlanes = dstPlanes;
  9761. return this;
  9762. },
  9763. dispose: function () {
  9764. this.dispatchEvent( { type: 'dispose' } );
  9765. }
  9766. } );
  9767. function MeshBasicMaterial( parameters ) {
  9768. Material.call( this );
  9769. this.type = 'MeshBasicMaterial';
  9770. this.color = new Color( 0xffffff ); // emissive
  9771. this.map = null;
  9772. this.lightMap = null;
  9773. this.lightMapIntensity = 1.0;
  9774. this.aoMap = null;
  9775. this.aoMapIntensity = 1.0;
  9776. this.specularMap = null;
  9777. this.alphaMap = null;
  9778. this.envMap = null;
  9779. this.combine = MultiplyOperation;
  9780. this.reflectivity = 1;
  9781. this.refractionRatio = 0.98;
  9782. this.wireframe = false;
  9783. this.wireframeLinewidth = 1;
  9784. this.wireframeLinecap = 'round';
  9785. this.wireframeLinejoin = 'round';
  9786. this.skinning = false;
  9787. this.morphTargets = false;
  9788. this.lights = false;
  9789. this.setValues( parameters );
  9790. }
  9791. MeshBasicMaterial.prototype = Object.create( Material.prototype );
  9792. MeshBasicMaterial.prototype.constructor = MeshBasicMaterial;
  9793. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  9794. MeshBasicMaterial.prototype.copy = function ( source ) {
  9795. Material.prototype.copy.call( this, source );
  9796. this.color.copy( source.color );
  9797. this.map = source.map;
  9798. this.lightMap = source.lightMap;
  9799. this.lightMapIntensity = source.lightMapIntensity;
  9800. this.aoMap = source.aoMap;
  9801. this.aoMapIntensity = source.aoMapIntensity;
  9802. this.specularMap = source.specularMap;
  9803. this.alphaMap = source.alphaMap;
  9804. this.envMap = source.envMap;
  9805. this.combine = source.combine;
  9806. this.reflectivity = source.reflectivity;
  9807. this.refractionRatio = source.refractionRatio;
  9808. this.wireframe = source.wireframe;
  9809. this.wireframeLinewidth = source.wireframeLinewidth;
  9810. this.wireframeLinecap = source.wireframeLinecap;
  9811. this.wireframeLinejoin = source.wireframeLinejoin;
  9812. this.skinning = source.skinning;
  9813. this.morphTargets = source.morphTargets;
  9814. return this;
  9815. };
  9816. function Mesh( geometry, material ) {
  9817. Object3D.call( this );
  9818. this.type = 'Mesh';
  9819. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  9820. this.material = material !== undefined ? material : new MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  9821. this.drawMode = TrianglesDrawMode;
  9822. this.updateMorphTargets();
  9823. }
  9824. Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
  9825. constructor: Mesh,
  9826. isMesh: true,
  9827. setDrawMode: function ( value ) {
  9828. this.drawMode = value;
  9829. },
  9830. copy: function ( source ) {
  9831. Object3D.prototype.copy.call( this, source );
  9832. this.drawMode = source.drawMode;
  9833. if ( source.morphTargetInfluences !== undefined ) {
  9834. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  9835. }
  9836. if ( source.morphTargetDictionary !== undefined ) {
  9837. this.morphTargetDictionary = Object.assign( {}, source.morphTargetDictionary );
  9838. }
  9839. return this;
  9840. },
  9841. updateMorphTargets: function () {
  9842. var geometry = this.geometry;
  9843. var m, ml, name;
  9844. if ( geometry.isBufferGeometry ) {
  9845. var morphAttributes = geometry.morphAttributes;
  9846. var keys = Object.keys( morphAttributes );
  9847. if ( keys.length > 0 ) {
  9848. var morphAttribute = morphAttributes[ keys[ 0 ] ];
  9849. if ( morphAttribute !== undefined ) {
  9850. this.morphTargetInfluences = [];
  9851. this.morphTargetDictionary = {};
  9852. for ( m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  9853. name = morphAttribute[ m ].name || String( m );
  9854. this.morphTargetInfluences.push( 0 );
  9855. this.morphTargetDictionary[ name ] = m;
  9856. }
  9857. }
  9858. }
  9859. } else {
  9860. var morphTargets = geometry.morphTargets;
  9861. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  9862. this.morphTargetInfluences = [];
  9863. this.morphTargetDictionary = {};
  9864. for ( m = 0, ml = morphTargets.length; m < ml; m ++ ) {
  9865. name = morphTargets[ m ].name || String( m );
  9866. this.morphTargetInfluences.push( 0 );
  9867. this.morphTargetDictionary[ name ] = m;
  9868. }
  9869. }
  9870. }
  9871. },
  9872. raycast: ( function () {
  9873. var inverseMatrix = new Matrix4();
  9874. var ray = new Ray();
  9875. var sphere = new Sphere();
  9876. var vA = new Vector3();
  9877. var vB = new Vector3();
  9878. var vC = new Vector3();
  9879. var tempA = new Vector3();
  9880. var tempB = new Vector3();
  9881. var tempC = new Vector3();
  9882. var uvA = new Vector2();
  9883. var uvB = new Vector2();
  9884. var uvC = new Vector2();
  9885. var barycoord = new Vector3();
  9886. var intersectionPoint = new Vector3();
  9887. var intersectionPointWorld = new Vector3();
  9888. function uvIntersection( point, p1, p2, p3, uv1, uv2, uv3 ) {
  9889. Triangle.barycoordFromPoint( point, p1, p2, p3, barycoord );
  9890. uv1.multiplyScalar( barycoord.x );
  9891. uv2.multiplyScalar( barycoord.y );
  9892. uv3.multiplyScalar( barycoord.z );
  9893. uv1.add( uv2 ).add( uv3 );
  9894. return uv1.clone();
  9895. }
  9896. function checkIntersection( object, material, raycaster, ray, pA, pB, pC, point ) {
  9897. var intersect;
  9898. if ( material.side === BackSide ) {
  9899. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  9900. } else {
  9901. intersect = ray.intersectTriangle( pA, pB, pC, material.side !== DoubleSide, point );
  9902. }
  9903. if ( intersect === null ) return null;
  9904. intersectionPointWorld.copy( point );
  9905. intersectionPointWorld.applyMatrix4( object.matrixWorld );
  9906. var distance = raycaster.ray.origin.distanceTo( intersectionPointWorld );
  9907. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  9908. return {
  9909. distance: distance,
  9910. point: intersectionPointWorld.clone(),
  9911. object: object
  9912. };
  9913. }
  9914. function checkBufferGeometryIntersection( object, raycaster, ray, position, uv, a, b, c ) {
  9915. vA.fromBufferAttribute( position, a );
  9916. vB.fromBufferAttribute( position, b );
  9917. vC.fromBufferAttribute( position, c );
  9918. var intersection = checkIntersection( object, object.material, raycaster, ray, vA, vB, vC, intersectionPoint );
  9919. if ( intersection ) {
  9920. if ( uv ) {
  9921. uvA.fromBufferAttribute( uv, a );
  9922. uvB.fromBufferAttribute( uv, b );
  9923. uvC.fromBufferAttribute( uv, c );
  9924. intersection.uv = uvIntersection( intersectionPoint, vA, vB, vC, uvA, uvB, uvC );
  9925. }
  9926. intersection.face = new Face3( a, b, c, Triangle.normal( vA, vB, vC ) );
  9927. intersection.faceIndex = a;
  9928. }
  9929. return intersection;
  9930. }
  9931. return function raycast( raycaster, intersects ) {
  9932. var geometry = this.geometry;
  9933. var material = this.material;
  9934. var matrixWorld = this.matrixWorld;
  9935. if ( material === undefined ) return;
  9936. // Checking boundingSphere distance to ray
  9937. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  9938. sphere.copy( geometry.boundingSphere );
  9939. sphere.applyMatrix4( matrixWorld );
  9940. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  9941. //
  9942. inverseMatrix.getInverse( matrixWorld );
  9943. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  9944. // Check boundingBox before continuing
  9945. if ( geometry.boundingBox !== null ) {
  9946. if ( ray.intersectsBox( geometry.boundingBox ) === false ) return;
  9947. }
  9948. var intersection;
  9949. if ( geometry.isBufferGeometry ) {
  9950. var a, b, c;
  9951. var index = geometry.index;
  9952. var position = geometry.attributes.position;
  9953. var uv = geometry.attributes.uv;
  9954. var i, l;
  9955. if ( index !== null ) {
  9956. // indexed buffer geometry
  9957. for ( i = 0, l = index.count; i < l; i += 3 ) {
  9958. a = index.getX( i );
  9959. b = index.getX( i + 1 );
  9960. c = index.getX( i + 2 );
  9961. intersection = checkBufferGeometryIntersection( this, raycaster, ray, position, uv, a, b, c );
  9962. if ( intersection ) {
  9963. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indices buffer semantics
  9964. intersects.push( intersection );
  9965. }
  9966. }
  9967. } else if ( position !== undefined ) {
  9968. // non-indexed buffer geometry
  9969. for ( i = 0, l = position.count; i < l; i += 3 ) {
  9970. a = i;
  9971. b = i + 1;
  9972. c = i + 2;
  9973. intersection = checkBufferGeometryIntersection( this, raycaster, ray, position, uv, a, b, c );
  9974. if ( intersection ) {
  9975. intersection.index = a; // triangle number in positions buffer semantics
  9976. intersects.push( intersection );
  9977. }
  9978. }
  9979. }
  9980. } else if ( geometry.isGeometry ) {
  9981. var fvA, fvB, fvC;
  9982. var isMultiMaterial = Array.isArray( material );
  9983. var vertices = geometry.vertices;
  9984. var faces = geometry.faces;
  9985. var uvs;
  9986. var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
  9987. if ( faceVertexUvs.length > 0 ) uvs = faceVertexUvs;
  9988. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  9989. var face = faces[ f ];
  9990. var faceMaterial = isMultiMaterial ? material[ face.materialIndex ] : material;
  9991. if ( faceMaterial === undefined ) continue;
  9992. fvA = vertices[ face.a ];
  9993. fvB = vertices[ face.b ];
  9994. fvC = vertices[ face.c ];
  9995. if ( faceMaterial.morphTargets === true ) {
  9996. var morphTargets = geometry.morphTargets;
  9997. var morphInfluences = this.morphTargetInfluences;
  9998. vA.set( 0, 0, 0 );
  9999. vB.set( 0, 0, 0 );
  10000. vC.set( 0, 0, 0 );
  10001. for ( var t = 0, tl = morphTargets.length; t < tl; t ++ ) {
  10002. var influence = morphInfluences[ t ];
  10003. if ( influence === 0 ) continue;
  10004. var targets = morphTargets[ t ].vertices;
  10005. vA.addScaledVector( tempA.subVectors( targets[ face.a ], fvA ), influence );
  10006. vB.addScaledVector( tempB.subVectors( targets[ face.b ], fvB ), influence );
  10007. vC.addScaledVector( tempC.subVectors( targets[ face.c ], fvC ), influence );
  10008. }
  10009. vA.add( fvA );
  10010. vB.add( fvB );
  10011. vC.add( fvC );
  10012. fvA = vA;
  10013. fvB = vB;
  10014. fvC = vC;
  10015. }
  10016. intersection = checkIntersection( this, faceMaterial, raycaster, ray, fvA, fvB, fvC, intersectionPoint );
  10017. if ( intersection ) {
  10018. if ( uvs && uvs[ f ] ) {
  10019. var uvs_f = uvs[ f ];
  10020. uvA.copy( uvs_f[ 0 ] );
  10021. uvB.copy( uvs_f[ 1 ] );
  10022. uvC.copy( uvs_f[ 2 ] );
  10023. intersection.uv = uvIntersection( intersectionPoint, fvA, fvB, fvC, uvA, uvB, uvC );
  10024. }
  10025. intersection.face = face;
  10026. intersection.faceIndex = f;
  10027. intersects.push( intersection );
  10028. }
  10029. }
  10030. }
  10031. };
  10032. }() ),
  10033. clone: function () {
  10034. return new this.constructor( this.geometry, this.material ).copy( this );
  10035. }
  10036. } );
  10037. /**
  10038. * @author TristanVALCKE / https://github.com/Itee
  10039. * @author Anonymous
  10040. */
  10041. /* global QUnit */
  10042. QUnit.module( 'Animation', () => {
  10043. QUnit.module.todo( 'PropertyBinding', () => {
  10044. // INSTANCING
  10045. QUnit.test( "Instancing", ( assert ) => {
  10046. assert.ok( false, "everything's gonna be alright" );
  10047. } );
  10048. // STATIC STUFF
  10049. QUnit.test( "Composite", ( assert ) => {
  10050. assert.ok( false, "everything's gonna be alright" );
  10051. } );
  10052. QUnit.test( "create", ( assert ) => {
  10053. assert.ok( false, "everything's gonna be alright" );
  10054. } );
  10055. QUnit.test( 'sanitizeNodeName', ( assert ) => {
  10056. assert.equal(
  10057. PropertyBinding.sanitizeNodeName( 'valid-name-123_' ),
  10058. 'valid-name-123_',
  10059. 'Leaves valid name intact.'
  10060. );
  10061. assert.equal(
  10062. PropertyBinding.sanitizeNodeName( 'space separated name 123_ -' ),
  10063. 'space_separated_name_123__-',
  10064. 'Replaces spaces with underscores.'
  10065. );
  10066. assert.equal(
  10067. PropertyBinding.sanitizeNodeName( '"invalid" name %123%_' ),
  10068. 'invalid_name_123_',
  10069. 'Strips invalid characters.'
  10070. );
  10071. } );
  10072. QUnit.test( 'parseTrackName', ( assert ) => {
  10073. var paths = [
  10074. [
  10075. '.property',
  10076. {
  10077. nodeName: undefined,
  10078. objectName: undefined,
  10079. objectIndex: undefined,
  10080. propertyName: 'property',
  10081. propertyIndex: undefined
  10082. }
  10083. ],
  10084. [
  10085. 'nodeName.property',
  10086. {
  10087. nodeName: 'nodeName',
  10088. objectName: undefined,
  10089. objectIndex: undefined,
  10090. propertyName: 'property',
  10091. propertyIndex: undefined
  10092. }
  10093. ],
  10094. [
  10095. 'a.property',
  10096. {
  10097. nodeName: 'a',
  10098. objectName: undefined,
  10099. objectIndex: undefined,
  10100. propertyName: 'property',
  10101. propertyIndex: undefined
  10102. }
  10103. ],
  10104. [
  10105. 'no.de.Name.property',
  10106. {
  10107. nodeName: 'no.de.Name',
  10108. objectName: undefined,
  10109. objectIndex: undefined,
  10110. propertyName: 'property',
  10111. propertyIndex: undefined
  10112. }
  10113. ],
  10114. [
  10115. 'no.d-e.Name.property',
  10116. {
  10117. nodeName: 'no.d-e.Name',
  10118. objectName: undefined,
  10119. objectIndex: undefined,
  10120. propertyName: 'property',
  10121. propertyIndex: undefined
  10122. }
  10123. ],
  10124. [
  10125. 'nodeName.property[accessor]',
  10126. {
  10127. nodeName: 'nodeName',
  10128. objectName: undefined,
  10129. objectIndex: undefined,
  10130. propertyName: 'property',
  10131. propertyIndex: 'accessor'
  10132. }
  10133. ],
  10134. [
  10135. 'nodeName.material.property[accessor]',
  10136. {
  10137. nodeName: 'nodeName',
  10138. objectName: 'material',
  10139. objectIndex: undefined,
  10140. propertyName: 'property',
  10141. propertyIndex: 'accessor'
  10142. }
  10143. ],
  10144. [
  10145. 'no.de.Name.material.property',
  10146. {
  10147. nodeName: 'no.de.Name',
  10148. objectName: 'material',
  10149. objectIndex: undefined,
  10150. propertyName: 'property',
  10151. propertyIndex: undefined
  10152. }
  10153. ],
  10154. [
  10155. 'no.de.Name.material[materialIndex].property',
  10156. {
  10157. nodeName: 'no.de.Name',
  10158. objectName: 'material',
  10159. objectIndex: 'materialIndex',
  10160. propertyName: 'property',
  10161. propertyIndex: undefined
  10162. }
  10163. ],
  10164. [
  10165. 'uuid.property[accessor]',
  10166. {
  10167. nodeName: 'uuid',
  10168. objectName: undefined,
  10169. objectIndex: undefined,
  10170. propertyName: 'property',
  10171. propertyIndex: 'accessor'
  10172. }
  10173. ],
  10174. [
  10175. 'uuid.objectName[objectIndex].propertyName[propertyIndex]',
  10176. {
  10177. nodeName: 'uuid',
  10178. objectName: 'objectName',
  10179. objectIndex: 'objectIndex',
  10180. propertyName: 'propertyName',
  10181. propertyIndex: 'propertyIndex'
  10182. }
  10183. ],
  10184. [
  10185. 'parentName/nodeName.property',
  10186. {
  10187. // directoryName is currently unused.
  10188. nodeName: 'nodeName',
  10189. objectName: undefined,
  10190. objectIndex: undefined,
  10191. propertyName: 'property',
  10192. propertyIndex: undefined
  10193. }
  10194. ],
  10195. [
  10196. 'parentName/no.de.Name.property',
  10197. {
  10198. // directoryName is currently unused.
  10199. nodeName: 'no.de.Name',
  10200. objectName: undefined,
  10201. objectIndex: undefined,
  10202. propertyName: 'property',
  10203. propertyIndex: undefined
  10204. }
  10205. ],
  10206. [
  10207. 'parentName/parentName/nodeName.property[index]',
  10208. {
  10209. // directoryName is currently unused.
  10210. nodeName: 'nodeName',
  10211. objectName: undefined,
  10212. objectIndex: undefined,
  10213. propertyName: 'property',
  10214. propertyIndex: 'index'
  10215. }
  10216. ],
  10217. [
  10218. '.bone[Armature.DEF_cog].position',
  10219. {
  10220. nodeName: undefined,
  10221. objectName: 'bone',
  10222. objectIndex: 'Armature.DEF_cog',
  10223. propertyName: 'position',
  10224. propertyIndex: undefined
  10225. }
  10226. ],
  10227. [
  10228. 'scene:helium_balloon_model:helium_balloon_model.position',
  10229. {
  10230. nodeName: 'helium_balloon_model',
  10231. objectName: undefined,
  10232. objectIndex: undefined,
  10233. propertyName: 'position',
  10234. propertyIndex: undefined
  10235. }
  10236. ]
  10237. ];
  10238. paths.forEach( function ( path ) {
  10239. assert.smartEqual(
  10240. PropertyBinding.parseTrackName( path[ 0 ] ),
  10241. path[ 1 ],
  10242. 'Parses track name: ' + path[ 0 ]
  10243. );
  10244. } );
  10245. } );
  10246. QUnit.test( "findNode", ( assert ) => {
  10247. assert.ok( false, "everything's gonna be alright" );
  10248. } );
  10249. // PUBLIC STUFF
  10250. QUnit.test( "BindingType", ( assert ) => {
  10251. assert.ok( false, "everything's gonna be alright" );
  10252. } );
  10253. QUnit.test( "Versioning", ( assert ) => {
  10254. assert.ok( false, "everything's gonna be alright" );
  10255. } );
  10256. QUnit.test( "GetterByBindingType", ( assert ) => {
  10257. assert.ok( false, "everything's gonna be alright" );
  10258. } );
  10259. QUnit.test( "SetterByBindingTypeAndVersioning", ( assert ) => {
  10260. assert.ok( false, "everything's gonna be alright" );
  10261. } );
  10262. QUnit.test( "getValue", ( assert ) => {
  10263. assert.ok( false, "everything's gonna be alright" );
  10264. } );
  10265. QUnit.test( 'setValue', ( assert ) => {
  10266. var paths = [
  10267. '.material.opacity',
  10268. '.material[opacity]'
  10269. ];
  10270. paths.forEach( function ( path ) {
  10271. var originalValue = 0;
  10272. var expectedValue = 1;
  10273. var geometry = new BoxGeometry();
  10274. var material = new MeshBasicMaterial();
  10275. material.opacity = originalValue;
  10276. var mesh = new Mesh( geometry, material );
  10277. var binding = new PropertyBinding( mesh, path, null );
  10278. binding.bind();
  10279. assert.equal(
  10280. material.opacity,
  10281. originalValue,
  10282. 'Sets property of material with "' + path + '" (pre-setValue)'
  10283. );
  10284. binding.setValue( [ expectedValue ], 0 );
  10285. assert.equal(
  10286. material.opacity,
  10287. expectedValue,
  10288. 'Sets property of material with "' + path + '" (post-setValue)'
  10289. );
  10290. } );
  10291. } );
  10292. QUnit.test( "bind", ( assert ) => {
  10293. assert.ok( false, "everything's gonna be alright" );
  10294. } );
  10295. QUnit.test( "unbind", ( assert ) => {
  10296. assert.ok( false, "everything's gonna be alright" );
  10297. } );
  10298. // OTHERS
  10299. QUnit.test( "_getValue_unavailable", ( assert ) => {
  10300. assert.ok( false, "everything's gonna be alright" );
  10301. } );
  10302. QUnit.test( "_setValue_unavailable", ( assert ) => {
  10303. assert.ok( false, "everything's gonna be alright" );
  10304. } );
  10305. } );
  10306. } );
  10307. /**
  10308. * @author TristanVALCKE / https://github.com/Itee
  10309. */
  10310. /* global QUnit */
  10311. QUnit.module( 'Animation', () => {
  10312. QUnit.module.todo( 'PropertyMixer', () => {
  10313. // INSTANCING
  10314. QUnit.test( "Instancing", ( assert ) => {
  10315. assert.ok( false, "everything's gonna be alright" );
  10316. } );
  10317. // PRIVATE STUFF
  10318. QUnit.test( "_select", ( assert ) => {
  10319. assert.ok( false, "everything's gonna be alright" );
  10320. } );
  10321. QUnit.test( "_slerp", ( assert ) => {
  10322. assert.ok( false, "everything's gonna be alright" );
  10323. } );
  10324. QUnit.test( "_lerp", ( assert ) => {
  10325. assert.ok( false, "everything's gonna be alright" );
  10326. } );
  10327. // PUBLIC STUFF
  10328. QUnit.test( "accumulate", ( assert ) => {
  10329. assert.ok( false, "everything's gonna be alright" );
  10330. } );
  10331. QUnit.test( "apply", ( assert ) => {
  10332. assert.ok( false, "everything's gonna be alright" );
  10333. } );
  10334. QUnit.test( "saveOriginalState", ( assert ) => {
  10335. assert.ok( false, "everything's gonna be alright" );
  10336. } );
  10337. QUnit.test( "restoreOriginalState", ( assert ) => {
  10338. assert.ok( false, "everything's gonna be alright" );
  10339. } );
  10340. } );
  10341. } );
  10342. /**
  10343. * @author TristanVALCKE / https://github.com/Itee
  10344. */
  10345. /* global QUnit */
  10346. QUnit.module( 'Animation', () => {
  10347. QUnit.module( 'Tracks', () => {
  10348. QUnit.module.todo( 'BooleanKeyframeTrack', () => {
  10349. QUnit.test( 'write me !', ( assert ) => {
  10350. assert.ok( false, "everything's gonna be alright" );
  10351. } );
  10352. } );
  10353. } );
  10354. } );
  10355. /**
  10356. * @author TristanVALCKE / https://github.com/Itee
  10357. */
  10358. /* global QUnit */
  10359. QUnit.module( 'Animation', () => {
  10360. QUnit.module( 'Tracks', () => {
  10361. QUnit.module.todo( 'ColorKeyframeTrack', () => {
  10362. QUnit.test( 'write me !', ( assert ) => {
  10363. assert.ok( false, "everything's gonna be alright" );
  10364. } );
  10365. } );
  10366. } );
  10367. } );
  10368. /**
  10369. * @author TristanVALCKE / https://github.com/Itee
  10370. */
  10371. /* global QUnit */
  10372. QUnit.module( 'Animation', () => {
  10373. QUnit.module( 'Tracks', () => {
  10374. QUnit.module.todo( 'NumberKeyframeTrack', () => {
  10375. QUnit.test( 'write me !', ( assert ) => {
  10376. assert.ok( false, "everything's gonna be alright" );
  10377. } );
  10378. } );
  10379. } );
  10380. } );
  10381. /**
  10382. * @author TristanVALCKE / https://github.com/Itee
  10383. */
  10384. /* global QUnit */
  10385. QUnit.module( 'Animation', () => {
  10386. QUnit.module( 'Tracks', () => {
  10387. QUnit.module.todo( 'QuaternionKeyframeTrack', () => {
  10388. QUnit.test( 'write me !', ( assert ) => {
  10389. assert.ok( false, "everything's gonna be alright" );
  10390. } );
  10391. } );
  10392. } );
  10393. } );
  10394. /**
  10395. * @author TristanVALCKE / https://github.com/Itee
  10396. */
  10397. /* global QUnit */
  10398. QUnit.module( 'Animation', () => {
  10399. QUnit.module( 'Tracks', () => {
  10400. QUnit.module.todo( 'StringKeyframeTrack', () => {
  10401. QUnit.test( 'write me !', ( assert ) => {
  10402. assert.ok( false, "everything's gonna be alright" );
  10403. } );
  10404. } );
  10405. } );
  10406. } );
  10407. /**
  10408. * @author TristanVALCKE / https://github.com/Itee
  10409. */
  10410. /* global QUnit */
  10411. QUnit.module( 'Animation', () => {
  10412. QUnit.module( 'Tracks', () => {
  10413. QUnit.module.todo( 'VectorKeyframeTrack', () => {
  10414. QUnit.test( 'write me !', ( assert ) => {
  10415. assert.ok( false, "everything's gonna be alright" );
  10416. } );
  10417. } );
  10418. } );
  10419. } );
  10420. /**
  10421. * @author mrdoob / http://mrdoob.com/
  10422. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  10423. */
  10424. function Audio( listener ) {
  10425. Object3D.call( this );
  10426. this.type = 'Audio';
  10427. this.context = listener.context;
  10428. this.gain = this.context.createGain();
  10429. this.gain.connect( listener.getInput() );
  10430. this.autoplay = false;
  10431. this.buffer = null;
  10432. this.loop = false;
  10433. this.startTime = 0;
  10434. this.offset = 0;
  10435. this.playbackRate = 1;
  10436. this.isPlaying = false;
  10437. this.hasPlaybackControl = true;
  10438. this.sourceType = 'empty';
  10439. this.filters = [];
  10440. }
  10441. Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
  10442. constructor: Audio,
  10443. getOutput: function () {
  10444. return this.gain;
  10445. },
  10446. setNodeSource: function ( audioNode ) {
  10447. this.hasPlaybackControl = false;
  10448. this.sourceType = 'audioNode';
  10449. this.source = audioNode;
  10450. this.connect();
  10451. return this;
  10452. },
  10453. setBuffer: function ( audioBuffer ) {
  10454. this.buffer = audioBuffer;
  10455. this.sourceType = 'buffer';
  10456. if ( this.autoplay ) this.play();
  10457. return this;
  10458. },
  10459. play: function () {
  10460. if ( this.isPlaying === true ) {
  10461. console.warn( 'THREE.Audio: Audio is already playing.' );
  10462. return;
  10463. }
  10464. if ( this.hasPlaybackControl === false ) {
  10465. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  10466. return;
  10467. }
  10468. var source = this.context.createBufferSource();
  10469. source.buffer = this.buffer;
  10470. source.loop = this.loop;
  10471. source.onended = this.onEnded.bind( this );
  10472. source.playbackRate.setValueAtTime( this.playbackRate, this.startTime );
  10473. this.startTime = this.context.currentTime;
  10474. source.start( this.startTime, this.offset );
  10475. this.isPlaying = true;
  10476. this.source = source;
  10477. return this.connect();
  10478. },
  10479. pause: function () {
  10480. if ( this.hasPlaybackControl === false ) {
  10481. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  10482. return;
  10483. }
  10484. if ( this.isPlaying === true ) {
  10485. this.source.stop();
  10486. this.offset += ( this.context.currentTime - this.startTime ) * this.playbackRate;
  10487. this.isPlaying = false;
  10488. }
  10489. return this;
  10490. },
  10491. stop: function () {
  10492. if ( this.hasPlaybackControl === false ) {
  10493. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  10494. return;
  10495. }
  10496. this.source.stop();
  10497. this.offset = 0;
  10498. this.isPlaying = false;
  10499. return this;
  10500. },
  10501. connect: function () {
  10502. if ( this.filters.length > 0 ) {
  10503. this.source.connect( this.filters[ 0 ] );
  10504. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  10505. this.filters[ i - 1 ].connect( this.filters[ i ] );
  10506. }
  10507. this.filters[ this.filters.length - 1 ].connect( this.getOutput() );
  10508. } else {
  10509. this.source.connect( this.getOutput() );
  10510. }
  10511. return this;
  10512. },
  10513. disconnect: function () {
  10514. if ( this.filters.length > 0 ) {
  10515. this.source.disconnect( this.filters[ 0 ] );
  10516. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  10517. this.filters[ i - 1 ].disconnect( this.filters[ i ] );
  10518. }
  10519. this.filters[ this.filters.length - 1 ].disconnect( this.getOutput() );
  10520. } else {
  10521. this.source.disconnect( this.getOutput() );
  10522. }
  10523. return this;
  10524. },
  10525. getFilters: function () {
  10526. return this.filters;
  10527. },
  10528. setFilters: function ( value ) {
  10529. if ( ! value ) value = [];
  10530. if ( this.isPlaying === true ) {
  10531. this.disconnect();
  10532. this.filters = value;
  10533. this.connect();
  10534. } else {
  10535. this.filters = value;
  10536. }
  10537. return this;
  10538. },
  10539. getFilter: function () {
  10540. return this.getFilters()[ 0 ];
  10541. },
  10542. setFilter: function ( filter ) {
  10543. return this.setFilters( filter ? [ filter ] : [] );
  10544. },
  10545. setPlaybackRate: function ( value ) {
  10546. if ( this.hasPlaybackControl === false ) {
  10547. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  10548. return;
  10549. }
  10550. this.playbackRate = value;
  10551. if ( this.isPlaying === true ) {
  10552. this.source.playbackRate.setValueAtTime( this.playbackRate, this.context.currentTime );
  10553. }
  10554. return this;
  10555. },
  10556. getPlaybackRate: function () {
  10557. return this.playbackRate;
  10558. },
  10559. onEnded: function () {
  10560. this.isPlaying = false;
  10561. },
  10562. getLoop: function () {
  10563. if ( this.hasPlaybackControl === false ) {
  10564. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  10565. return false;
  10566. }
  10567. return this.loop;
  10568. },
  10569. setLoop: function ( value ) {
  10570. if ( this.hasPlaybackControl === false ) {
  10571. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  10572. return;
  10573. }
  10574. this.loop = value;
  10575. if ( this.isPlaying === true ) {
  10576. this.source.loop = this.loop;
  10577. }
  10578. return this;
  10579. },
  10580. getVolume: function () {
  10581. return this.gain.gain.value;
  10582. },
  10583. setVolume: function ( value ) {
  10584. this.gain.gain.value = value;
  10585. return this;
  10586. }
  10587. } );
  10588. /**
  10589. * @author TristanVALCKE / https://github.com/Itee
  10590. */
  10591. /* global QUnit */
  10592. QUnit.module( 'Audios', () => {
  10593. QUnit.module.todo( 'Audio', () => {
  10594. // INHERITANCE
  10595. QUnit.test( "Extending", ( assert ) => {
  10596. assert.ok( false, "everything's gonna be alright" );
  10597. } );
  10598. // INSTANCING
  10599. QUnit.test( "Instancing", ( assert ) => {
  10600. assert.ok( false, "everything's gonna be alright" );
  10601. } );
  10602. // PUBLIC STUFF
  10603. QUnit.test( "getOutput", ( assert ) => {
  10604. assert.ok( false, "everything's gonna be alright" );
  10605. } );
  10606. QUnit.test( "setNodeSource", ( assert ) => {
  10607. assert.ok( false, "everything's gonna be alright" );
  10608. } );
  10609. QUnit.test( "setBuffer", ( assert ) => {
  10610. assert.ok( false, "everything's gonna be alright" );
  10611. } );
  10612. QUnit.test( "play", ( assert ) => {
  10613. assert.ok( false, "everything's gonna be alright" );
  10614. } );
  10615. QUnit.test( "pause", ( assert ) => {
  10616. assert.ok( false, "everything's gonna be alright" );
  10617. } );
  10618. QUnit.test( "stop", ( assert ) => {
  10619. assert.ok( false, "everything's gonna be alright" );
  10620. } );
  10621. QUnit.test( "connect", ( assert ) => {
  10622. assert.ok( false, "everything's gonna be alright" );
  10623. } );
  10624. QUnit.test( "disconnect", ( assert ) => {
  10625. assert.ok( false, "everything's gonna be alright" );
  10626. } );
  10627. QUnit.test( "getFilters", ( assert ) => {
  10628. assert.ok( false, "everything's gonna be alright" );
  10629. } );
  10630. QUnit.test( "setFilters", ( assert ) => {
  10631. assert.ok( false, "everything's gonna be alright" );
  10632. } );
  10633. QUnit.test( "getFilter", ( assert ) => {
  10634. assert.ok( false, "everything's gonna be alright" );
  10635. } );
  10636. QUnit.test( "setFilter", ( assert ) => {
  10637. assert.ok( false, "everything's gonna be alright" );
  10638. } );
  10639. QUnit.test( "setPlaybackRate", ( assert ) => {
  10640. assert.ok( false, "everything's gonna be alright" );
  10641. } );
  10642. QUnit.test( "getPlaybackRate", ( assert ) => {
  10643. assert.ok( false, "everything's gonna be alright" );
  10644. } );
  10645. QUnit.test( "onEnded", ( assert ) => {
  10646. assert.ok( false, "everything's gonna be alright" );
  10647. } );
  10648. QUnit.test( "getLoop", ( assert ) => {
  10649. assert.ok( false, "everything's gonna be alright" );
  10650. } );
  10651. QUnit.test( "setLoop", ( assert ) => {
  10652. assert.ok( false, "everything's gonna be alright" );
  10653. } );
  10654. QUnit.test( "getVolume", ( assert ) => {
  10655. assert.ok( false, "everything's gonna be alright" );
  10656. } );
  10657. QUnit.test( "setVolume", ( assert ) => {
  10658. assert.ok( false, "everything's gonna be alright" );
  10659. } );
  10660. } );
  10661. } );
  10662. /**
  10663. * @author mrdoob / http://mrdoob.com/
  10664. */
  10665. function AudioAnalyser( audio, fftSize ) {
  10666. this.analyser = audio.context.createAnalyser();
  10667. this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
  10668. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  10669. audio.getOutput().connect( this.analyser );
  10670. }
  10671. Object.assign( AudioAnalyser.prototype, {
  10672. getFrequencyData: function () {
  10673. this.analyser.getByteFrequencyData( this.data );
  10674. return this.data;
  10675. },
  10676. getAverageFrequency: function () {
  10677. var value = 0, data = this.getFrequencyData();
  10678. for ( var i = 0; i < data.length; i ++ ) {
  10679. value += data[ i ];
  10680. }
  10681. return value / data.length;
  10682. }
  10683. } );
  10684. /**
  10685. * @author TristanVALCKE / https://github.com/Itee
  10686. */
  10687. /* global QUnit */
  10688. QUnit.module( 'Audios', () => {
  10689. QUnit.module.todo( 'AudioAnalyser', () => {
  10690. // INSTANCING
  10691. QUnit.test( "Instancing", ( assert ) => {
  10692. assert.ok( false, "everything's gonna be alright" );
  10693. } );
  10694. // PUBLIC STUFF
  10695. QUnit.test( "getFrequencyData", ( assert ) => {
  10696. assert.ok( false, "everything's gonna be alright" );
  10697. } );
  10698. QUnit.test( "getAverageFrequency", ( assert ) => {
  10699. assert.ok( false, "everything's gonna be alright" );
  10700. } );
  10701. } );
  10702. } );
  10703. var context;
  10704. var AudioContext = {
  10705. getContext: function () {
  10706. if ( context === undefined ) {
  10707. context = new ( window.AudioContext || window.webkitAudioContext )();
  10708. }
  10709. return context;
  10710. },
  10711. setContext: function ( value ) {
  10712. context = value;
  10713. }
  10714. };
  10715. /**
  10716. * @author TristanVALCKE / https://github.com/Itee
  10717. */
  10718. /* global QUnit */
  10719. QUnit.module( 'Audios', () => {
  10720. QUnit.module.todo( 'AudioContext', () => {
  10721. // PUBLIC STUFF
  10722. QUnit.test( "getContext", ( assert ) => {
  10723. assert.ok( false, "everything's gonna be alright" );
  10724. } );
  10725. QUnit.test( "setContext", ( assert ) => {
  10726. assert.ok( false, "everything's gonna be alright" );
  10727. } );
  10728. } );
  10729. } );
  10730. /**
  10731. * @author mrdoob / http://mrdoob.com/
  10732. */
  10733. function AudioListener() {
  10734. Object3D.call( this );
  10735. this.type = 'AudioListener';
  10736. this.context = AudioContext.getContext();
  10737. this.gain = this.context.createGain();
  10738. this.gain.connect( this.context.destination );
  10739. this.filter = null;
  10740. }
  10741. AudioListener.prototype = Object.assign( Object.create( Object3D.prototype ), {
  10742. constructor: AudioListener,
  10743. getInput: function () {
  10744. return this.gain;
  10745. },
  10746. removeFilter: function ( ) {
  10747. if ( this.filter !== null ) {
  10748. this.gain.disconnect( this.filter );
  10749. this.filter.disconnect( this.context.destination );
  10750. this.gain.connect( this.context.destination );
  10751. this.filter = null;
  10752. }
  10753. },
  10754. getFilter: function () {
  10755. return this.filter;
  10756. },
  10757. setFilter: function ( value ) {
  10758. if ( this.filter !== null ) {
  10759. this.gain.disconnect( this.filter );
  10760. this.filter.disconnect( this.context.destination );
  10761. } else {
  10762. this.gain.disconnect( this.context.destination );
  10763. }
  10764. this.filter = value;
  10765. this.gain.connect( this.filter );
  10766. this.filter.connect( this.context.destination );
  10767. },
  10768. getMasterVolume: function () {
  10769. return this.gain.gain.value;
  10770. },
  10771. setMasterVolume: function ( value ) {
  10772. this.gain.gain.value = value;
  10773. },
  10774. updateMatrixWorld: ( function () {
  10775. var position = new Vector3();
  10776. var quaternion = new Quaternion();
  10777. var scale = new Vector3();
  10778. var orientation = new Vector3();
  10779. return function updateMatrixWorld( force ) {
  10780. Object3D.prototype.updateMatrixWorld.call( this, force );
  10781. var listener = this.context.listener;
  10782. var up = this.up;
  10783. this.matrixWorld.decompose( position, quaternion, scale );
  10784. orientation.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  10785. if ( listener.positionX ) {
  10786. listener.positionX.setValueAtTime( position.x, this.context.currentTime );
  10787. listener.positionY.setValueAtTime( position.y, this.context.currentTime );
  10788. listener.positionZ.setValueAtTime( position.z, this.context.currentTime );
  10789. listener.forwardX.setValueAtTime( orientation.x, this.context.currentTime );
  10790. listener.forwardY.setValueAtTime( orientation.y, this.context.currentTime );
  10791. listener.forwardZ.setValueAtTime( orientation.z, this.context.currentTime );
  10792. listener.upX.setValueAtTime( up.x, this.context.currentTime );
  10793. listener.upY.setValueAtTime( up.y, this.context.currentTime );
  10794. listener.upZ.setValueAtTime( up.z, this.context.currentTime );
  10795. } else {
  10796. listener.setPosition( position.x, position.y, position.z );
  10797. listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
  10798. }
  10799. };
  10800. } )()
  10801. } );
  10802. /**
  10803. * @author TristanVALCKE / https://github.com/Itee
  10804. */
  10805. /* global QUnit */
  10806. QUnit.module( 'Audios', () => {
  10807. QUnit.module.todo( 'AudioListener', () => {
  10808. // INHERITANCE
  10809. QUnit.test( "Extending", ( assert ) => {
  10810. assert.ok( false, "everything's gonna be alright" );
  10811. } );
  10812. // INSTANCING
  10813. QUnit.test( "Instancing", ( assert ) => {
  10814. assert.ok( false, "everything's gonna be alright" );
  10815. } );
  10816. // PUBLIC STUFF
  10817. QUnit.test( "getInput", ( assert ) => {
  10818. assert.ok( false, "everything's gonna be alright" );
  10819. } );
  10820. QUnit.test( "removeFilter", ( assert ) => {
  10821. assert.ok( false, "everything's gonna be alright" );
  10822. } );
  10823. QUnit.test( "getFilter", ( assert ) => {
  10824. assert.ok( false, "everything's gonna be alright" );
  10825. } );
  10826. QUnit.test( "setFilter", ( assert ) => {
  10827. assert.ok( false, "everything's gonna be alright" );
  10828. } );
  10829. QUnit.test( "getMasterVolume", ( assert ) => {
  10830. assert.ok( false, "everything's gonna be alright" );
  10831. } );
  10832. QUnit.test( "setMasterVolume", ( assert ) => {
  10833. assert.ok( false, "everything's gonna be alright" );
  10834. } );
  10835. QUnit.test( "updateMatrixWorld", ( assert ) => {
  10836. assert.ok( false, "everything's gonna be alright" );
  10837. } );
  10838. } );
  10839. } );
  10840. /**
  10841. * @author mrdoob / http://mrdoob.com/
  10842. */
  10843. function PositionalAudio( listener ) {
  10844. Audio.call( this, listener );
  10845. this.panner = this.context.createPanner();
  10846. this.panner.connect( this.gain );
  10847. }
  10848. PositionalAudio.prototype = Object.assign( Object.create( Audio.prototype ), {
  10849. constructor: PositionalAudio,
  10850. getOutput: function () {
  10851. return this.panner;
  10852. },
  10853. getRefDistance: function () {
  10854. return this.panner.refDistance;
  10855. },
  10856. setRefDistance: function ( value ) {
  10857. this.panner.refDistance = value;
  10858. },
  10859. getRolloffFactor: function () {
  10860. return this.panner.rolloffFactor;
  10861. },
  10862. setRolloffFactor: function ( value ) {
  10863. this.panner.rolloffFactor = value;
  10864. },
  10865. getDistanceModel: function () {
  10866. return this.panner.distanceModel;
  10867. },
  10868. setDistanceModel: function ( value ) {
  10869. this.panner.distanceModel = value;
  10870. },
  10871. getMaxDistance: function () {
  10872. return this.panner.maxDistance;
  10873. },
  10874. setMaxDistance: function ( value ) {
  10875. this.panner.maxDistance = value;
  10876. },
  10877. updateMatrixWorld: ( function () {
  10878. var position = new Vector3();
  10879. return function updateMatrixWorld( force ) {
  10880. Object3D.prototype.updateMatrixWorld.call( this, force );
  10881. position.setFromMatrixPosition( this.matrixWorld );
  10882. this.panner.setPosition( position.x, position.y, position.z );
  10883. };
  10884. } )()
  10885. } );
  10886. /**
  10887. * @author TristanVALCKE / https://github.com/Itee
  10888. */
  10889. /* global QUnit */
  10890. QUnit.module( 'Audios', () => {
  10891. QUnit.module.todo( 'PositionalAudio', () => {
  10892. // INHERITANCE
  10893. QUnit.test( "Extending", ( assert ) => {
  10894. assert.ok( false, "everything's gonna be alright" );
  10895. } );
  10896. // INSTANCING
  10897. QUnit.test( "Instancing", ( assert ) => {
  10898. assert.ok( false, "everything's gonna be alright" );
  10899. } );
  10900. // PUBLIC STUFF
  10901. QUnit.test( "getOutput", ( assert ) => {
  10902. assert.ok( false, "everything's gonna be alright" );
  10903. } );
  10904. QUnit.test( "getRefDistance", ( assert ) => {
  10905. assert.ok( false, "everything's gonna be alright" );
  10906. } );
  10907. QUnit.test( "setRefDistance", ( assert ) => {
  10908. assert.ok( false, "everything's gonna be alright" );
  10909. } );
  10910. QUnit.test( "getRolloffFactor", ( assert ) => {
  10911. assert.ok( false, "everything's gonna be alright" );
  10912. } );
  10913. QUnit.test( "setRolloffFactor", ( assert ) => {
  10914. assert.ok( false, "everything's gonna be alright" );
  10915. } );
  10916. QUnit.test( "getDistanceModel", ( assert ) => {
  10917. assert.ok( false, "everything's gonna be alright" );
  10918. } );
  10919. QUnit.test( "setDistanceModel", ( assert ) => {
  10920. assert.ok( false, "everything's gonna be alright" );
  10921. } );
  10922. QUnit.test( "getMaxDistance", ( assert ) => {
  10923. assert.ok( false, "everything's gonna be alright" );
  10924. } );
  10925. QUnit.test( "setMaxDistance", ( assert ) => {
  10926. assert.ok( false, "everything's gonna be alright" );
  10927. } );
  10928. QUnit.test( "updateMatrixWorld", ( assert ) => {
  10929. assert.ok( false, "everything's gonna be alright" );
  10930. } );
  10931. } );
  10932. } );
  10933. /**
  10934. * @author mrdoob / http://mrdoob.com/
  10935. * @author mikael emtinger / http://gomo.se/
  10936. * @author WestLangley / http://github.com/WestLangley
  10937. */
  10938. function Camera() {
  10939. Object3D.call( this );
  10940. this.type = 'Camera';
  10941. this.matrixWorldInverse = new Matrix4();
  10942. this.projectionMatrix = new Matrix4();
  10943. }
  10944. Camera.prototype = Object.assign( Object.create( Object3D.prototype ), {
  10945. constructor: Camera,
  10946. isCamera: true,
  10947. copy: function ( source, recursive ) {
  10948. Object3D.prototype.copy.call( this, source, recursive );
  10949. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  10950. this.projectionMatrix.copy( source.projectionMatrix );
  10951. return this;
  10952. },
  10953. getWorldDirection: function () {
  10954. var quaternion = new Quaternion();
  10955. return function getWorldDirection( optionalTarget ) {
  10956. var result = optionalTarget || new Vector3();
  10957. this.getWorldQuaternion( quaternion );
  10958. return result.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  10959. };
  10960. }(),
  10961. updateMatrixWorld: function ( force ) {
  10962. Object3D.prototype.updateMatrixWorld.call( this, force );
  10963. this.matrixWorldInverse.getInverse( this.matrixWorld );
  10964. },
  10965. clone: function () {
  10966. return new this.constructor().copy( this );
  10967. }
  10968. } );
  10969. function PerspectiveCamera( fov, aspect, near, far ) {
  10970. Camera.call( this );
  10971. this.type = 'PerspectiveCamera';
  10972. this.fov = fov !== undefined ? fov : 50;
  10973. this.zoom = 1;
  10974. this.near = near !== undefined ? near : 0.1;
  10975. this.far = far !== undefined ? far : 2000;
  10976. this.focus = 10;
  10977. this.aspect = aspect !== undefined ? aspect : 1;
  10978. this.view = null;
  10979. this.filmGauge = 35; // width of the film (default in millimeters)
  10980. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  10981. this.updateProjectionMatrix();
  10982. }
  10983. PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  10984. constructor: PerspectiveCamera,
  10985. isPerspectiveCamera: true,
  10986. copy: function ( source, recursive ) {
  10987. Camera.prototype.copy.call( this, source, recursive );
  10988. this.fov = source.fov;
  10989. this.zoom = source.zoom;
  10990. this.near = source.near;
  10991. this.far = source.far;
  10992. this.focus = source.focus;
  10993. this.aspect = source.aspect;
  10994. this.view = source.view === null ? null : Object.assign( {}, source.view );
  10995. this.filmGauge = source.filmGauge;
  10996. this.filmOffset = source.filmOffset;
  10997. return this;
  10998. },
  10999. /**
  11000. * Sets the FOV by focal length in respect to the current .filmGauge.
  11001. *
  11002. * The default film gauge is 35, so that the focal length can be specified for
  11003. * a 35mm (full frame) camera.
  11004. *
  11005. * Values for focal length and film gauge must have the same unit.
  11006. */
  11007. setFocalLength: function ( focalLength ) {
  11008. // see http://www.bobatkins.com/photography/technical/field_of_view.html
  11009. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  11010. this.fov = _Math.RAD2DEG * 2 * Math.atan( vExtentSlope );
  11011. this.updateProjectionMatrix();
  11012. },
  11013. /**
  11014. * Calculates the focal length from the current .fov and .filmGauge.
  11015. */
  11016. getFocalLength: function () {
  11017. var vExtentSlope = Math.tan( _Math.DEG2RAD * 0.5 * this.fov );
  11018. return 0.5 * this.getFilmHeight() / vExtentSlope;
  11019. },
  11020. getEffectiveFOV: function () {
  11021. return _Math.RAD2DEG * 2 * Math.atan(
  11022. Math.tan( _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom );
  11023. },
  11024. getFilmWidth: function () {
  11025. // film not completely covered in portrait format (aspect < 1)
  11026. return this.filmGauge * Math.min( this.aspect, 1 );
  11027. },
  11028. getFilmHeight: function () {
  11029. // film not completely covered in landscape format (aspect > 1)
  11030. return this.filmGauge / Math.max( this.aspect, 1 );
  11031. },
  11032. /**
  11033. * Sets an offset in a larger frustum. This is useful for multi-window or
  11034. * multi-monitor/multi-machine setups.
  11035. *
  11036. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  11037. * the monitors are in grid like this
  11038. *
  11039. * +---+---+---+
  11040. * | A | B | C |
  11041. * +---+---+---+
  11042. * | D | E | F |
  11043. * +---+---+---+
  11044. *
  11045. * then for each monitor you would call it like this
  11046. *
  11047. * var w = 1920;
  11048. * var h = 1080;
  11049. * var fullWidth = w * 3;
  11050. * var fullHeight = h * 2;
  11051. *
  11052. * --A--
  11053. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  11054. * --B--
  11055. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  11056. * --C--
  11057. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  11058. * --D--
  11059. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  11060. * --E--
  11061. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  11062. * --F--
  11063. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  11064. *
  11065. * Note there is no reason monitors have to be the same size or in a grid.
  11066. */
  11067. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  11068. this.aspect = fullWidth / fullHeight;
  11069. if ( this.view === null ) {
  11070. this.view = {
  11071. enabled: true,
  11072. fullWidth: 1,
  11073. fullHeight: 1,
  11074. offsetX: 0,
  11075. offsetY: 0,
  11076. width: 1,
  11077. height: 1
  11078. };
  11079. }
  11080. this.view.enabled = true;
  11081. this.view.fullWidth = fullWidth;
  11082. this.view.fullHeight = fullHeight;
  11083. this.view.offsetX = x;
  11084. this.view.offsetY = y;
  11085. this.view.width = width;
  11086. this.view.height = height;
  11087. this.updateProjectionMatrix();
  11088. },
  11089. clearViewOffset: function () {
  11090. if ( this.view !== null ) {
  11091. this.view.enabled = false;
  11092. }
  11093. this.updateProjectionMatrix();
  11094. },
  11095. updateProjectionMatrix: function () {
  11096. var near = this.near,
  11097. top = near * Math.tan(
  11098. _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom,
  11099. height = 2 * top,
  11100. width = this.aspect * height,
  11101. left = - 0.5 * width,
  11102. view = this.view;
  11103. if ( this.view !== null && this.view.enabled ) {
  11104. var fullWidth = view.fullWidth,
  11105. fullHeight = view.fullHeight;
  11106. left += view.offsetX * width / fullWidth;
  11107. top -= view.offsetY * height / fullHeight;
  11108. width *= view.width / fullWidth;
  11109. height *= view.height / fullHeight;
  11110. }
  11111. var skew = this.filmOffset;
  11112. if ( skew !== 0 ) left += near * skew / this.getFilmWidth();
  11113. this.projectionMatrix.makePerspective( left, left + width, top, top - height, near, this.far );
  11114. },
  11115. toJSON: function ( meta ) {
  11116. var data = Object3D.prototype.toJSON.call( this, meta );
  11117. data.object.fov = this.fov;
  11118. data.object.zoom = this.zoom;
  11119. data.object.near = this.near;
  11120. data.object.far = this.far;
  11121. data.object.focus = this.focus;
  11122. data.object.aspect = this.aspect;
  11123. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  11124. data.object.filmGauge = this.filmGauge;
  11125. data.object.filmOffset = this.filmOffset;
  11126. return data;
  11127. }
  11128. } );
  11129. /**
  11130. * @author mrdoob / http://mrdoob.com/
  11131. */
  11132. function ArrayCamera( array ) {
  11133. PerspectiveCamera.call( this );
  11134. this.cameras = array || [];
  11135. }
  11136. ArrayCamera.prototype = Object.assign( Object.create( PerspectiveCamera.prototype ), {
  11137. constructor: ArrayCamera,
  11138. isArrayCamera: true
  11139. } );
  11140. /**
  11141. * @author TristanVALCKE / https://github.com/Itee
  11142. */
  11143. /* global QUnit */
  11144. QUnit.module( 'Cameras', () => {
  11145. QUnit.module.todo( 'ArrayCamera', () => {
  11146. // INHERITANCE
  11147. QUnit.test( "Extending", ( assert ) => {
  11148. assert.ok( false, "everything's gonna be alright" );
  11149. } );
  11150. // INSTANCING
  11151. QUnit.test( "Instancing", ( assert ) => {
  11152. assert.ok( false, "everything's gonna be alright" );
  11153. } );
  11154. // PUBLIC STUFF
  11155. QUnit.test( "isArrayCamera", ( assert ) => {
  11156. assert.ok( false, "everything's gonna be alright" );
  11157. } );
  11158. } );
  11159. } );
  11160. /**
  11161. * @author simonThiele / https://github.com/simonThiele
  11162. * @author TristanVALCKE / https://github.com/Itee
  11163. */
  11164. /* global QUnit */
  11165. QUnit.module( 'Cameras', () => {
  11166. QUnit.module.todo( 'Camera', () => {
  11167. // INHERITANCE
  11168. QUnit.test( "Extending", ( assert ) => {
  11169. assert.ok( false, "everything's gonna be alright" );
  11170. } );
  11171. // INSTANCING
  11172. QUnit.test( "Instancing", ( assert ) => {
  11173. assert.ok( false, "everything's gonna be alright" );
  11174. } );
  11175. // PUBLIC STUFF
  11176. QUnit.test( "isCamera", ( assert ) => {
  11177. assert.ok( false, "everything's gonna be alright" );
  11178. } );
  11179. QUnit.test( "copy", ( assert ) => {
  11180. assert.ok( false, "everything's gonna be alright" );
  11181. } );
  11182. QUnit.test( "getWorldDirection", ( assert ) => {
  11183. assert.ok( false, "everything's gonna be alright" );
  11184. } );
  11185. QUnit.test( "updateMatrixWorld", ( assert ) => {
  11186. assert.ok( false, "everything's gonna be alright" );
  11187. } );
  11188. QUnit.test( "clone", ( assert ) => {
  11189. var cam = new Camera();
  11190. // fill the matrices with any nonsense values just to see if they get copied
  11191. cam.matrixWorldInverse.set( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 );
  11192. cam.projectionMatrix.set( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 );
  11193. var clonedCam = cam.clone();
  11194. // TODO: Uuuummmhhh DO NOT relie equality on object methods !
  11195. // TODO: What's append if matrix.equal is wrongly implemented ???
  11196. // TODO: this MUST be check by assert
  11197. assert.ok( cam.matrixWorldInverse.equals( clonedCam.matrixWorldInverse ), "matrixWorldInverse is equal" );
  11198. assert.ok( cam.projectionMatrix.equals( clonedCam.projectionMatrix ), "projectionMatrix is equal" );
  11199. } );
  11200. // OTHERS
  11201. // TODO: this should not be here !!! This is Object3D stuff !!!
  11202. QUnit.test( "lookAt", ( assert ) => {
  11203. var cam = new Camera();
  11204. cam.lookAt( new Vector3( 0, 1, - 1 ) );
  11205. assert.numEqual( cam.rotation.x * ( 180 / Math.PI ), 45, "x is equal" );
  11206. } );
  11207. } );
  11208. } );
  11209. /**
  11210. * @author mrdoob / http://mrdoob.com/
  11211. * @author alteredq / http://alteredqualia.com/
  11212. * @author szimek / https://github.com/szimek/
  11213. */
  11214. var textureId = 0;
  11215. function Texture( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  11216. Object.defineProperty( this, 'id', { value: textureId ++ } );
  11217. this.uuid = _Math.generateUUID();
  11218. this.name = '';
  11219. this.image = image !== undefined ? image : Texture.DEFAULT_IMAGE;
  11220. this.mipmaps = [];
  11221. this.mapping = mapping !== undefined ? mapping : Texture.DEFAULT_MAPPING;
  11222. this.wrapS = wrapS !== undefined ? wrapS : ClampToEdgeWrapping;
  11223. this.wrapT = wrapT !== undefined ? wrapT : ClampToEdgeWrapping;
  11224. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  11225. this.minFilter = minFilter !== undefined ? minFilter : LinearMipMapLinearFilter;
  11226. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  11227. this.format = format !== undefined ? format : RGBAFormat;
  11228. this.type = type !== undefined ? type : UnsignedByteType;
  11229. this.offset = new Vector2( 0, 0 );
  11230. this.repeat = new Vector2( 1, 1 );
  11231. this.center = new Vector2( 0, 0 );
  11232. this.rotation = 0;
  11233. this.matrixAutoUpdate = true;
  11234. this.matrix = new Matrix3();
  11235. this.generateMipmaps = true;
  11236. this.premultiplyAlpha = false;
  11237. this.flipY = true;
  11238. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  11239. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  11240. //
  11241. // Also changing the encoding after already used by a Material will not automatically make the Material
  11242. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  11243. this.encoding = encoding !== undefined ? encoding : LinearEncoding;
  11244. this.version = 0;
  11245. this.onUpdate = null;
  11246. }
  11247. Texture.DEFAULT_IMAGE = undefined;
  11248. Texture.DEFAULT_MAPPING = UVMapping;
  11249. Object.defineProperty( Texture.prototype, "needsUpdate", {
  11250. set: function ( value ) {
  11251. if ( value === true ) this.version ++;
  11252. }
  11253. } );
  11254. Object.assign( Texture.prototype, EventDispatcher.prototype, {
  11255. constructor: Texture,
  11256. isTexture: true,
  11257. clone: function () {
  11258. return new this.constructor().copy( this );
  11259. },
  11260. copy: function ( source ) {
  11261. this.name = source.name;
  11262. this.image = source.image;
  11263. this.mipmaps = source.mipmaps.slice( 0 );
  11264. this.mapping = source.mapping;
  11265. this.wrapS = source.wrapS;
  11266. this.wrapT = source.wrapT;
  11267. this.magFilter = source.magFilter;
  11268. this.minFilter = source.minFilter;
  11269. this.anisotropy = source.anisotropy;
  11270. this.format = source.format;
  11271. this.type = source.type;
  11272. this.offset.copy( source.offset );
  11273. this.repeat.copy( source.repeat );
  11274. this.center.copy( source.center );
  11275. this.rotation = source.rotation;
  11276. this.matrixAutoUpdate = source.matrixAutoUpdate;
  11277. this.matrix.copy( source.matrix );
  11278. this.generateMipmaps = source.generateMipmaps;
  11279. this.premultiplyAlpha = source.premultiplyAlpha;
  11280. this.flipY = source.flipY;
  11281. this.unpackAlignment = source.unpackAlignment;
  11282. this.encoding = source.encoding;
  11283. return this;
  11284. },
  11285. toJSON: function ( meta ) {
  11286. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  11287. if ( ! isRootObject && meta.textures[ this.uuid ] !== undefined ) {
  11288. return meta.textures[ this.uuid ];
  11289. }
  11290. function getDataURL( image ) {
  11291. var canvas;
  11292. if ( image instanceof HTMLCanvasElement ) {
  11293. canvas = image;
  11294. } else {
  11295. canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  11296. canvas.width = image.width;
  11297. canvas.height = image.height;
  11298. var context = canvas.getContext( '2d' );
  11299. if ( image instanceof ImageData ) {
  11300. context.putImageData( image, 0, 0 );
  11301. } else {
  11302. context.drawImage( image, 0, 0, image.width, image.height );
  11303. }
  11304. }
  11305. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  11306. return canvas.toDataURL( 'image/jpeg', 0.6 );
  11307. } else {
  11308. return canvas.toDataURL( 'image/png' );
  11309. }
  11310. }
  11311. var output = {
  11312. metadata: {
  11313. version: 4.5,
  11314. type: 'Texture',
  11315. generator: 'Texture.toJSON'
  11316. },
  11317. uuid: this.uuid,
  11318. name: this.name,
  11319. mapping: this.mapping,
  11320. repeat: [ this.repeat.x, this.repeat.y ],
  11321. offset: [ this.offset.x, this.offset.y ],
  11322. center: [ this.center.x, this.center.y ],
  11323. rotation: this.rotation,
  11324. wrap: [ this.wrapS, this.wrapT ],
  11325. minFilter: this.minFilter,
  11326. magFilter: this.magFilter,
  11327. anisotropy: this.anisotropy,
  11328. flipY: this.flipY
  11329. };
  11330. if ( this.image !== undefined ) {
  11331. // TODO: Move to THREE.Image
  11332. var image = this.image;
  11333. if ( image.uuid === undefined ) {
  11334. image.uuid = _Math.generateUUID(); // UGH
  11335. }
  11336. if ( ! isRootObject && meta.images[ image.uuid ] === undefined ) {
  11337. meta.images[ image.uuid ] = {
  11338. uuid: image.uuid,
  11339. url: getDataURL( image )
  11340. };
  11341. }
  11342. output.image = image.uuid;
  11343. }
  11344. if ( ! isRootObject ) {
  11345. meta.textures[ this.uuid ] = output;
  11346. }
  11347. return output;
  11348. },
  11349. dispose: function () {
  11350. this.dispatchEvent( { type: 'dispose' } );
  11351. },
  11352. transformUv: function ( uv ) {
  11353. if ( this.mapping !== UVMapping ) return;
  11354. uv.applyMatrix3( this.matrix );
  11355. if ( uv.x < 0 || uv.x > 1 ) {
  11356. switch ( this.wrapS ) {
  11357. case RepeatWrapping:
  11358. uv.x = uv.x - Math.floor( uv.x );
  11359. break;
  11360. case ClampToEdgeWrapping:
  11361. uv.x = uv.x < 0 ? 0 : 1;
  11362. break;
  11363. case MirroredRepeatWrapping:
  11364. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  11365. uv.x = Math.ceil( uv.x ) - uv.x;
  11366. } else {
  11367. uv.x = uv.x - Math.floor( uv.x );
  11368. }
  11369. break;
  11370. }
  11371. }
  11372. if ( uv.y < 0 || uv.y > 1 ) {
  11373. switch ( this.wrapT ) {
  11374. case RepeatWrapping:
  11375. uv.y = uv.y - Math.floor( uv.y );
  11376. break;
  11377. case ClampToEdgeWrapping:
  11378. uv.y = uv.y < 0 ? 0 : 1;
  11379. break;
  11380. case MirroredRepeatWrapping:
  11381. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  11382. uv.y = Math.ceil( uv.y ) - uv.y;
  11383. } else {
  11384. uv.y = uv.y - Math.floor( uv.y );
  11385. }
  11386. break;
  11387. }
  11388. }
  11389. if ( this.flipY ) {
  11390. uv.y = 1 - uv.y;
  11391. }
  11392. }
  11393. } );
  11394. function WebGLRenderTarget( width, height, options ) {
  11395. this.uuid = _Math.generateUUID();
  11396. this.width = width;
  11397. this.height = height;
  11398. this.scissor = new Vector4( 0, 0, width, height );
  11399. this.scissorTest = false;
  11400. this.viewport = new Vector4( 0, 0, width, height );
  11401. options = options || {};
  11402. if ( options.minFilter === undefined ) options.minFilter = LinearFilter;
  11403. this.texture = new Texture( undefined, undefined, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
  11404. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  11405. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  11406. this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  11407. }
  11408. Object.assign( WebGLRenderTarget.prototype, EventDispatcher.prototype, {
  11409. isWebGLRenderTarget: true,
  11410. setSize: function ( width, height ) {
  11411. if ( this.width !== width || this.height !== height ) {
  11412. this.width = width;
  11413. this.height = height;
  11414. this.dispose();
  11415. }
  11416. this.viewport.set( 0, 0, width, height );
  11417. this.scissor.set( 0, 0, width, height );
  11418. },
  11419. clone: function () {
  11420. return new this.constructor().copy( this );
  11421. },
  11422. copy: function ( source ) {
  11423. this.width = source.width;
  11424. this.height = source.height;
  11425. this.viewport.copy( source.viewport );
  11426. this.texture = source.texture.clone();
  11427. this.depthBuffer = source.depthBuffer;
  11428. this.stencilBuffer = source.stencilBuffer;
  11429. this.depthTexture = source.depthTexture;
  11430. return this;
  11431. },
  11432. dispose: function () {
  11433. this.dispatchEvent( { type: 'dispose' } );
  11434. }
  11435. } );
  11436. /**
  11437. * @author TristanVALCKE / https://github.com/Itee
  11438. */
  11439. /* global QUnit */
  11440. QUnit.module( 'Cameras', () => {
  11441. QUnit.module.todo( 'CubeCamera', () => {
  11442. // INHERITANCE
  11443. QUnit.test( "Extending", ( assert ) => {
  11444. assert.ok( false, "everything's gonna be alright" );
  11445. } );
  11446. // INSTANCING
  11447. QUnit.test( "Instancing", ( assert ) => {
  11448. assert.ok( false, "everything's gonna be alright" );
  11449. } );
  11450. } );
  11451. } );
  11452. function OrthographicCamera( left, right, top, bottom, near, far ) {
  11453. Camera.call( this );
  11454. this.type = 'OrthographicCamera';
  11455. this.zoom = 1;
  11456. this.view = null;
  11457. this.left = left;
  11458. this.right = right;
  11459. this.top = top;
  11460. this.bottom = bottom;
  11461. this.near = ( near !== undefined ) ? near : 0.1;
  11462. this.far = ( far !== undefined ) ? far : 2000;
  11463. this.updateProjectionMatrix();
  11464. }
  11465. OrthographicCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  11466. constructor: OrthographicCamera,
  11467. isOrthographicCamera: true,
  11468. copy: function ( source, recursive ) {
  11469. Camera.prototype.copy.call( this, source, recursive );
  11470. this.left = source.left;
  11471. this.right = source.right;
  11472. this.top = source.top;
  11473. this.bottom = source.bottom;
  11474. this.near = source.near;
  11475. this.far = source.far;
  11476. this.zoom = source.zoom;
  11477. this.view = source.view === null ? null : Object.assign( {}, source.view );
  11478. return this;
  11479. },
  11480. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  11481. if ( this.view === null ) {
  11482. this.view = {
  11483. enabled: true,
  11484. fullWidth: 1,
  11485. fullHeight: 1,
  11486. offsetX: 0,
  11487. offsetY: 0,
  11488. width: 1,
  11489. height: 1
  11490. };
  11491. }
  11492. this.view.enabled = true;
  11493. this.view.fullWidth = fullWidth;
  11494. this.view.fullHeight = fullHeight;
  11495. this.view.offsetX = x;
  11496. this.view.offsetY = y;
  11497. this.view.width = width;
  11498. this.view.height = height;
  11499. this.updateProjectionMatrix();
  11500. },
  11501. clearViewOffset: function () {
  11502. if ( this.view !== null ) {
  11503. this.view.enabled = false;
  11504. }
  11505. this.updateProjectionMatrix();
  11506. },
  11507. updateProjectionMatrix: function () {
  11508. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  11509. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  11510. var cx = ( this.right + this.left ) / 2;
  11511. var cy = ( this.top + this.bottom ) / 2;
  11512. var left = cx - dx;
  11513. var right = cx + dx;
  11514. var top = cy + dy;
  11515. var bottom = cy - dy;
  11516. if ( this.view !== null && this.view.enabled ) {
  11517. var zoomW = this.zoom / ( this.view.width / this.view.fullWidth );
  11518. var zoomH = this.zoom / ( this.view.height / this.view.fullHeight );
  11519. var scaleW = ( this.right - this.left ) / this.view.width;
  11520. var scaleH = ( this.top - this.bottom ) / this.view.height;
  11521. left += scaleW * ( this.view.offsetX / zoomW );
  11522. right = left + scaleW * ( this.view.width / zoomW );
  11523. top -= scaleH * ( this.view.offsetY / zoomH );
  11524. bottom = top - scaleH * ( this.view.height / zoomH );
  11525. }
  11526. this.projectionMatrix.makeOrthographic( left, right, top, bottom, this.near, this.far );
  11527. },
  11528. toJSON: function ( meta ) {
  11529. var data = Object3D.prototype.toJSON.call( this, meta );
  11530. data.object.zoom = this.zoom;
  11531. data.object.left = this.left;
  11532. data.object.right = this.right;
  11533. data.object.top = this.top;
  11534. data.object.bottom = this.bottom;
  11535. data.object.near = this.near;
  11536. data.object.far = this.far;
  11537. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  11538. return data;
  11539. }
  11540. } );
  11541. /**
  11542. * @author simonThiele / https://github.com/simonThiele
  11543. * @author TristanVALCKE / https://github.com/Itee
  11544. */
  11545. /* global QUnit */
  11546. QUnit.module( 'Cameras', () => {
  11547. QUnit.module.todo( 'OrthographicCamera', () => {
  11548. // INHERITANCE
  11549. QUnit.test( "Extending", ( assert ) => {
  11550. assert.ok( false, "everything's gonna be alright" );
  11551. } );
  11552. // INSTANCING
  11553. QUnit.test( "Instancing", ( assert ) => {
  11554. assert.ok( false, "everything's gonna be alright" );
  11555. } );
  11556. // PUBLIC STUFF
  11557. QUnit.test( "isOrthographicCamera", ( assert ) => {
  11558. assert.ok( false, "everything's gonna be alright" );
  11559. } );
  11560. QUnit.test( "copy", ( assert ) => {
  11561. assert.ok( false, "everything's gonna be alright" );
  11562. } );
  11563. QUnit.test( "setViewOffset", ( assert ) => {
  11564. assert.ok( false, "everything's gonna be alright" );
  11565. } );
  11566. QUnit.test( "clearViewOffset", ( assert ) => {
  11567. assert.ok( false, "everything's gonna be alright" );
  11568. } );
  11569. QUnit.test( "updateProjectionMatrix", ( assert ) => {
  11570. var left = - 1, right = 1, top = 1, bottom = - 1, near = 1, far = 3;
  11571. var cam = new OrthographicCamera( left, right, top, bottom, near, far );
  11572. // updateProjectionMatrix is called in contructor
  11573. var pMatrix = cam.projectionMatrix.elements;
  11574. // orthographic projection is given my the 4x4 Matrix
  11575. // 2/r-l 0 0 -(l+r/r-l)
  11576. // 0 2/t-b 0 -(t+b/t-b)
  11577. // 0 0 -2/f-n -(f+n/f-n)
  11578. // 0 0 0 1
  11579. assert.ok( pMatrix[ 0 ] === 2 / ( right - left ), "m[0,0] === 2 / (r - l)" );
  11580. assert.ok( pMatrix[ 5 ] === 2 / ( top - bottom ), "m[1,1] === 2 / (t - b)" );
  11581. assert.ok( pMatrix[ 10 ] === - 2 / ( far - near ), "m[2,2] === -2 / (f - n)" );
  11582. assert.ok( pMatrix[ 12 ] === - ( ( right + left ) / ( right - left ) ), "m[3,0] === -(r+l/r-l)" );
  11583. assert.ok( pMatrix[ 13 ] === - ( ( top + bottom ) / ( top - bottom ) ), "m[3,1] === -(t+b/b-t)" );
  11584. assert.ok( pMatrix[ 14 ] === - ( ( far + near ) / ( far - near ) ), "m[3,2] === -(f+n/f-n)" );
  11585. } );
  11586. QUnit.test( "toJSON", ( assert ) => {
  11587. assert.ok( false, "everything's gonna be alright" );
  11588. } );
  11589. // OTHERS
  11590. // TODO: no no no clone is a camera methods that relied to copy method
  11591. QUnit.test( "clone", ( assert ) => {
  11592. var left = - 1.5, right = 1.5, top = 1, bottom = - 1, near = 0.1, far = 42;
  11593. var cam = new OrthographicCamera( left, right, top, bottom, near, far );
  11594. var clonedCam = cam.clone();
  11595. assert.ok( cam.left === clonedCam.left, "left is equal" );
  11596. assert.ok( cam.right === clonedCam.right, "right is equal" );
  11597. assert.ok( cam.top === clonedCam.top, "top is equal" );
  11598. assert.ok( cam.bottom === clonedCam.bottom, "bottom is equal" );
  11599. assert.ok( cam.near === clonedCam.near, "near is equal" );
  11600. assert.ok( cam.far === clonedCam.far, "far is equal" );
  11601. assert.ok( cam.zoom === clonedCam.zoom, "zoom is equal" );
  11602. } );
  11603. } );
  11604. } );
  11605. /**
  11606. * @author simonThiele / https://github.com/simonThiele
  11607. * @author TristanVALCKE / https://github.com/Itee
  11608. */
  11609. /* global QUnit */
  11610. QUnit.module( 'Cameras', () => {
  11611. QUnit.module.todo( 'PerspectiveCamera', () => {
  11612. // see e.g. math/Matrix4.js
  11613. var matrixEquals4 = function ( a, b, tolerance ) {
  11614. tolerance = tolerance || 0.0001;
  11615. if ( a.elements.length != b.elements.length ) {
  11616. return false;
  11617. }
  11618. for ( var i = 0, il = a.elements.length; i < il; i ++ ) {
  11619. var delta = a.elements[ i ] - b.elements[ i ];
  11620. if ( delta > tolerance ) {
  11621. return false;
  11622. }
  11623. }
  11624. return true;
  11625. };
  11626. // INHERITANCE
  11627. QUnit.test( "Extending", ( assert ) => {
  11628. assert.ok( false, "everything's gonna be alright" );
  11629. } );
  11630. // INSTANCING
  11631. QUnit.test( "Instancing", ( assert ) => {
  11632. assert.ok( false, "everything's gonna be alright" );
  11633. } );
  11634. // PUBLIC STUFF
  11635. QUnit.test( "isPerspectiveCamera", ( assert ) => {
  11636. assert.ok( false, "everything's gonna be alright" );
  11637. } );
  11638. QUnit.test( "copy", ( assert ) => {
  11639. assert.ok( false, "everything's gonna be alright" );
  11640. } );
  11641. QUnit.test( "setFocalLength", ( assert ) => {
  11642. assert.ok( false, "everything's gonna be alright" );
  11643. } );
  11644. QUnit.test( "getFocalLength", ( assert ) => {
  11645. assert.ok( false, "everything's gonna be alright" );
  11646. } );
  11647. QUnit.test( "getEffectiveFOV", ( assert ) => {
  11648. assert.ok( false, "everything's gonna be alright" );
  11649. } );
  11650. QUnit.test( "getFilmWidth", ( assert ) => {
  11651. assert.ok( false, "everything's gonna be alright" );
  11652. } );
  11653. QUnit.test( "getFilmHeight", ( assert ) => {
  11654. assert.ok( false, "everything's gonna be alright" );
  11655. } );
  11656. QUnit.test( "setViewOffset", ( assert ) => {
  11657. assert.ok( false, "everything's gonna be alright" );
  11658. } );
  11659. QUnit.test( "clearViewOffset", ( assert ) => {
  11660. assert.ok( false, "everything's gonna be alright" );
  11661. } );
  11662. QUnit.test( "updateProjectionMatrix", ( assert ) => {
  11663. var cam = new PerspectiveCamera( 75, 16 / 9, 0.1, 300.0 );
  11664. // updateProjectionMatrix is called in contructor
  11665. var m = cam.projectionMatrix;
  11666. // perspective projection is given my the 4x4 Matrix
  11667. // 2n/r-l 0 l+r/r-l 0
  11668. // 0 2n/t-b t+b/t-b 0
  11669. // 0 0 -(f+n/f-n) -(2fn/f-n)
  11670. // 0 0 -1 0
  11671. // this matrix was calculated by hand via glMatrix.perspective(75, 16 / 9, 0.1, 300.0, pMatrix)
  11672. // to get a reference matrix from plain WebGL
  11673. var reference = new Matrix4().set(
  11674. 0.7330642938613892, 0, 0, 0,
  11675. 0, 1.3032253980636597, 0, 0,
  11676. 0, 0, - 1.000666856765747, - 0.2000666856765747,
  11677. 0, 0, - 1, 0
  11678. );
  11679. // assert.ok( reference.equals(m) );
  11680. assert.ok( matrixEquals4( reference, m, 0.000001 ) );
  11681. } );
  11682. QUnit.test( "toJSON", ( assert ) => {
  11683. assert.ok( false, "everything's gonna be alright" );
  11684. } );
  11685. // OTHERS
  11686. // TODO: no no no clone is a camera methods that relied to copy method
  11687. QUnit.test( "clone", ( assert ) => {
  11688. var near = 1,
  11689. far = 3,
  11690. aspect = 16 / 9,
  11691. fov = 90;
  11692. var cam = new PerspectiveCamera( fov, aspect, near, far );
  11693. var clonedCam = cam.clone();
  11694. assert.ok( cam.fov === clonedCam.fov, "fov is equal" );
  11695. assert.ok( cam.aspect === clonedCam.aspect, "aspect is equal" );
  11696. assert.ok( cam.near === clonedCam.near, "near is equal" );
  11697. assert.ok( cam.far === clonedCam.far, "far is equal" );
  11698. assert.ok( cam.zoom === clonedCam.zoom, "zoom is equal" );
  11699. assert.ok( cam.projectionMatrix.equals( clonedCam.projectionMatrix ), "projectionMatrix is equal" );
  11700. } );
  11701. } );
  11702. } );
  11703. function StereoCamera() {
  11704. this.type = 'StereoCamera';
  11705. this.aspect = 1;
  11706. this.eyeSep = 0.064;
  11707. this.cameraL = new PerspectiveCamera();
  11708. this.cameraL.layers.enable( 1 );
  11709. this.cameraL.matrixAutoUpdate = false;
  11710. this.cameraR = new PerspectiveCamera();
  11711. this.cameraR.layers.enable( 2 );
  11712. this.cameraR.matrixAutoUpdate = false;
  11713. }
  11714. Object.assign( StereoCamera.prototype, {
  11715. update: ( function () {
  11716. var instance, focus, fov, aspect, near, far, zoom, eyeSep;
  11717. var eyeRight = new Matrix4();
  11718. var eyeLeft = new Matrix4();
  11719. return function update( camera ) {
  11720. var needsUpdate = instance !== this || focus !== camera.focus || fov !== camera.fov ||
  11721. aspect !== camera.aspect * this.aspect || near !== camera.near ||
  11722. far !== camera.far || zoom !== camera.zoom || eyeSep !== this.eyeSep;
  11723. if ( needsUpdate ) {
  11724. instance = this;
  11725. focus = camera.focus;
  11726. fov = camera.fov;
  11727. aspect = camera.aspect * this.aspect;
  11728. near = camera.near;
  11729. far = camera.far;
  11730. zoom = camera.zoom;
  11731. // Off-axis stereoscopic effect based on
  11732. // http://paulbourke.net/stereographics/stereorender/
  11733. var projectionMatrix = camera.projectionMatrix.clone();
  11734. eyeSep = this.eyeSep / 2;
  11735. var eyeSepOnProjection = eyeSep * near / focus;
  11736. var ymax = ( near * Math.tan( _Math.DEG2RAD * fov * 0.5 ) ) / zoom;
  11737. var xmin, xmax;
  11738. // translate xOffset
  11739. eyeLeft.elements[ 12 ] = - eyeSep;
  11740. eyeRight.elements[ 12 ] = eyeSep;
  11741. // for left eye
  11742. xmin = - ymax * aspect + eyeSepOnProjection;
  11743. xmax = ymax * aspect + eyeSepOnProjection;
  11744. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  11745. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  11746. this.cameraL.projectionMatrix.copy( projectionMatrix );
  11747. // for right eye
  11748. xmin = - ymax * aspect - eyeSepOnProjection;
  11749. xmax = ymax * aspect - eyeSepOnProjection;
  11750. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  11751. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  11752. this.cameraR.projectionMatrix.copy( projectionMatrix );
  11753. }
  11754. this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( eyeLeft );
  11755. this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( eyeRight );
  11756. };
  11757. } )()
  11758. } );
  11759. /**
  11760. * @author TristanVALCKE / https://github.com/Itee
  11761. */
  11762. /* global QUnit */
  11763. QUnit.module( 'Cameras', () => {
  11764. QUnit.module.todo( 'StereoCamera', () => {
  11765. // INSTANCING
  11766. QUnit.test( "Instancing", ( assert ) => {
  11767. assert.ok( false, "everything's gonna be alright" );
  11768. } );
  11769. // PUBLIC STUFF
  11770. QUnit.test( "update", ( assert ) => {
  11771. assert.ok( false, "everything's gonna be alright" );
  11772. } );
  11773. } );
  11774. } );
  11775. /**
  11776. * @author simonThiele / https://github.com/simonThiele
  11777. */
  11778. /* global QUnit */
  11779. QUnit.module( 'Core', () => {
  11780. QUnit.module.todo( 'BufferAttribute', () => {
  11781. // INSTANCING
  11782. QUnit.test( "Instancing", ( assert ) => {
  11783. assert.throws(
  11784. function () {
  11785. var a = new BufferAttribute( [ 1, 2, 3, 4 ], 2, false );
  11786. },
  11787. /array should be a Typed Array/,
  11788. "Calling constructor with a simple array throws Error"
  11789. );
  11790. } );
  11791. // PROPERTIES
  11792. QUnit.test( "needsUpdate", ( assert ) => {
  11793. assert.ok( false, "everything's gonna be alright" );
  11794. } );
  11795. // PUBLIC STUFF
  11796. QUnit.test( "isBufferAttribute", ( assert ) => {
  11797. assert.ok( false, "everything's gonna be alright" );
  11798. } );
  11799. QUnit.test( "setArray", ( assert ) => {
  11800. var f32a = new Float32Array( [ 1, 2, 3, 4 ] );
  11801. var a = new BufferAttribute( f32a, 2, false );
  11802. a.setArray( f32a, 2 );
  11803. assert.strictEqual( a.count, 2, "Check item count" );
  11804. assert.strictEqual( a.array, f32a, "Check array" );
  11805. assert.throws(
  11806. function () {
  11807. a.setArray( [ 1, 2, 3, 4 ] );
  11808. },
  11809. /array should be a Typed Array/,
  11810. "Calling setArray with a simple array throws Error"
  11811. );
  11812. } );
  11813. QUnit.test( "setDynamic", ( assert ) => {
  11814. assert.ok( false, "everything's gonna be alright" );
  11815. } );
  11816. QUnit.test( "copy", ( assert ) => {
  11817. var attr = new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 5, 6 ] ), 3 );
  11818. attr.setDynamic( true );
  11819. attr.needsUpdate = true;
  11820. var attrCopy = new BufferAttribute().copy( attr );
  11821. assert.ok( attr.count === attrCopy.count, 'count is equal' );
  11822. assert.ok( attr.itemSize === attrCopy.itemSize, 'itemSize is equal' );
  11823. assert.ok( attr.dynamic === attrCopy.dynamic, 'dynamic is equal' );
  11824. assert.ok( attr.array.length === attrCopy.array.length, 'array length is equal' );
  11825. assert.ok( attr.version === 1 && attrCopy.version === 0, 'version is not copied which is good' );
  11826. } );
  11827. QUnit.test( "copyAt", ( assert ) => {
  11828. var attr = new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ] ), 3 );
  11829. var attr2 = new BufferAttribute( new Float32Array( 9 ), 3 );
  11830. attr2.copyAt( 1, attr, 2 );
  11831. attr2.copyAt( 0, attr, 1 );
  11832. attr2.copyAt( 2, attr, 0 );
  11833. var i = attr.array;
  11834. var i2 = attr2.array; // should be [4, 5, 6, 7, 8, 9, 1, 2, 3]
  11835. assert.ok( i2[ 0 ] === i[ 3 ] && i2[ 1 ] === i[ 4 ] && i2[ 2 ] === i[ 5 ], 'chunck copied to correct place' );
  11836. assert.ok( i2[ 3 ] === i[ 6 ] && i2[ 4 ] === i[ 7 ] && i2[ 5 ] === i[ 8 ], 'chunck copied to correct place' );
  11837. assert.ok( i2[ 6 ] === i[ 0 ] && i2[ 7 ] === i[ 1 ] && i2[ 8 ] === i[ 2 ], 'chunck copied to correct place' );
  11838. } );
  11839. QUnit.test( "copyArray", ( assert ) => {
  11840. var f32a = new Float32Array( [ 5, 6, 7, 8 ] );
  11841. var a = new BufferAttribute( new Float32Array( [ 1, 2, 3, 4 ] ), 2, false );
  11842. a.copyArray( f32a );
  11843. assert.deepEqual( a.array, f32a, "Check array has new values" );
  11844. } );
  11845. QUnit.test( "copyColorsArray", ( assert ) => {
  11846. var attr = new BufferAttribute( new Float32Array( 6 ), 3 );
  11847. attr.copyColorsArray( [
  11848. new Color( 0, 0.5, 1 ),
  11849. new Color( 0.25, 1, 0 )
  11850. ] );
  11851. var i = attr.array;
  11852. assert.ok( i[ 0 ] === 0 && i[ 1 ] === 0.5 && i[ 2 ] === 1, 'first color was copied correctly' );
  11853. assert.ok( i[ 3 ] === 0.25 && i[ 4 ] === 1 && i[ 5 ] === 0, 'second color was copied correctly' );
  11854. } );
  11855. QUnit.test( "copyIndicesArray", ( assert ) => {
  11856. var attr = new BufferAttribute( new Float32Array( 6 ), 3 );
  11857. attr.copyIndicesArray( [
  11858. {
  11859. a: 1,
  11860. b: 2,
  11861. c: 3
  11862. },
  11863. {
  11864. a: 4,
  11865. b: 5,
  11866. c: 6
  11867. }
  11868. ] );
  11869. var i = attr.array;
  11870. assert.ok( i[ 0 ] === 1 && i[ 1 ] === 2 && i[ 2 ] === 3, 'first indices were copied correctly' );
  11871. assert.ok( i[ 3 ] === 4 && i[ 4 ] === 5 && i[ 5 ] === 6, 'second indices were copied correctly' );
  11872. } );
  11873. QUnit.test( "copyVector2sArray", ( assert ) => {
  11874. var attr = new BufferAttribute( new Float32Array( 4 ), 2 );
  11875. attr.copyVector2sArray( [
  11876. new Vector2( 1, 2 ),
  11877. new Vector2( 4, 5 )
  11878. ] );
  11879. var i = attr.array;
  11880. assert.ok( i[ 0 ] === 1 && i[ 1 ] === 2, 'first vector was copied correctly' );
  11881. assert.ok( i[ 2 ] === 4 && i[ 3 ] === 5, 'second vector was copied correctly' );
  11882. } );
  11883. QUnit.test( "copyVector3sArray", ( assert ) => {
  11884. var attr = new BufferAttribute( new Float32Array( 6 ), 2 );
  11885. attr.copyVector3sArray( [
  11886. new Vector3( 1, 2, 3 ),
  11887. new Vector3( 10, 20, 30 )
  11888. ] );
  11889. var i = attr.array;
  11890. assert.ok( i[ 0 ] === 1 && i[ 1 ] === 2 && i[ 2 ] === 3, 'first vector was copied correctly' );
  11891. assert.ok( i[ 3 ] === 10 && i[ 4 ] === 20 && i[ 5 ] === 30, 'second vector was copied correctly' );
  11892. } );
  11893. QUnit.test( "copyVector4sArray", ( assert ) => {
  11894. var attr = new BufferAttribute( new Float32Array( 8 ), 2 );
  11895. attr.copyVector4sArray( [
  11896. new Vector4( 1, 2, 3, 4 ),
  11897. new Vector4( 10, 20, 30, 40 )
  11898. ] );
  11899. var i = attr.array;
  11900. assert.ok( i[ 0 ] === 1 && i[ 1 ] === 2 && i[ 2 ] === 3 && i[ 3 ] === 4, 'first vector was copied correctly' );
  11901. assert.ok( i[ 4 ] === 10 && i[ 5 ] === 20 && i[ 6 ] === 30 && i[ 7 ] === 40, 'second vector was copied correctly' );
  11902. } );
  11903. QUnit.test( "set", ( assert ) => {
  11904. var f32a = new Float32Array( [ 1, 2, 3, 4 ] );
  11905. var a = new BufferAttribute( f32a, 2, false );
  11906. var expected = new Float32Array( [ 9, 2, 8, 4 ] );
  11907. a.set( [ 9 ] );
  11908. a.set( [ 8 ], 2 );
  11909. assert.deepEqual( a.array, expected, "Check array has expected values" );
  11910. } );
  11911. QUnit.test( "set[X, Y, Z, W, XYZ, XYZW]/get[X, Y, Z, W]", ( assert ) => {
  11912. var f32a = new Float32Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] );
  11913. var a = new BufferAttribute( f32a, 4, false );
  11914. var expected = new Float32Array( [ 1, 2, - 3, - 4, - 5, - 6, 7, 8 ] );
  11915. a.setX( 1, a.getX( 1 ) * - 1 );
  11916. a.setY( 1, a.getY( 1 ) * - 1 );
  11917. a.setZ( 0, a.getZ( 0 ) * - 1 );
  11918. a.setW( 0, a.getW( 0 ) * - 1 );
  11919. assert.deepEqual( a.array, expected, "Check all set* calls set the correct values" );
  11920. } );
  11921. QUnit.test( "setXY", ( assert ) => {
  11922. var f32a = new Float32Array( [ 1, 2, 3, 4 ] );
  11923. var a = new BufferAttribute( f32a, 2, false );
  11924. var expected = new Float32Array( [ - 1, - 2, 3, 4 ] );
  11925. a.setXY( 0, - 1, - 2 );
  11926. assert.deepEqual( a.array, expected, "Check for the correct values" );
  11927. } );
  11928. QUnit.test( "setXYZ", ( assert ) => {
  11929. var f32a = new Float32Array( [ 1, 2, 3, 4, 5, 6 ] );
  11930. var a = new BufferAttribute( f32a, 3, false );
  11931. var expected = new Float32Array( [ 1, 2, 3, - 4, - 5, - 6 ] );
  11932. a.setXYZ( 1, - 4, - 5, - 6 );
  11933. assert.deepEqual( a.array, expected, "Check for the correct values" );
  11934. } );
  11935. QUnit.test( "setXYZW", ( assert ) => {
  11936. var f32a = new Float32Array( [ 1, 2, 3, 4 ] );
  11937. var a = new BufferAttribute( f32a, 4, false );
  11938. var expected = new Float32Array( [ - 1, - 2, - 3, - 4 ] );
  11939. a.setXYZW( 0, - 1, - 2, - 3, - 4 );
  11940. assert.deepEqual( a.array, expected, "Check for the correct values" );
  11941. } );
  11942. QUnit.test( "onUpload", ( assert ) => {
  11943. var a = new BufferAttribute();
  11944. var func = function () { };
  11945. a.onUpload( func );
  11946. assert.strictEqual( a.onUploadCallback, func, "Check callback was set properly" );
  11947. } );
  11948. QUnit.test( "clone", ( assert ) => {
  11949. var attr = new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 0.12, - 12 ] ), 2 );
  11950. var attrCopy = attr.clone();
  11951. assert.ok( attr.array.length === attrCopy.array.length, 'attribute was cloned' );
  11952. for ( var i = 0; i < attr.array.length; i ++ ) {
  11953. assert.ok( attr.array[ i ] === attrCopy.array[ i ], 'array item is equal' );
  11954. }
  11955. } );
  11956. // OTHERS
  11957. QUnit.test( "count", ( assert ) => {
  11958. assert.ok(
  11959. new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 5, 6 ] ), 3 ).count === 2,
  11960. 'count is equal to the number of chunks'
  11961. );
  11962. } );
  11963. } );
  11964. QUnit.module.todo( 'Int8BufferAttribute', () => {
  11965. // INHERITANCE
  11966. QUnit.test( "Extending", ( assert ) => {
  11967. assert.ok( false, "everything's gonna be alright" );
  11968. } );
  11969. // INSTANCING
  11970. QUnit.test( "Instancing", ( assert ) => {
  11971. assert.ok( false, "everything's gonna be alright" );
  11972. } );
  11973. } );
  11974. QUnit.module.todo( 'Uint8BufferAttribute', () => {
  11975. // INHERITANCE
  11976. QUnit.test( "Extending", ( assert ) => {
  11977. assert.ok( false, "everything's gonna be alright" );
  11978. } );
  11979. // INSTANCING
  11980. QUnit.test( "Instancing", ( assert ) => {
  11981. assert.ok( false, "everything's gonna be alright" );
  11982. } );
  11983. } );
  11984. QUnit.module.todo( 'Uint8ClampedBufferAttribute', () => {
  11985. // INHERITANCE
  11986. QUnit.test( "Extending", ( assert ) => {
  11987. assert.ok( false, "everything's gonna be alright" );
  11988. } );
  11989. // INSTANCING
  11990. QUnit.test( "Instancing", ( assert ) => {
  11991. assert.ok( false, "everything's gonna be alright" );
  11992. } );
  11993. } );
  11994. QUnit.module.todo( 'Int16BufferAttribute', () => {
  11995. // INHERITANCE
  11996. QUnit.test( "Extending", ( assert ) => {
  11997. assert.ok( false, "everything's gonna be alright" );
  11998. } );
  11999. // INSTANCING
  12000. QUnit.test( "Instancing", ( assert ) => {
  12001. assert.ok( false, "everything's gonna be alright" );
  12002. } );
  12003. } );
  12004. QUnit.module.todo( 'Uint16BufferAttribute', () => {
  12005. // INHERITANCE
  12006. QUnit.test( "Extending", ( assert ) => {
  12007. assert.ok( false, "everything's gonna be alright" );
  12008. } );
  12009. // INSTANCING
  12010. QUnit.test( "Instancing", ( assert ) => {
  12011. assert.ok( false, "everything's gonna be alright" );
  12012. } );
  12013. } );
  12014. QUnit.module.todo( 'Int32BufferAttribute', () => {
  12015. // INHERITANCE
  12016. QUnit.test( "Extending", ( assert ) => {
  12017. assert.ok( false, "everything's gonna be alright" );
  12018. } );
  12019. // INSTANCING
  12020. QUnit.test( "Instancing", ( assert ) => {
  12021. assert.ok( false, "everything's gonna be alright" );
  12022. } );
  12023. } );
  12024. QUnit.module.todo( 'Uint32BufferAttribute', () => {
  12025. // INHERITANCE
  12026. QUnit.test( "Extending", ( assert ) => {
  12027. assert.ok( false, "everything's gonna be alright" );
  12028. } );
  12029. // INSTANCING
  12030. QUnit.test( "Instancing", ( assert ) => {
  12031. assert.ok( false, "everything's gonna be alright" );
  12032. } );
  12033. } );
  12034. QUnit.module.todo( 'Float32BufferAttribute', () => {
  12035. // INHERITANCE
  12036. QUnit.test( "Extending", ( assert ) => {
  12037. assert.ok( false, "everything's gonna be alright" );
  12038. } );
  12039. // INSTANCING
  12040. QUnit.test( "Instancing", ( assert ) => {
  12041. assert.ok( false, "everything's gonna be alright" );
  12042. } );
  12043. } );
  12044. QUnit.module.todo( 'Float64BufferAttribute', () => {
  12045. // INHERITANCE
  12046. QUnit.test( "Extending", ( assert ) => {
  12047. assert.ok( false, "everything's gonna be alright" );
  12048. } );
  12049. // INSTANCING
  12050. QUnit.test( "Instancing", ( assert ) => {
  12051. assert.ok( false, "everything's gonna be alright" );
  12052. } );
  12053. } );
  12054. } );
  12055. /**
  12056. * @author mrdoob / http://mrdoob.com/
  12057. */
  12058. var Cache = {
  12059. enabled: false,
  12060. files: {},
  12061. add: function ( key, file ) {
  12062. if ( this.enabled === false ) return;
  12063. // console.log( 'THREE.Cache', 'Adding key:', key );
  12064. this.files[ key ] = file;
  12065. },
  12066. get: function ( key ) {
  12067. if ( this.enabled === false ) return;
  12068. // console.log( 'THREE.Cache', 'Checking key:', key );
  12069. return this.files[ key ];
  12070. },
  12071. remove: function ( key ) {
  12072. delete this.files[ key ];
  12073. },
  12074. clear: function () {
  12075. this.files = {};
  12076. }
  12077. };
  12078. /**
  12079. * @author mrdoob / http://mrdoob.com/
  12080. */
  12081. function LoadingManager( onLoad, onProgress, onError ) {
  12082. var scope = this;
  12083. var isLoading = false;
  12084. var itemsLoaded = 0;
  12085. var itemsTotal = 0;
  12086. var urlModifier = undefined;
  12087. this.onStart = undefined;
  12088. this.onLoad = onLoad;
  12089. this.onProgress = onProgress;
  12090. this.onError = onError;
  12091. this.itemStart = function ( url ) {
  12092. itemsTotal ++;
  12093. if ( isLoading === false ) {
  12094. if ( scope.onStart !== undefined ) {
  12095. scope.onStart( url, itemsLoaded, itemsTotal );
  12096. }
  12097. }
  12098. isLoading = true;
  12099. };
  12100. this.itemEnd = function ( url ) {
  12101. itemsLoaded ++;
  12102. if ( scope.onProgress !== undefined ) {
  12103. scope.onProgress( url, itemsLoaded, itemsTotal );
  12104. }
  12105. if ( itemsLoaded === itemsTotal ) {
  12106. isLoading = false;
  12107. if ( scope.onLoad !== undefined ) {
  12108. scope.onLoad();
  12109. }
  12110. }
  12111. };
  12112. this.itemError = function ( url ) {
  12113. if ( scope.onError !== undefined ) {
  12114. scope.onError( url );
  12115. }
  12116. };
  12117. this.resolveURL = function ( url ) {
  12118. if ( urlModifier ) {
  12119. return urlModifier( url );
  12120. }
  12121. return url;
  12122. };
  12123. this.setURLModifier = function ( transform ) {
  12124. urlModifier = transform;
  12125. };
  12126. }
  12127. var DefaultLoadingManager = new LoadingManager();
  12128. /**
  12129. * @author mrdoob / http://mrdoob.com/
  12130. */
  12131. var loading = {};
  12132. function FileLoader( manager ) {
  12133. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  12134. }
  12135. Object.assign( FileLoader.prototype, {
  12136. load: function ( url, onLoad, onProgress, onError ) {
  12137. if ( url === undefined ) url = '';
  12138. if ( this.path !== undefined ) url = this.path + url;
  12139. url = this.manager.resolveURL( url );
  12140. var scope = this;
  12141. var cached = Cache.get( url );
  12142. if ( cached !== undefined ) {
  12143. scope.manager.itemStart( url );
  12144. setTimeout( function () {
  12145. if ( onLoad ) onLoad( cached );
  12146. scope.manager.itemEnd( url );
  12147. }, 0 );
  12148. return cached;
  12149. }
  12150. // Check if request is duplicate
  12151. if ( loading[ url ] !== undefined ) {
  12152. loading[ url ].push( {
  12153. onLoad: onLoad,
  12154. onProgress: onProgress,
  12155. onError: onError
  12156. } );
  12157. return;
  12158. }
  12159. // Check for data: URI
  12160. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  12161. var dataUriRegexResult = url.match( dataUriRegex );
  12162. // Safari can not handle Data URIs through XMLHttpRequest so process manually
  12163. if ( dataUriRegexResult ) {
  12164. var mimeType = dataUriRegexResult[ 1 ];
  12165. var isBase64 = !! dataUriRegexResult[ 2 ];
  12166. var data = dataUriRegexResult[ 3 ];
  12167. data = window.decodeURIComponent( data );
  12168. if ( isBase64 ) data = window.atob( data );
  12169. try {
  12170. var response;
  12171. var responseType = ( this.responseType || '' ).toLowerCase();
  12172. switch ( responseType ) {
  12173. case 'arraybuffer':
  12174. case 'blob':
  12175. var view = new Uint8Array( data.length );
  12176. for ( var i = 0; i < data.length; i ++ ) {
  12177. view[ i ] = data.charCodeAt( i );
  12178. }
  12179. if ( responseType === 'blob' ) {
  12180. response = new Blob( [ view.buffer ], { type: mimeType } );
  12181. } else {
  12182. response = view.buffer;
  12183. }
  12184. break;
  12185. case 'document':
  12186. var parser = new DOMParser();
  12187. response = parser.parseFromString( data, mimeType );
  12188. break;
  12189. case 'json':
  12190. response = JSON.parse( data );
  12191. break;
  12192. default: // 'text' or other
  12193. response = data;
  12194. break;
  12195. }
  12196. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  12197. window.setTimeout( function () {
  12198. if ( onLoad ) onLoad( response );
  12199. scope.manager.itemEnd( url );
  12200. }, 0 );
  12201. } catch ( error ) {
  12202. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  12203. window.setTimeout( function () {
  12204. if ( onError ) onError( error );
  12205. scope.manager.itemEnd( url );
  12206. scope.manager.itemError( url );
  12207. }, 0 );
  12208. }
  12209. } else {
  12210. // Initialise array for duplicate requests
  12211. loading[ url ] = [];
  12212. loading[ url ].push( {
  12213. onLoad: onLoad,
  12214. onProgress: onProgress,
  12215. onError: onError
  12216. } );
  12217. var request = new XMLHttpRequest();
  12218. request.open( 'GET', url, true );
  12219. request.addEventListener( 'load', function ( event ) {
  12220. var response = event.target.response;
  12221. Cache.add( url, response );
  12222. var callbacks = loading[ url ];
  12223. delete loading[ url ];
  12224. if ( this.status === 200 ) {
  12225. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  12226. var callback = callbacks[ i ];
  12227. if ( callback.onLoad ) callback.onLoad( response );
  12228. }
  12229. scope.manager.itemEnd( url );
  12230. } else if ( this.status === 0 ) {
  12231. // Some browsers return HTTP Status 0 when using non-http protocol
  12232. // e.g. 'file://' or 'data://'. Handle as success.
  12233. console.warn( 'THREE.FileLoader: HTTP Status 0 received.' );
  12234. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  12235. var callback = callbacks[ i ];
  12236. if ( callback.onLoad ) callback.onLoad( response );
  12237. }
  12238. scope.manager.itemEnd( url );
  12239. } else {
  12240. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  12241. var callback = callbacks[ i ];
  12242. if ( callback.onError ) callback.onError( event );
  12243. }
  12244. scope.manager.itemEnd( url );
  12245. scope.manager.itemError( url );
  12246. }
  12247. }, false );
  12248. request.addEventListener( 'progress', function ( event ) {
  12249. var callbacks = loading[ url ];
  12250. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  12251. var callback = callbacks[ i ];
  12252. if ( callback.onProgress ) callback.onProgress( event );
  12253. }
  12254. }, false );
  12255. request.addEventListener( 'error', function ( event ) {
  12256. var callbacks = loading[ url ];
  12257. delete loading[ url ];
  12258. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  12259. var callback = callbacks[ i ];
  12260. if ( callback.onError ) callback.onError( event );
  12261. }
  12262. scope.manager.itemEnd( url );
  12263. scope.manager.itemError( url );
  12264. }, false );
  12265. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  12266. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  12267. if ( request.overrideMimeType ) request.overrideMimeType( this.mimeType !== undefined ? this.mimeType : 'text/plain' );
  12268. for ( var header in this.requestHeader ) {
  12269. request.setRequestHeader( header, this.requestHeader[ header ] );
  12270. }
  12271. request.send( null );
  12272. }
  12273. scope.manager.itemStart( url );
  12274. return request;
  12275. },
  12276. setPath: function ( value ) {
  12277. this.path = value;
  12278. return this;
  12279. },
  12280. setResponseType: function ( value ) {
  12281. this.responseType = value;
  12282. return this;
  12283. },
  12284. setWithCredentials: function ( value ) {
  12285. this.withCredentials = value;
  12286. return this;
  12287. },
  12288. setMimeType: function ( value ) {
  12289. this.mimeType = value;
  12290. return this;
  12291. },
  12292. setRequestHeader: function ( value ) {
  12293. this.requestHeader = value;
  12294. return this;
  12295. }
  12296. } );
  12297. /**
  12298. * @author mrdoob / http://mrdoob.com/
  12299. *
  12300. * parameters = {
  12301. * color: <THREE.Color>,
  12302. * opacity: <float>
  12303. * }
  12304. */
  12305. function ShadowMaterial( parameters ) {
  12306. Material.call( this );
  12307. this.type = 'ShadowMaterial';
  12308. this.color = new Color( 0x000000 );
  12309. this.opacity = 1.0;
  12310. this.lights = true;
  12311. this.transparent = true;
  12312. this.setValues( parameters );
  12313. }
  12314. ShadowMaterial.prototype = Object.create( Material.prototype );
  12315. ShadowMaterial.prototype.constructor = ShadowMaterial;
  12316. ShadowMaterial.prototype.isShadowMaterial = true;
  12317. function SpriteMaterial( parameters ) {
  12318. Material.call( this );
  12319. this.type = 'SpriteMaterial';
  12320. this.color = new Color( 0xffffff );
  12321. this.map = null;
  12322. this.rotation = 0;
  12323. this.fog = false;
  12324. this.lights = false;
  12325. this.setValues( parameters );
  12326. }
  12327. SpriteMaterial.prototype = Object.create( Material.prototype );
  12328. SpriteMaterial.prototype.constructor = SpriteMaterial;
  12329. SpriteMaterial.prototype.isSpriteMaterial = true;
  12330. SpriteMaterial.prototype.copy = function ( source ) {
  12331. Material.prototype.copy.call( this, source );
  12332. this.color.copy( source.color );
  12333. this.map = source.map;
  12334. this.rotation = source.rotation;
  12335. return this;
  12336. };
  12337. /**
  12338. * Uniform Utilities
  12339. */
  12340. var UniformsUtils = {
  12341. merge: function ( uniforms ) {
  12342. var merged = {};
  12343. for ( var u = 0; u < uniforms.length; u ++ ) {
  12344. var tmp = this.clone( uniforms[ u ] );
  12345. for ( var p in tmp ) {
  12346. merged[ p ] = tmp[ p ];
  12347. }
  12348. }
  12349. return merged;
  12350. },
  12351. clone: function ( uniforms_src ) {
  12352. var uniforms_dst = {};
  12353. for ( var u in uniforms_src ) {
  12354. uniforms_dst[ u ] = {};
  12355. for ( var p in uniforms_src[ u ] ) {
  12356. var parameter_src = uniforms_src[ u ][ p ];
  12357. if ( parameter_src && ( parameter_src.isColor ||
  12358. parameter_src.isMatrix3 || parameter_src.isMatrix4 ||
  12359. parameter_src.isVector2 || parameter_src.isVector3 || parameter_src.isVector4 ||
  12360. parameter_src.isTexture ) ) {
  12361. uniforms_dst[ u ][ p ] = parameter_src.clone();
  12362. } else if ( Array.isArray( parameter_src ) ) {
  12363. uniforms_dst[ u ][ p ] = parameter_src.slice();
  12364. } else {
  12365. uniforms_dst[ u ][ p ] = parameter_src;
  12366. }
  12367. }
  12368. }
  12369. return uniforms_dst;
  12370. }
  12371. };
  12372. function ShaderMaterial( parameters ) {
  12373. Material.call( this );
  12374. this.type = 'ShaderMaterial';
  12375. this.defines = {};
  12376. this.uniforms = {};
  12377. this.vertexShader = 'void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}';
  12378. this.fragmentShader = 'void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}';
  12379. this.linewidth = 1;
  12380. this.wireframe = false;
  12381. this.wireframeLinewidth = 1;
  12382. this.fog = false; // set to use scene fog
  12383. this.lights = false; // set to use scene lights
  12384. this.clipping = false; // set to use user-defined clipping planes
  12385. this.skinning = false; // set to use skinning attribute streams
  12386. this.morphTargets = false; // set to use morph targets
  12387. this.morphNormals = false; // set to use morph normals
  12388. this.extensions = {
  12389. derivatives: false, // set to use derivatives
  12390. fragDepth: false, // set to use fragment depth values
  12391. drawBuffers: false, // set to use draw buffers
  12392. shaderTextureLOD: false // set to use shader texture LOD
  12393. };
  12394. // When rendered geometry doesn't include these attributes but the material does,
  12395. // use these default values in WebGL. This avoids errors when buffer data is missing.
  12396. this.defaultAttributeValues = {
  12397. 'color': [ 1, 1, 1 ],
  12398. 'uv': [ 0, 0 ],
  12399. 'uv2': [ 0, 0 ]
  12400. };
  12401. this.index0AttributeName = undefined;
  12402. if ( parameters !== undefined ) {
  12403. if ( parameters.attributes !== undefined ) {
  12404. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  12405. }
  12406. this.setValues( parameters );
  12407. }
  12408. }
  12409. ShaderMaterial.prototype = Object.create( Material.prototype );
  12410. ShaderMaterial.prototype.constructor = ShaderMaterial;
  12411. ShaderMaterial.prototype.isShaderMaterial = true;
  12412. ShaderMaterial.prototype.copy = function ( source ) {
  12413. Material.prototype.copy.call( this, source );
  12414. this.fragmentShader = source.fragmentShader;
  12415. this.vertexShader = source.vertexShader;
  12416. this.uniforms = UniformsUtils.clone( source.uniforms );
  12417. this.defines = source.defines;
  12418. this.wireframe = source.wireframe;
  12419. this.wireframeLinewidth = source.wireframeLinewidth;
  12420. this.lights = source.lights;
  12421. this.clipping = source.clipping;
  12422. this.skinning = source.skinning;
  12423. this.morphTargets = source.morphTargets;
  12424. this.morphNormals = source.morphNormals;
  12425. this.extensions = source.extensions;
  12426. return this;
  12427. };
  12428. ShaderMaterial.prototype.toJSON = function ( meta ) {
  12429. var data = Material.prototype.toJSON.call( this, meta );
  12430. data.uniforms = this.uniforms;
  12431. data.vertexShader = this.vertexShader;
  12432. data.fragmentShader = this.fragmentShader;
  12433. return data;
  12434. };
  12435. function RawShaderMaterial( parameters ) {
  12436. ShaderMaterial.call( this, parameters );
  12437. this.type = 'RawShaderMaterial';
  12438. }
  12439. RawShaderMaterial.prototype = Object.create( ShaderMaterial.prototype );
  12440. RawShaderMaterial.prototype.constructor = RawShaderMaterial;
  12441. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  12442. function PointsMaterial( parameters ) {
  12443. Material.call( this );
  12444. this.type = 'PointsMaterial';
  12445. this.color = new Color( 0xffffff );
  12446. this.map = null;
  12447. this.size = 1;
  12448. this.sizeAttenuation = true;
  12449. this.lights = false;
  12450. this.setValues( parameters );
  12451. }
  12452. PointsMaterial.prototype = Object.create( Material.prototype );
  12453. PointsMaterial.prototype.constructor = PointsMaterial;
  12454. PointsMaterial.prototype.isPointsMaterial = true;
  12455. PointsMaterial.prototype.copy = function ( source ) {
  12456. Material.prototype.copy.call( this, source );
  12457. this.color.copy( source.color );
  12458. this.map = source.map;
  12459. this.size = source.size;
  12460. this.sizeAttenuation = source.sizeAttenuation;
  12461. return this;
  12462. };
  12463. function MeshStandardMaterial( parameters ) {
  12464. Material.call( this );
  12465. this.defines = { 'STANDARD': '' };
  12466. this.type = 'MeshStandardMaterial';
  12467. this.color = new Color( 0xffffff ); // diffuse
  12468. this.roughness = 0.5;
  12469. this.metalness = 0.5;
  12470. this.map = null;
  12471. this.lightMap = null;
  12472. this.lightMapIntensity = 1.0;
  12473. this.aoMap = null;
  12474. this.aoMapIntensity = 1.0;
  12475. this.emissive = new Color( 0x000000 );
  12476. this.emissiveIntensity = 1.0;
  12477. this.emissiveMap = null;
  12478. this.bumpMap = null;
  12479. this.bumpScale = 1;
  12480. this.normalMap = null;
  12481. this.normalScale = new Vector2( 1, 1 );
  12482. this.displacementMap = null;
  12483. this.displacementScale = 1;
  12484. this.displacementBias = 0;
  12485. this.roughnessMap = null;
  12486. this.metalnessMap = null;
  12487. this.alphaMap = null;
  12488. this.envMap = null;
  12489. this.envMapIntensity = 1.0;
  12490. this.refractionRatio = 0.98;
  12491. this.wireframe = false;
  12492. this.wireframeLinewidth = 1;
  12493. this.wireframeLinecap = 'round';
  12494. this.wireframeLinejoin = 'round';
  12495. this.skinning = false;
  12496. this.morphTargets = false;
  12497. this.morphNormals = false;
  12498. this.setValues( parameters );
  12499. }
  12500. MeshStandardMaterial.prototype = Object.create( Material.prototype );
  12501. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  12502. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  12503. MeshStandardMaterial.prototype.copy = function ( source ) {
  12504. Material.prototype.copy.call( this, source );
  12505. this.defines = { 'STANDARD': '' };
  12506. this.color.copy( source.color );
  12507. this.roughness = source.roughness;
  12508. this.metalness = source.metalness;
  12509. this.map = source.map;
  12510. this.lightMap = source.lightMap;
  12511. this.lightMapIntensity = source.lightMapIntensity;
  12512. this.aoMap = source.aoMap;
  12513. this.aoMapIntensity = source.aoMapIntensity;
  12514. this.emissive.copy( source.emissive );
  12515. this.emissiveMap = source.emissiveMap;
  12516. this.emissiveIntensity = source.emissiveIntensity;
  12517. this.bumpMap = source.bumpMap;
  12518. this.bumpScale = source.bumpScale;
  12519. this.normalMap = source.normalMap;
  12520. this.normalScale.copy( source.normalScale );
  12521. this.displacementMap = source.displacementMap;
  12522. this.displacementScale = source.displacementScale;
  12523. this.displacementBias = source.displacementBias;
  12524. this.roughnessMap = source.roughnessMap;
  12525. this.metalnessMap = source.metalnessMap;
  12526. this.alphaMap = source.alphaMap;
  12527. this.envMap = source.envMap;
  12528. this.envMapIntensity = source.envMapIntensity;
  12529. this.refractionRatio = source.refractionRatio;
  12530. this.wireframe = source.wireframe;
  12531. this.wireframeLinewidth = source.wireframeLinewidth;
  12532. this.wireframeLinecap = source.wireframeLinecap;
  12533. this.wireframeLinejoin = source.wireframeLinejoin;
  12534. this.skinning = source.skinning;
  12535. this.morphTargets = source.morphTargets;
  12536. this.morphNormals = source.morphNormals;
  12537. return this;
  12538. };
  12539. function MeshPhysicalMaterial( parameters ) {
  12540. MeshStandardMaterial.call( this );
  12541. this.defines = { 'PHYSICAL': '' };
  12542. this.type = 'MeshPhysicalMaterial';
  12543. this.reflectivity = 0.5; // maps to F0 = 0.04
  12544. this.clearCoat = 0.0;
  12545. this.clearCoatRoughness = 0.0;
  12546. this.setValues( parameters );
  12547. }
  12548. MeshPhysicalMaterial.prototype = Object.create( MeshStandardMaterial.prototype );
  12549. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  12550. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  12551. MeshPhysicalMaterial.prototype.copy = function ( source ) {
  12552. MeshStandardMaterial.prototype.copy.call( this, source );
  12553. this.defines = { 'PHYSICAL': '' };
  12554. this.reflectivity = source.reflectivity;
  12555. this.clearCoat = source.clearCoat;
  12556. this.clearCoatRoughness = source.clearCoatRoughness;
  12557. return this;
  12558. };
  12559. function MeshPhongMaterial( parameters ) {
  12560. Material.call( this );
  12561. this.type = 'MeshPhongMaterial';
  12562. this.color = new Color( 0xffffff ); // diffuse
  12563. this.specular = new Color( 0x111111 );
  12564. this.shininess = 30;
  12565. this.map = null;
  12566. this.lightMap = null;
  12567. this.lightMapIntensity = 1.0;
  12568. this.aoMap = null;
  12569. this.aoMapIntensity = 1.0;
  12570. this.emissive = new Color( 0x000000 );
  12571. this.emissiveIntensity = 1.0;
  12572. this.emissiveMap = null;
  12573. this.bumpMap = null;
  12574. this.bumpScale = 1;
  12575. this.normalMap = null;
  12576. this.normalScale = new Vector2( 1, 1 );
  12577. this.displacementMap = null;
  12578. this.displacementScale = 1;
  12579. this.displacementBias = 0;
  12580. this.specularMap = null;
  12581. this.alphaMap = null;
  12582. this.envMap = null;
  12583. this.combine = MultiplyOperation;
  12584. this.reflectivity = 1;
  12585. this.refractionRatio = 0.98;
  12586. this.wireframe = false;
  12587. this.wireframeLinewidth = 1;
  12588. this.wireframeLinecap = 'round';
  12589. this.wireframeLinejoin = 'round';
  12590. this.skinning = false;
  12591. this.morphTargets = false;
  12592. this.morphNormals = false;
  12593. this.setValues( parameters );
  12594. }
  12595. MeshPhongMaterial.prototype = Object.create( Material.prototype );
  12596. MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
  12597. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  12598. MeshPhongMaterial.prototype.copy = function ( source ) {
  12599. Material.prototype.copy.call( this, source );
  12600. this.color.copy( source.color );
  12601. this.specular.copy( source.specular );
  12602. this.shininess = source.shininess;
  12603. this.map = source.map;
  12604. this.lightMap = source.lightMap;
  12605. this.lightMapIntensity = source.lightMapIntensity;
  12606. this.aoMap = source.aoMap;
  12607. this.aoMapIntensity = source.aoMapIntensity;
  12608. this.emissive.copy( source.emissive );
  12609. this.emissiveMap = source.emissiveMap;
  12610. this.emissiveIntensity = source.emissiveIntensity;
  12611. this.bumpMap = source.bumpMap;
  12612. this.bumpScale = source.bumpScale;
  12613. this.normalMap = source.normalMap;
  12614. this.normalScale.copy( source.normalScale );
  12615. this.displacementMap = source.displacementMap;
  12616. this.displacementScale = source.displacementScale;
  12617. this.displacementBias = source.displacementBias;
  12618. this.specularMap = source.specularMap;
  12619. this.alphaMap = source.alphaMap;
  12620. this.envMap = source.envMap;
  12621. this.combine = source.combine;
  12622. this.reflectivity = source.reflectivity;
  12623. this.refractionRatio = source.refractionRatio;
  12624. this.wireframe = source.wireframe;
  12625. this.wireframeLinewidth = source.wireframeLinewidth;
  12626. this.wireframeLinecap = source.wireframeLinecap;
  12627. this.wireframeLinejoin = source.wireframeLinejoin;
  12628. this.skinning = source.skinning;
  12629. this.morphTargets = source.morphTargets;
  12630. this.morphNormals = source.morphNormals;
  12631. return this;
  12632. };
  12633. function MeshToonMaterial( parameters ) {
  12634. MeshPhongMaterial.call( this );
  12635. this.defines = { 'TOON': '' };
  12636. this.type = 'MeshToonMaterial';
  12637. this.gradientMap = null;
  12638. this.setValues( parameters );
  12639. }
  12640. MeshToonMaterial.prototype = Object.create( MeshPhongMaterial.prototype );
  12641. MeshToonMaterial.prototype.constructor = MeshToonMaterial;
  12642. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  12643. MeshToonMaterial.prototype.copy = function ( source ) {
  12644. MeshPhongMaterial.prototype.copy.call( this, source );
  12645. this.gradientMap = source.gradientMap;
  12646. return this;
  12647. };
  12648. function MeshNormalMaterial( parameters ) {
  12649. Material.call( this );
  12650. this.type = 'MeshNormalMaterial';
  12651. this.bumpMap = null;
  12652. this.bumpScale = 1;
  12653. this.normalMap = null;
  12654. this.normalScale = new Vector2( 1, 1 );
  12655. this.displacementMap = null;
  12656. this.displacementScale = 1;
  12657. this.displacementBias = 0;
  12658. this.wireframe = false;
  12659. this.wireframeLinewidth = 1;
  12660. this.fog = false;
  12661. this.lights = false;
  12662. this.skinning = false;
  12663. this.morphTargets = false;
  12664. this.morphNormals = false;
  12665. this.setValues( parameters );
  12666. }
  12667. MeshNormalMaterial.prototype = Object.create( Material.prototype );
  12668. MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
  12669. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  12670. MeshNormalMaterial.prototype.copy = function ( source ) {
  12671. Material.prototype.copy.call( this, source );
  12672. this.bumpMap = source.bumpMap;
  12673. this.bumpScale = source.bumpScale;
  12674. this.normalMap = source.normalMap;
  12675. this.normalScale.copy( source.normalScale );
  12676. this.displacementMap = source.displacementMap;
  12677. this.displacementScale = source.displacementScale;
  12678. this.displacementBias = source.displacementBias;
  12679. this.wireframe = source.wireframe;
  12680. this.wireframeLinewidth = source.wireframeLinewidth;
  12681. this.skinning = source.skinning;
  12682. this.morphTargets = source.morphTargets;
  12683. this.morphNormals = source.morphNormals;
  12684. return this;
  12685. };
  12686. function MeshLambertMaterial( parameters ) {
  12687. Material.call( this );
  12688. this.type = 'MeshLambertMaterial';
  12689. this.color = new Color( 0xffffff ); // diffuse
  12690. this.map = null;
  12691. this.lightMap = null;
  12692. this.lightMapIntensity = 1.0;
  12693. this.aoMap = null;
  12694. this.aoMapIntensity = 1.0;
  12695. this.emissive = new Color( 0x000000 );
  12696. this.emissiveIntensity = 1.0;
  12697. this.emissiveMap = null;
  12698. this.specularMap = null;
  12699. this.alphaMap = null;
  12700. this.envMap = null;
  12701. this.combine = MultiplyOperation;
  12702. this.reflectivity = 1;
  12703. this.refractionRatio = 0.98;
  12704. this.wireframe = false;
  12705. this.wireframeLinewidth = 1;
  12706. this.wireframeLinecap = 'round';
  12707. this.wireframeLinejoin = 'round';
  12708. this.skinning = false;
  12709. this.morphTargets = false;
  12710. this.morphNormals = false;
  12711. this.setValues( parameters );
  12712. }
  12713. MeshLambertMaterial.prototype = Object.create( Material.prototype );
  12714. MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
  12715. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  12716. MeshLambertMaterial.prototype.copy = function ( source ) {
  12717. Material.prototype.copy.call( this, source );
  12718. this.color.copy( source.color );
  12719. this.map = source.map;
  12720. this.lightMap = source.lightMap;
  12721. this.lightMapIntensity = source.lightMapIntensity;
  12722. this.aoMap = source.aoMap;
  12723. this.aoMapIntensity = source.aoMapIntensity;
  12724. this.emissive.copy( source.emissive );
  12725. this.emissiveMap = source.emissiveMap;
  12726. this.emissiveIntensity = source.emissiveIntensity;
  12727. this.specularMap = source.specularMap;
  12728. this.alphaMap = source.alphaMap;
  12729. this.envMap = source.envMap;
  12730. this.combine = source.combine;
  12731. this.reflectivity = source.reflectivity;
  12732. this.refractionRatio = source.refractionRatio;
  12733. this.wireframe = source.wireframe;
  12734. this.wireframeLinewidth = source.wireframeLinewidth;
  12735. this.wireframeLinecap = source.wireframeLinecap;
  12736. this.wireframeLinejoin = source.wireframeLinejoin;
  12737. this.skinning = source.skinning;
  12738. this.morphTargets = source.morphTargets;
  12739. this.morphNormals = source.morphNormals;
  12740. return this;
  12741. };
  12742. function MeshDepthMaterial( parameters ) {
  12743. Material.call( this );
  12744. this.type = 'MeshDepthMaterial';
  12745. this.depthPacking = BasicDepthPacking;
  12746. this.skinning = false;
  12747. this.morphTargets = false;
  12748. this.map = null;
  12749. this.alphaMap = null;
  12750. this.displacementMap = null;
  12751. this.displacementScale = 1;
  12752. this.displacementBias = 0;
  12753. this.wireframe = false;
  12754. this.wireframeLinewidth = 1;
  12755. this.fog = false;
  12756. this.lights = false;
  12757. this.setValues( parameters );
  12758. }
  12759. MeshDepthMaterial.prototype = Object.create( Material.prototype );
  12760. MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
  12761. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  12762. MeshDepthMaterial.prototype.copy = function ( source ) {
  12763. Material.prototype.copy.call( this, source );
  12764. this.depthPacking = source.depthPacking;
  12765. this.skinning = source.skinning;
  12766. this.morphTargets = source.morphTargets;
  12767. this.map = source.map;
  12768. this.alphaMap = source.alphaMap;
  12769. this.displacementMap = source.displacementMap;
  12770. this.displacementScale = source.displacementScale;
  12771. this.displacementBias = source.displacementBias;
  12772. this.wireframe = source.wireframe;
  12773. this.wireframeLinewidth = source.wireframeLinewidth;
  12774. return this;
  12775. };
  12776. function MeshDistanceMaterial( parameters ) {
  12777. Material.call( this );
  12778. this.type = 'MeshDistanceMaterial';
  12779. this.referencePosition = new Vector3();
  12780. this.nearDistance = 1;
  12781. this.farDistance = 1000;
  12782. this.skinning = false;
  12783. this.morphTargets = false;
  12784. this.map = null;
  12785. this.alphaMap = null;
  12786. this.displacementMap = null;
  12787. this.displacementScale = 1;
  12788. this.displacementBias = 0;
  12789. this.fog = false;
  12790. this.lights = false;
  12791. this.setValues( parameters );
  12792. }
  12793. MeshDistanceMaterial.prototype = Object.create( Material.prototype );
  12794. MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial;
  12795. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  12796. MeshDistanceMaterial.prototype.copy = function ( source ) {
  12797. Material.prototype.copy.call( this, source );
  12798. this.referencePosition.copy( source.referencePosition );
  12799. this.nearDistance = source.nearDistance;
  12800. this.farDistance = source.farDistance;
  12801. this.skinning = source.skinning;
  12802. this.morphTargets = source.morphTargets;
  12803. this.map = source.map;
  12804. this.alphaMap = source.alphaMap;
  12805. this.displacementMap = source.displacementMap;
  12806. this.displacementScale = source.displacementScale;
  12807. this.displacementBias = source.displacementBias;
  12808. return this;
  12809. };
  12810. function LineBasicMaterial( parameters ) {
  12811. Material.call( this );
  12812. this.type = 'LineBasicMaterial';
  12813. this.color = new Color( 0xffffff );
  12814. this.linewidth = 1;
  12815. this.linecap = 'round';
  12816. this.linejoin = 'round';
  12817. this.lights = false;
  12818. this.setValues( parameters );
  12819. }
  12820. LineBasicMaterial.prototype = Object.create( Material.prototype );
  12821. LineBasicMaterial.prototype.constructor = LineBasicMaterial;
  12822. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  12823. LineBasicMaterial.prototype.copy = function ( source ) {
  12824. Material.prototype.copy.call( this, source );
  12825. this.color.copy( source.color );
  12826. this.linewidth = source.linewidth;
  12827. this.linecap = source.linecap;
  12828. this.linejoin = source.linejoin;
  12829. return this;
  12830. };
  12831. /**
  12832. * @author alteredq / http://alteredqualia.com/
  12833. *
  12834. * parameters = {
  12835. * color: <hex>,
  12836. * opacity: <float>,
  12837. *
  12838. * linewidth: <float>,
  12839. *
  12840. * scale: <float>,
  12841. * dashSize: <float>,
  12842. * gapSize: <float>
  12843. * }
  12844. */
  12845. function LineDashedMaterial( parameters ) {
  12846. LineBasicMaterial.call( this );
  12847. this.type = 'LineDashedMaterial';
  12848. this.scale = 1;
  12849. this.dashSize = 3;
  12850. this.gapSize = 1;
  12851. this.setValues( parameters );
  12852. }
  12853. LineDashedMaterial.prototype = Object.create( LineBasicMaterial.prototype );
  12854. LineDashedMaterial.prototype.constructor = LineDashedMaterial;
  12855. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  12856. LineDashedMaterial.prototype.copy = function ( source ) {
  12857. LineBasicMaterial.prototype.copy.call( this, source );
  12858. this.scale = source.scale;
  12859. this.dashSize = source.dashSize;
  12860. this.gapSize = source.gapSize;
  12861. return this;
  12862. };
  12863. var Materials = Object.freeze({
  12864. ShadowMaterial: ShadowMaterial,
  12865. SpriteMaterial: SpriteMaterial,
  12866. RawShaderMaterial: RawShaderMaterial,
  12867. ShaderMaterial: ShaderMaterial,
  12868. PointsMaterial: PointsMaterial,
  12869. MeshPhysicalMaterial: MeshPhysicalMaterial,
  12870. MeshStandardMaterial: MeshStandardMaterial,
  12871. MeshPhongMaterial: MeshPhongMaterial,
  12872. MeshToonMaterial: MeshToonMaterial,
  12873. MeshNormalMaterial: MeshNormalMaterial,
  12874. MeshLambertMaterial: MeshLambertMaterial,
  12875. MeshDepthMaterial: MeshDepthMaterial,
  12876. MeshDistanceMaterial: MeshDistanceMaterial,
  12877. MeshBasicMaterial: MeshBasicMaterial,
  12878. LineDashedMaterial: LineDashedMaterial,
  12879. LineBasicMaterial: LineBasicMaterial,
  12880. Material: Material
  12881. });
  12882. function MaterialLoader( manager ) {
  12883. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  12884. this.textures = {};
  12885. }
  12886. Object.assign( MaterialLoader.prototype, {
  12887. load: function ( url, onLoad, onProgress, onError ) {
  12888. var scope = this;
  12889. var loader = new FileLoader( scope.manager );
  12890. loader.load( url, function ( text ) {
  12891. onLoad( scope.parse( JSON.parse( text ) ) );
  12892. }, onProgress, onError );
  12893. },
  12894. setTextures: function ( value ) {
  12895. this.textures = value;
  12896. },
  12897. parse: function ( json ) {
  12898. var textures = this.textures;
  12899. function getTexture( name ) {
  12900. if ( textures[ name ] === undefined ) {
  12901. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  12902. }
  12903. return textures[ name ];
  12904. }
  12905. var material = new Materials[ json.type ]();
  12906. if ( json.uuid !== undefined ) material.uuid = json.uuid;
  12907. if ( json.name !== undefined ) material.name = json.name;
  12908. if ( json.color !== undefined ) material.color.setHex( json.color );
  12909. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  12910. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  12911. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  12912. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  12913. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  12914. if ( json.clearCoat !== undefined ) material.clearCoat = json.clearCoat;
  12915. if ( json.clearCoatRoughness !== undefined ) material.clearCoatRoughness = json.clearCoatRoughness;
  12916. if ( json.uniforms !== undefined ) material.uniforms = json.uniforms;
  12917. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  12918. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  12919. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  12920. if ( json.fog !== undefined ) material.fog = json.fog;
  12921. if ( json.flatShading !== undefined ) material.flatShading = json.flatShading;
  12922. if ( json.blending !== undefined ) material.blending = json.blending;
  12923. if ( json.side !== undefined ) material.side = json.side;
  12924. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  12925. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  12926. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  12927. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  12928. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  12929. if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
  12930. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  12931. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  12932. if ( json.wireframeLinecap !== undefined ) material.wireframeLinecap = json.wireframeLinecap;
  12933. if ( json.wireframeLinejoin !== undefined ) material.wireframeLinejoin = json.wireframeLinejoin;
  12934. if ( json.rotation !== undefined ) material.rotation = json.rotation;
  12935. if ( json.linewidth !== 1 ) material.linewidth = json.linewidth;
  12936. if ( json.dashSize !== undefined ) material.dashSize = json.dashSize;
  12937. if ( json.gapSize !== undefined ) material.gapSize = json.gapSize;
  12938. if ( json.scale !== undefined ) material.scale = json.scale;
  12939. if ( json.skinning !== undefined ) material.skinning = json.skinning;
  12940. if ( json.morphTargets !== undefined ) material.morphTargets = json.morphTargets;
  12941. if ( json.dithering !== undefined ) material.dithering = json.dithering;
  12942. if ( json.visible !== undefined ) material.visible = json.visible;
  12943. if ( json.userData !== undefined ) material.userData = json.userData;
  12944. // Deprecated
  12945. if ( json.shading !== undefined ) material.flatShading = json.shading === 1; // THREE.FlatShading
  12946. // for PointsMaterial
  12947. if ( json.size !== undefined ) material.size = json.size;
  12948. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  12949. // maps
  12950. if ( json.map !== undefined ) material.map = getTexture( json.map );
  12951. if ( json.alphaMap !== undefined ) {
  12952. material.alphaMap = getTexture( json.alphaMap );
  12953. material.transparent = true;
  12954. }
  12955. if ( json.bumpMap !== undefined ) material.bumpMap = getTexture( json.bumpMap );
  12956. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  12957. if ( json.normalMap !== undefined ) material.normalMap = getTexture( json.normalMap );
  12958. if ( json.normalScale !== undefined ) {
  12959. var normalScale = json.normalScale;
  12960. if ( Array.isArray( normalScale ) === false ) {
  12961. // Blender exporter used to export a scalar. See #7459
  12962. normalScale = [ normalScale, normalScale ];
  12963. }
  12964. material.normalScale = new Vector2().fromArray( normalScale );
  12965. }
  12966. if ( json.displacementMap !== undefined ) material.displacementMap = getTexture( json.displacementMap );
  12967. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  12968. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  12969. if ( json.roughnessMap !== undefined ) material.roughnessMap = getTexture( json.roughnessMap );
  12970. if ( json.metalnessMap !== undefined ) material.metalnessMap = getTexture( json.metalnessMap );
  12971. if ( json.emissiveMap !== undefined ) material.emissiveMap = getTexture( json.emissiveMap );
  12972. if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity;
  12973. if ( json.specularMap !== undefined ) material.specularMap = getTexture( json.specularMap );
  12974. if ( json.envMap !== undefined ) material.envMap = getTexture( json.envMap );
  12975. if ( json.reflectivity !== undefined ) material.reflectivity = json.reflectivity;
  12976. if ( json.lightMap !== undefined ) material.lightMap = getTexture( json.lightMap );
  12977. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  12978. if ( json.aoMap !== undefined ) material.aoMap = getTexture( json.aoMap );
  12979. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  12980. if ( json.gradientMap !== undefined ) material.gradientMap = getTexture( json.gradientMap );
  12981. return material;
  12982. }
  12983. } );
  12984. /**
  12985. * @author mrdoob / http://mrdoob.com/
  12986. */
  12987. function ImageLoader( manager ) {
  12988. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  12989. }
  12990. Object.assign( ImageLoader.prototype, {
  12991. crossOrigin: 'Anonymous',
  12992. load: function ( url, onLoad, onProgress, onError ) {
  12993. if ( url === undefined ) url = '';
  12994. if ( this.path !== undefined ) url = this.path + url;
  12995. url = this.manager.resolveURL( url );
  12996. var scope = this;
  12997. var cached = Cache.get( url );
  12998. if ( cached !== undefined ) {
  12999. scope.manager.itemStart( url );
  13000. setTimeout( function () {
  13001. if ( onLoad ) onLoad( cached );
  13002. scope.manager.itemEnd( url );
  13003. }, 0 );
  13004. return cached;
  13005. }
  13006. var image = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'img' );
  13007. image.addEventListener( 'load', function () {
  13008. Cache.add( url, this );
  13009. if ( onLoad ) onLoad( this );
  13010. scope.manager.itemEnd( url );
  13011. }, false );
  13012. /*
  13013. image.addEventListener( 'progress', function ( event ) {
  13014. if ( onProgress ) onProgress( event );
  13015. }, false );
  13016. */
  13017. image.addEventListener( 'error', function ( event ) {
  13018. if ( onError ) onError( event );
  13019. scope.manager.itemEnd( url );
  13020. scope.manager.itemError( url );
  13021. }, false );
  13022. if ( url.substr( 0, 5 ) !== 'data:' ) {
  13023. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  13024. }
  13025. scope.manager.itemStart( url );
  13026. image.src = url;
  13027. return image;
  13028. },
  13029. setCrossOrigin: function ( value ) {
  13030. this.crossOrigin = value;
  13031. return this;
  13032. },
  13033. setPath: function ( value ) {
  13034. this.path = value;
  13035. return this;
  13036. }
  13037. } );
  13038. /**
  13039. * @author mrdoob / http://mrdoob.com/
  13040. */
  13041. function TextureLoader( manager ) {
  13042. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  13043. }
  13044. Object.assign( TextureLoader.prototype, {
  13045. crossOrigin: 'Anonymous',
  13046. load: function ( url, onLoad, onProgress, onError ) {
  13047. var loader = new ImageLoader( this.manager );
  13048. loader.setCrossOrigin( this.crossOrigin );
  13049. loader.setPath( this.path );
  13050. var texture = new Texture();
  13051. texture.image = loader.load( url, function () {
  13052. // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  13053. var isJPEG = url.search( /\.(jpg|jpeg)$/ ) > 0 || url.search( /^data\:image\/jpeg/ ) === 0;
  13054. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  13055. texture.needsUpdate = true;
  13056. if ( onLoad !== undefined ) {
  13057. onLoad( texture );
  13058. }
  13059. }, onProgress, onError );
  13060. return texture;
  13061. },
  13062. setCrossOrigin: function ( value ) {
  13063. this.crossOrigin = value;
  13064. return this;
  13065. },
  13066. setPath: function ( value ) {
  13067. this.path = value;
  13068. return this;
  13069. }
  13070. } );
  13071. function Loader() {
  13072. this.onLoadStart = function () {};
  13073. this.onLoadProgress = function () {};
  13074. this.onLoadComplete = function () {};
  13075. }
  13076. Loader.Handlers = {
  13077. handlers: [],
  13078. add: function ( regex, loader ) {
  13079. this.handlers.push( regex, loader );
  13080. },
  13081. get: function ( file ) {
  13082. var handlers = this.handlers;
  13083. for ( var i = 0, l = handlers.length; i < l; i += 2 ) {
  13084. var regex = handlers[ i ];
  13085. var loader = handlers[ i + 1 ];
  13086. if ( regex.test( file ) ) {
  13087. return loader;
  13088. }
  13089. }
  13090. return null;
  13091. }
  13092. };
  13093. Object.assign( Loader.prototype, {
  13094. crossOrigin: undefined,
  13095. extractUrlBase: function ( url ) {
  13096. var parts = url.split( '/' );
  13097. if ( parts.length === 1 ) return './';
  13098. parts.pop();
  13099. return parts.join( '/' ) + '/';
  13100. },
  13101. initMaterials: function ( materials, texturePath, crossOrigin ) {
  13102. var array = [];
  13103. for ( var i = 0; i < materials.length; ++ i ) {
  13104. array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
  13105. }
  13106. return array;
  13107. },
  13108. createMaterial: ( function () {
  13109. var BlendingMode = {
  13110. NoBlending: NoBlending,
  13111. NormalBlending: NormalBlending,
  13112. AdditiveBlending: AdditiveBlending,
  13113. SubtractiveBlending: SubtractiveBlending,
  13114. MultiplyBlending: MultiplyBlending,
  13115. CustomBlending: CustomBlending
  13116. };
  13117. var color = new Color();
  13118. var textureLoader = new TextureLoader();
  13119. var materialLoader = new MaterialLoader();
  13120. return function createMaterial( m, texturePath, crossOrigin ) {
  13121. // convert from old material format
  13122. var textures = {};
  13123. function loadTexture( path, repeat, offset, wrap, anisotropy ) {
  13124. var fullPath = texturePath + path;
  13125. var loader = Loader.Handlers.get( fullPath );
  13126. var texture;
  13127. if ( loader !== null ) {
  13128. texture = loader.load( fullPath );
  13129. } else {
  13130. textureLoader.setCrossOrigin( crossOrigin );
  13131. texture = textureLoader.load( fullPath );
  13132. }
  13133. if ( repeat !== undefined ) {
  13134. texture.repeat.fromArray( repeat );
  13135. if ( repeat[ 0 ] !== 1 ) texture.wrapS = RepeatWrapping;
  13136. if ( repeat[ 1 ] !== 1 ) texture.wrapT = RepeatWrapping;
  13137. }
  13138. if ( offset !== undefined ) {
  13139. texture.offset.fromArray( offset );
  13140. }
  13141. if ( wrap !== undefined ) {
  13142. if ( wrap[ 0 ] === 'repeat' ) texture.wrapS = RepeatWrapping;
  13143. if ( wrap[ 0 ] === 'mirror' ) texture.wrapS = MirroredRepeatWrapping;
  13144. if ( wrap[ 1 ] === 'repeat' ) texture.wrapT = RepeatWrapping;
  13145. if ( wrap[ 1 ] === 'mirror' ) texture.wrapT = MirroredRepeatWrapping;
  13146. }
  13147. if ( anisotropy !== undefined ) {
  13148. texture.anisotropy = anisotropy;
  13149. }
  13150. var uuid = _Math.generateUUID();
  13151. textures[ uuid ] = texture;
  13152. return uuid;
  13153. }
  13154. //
  13155. var json = {
  13156. uuid: _Math.generateUUID(),
  13157. type: 'MeshLambertMaterial'
  13158. };
  13159. for ( var name in m ) {
  13160. var value = m[ name ];
  13161. switch ( name ) {
  13162. case 'DbgColor':
  13163. case 'DbgIndex':
  13164. case 'opticalDensity':
  13165. case 'illumination':
  13166. break;
  13167. case 'DbgName':
  13168. json.name = value;
  13169. break;
  13170. case 'blending':
  13171. json.blending = BlendingMode[ value ];
  13172. break;
  13173. case 'colorAmbient':
  13174. case 'mapAmbient':
  13175. console.warn( 'THREE.Loader.createMaterial:', name, 'is no longer supported.' );
  13176. break;
  13177. case 'colorDiffuse':
  13178. json.color = color.fromArray( value ).getHex();
  13179. break;
  13180. case 'colorSpecular':
  13181. json.specular = color.fromArray( value ).getHex();
  13182. break;
  13183. case 'colorEmissive':
  13184. json.emissive = color.fromArray( value ).getHex();
  13185. break;
  13186. case 'specularCoef':
  13187. json.shininess = value;
  13188. break;
  13189. case 'shading':
  13190. if ( value.toLowerCase() === 'basic' ) json.type = 'MeshBasicMaterial';
  13191. if ( value.toLowerCase() === 'phong' ) json.type = 'MeshPhongMaterial';
  13192. if ( value.toLowerCase() === 'standard' ) json.type = 'MeshStandardMaterial';
  13193. break;
  13194. case 'mapDiffuse':
  13195. json.map = loadTexture( value, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  13196. break;
  13197. case 'mapDiffuseRepeat':
  13198. case 'mapDiffuseOffset':
  13199. case 'mapDiffuseWrap':
  13200. case 'mapDiffuseAnisotropy':
  13201. break;
  13202. case 'mapEmissive':
  13203. json.emissiveMap = loadTexture( value, m.mapEmissiveRepeat, m.mapEmissiveOffset, m.mapEmissiveWrap, m.mapEmissiveAnisotropy );
  13204. break;
  13205. case 'mapEmissiveRepeat':
  13206. case 'mapEmissiveOffset':
  13207. case 'mapEmissiveWrap':
  13208. case 'mapEmissiveAnisotropy':
  13209. break;
  13210. case 'mapLight':
  13211. json.lightMap = loadTexture( value, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  13212. break;
  13213. case 'mapLightRepeat':
  13214. case 'mapLightOffset':
  13215. case 'mapLightWrap':
  13216. case 'mapLightAnisotropy':
  13217. break;
  13218. case 'mapAO':
  13219. json.aoMap = loadTexture( value, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  13220. break;
  13221. case 'mapAORepeat':
  13222. case 'mapAOOffset':
  13223. case 'mapAOWrap':
  13224. case 'mapAOAnisotropy':
  13225. break;
  13226. case 'mapBump':
  13227. json.bumpMap = loadTexture( value, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  13228. break;
  13229. case 'mapBumpScale':
  13230. json.bumpScale = value;
  13231. break;
  13232. case 'mapBumpRepeat':
  13233. case 'mapBumpOffset':
  13234. case 'mapBumpWrap':
  13235. case 'mapBumpAnisotropy':
  13236. break;
  13237. case 'mapNormal':
  13238. json.normalMap = loadTexture( value, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  13239. break;
  13240. case 'mapNormalFactor':
  13241. json.normalScale = [ value, value ];
  13242. break;
  13243. case 'mapNormalRepeat':
  13244. case 'mapNormalOffset':
  13245. case 'mapNormalWrap':
  13246. case 'mapNormalAnisotropy':
  13247. break;
  13248. case 'mapSpecular':
  13249. json.specularMap = loadTexture( value, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  13250. break;
  13251. case 'mapSpecularRepeat':
  13252. case 'mapSpecularOffset':
  13253. case 'mapSpecularWrap':
  13254. case 'mapSpecularAnisotropy':
  13255. break;
  13256. case 'mapMetalness':
  13257. json.metalnessMap = loadTexture( value, m.mapMetalnessRepeat, m.mapMetalnessOffset, m.mapMetalnessWrap, m.mapMetalnessAnisotropy );
  13258. break;
  13259. case 'mapMetalnessRepeat':
  13260. case 'mapMetalnessOffset':
  13261. case 'mapMetalnessWrap':
  13262. case 'mapMetalnessAnisotropy':
  13263. break;
  13264. case 'mapRoughness':
  13265. json.roughnessMap = loadTexture( value, m.mapRoughnessRepeat, m.mapRoughnessOffset, m.mapRoughnessWrap, m.mapRoughnessAnisotropy );
  13266. break;
  13267. case 'mapRoughnessRepeat':
  13268. case 'mapRoughnessOffset':
  13269. case 'mapRoughnessWrap':
  13270. case 'mapRoughnessAnisotropy':
  13271. break;
  13272. case 'mapAlpha':
  13273. json.alphaMap = loadTexture( value, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  13274. break;
  13275. case 'mapAlphaRepeat':
  13276. case 'mapAlphaOffset':
  13277. case 'mapAlphaWrap':
  13278. case 'mapAlphaAnisotropy':
  13279. break;
  13280. case 'flipSided':
  13281. json.side = BackSide;
  13282. break;
  13283. case 'doubleSided':
  13284. json.side = DoubleSide;
  13285. break;
  13286. case 'transparency':
  13287. console.warn( 'THREE.Loader.createMaterial: transparency has been renamed to opacity' );
  13288. json.opacity = value;
  13289. break;
  13290. case 'depthTest':
  13291. case 'depthWrite':
  13292. case 'colorWrite':
  13293. case 'opacity':
  13294. case 'reflectivity':
  13295. case 'transparent':
  13296. case 'visible':
  13297. case 'wireframe':
  13298. json[ name ] = value;
  13299. break;
  13300. case 'vertexColors':
  13301. if ( value === true ) json.vertexColors = VertexColors;
  13302. if ( value === 'face' ) json.vertexColors = FaceColors;
  13303. break;
  13304. default:
  13305. console.error( 'THREE.Loader.createMaterial: Unsupported', name, value );
  13306. break;
  13307. }
  13308. }
  13309. if ( json.type === 'MeshBasicMaterial' ) delete json.emissive;
  13310. if ( json.type !== 'MeshPhongMaterial' ) delete json.specular;
  13311. if ( json.opacity < 1 ) json.transparent = true;
  13312. materialLoader.setTextures( textures );
  13313. return materialLoader.parse( json );
  13314. };
  13315. } )()
  13316. } );
  13317. function JSONLoader( manager ) {
  13318. if ( typeof manager === 'boolean' ) {
  13319. console.warn( 'THREE.JSONLoader: showStatus parameter has been removed from constructor.' );
  13320. manager = undefined;
  13321. }
  13322. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  13323. this.withCredentials = false;
  13324. }
  13325. Object.assign( JSONLoader.prototype, {
  13326. load: function ( url, onLoad, onProgress, onError ) {
  13327. var scope = this;
  13328. var texturePath = this.texturePath && ( typeof this.texturePath === "string" ) ? this.texturePath : Loader.prototype.extractUrlBase( url );
  13329. var loader = new FileLoader( this.manager );
  13330. loader.setWithCredentials( this.withCredentials );
  13331. loader.load( url, function ( text ) {
  13332. var json = JSON.parse( text );
  13333. var metadata = json.metadata;
  13334. if ( metadata !== undefined ) {
  13335. var type = metadata.type;
  13336. if ( type !== undefined ) {
  13337. if ( type.toLowerCase() === 'object' ) {
  13338. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.ObjectLoader instead.' );
  13339. return;
  13340. }
  13341. if ( type.toLowerCase() === 'scene' ) {
  13342. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.SceneLoader instead.' );
  13343. return;
  13344. }
  13345. }
  13346. }
  13347. var object = scope.parse( json, texturePath );
  13348. onLoad( object.geometry, object.materials );
  13349. }, onProgress, onError );
  13350. },
  13351. setTexturePath: function ( value ) {
  13352. this.texturePath = value;
  13353. },
  13354. parse: ( function () {
  13355. function parseModel( json, geometry ) {
  13356. function isBitSet( value, position ) {
  13357. return value & ( 1 << position );
  13358. }
  13359. var i, j, fi,
  13360. offset, zLength,
  13361. colorIndex, normalIndex, uvIndex, materialIndex,
  13362. type,
  13363. isQuad,
  13364. hasMaterial,
  13365. hasFaceVertexUv,
  13366. hasFaceNormal, hasFaceVertexNormal,
  13367. hasFaceColor, hasFaceVertexColor,
  13368. vertex, face, faceA, faceB, hex, normal,
  13369. uvLayer, uv, u, v,
  13370. faces = json.faces,
  13371. vertices = json.vertices,
  13372. normals = json.normals,
  13373. colors = json.colors,
  13374. scale = json.scale,
  13375. nUvLayers = 0;
  13376. if ( json.uvs !== undefined ) {
  13377. // disregard empty arrays
  13378. for ( i = 0; i < json.uvs.length; i ++ ) {
  13379. if ( json.uvs[ i ].length ) nUvLayers ++;
  13380. }
  13381. for ( i = 0; i < nUvLayers; i ++ ) {
  13382. geometry.faceVertexUvs[ i ] = [];
  13383. }
  13384. }
  13385. offset = 0;
  13386. zLength = vertices.length;
  13387. while ( offset < zLength ) {
  13388. vertex = new Vector3();
  13389. vertex.x = vertices[ offset ++ ] * scale;
  13390. vertex.y = vertices[ offset ++ ] * scale;
  13391. vertex.z = vertices[ offset ++ ] * scale;
  13392. geometry.vertices.push( vertex );
  13393. }
  13394. offset = 0;
  13395. zLength = faces.length;
  13396. while ( offset < zLength ) {
  13397. type = faces[ offset ++ ];
  13398. isQuad = isBitSet( type, 0 );
  13399. hasMaterial = isBitSet( type, 1 );
  13400. hasFaceVertexUv = isBitSet( type, 3 );
  13401. hasFaceNormal = isBitSet( type, 4 );
  13402. hasFaceVertexNormal = isBitSet( type, 5 );
  13403. hasFaceColor = isBitSet( type, 6 );
  13404. hasFaceVertexColor = isBitSet( type, 7 );
  13405. // console.log("type", type, "bits", isQuad, hasMaterial, hasFaceVertexUv, hasFaceNormal, hasFaceVertexNormal, hasFaceColor, hasFaceVertexColor);
  13406. if ( isQuad ) {
  13407. faceA = new Face3();
  13408. faceA.a = faces[ offset ];
  13409. faceA.b = faces[ offset + 1 ];
  13410. faceA.c = faces[ offset + 3 ];
  13411. faceB = new Face3();
  13412. faceB.a = faces[ offset + 1 ];
  13413. faceB.b = faces[ offset + 2 ];
  13414. faceB.c = faces[ offset + 3 ];
  13415. offset += 4;
  13416. if ( hasMaterial ) {
  13417. materialIndex = faces[ offset ++ ];
  13418. faceA.materialIndex = materialIndex;
  13419. faceB.materialIndex = materialIndex;
  13420. }
  13421. // to get face <=> uv index correspondence
  13422. fi = geometry.faces.length;
  13423. if ( hasFaceVertexUv ) {
  13424. for ( i = 0; i < nUvLayers; i ++ ) {
  13425. uvLayer = json.uvs[ i ];
  13426. geometry.faceVertexUvs[ i ][ fi ] = [];
  13427. geometry.faceVertexUvs[ i ][ fi + 1 ] = [];
  13428. for ( j = 0; j < 4; j ++ ) {
  13429. uvIndex = faces[ offset ++ ];
  13430. u = uvLayer[ uvIndex * 2 ];
  13431. v = uvLayer[ uvIndex * 2 + 1 ];
  13432. uv = new Vector2( u, v );
  13433. if ( j !== 2 ) geometry.faceVertexUvs[ i ][ fi ].push( uv );
  13434. if ( j !== 0 ) geometry.faceVertexUvs[ i ][ fi + 1 ].push( uv );
  13435. }
  13436. }
  13437. }
  13438. if ( hasFaceNormal ) {
  13439. normalIndex = faces[ offset ++ ] * 3;
  13440. faceA.normal.set(
  13441. normals[ normalIndex ++ ],
  13442. normals[ normalIndex ++ ],
  13443. normals[ normalIndex ]
  13444. );
  13445. faceB.normal.copy( faceA.normal );
  13446. }
  13447. if ( hasFaceVertexNormal ) {
  13448. for ( i = 0; i < 4; i ++ ) {
  13449. normalIndex = faces[ offset ++ ] * 3;
  13450. normal = new Vector3(
  13451. normals[ normalIndex ++ ],
  13452. normals[ normalIndex ++ ],
  13453. normals[ normalIndex ]
  13454. );
  13455. if ( i !== 2 ) faceA.vertexNormals.push( normal );
  13456. if ( i !== 0 ) faceB.vertexNormals.push( normal );
  13457. }
  13458. }
  13459. if ( hasFaceColor ) {
  13460. colorIndex = faces[ offset ++ ];
  13461. hex = colors[ colorIndex ];
  13462. faceA.color.setHex( hex );
  13463. faceB.color.setHex( hex );
  13464. }
  13465. if ( hasFaceVertexColor ) {
  13466. for ( i = 0; i < 4; i ++ ) {
  13467. colorIndex = faces[ offset ++ ];
  13468. hex = colors[ colorIndex ];
  13469. if ( i !== 2 ) faceA.vertexColors.push( new Color( hex ) );
  13470. if ( i !== 0 ) faceB.vertexColors.push( new Color( hex ) );
  13471. }
  13472. }
  13473. geometry.faces.push( faceA );
  13474. geometry.faces.push( faceB );
  13475. } else {
  13476. face = new Face3();
  13477. face.a = faces[ offset ++ ];
  13478. face.b = faces[ offset ++ ];
  13479. face.c = faces[ offset ++ ];
  13480. if ( hasMaterial ) {
  13481. materialIndex = faces[ offset ++ ];
  13482. face.materialIndex = materialIndex;
  13483. }
  13484. // to get face <=> uv index correspondence
  13485. fi = geometry.faces.length;
  13486. if ( hasFaceVertexUv ) {
  13487. for ( i = 0; i < nUvLayers; i ++ ) {
  13488. uvLayer = json.uvs[ i ];
  13489. geometry.faceVertexUvs[ i ][ fi ] = [];
  13490. for ( j = 0; j < 3; j ++ ) {
  13491. uvIndex = faces[ offset ++ ];
  13492. u = uvLayer[ uvIndex * 2 ];
  13493. v = uvLayer[ uvIndex * 2 + 1 ];
  13494. uv = new Vector2( u, v );
  13495. geometry.faceVertexUvs[ i ][ fi ].push( uv );
  13496. }
  13497. }
  13498. }
  13499. if ( hasFaceNormal ) {
  13500. normalIndex = faces[ offset ++ ] * 3;
  13501. face.normal.set(
  13502. normals[ normalIndex ++ ],
  13503. normals[ normalIndex ++ ],
  13504. normals[ normalIndex ]
  13505. );
  13506. }
  13507. if ( hasFaceVertexNormal ) {
  13508. for ( i = 0; i < 3; i ++ ) {
  13509. normalIndex = faces[ offset ++ ] * 3;
  13510. normal = new Vector3(
  13511. normals[ normalIndex ++ ],
  13512. normals[ normalIndex ++ ],
  13513. normals[ normalIndex ]
  13514. );
  13515. face.vertexNormals.push( normal );
  13516. }
  13517. }
  13518. if ( hasFaceColor ) {
  13519. colorIndex = faces[ offset ++ ];
  13520. face.color.setHex( colors[ colorIndex ] );
  13521. }
  13522. if ( hasFaceVertexColor ) {
  13523. for ( i = 0; i < 3; i ++ ) {
  13524. colorIndex = faces[ offset ++ ];
  13525. face.vertexColors.push( new Color( colors[ colorIndex ] ) );
  13526. }
  13527. }
  13528. geometry.faces.push( face );
  13529. }
  13530. }
  13531. }
  13532. function parseSkin( json, geometry ) {
  13533. var influencesPerVertex = ( json.influencesPerVertex !== undefined ) ? json.influencesPerVertex : 2;
  13534. if ( json.skinWeights ) {
  13535. for ( var i = 0, l = json.skinWeights.length; i < l; i += influencesPerVertex ) {
  13536. var x = json.skinWeights[ i ];
  13537. var y = ( influencesPerVertex > 1 ) ? json.skinWeights[ i + 1 ] : 0;
  13538. var z = ( influencesPerVertex > 2 ) ? json.skinWeights[ i + 2 ] : 0;
  13539. var w = ( influencesPerVertex > 3 ) ? json.skinWeights[ i + 3 ] : 0;
  13540. geometry.skinWeights.push( new Vector4( x, y, z, w ) );
  13541. }
  13542. }
  13543. if ( json.skinIndices ) {
  13544. for ( var i = 0, l = json.skinIndices.length; i < l; i += influencesPerVertex ) {
  13545. var a = json.skinIndices[ i ];
  13546. var b = ( influencesPerVertex > 1 ) ? json.skinIndices[ i + 1 ] : 0;
  13547. var c = ( influencesPerVertex > 2 ) ? json.skinIndices[ i + 2 ] : 0;
  13548. var d = ( influencesPerVertex > 3 ) ? json.skinIndices[ i + 3 ] : 0;
  13549. geometry.skinIndices.push( new Vector4( a, b, c, d ) );
  13550. }
  13551. }
  13552. geometry.bones = json.bones;
  13553. if ( geometry.bones && geometry.bones.length > 0 && ( geometry.skinWeights.length !== geometry.skinIndices.length || geometry.skinIndices.length !== geometry.vertices.length ) ) {
  13554. console.warn( 'When skinning, number of vertices (' + geometry.vertices.length + '), skinIndices (' +
  13555. geometry.skinIndices.length + '), and skinWeights (' + geometry.skinWeights.length + ') should match.' );
  13556. }
  13557. }
  13558. function parseMorphing( json, geometry ) {
  13559. var scale = json.scale;
  13560. if ( json.morphTargets !== undefined ) {
  13561. for ( var i = 0, l = json.morphTargets.length; i < l; i ++ ) {
  13562. geometry.morphTargets[ i ] = {};
  13563. geometry.morphTargets[ i ].name = json.morphTargets[ i ].name;
  13564. geometry.morphTargets[ i ].vertices = [];
  13565. var dstVertices = geometry.morphTargets[ i ].vertices;
  13566. var srcVertices = json.morphTargets[ i ].vertices;
  13567. for ( var v = 0, vl = srcVertices.length; v < vl; v += 3 ) {
  13568. var vertex = new Vector3();
  13569. vertex.x = srcVertices[ v ] * scale;
  13570. vertex.y = srcVertices[ v + 1 ] * scale;
  13571. vertex.z = srcVertices[ v + 2 ] * scale;
  13572. dstVertices.push( vertex );
  13573. }
  13574. }
  13575. }
  13576. if ( json.morphColors !== undefined && json.morphColors.length > 0 ) {
  13577. console.warn( 'THREE.JSONLoader: "morphColors" no longer supported. Using them as face colors.' );
  13578. var faces = geometry.faces;
  13579. var morphColors = json.morphColors[ 0 ].colors;
  13580. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  13581. faces[ i ].color.fromArray( morphColors, i * 3 );
  13582. }
  13583. }
  13584. }
  13585. function parseAnimations( json, geometry ) {
  13586. var outputAnimations = [];
  13587. // parse old style Bone/Hierarchy animations
  13588. var animations = [];
  13589. if ( json.animation !== undefined ) {
  13590. animations.push( json.animation );
  13591. }
  13592. if ( json.animations !== undefined ) {
  13593. if ( json.animations.length ) {
  13594. animations = animations.concat( json.animations );
  13595. } else {
  13596. animations.push( json.animations );
  13597. }
  13598. }
  13599. for ( var i = 0; i < animations.length; i ++ ) {
  13600. var clip = AnimationClip.parseAnimation( animations[ i ], geometry.bones );
  13601. if ( clip ) outputAnimations.push( clip );
  13602. }
  13603. // parse implicit morph animations
  13604. if ( geometry.morphTargets ) {
  13605. // TODO: Figure out what an appropraite FPS is for morph target animations -- defaulting to 10, but really it is completely arbitrary.
  13606. var morphAnimationClips = AnimationClip.CreateClipsFromMorphTargetSequences( geometry.morphTargets, 10 );
  13607. outputAnimations = outputAnimations.concat( morphAnimationClips );
  13608. }
  13609. if ( outputAnimations.length > 0 ) geometry.animations = outputAnimations;
  13610. }
  13611. return function ( json, texturePath ) {
  13612. if ( json.data !== undefined ) {
  13613. // Geometry 4.0 spec
  13614. json = json.data;
  13615. }
  13616. if ( json.scale !== undefined ) {
  13617. json.scale = 1.0 / json.scale;
  13618. } else {
  13619. json.scale = 1.0;
  13620. }
  13621. var geometry = new Geometry();
  13622. parseModel( json, geometry );
  13623. parseSkin( json, geometry );
  13624. parseMorphing( json, geometry );
  13625. parseAnimations( json, geometry );
  13626. geometry.computeFaceNormals();
  13627. geometry.computeBoundingSphere();
  13628. if ( json.materials === undefined || json.materials.length === 0 ) {
  13629. return { geometry: geometry };
  13630. } else {
  13631. var materials = Loader.prototype.initMaterials( json.materials, texturePath, this.crossOrigin );
  13632. return { geometry: geometry, materials: materials };
  13633. }
  13634. };
  13635. } )()
  13636. } );
  13637. function Line( geometry, material, mode ) {
  13638. if ( mode === 1 ) {
  13639. console.warn( 'THREE.Line: parameter THREE.LinePieces no longer supported. Created THREE.LineSegments instead.' );
  13640. return new LineSegments( geometry, material );
  13641. }
  13642. Object3D.call( this );
  13643. this.type = 'Line';
  13644. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  13645. this.material = material !== undefined ? material : new LineBasicMaterial( { color: Math.random() * 0xffffff } );
  13646. }
  13647. Line.prototype = Object.assign( Object.create( Object3D.prototype ), {
  13648. constructor: Line,
  13649. isLine: true,
  13650. raycast: ( function () {
  13651. var inverseMatrix = new Matrix4();
  13652. var ray = new Ray();
  13653. var sphere = new Sphere();
  13654. return function raycast( raycaster, intersects ) {
  13655. var precision = raycaster.linePrecision;
  13656. var precisionSq = precision * precision;
  13657. var geometry = this.geometry;
  13658. var matrixWorld = this.matrixWorld;
  13659. // Checking boundingSphere distance to ray
  13660. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  13661. sphere.copy( geometry.boundingSphere );
  13662. sphere.applyMatrix4( matrixWorld );
  13663. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  13664. //
  13665. inverseMatrix.getInverse( matrixWorld );
  13666. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  13667. var vStart = new Vector3();
  13668. var vEnd = new Vector3();
  13669. var interSegment = new Vector3();
  13670. var interRay = new Vector3();
  13671. var step = ( this && this.isLineSegments ) ? 2 : 1;
  13672. if ( geometry.isBufferGeometry ) {
  13673. var index = geometry.index;
  13674. var attributes = geometry.attributes;
  13675. var positions = attributes.position.array;
  13676. if ( index !== null ) {
  13677. var indices = index.array;
  13678. for ( var i = 0, l = indices.length - 1; i < l; i += step ) {
  13679. var a = indices[ i ];
  13680. var b = indices[ i + 1 ];
  13681. vStart.fromArray( positions, a * 3 );
  13682. vEnd.fromArray( positions, b * 3 );
  13683. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  13684. if ( distSq > precisionSq ) continue;
  13685. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  13686. var distance = raycaster.ray.origin.distanceTo( interRay );
  13687. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  13688. intersects.push( {
  13689. distance: distance,
  13690. // What do we want? intersection point on the ray or on the segment??
  13691. // point: raycaster.ray.at( distance ),
  13692. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  13693. index: i,
  13694. face: null,
  13695. faceIndex: null,
  13696. object: this
  13697. } );
  13698. }
  13699. } else {
  13700. for ( var i = 0, l = positions.length / 3 - 1; i < l; i += step ) {
  13701. vStart.fromArray( positions, 3 * i );
  13702. vEnd.fromArray( positions, 3 * i + 3 );
  13703. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  13704. if ( distSq > precisionSq ) continue;
  13705. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  13706. var distance = raycaster.ray.origin.distanceTo( interRay );
  13707. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  13708. intersects.push( {
  13709. distance: distance,
  13710. // What do we want? intersection point on the ray or on the segment??
  13711. // point: raycaster.ray.at( distance ),
  13712. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  13713. index: i,
  13714. face: null,
  13715. faceIndex: null,
  13716. object: this
  13717. } );
  13718. }
  13719. }
  13720. } else if ( geometry.isGeometry ) {
  13721. var vertices = geometry.vertices;
  13722. var nbVertices = vertices.length;
  13723. for ( var i = 0; i < nbVertices - 1; i += step ) {
  13724. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  13725. if ( distSq > precisionSq ) continue;
  13726. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  13727. var distance = raycaster.ray.origin.distanceTo( interRay );
  13728. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  13729. intersects.push( {
  13730. distance: distance,
  13731. // What do we want? intersection point on the ray or on the segment??
  13732. // point: raycaster.ray.at( distance ),
  13733. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  13734. index: i,
  13735. face: null,
  13736. faceIndex: null,
  13737. object: this
  13738. } );
  13739. }
  13740. }
  13741. };
  13742. }() ),
  13743. clone: function () {
  13744. return new this.constructor( this.geometry, this.material ).copy( this );
  13745. }
  13746. } );
  13747. function LineSegments( geometry, material ) {
  13748. Line.call( this, geometry, material );
  13749. this.type = 'LineSegments';
  13750. }
  13751. LineSegments.prototype = Object.assign( Object.create( Line.prototype ), {
  13752. constructor: LineSegments,
  13753. isLineSegments: true
  13754. } );
  13755. /**
  13756. * @author bhouston / http://exocortex.com
  13757. */
  13758. const x = 2;
  13759. const y = 3;
  13760. const z = 4;
  13761. const w = 5;
  13762. const negInf2 = new Vector2( - Infinity, - Infinity );
  13763. const posInf2 = new Vector2( Infinity, Infinity );
  13764. const zero2 = new Vector2();
  13765. const one2 = new Vector2( 1, 1 );
  13766. const two2 = new Vector2( 2, 2 );
  13767. const negInf3 = new Vector3( - Infinity, - Infinity, - Infinity );
  13768. const posInf3 = new Vector3( Infinity, Infinity, Infinity );
  13769. const zero3 = new Vector3();
  13770. const one3 = new Vector3( 1, 1, 1 );
  13771. const two3 = new Vector3( 2, 2, 2 );
  13772. const eps = 0.0001;
  13773. /**
  13774. * @author simonThiele / https://github.com/simonThiele
  13775. * @author TristanVALCKE / https://github.com/Itee
  13776. */
  13777. /* global QUnit */
  13778. var DegToRad = Math.PI / 180;
  13779. function bufferAttributeEquals( a, b, tolerance ) {
  13780. tolerance = tolerance || 0.0001;
  13781. if ( a.count !== b.count || a.itemSize !== b.itemSize ) {
  13782. return false;
  13783. }
  13784. for ( var i = 0, il = a.count * a.itemSize; i < il; i ++ ) {
  13785. var delta = a[ i ] - b[ i ];
  13786. if ( delta > tolerance ) {
  13787. return false;
  13788. }
  13789. }
  13790. return true;
  13791. }
  13792. function getBBForVertices( vertices ) {
  13793. var geometry = new BufferGeometry();
  13794. geometry.addAttribute( "position", new BufferAttribute( new Float32Array( vertices ), 3 ) );
  13795. geometry.computeBoundingBox();
  13796. return geometry.boundingBox;
  13797. }
  13798. function getBSForVertices( vertices ) {
  13799. var geometry = new BufferGeometry();
  13800. geometry.addAttribute( "position", new BufferAttribute( new Float32Array( vertices ), 3 ) );
  13801. geometry.computeBoundingSphere();
  13802. return geometry.boundingSphere;
  13803. }
  13804. function getNormalsForVertices( vertices, assert ) {
  13805. var geometry = new BufferGeometry();
  13806. geometry.addAttribute( "position", new BufferAttribute( new Float32Array( vertices ), 3 ) );
  13807. geometry.computeVertexNormals();
  13808. assert.ok( geometry.attributes.normal !== undefined, "normal attribute was created" );
  13809. return geometry.attributes.normal.array;
  13810. }
  13811. function comparePositions( pos, v ) {
  13812. return (
  13813. pos[ 0 ] === v[ 0 ].x && pos[ 1 ] === v[ 0 ].y && pos[ 2 ] === v[ 0 ].z &&
  13814. pos[ 3 ] === v[ 1 ].x && pos[ 4 ] === v[ 1 ].y && pos[ 5 ] === v[ 1 ].z &&
  13815. pos[ 6 ] === v[ 2 ].x && pos[ 7 ] === v[ 2 ].y && pos[ 8 ] === v[ 2 ].z
  13816. );
  13817. }
  13818. function compareColors( col, c ) {
  13819. return (
  13820. col[ 0 ] === c[ 0 ].r && col[ 1 ] === c[ 0 ].g && col[ 2 ] === c[ 0 ].b &&
  13821. col[ 3 ] === c[ 1 ].r && col[ 4 ] === c[ 1 ].g && col[ 5 ] === c[ 1 ].b &&
  13822. col[ 6 ] === c[ 2 ].r && col[ 7 ] === c[ 2 ].g && col[ 8 ] === c[ 2 ].b
  13823. );
  13824. }
  13825. function compareUvs( uvs, u ) {
  13826. return (
  13827. uvs[ 0 ] === u[ 0 ].x && uvs[ 1 ] === u[ 0 ].y &&
  13828. uvs[ 2 ] === u[ 1 ].x && uvs[ 3 ] === u[ 1 ].y &&
  13829. uvs[ 4 ] === u[ 2 ].x && uvs[ 5 ] === u[ 2 ].y
  13830. );
  13831. }
  13832. QUnit.module( 'Core', () => {
  13833. QUnit.module.todo( 'BufferGeometry', () => {
  13834. // INHERITANCE
  13835. QUnit.test( "Extending", ( assert ) => {
  13836. assert.ok( false, "everything's gonna be alright" );
  13837. } );
  13838. // INSTANCING
  13839. QUnit.test( "Instancing", ( assert ) => {
  13840. assert.ok( false, "everything's gonna be alright" );
  13841. } );
  13842. // PUBLIC STUFF
  13843. QUnit.test( "isBufferGeometry", ( assert ) => {
  13844. assert.ok( false, "everything's gonna be alright" );
  13845. } );
  13846. QUnit.test( "setIndex/getIndex", ( assert ) => {
  13847. var a = new BufferGeometry();
  13848. var uint16 = [ 1, 2, 3 ];
  13849. var uint32 = [ 65535, 65536, 65537 ];
  13850. var str = "foo";
  13851. a.setIndex( uint16 );
  13852. assert.ok( a.getIndex() instanceof Uint16BufferAttribute, "Index has the right type" );
  13853. assert.deepEqual( a.getIndex().array, new Uint16Array( uint16 ), "Small index gets stored correctly" );
  13854. a.setIndex( uint32 );
  13855. assert.ok( a.getIndex() instanceof Uint32BufferAttribute, "Index has the right type" );
  13856. assert.deepEqual( a.getIndex().array, new Uint32Array( uint32 ), "Large index gets stored correctly" );
  13857. a.setIndex( str );
  13858. assert.strictEqual( a.getIndex(), str, "Weird index gets stored correctly" );
  13859. } );
  13860. QUnit.test( "getAttribute", ( assert ) => {
  13861. assert.ok( false, "everything's gonna be alright" );
  13862. } );
  13863. QUnit.test( "add / delete Attribute", ( assert ) => {
  13864. var geometry = new BufferGeometry();
  13865. var attributeName = "position";
  13866. assert.ok( geometry.attributes[ attributeName ] === undefined, 'no attribute defined' );
  13867. geometry.addAttribute( attributeName, new BufferAttribute( new Float32Array( [ 1, 2, 3 ], 1 ) ) );
  13868. assert.ok( geometry.attributes[ attributeName ] !== undefined, 'attribute is defined' );
  13869. geometry.removeAttribute( attributeName );
  13870. assert.ok( geometry.attributes[ attributeName ] === undefined, 'no attribute defined' );
  13871. } );
  13872. QUnit.test( "addGroup", ( assert ) => {
  13873. var a = new BufferGeometry();
  13874. var expected = [
  13875. {
  13876. start: 0,
  13877. count: 1,
  13878. materialIndex: 0
  13879. },
  13880. {
  13881. start: 1,
  13882. count: 2,
  13883. materialIndex: 2
  13884. }
  13885. ];
  13886. a.addGroup( 0, 1, 0 );
  13887. a.addGroup( 1, 2, 2 );
  13888. assert.deepEqual( a.groups, expected, "Check groups were stored correctly and in order" );
  13889. a.clearGroups();
  13890. assert.strictEqual( a.groups.length, 0, "Check groups were deleted correctly" );
  13891. } );
  13892. QUnit.test( "clearGroups", ( assert ) => {
  13893. assert.ok( false, "everything's gonna be alright" );
  13894. } );
  13895. QUnit.test( "setDrawRange", ( assert ) => {
  13896. var a = new BufferGeometry();
  13897. a.setDrawRange( 1.0, 7 );
  13898. assert.deepEqual( a.drawRange, {
  13899. start: 1,
  13900. count: 7
  13901. }, "Check draw range was stored correctly" );
  13902. } );
  13903. QUnit.test( "applyMatrix", ( assert ) => {
  13904. var geometry = new BufferGeometry();
  13905. geometry.addAttribute( "position", new BufferAttribute( new Float32Array( 6 ), 3 ) );
  13906. var matrix = new Matrix4().set(
  13907. 1, 0, 0, 1.5,
  13908. 0, 1, 0, - 2,
  13909. 0, 0, 1, 3,
  13910. 0, 0, 0, 1
  13911. );
  13912. geometry.applyMatrix( matrix );
  13913. var position = geometry.attributes.position.array;
  13914. var m = matrix.elements;
  13915. assert.ok( position[ 0 ] === m[ 12 ] && position[ 1 ] === m[ 13 ] && position[ 2 ] === m[ 14 ], "position was extracted from matrix" );
  13916. assert.ok( position[ 3 ] === m[ 12 ] && position[ 4 ] === m[ 13 ] && position[ 5 ] === m[ 14 ], "position was extracted from matrix twice" );
  13917. assert.ok( geometry.attributes.position.version === 1, "version was increased during update" );
  13918. } );
  13919. QUnit.test( "rotateX/Y/Z", ( assert ) => {
  13920. var geometry = new BufferGeometry();
  13921. geometry.addAttribute( "position", new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 5, 6 ] ), 3 ) );
  13922. var pos = geometry.attributes.position.array;
  13923. geometry.rotateX( 180 * DegToRad );
  13924. // object was rotated around x so all items should be flipped but the x ones
  13925. assert.ok( pos[ 0 ] === 1 && pos[ 1 ] === - 2 && pos[ 2 ] === - 3 &&
  13926. pos[ 3 ] === 4 && pos[ 4 ] === - 5 && pos[ 5 ] === - 6, "vertices were rotated around x by 180 degrees" );
  13927. geometry.rotateY( 180 * DegToRad );
  13928. // vertices were rotated around y so all items should be flipped again but the y ones
  13929. assert.ok( pos[ 0 ] === - 1 && pos[ 1 ] === - 2 && pos[ 2 ] === 3 &&
  13930. pos[ 3 ] === - 4 && pos[ 4 ] === - 5 && pos[ 5 ] === 6, "vertices were rotated around y by 180 degrees" );
  13931. geometry.rotateZ( 180 * DegToRad );
  13932. // vertices were rotated around z so all items should be flipped again but the z ones
  13933. assert.ok( pos[ 0 ] === 1 && pos[ 1 ] === 2 && pos[ 2 ] === 3 &&
  13934. pos[ 3 ] === 4 && pos[ 4 ] === 5 && pos[ 5 ] === 6, "vertices were rotated around z by 180 degrees" );
  13935. } );
  13936. QUnit.test( "translate", ( assert ) => {
  13937. var geometry = new BufferGeometry();
  13938. geometry.addAttribute( "position", new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 5, 6 ] ), 3 ) );
  13939. var pos = geometry.attributes.position.array;
  13940. geometry.translate( 10, 20, 30 );
  13941. assert.ok( pos[ 0 ] === 11 && pos[ 1 ] === 22 && pos[ 2 ] === 33 &&
  13942. pos[ 3 ] === 14 && pos[ 4 ] === 25 && pos[ 5 ] === 36, "vertices were translated" );
  13943. } );
  13944. QUnit.test( "scale", ( assert ) => {
  13945. var geometry = new BufferGeometry();
  13946. geometry.addAttribute( "position", new BufferAttribute( new Float32Array( [ - 1, - 1, - 1, 2, 2, 2 ] ), 3 ) );
  13947. var pos = geometry.attributes.position.array;
  13948. geometry.scale( 1, 2, 3 );
  13949. assert.ok( pos[ 0 ] === - 1 && pos[ 1 ] === - 2 && pos[ 2 ] === - 3 &&
  13950. pos[ 3 ] === 2 && pos[ 4 ] === 4 && pos[ 5 ] === 6, "vertices were scaled" );
  13951. } );
  13952. QUnit.test( "lookAt", ( assert ) => {
  13953. var a = new BufferGeometry();
  13954. var vertices = new Float32Array( [
  13955. - 1.0, - 1.0, 1.0,
  13956. 1.0, - 1.0, 1.0,
  13957. 1.0, 1.0, 1.0,
  13958. 1.0, 1.0, 1.0,
  13959. - 1.0, 1.0, 1.0,
  13960. - 1.0, - 1.0, 1.0
  13961. ] );
  13962. a.addAttribute( 'position', new BufferAttribute( vertices, 3 ) );
  13963. var sqrt = Math.sqrt( 2 );
  13964. var expected = new Float32Array( [
  13965. 1, 0, - sqrt,
  13966. - 1, 0, - sqrt,
  13967. - 1, sqrt, 0,
  13968. - 1, sqrt, 0,
  13969. 1, sqrt, 0,
  13970. 1, 0, - sqrt
  13971. ] );
  13972. a.lookAt( new Vector3( 0, 1, - 1 ) );
  13973. assert.ok( bufferAttributeEquals( a.attributes.position.array, expected ), "Rotation is correct" );
  13974. } );
  13975. QUnit.test( "center", ( assert ) => {
  13976. var geometry = new BufferGeometry();
  13977. geometry.addAttribute( "position", new BufferAttribute( new Float32Array( [
  13978. - 1, - 1, - 1,
  13979. 1, 1, 1,
  13980. 4, 4, 4
  13981. ] ), 3 ) );
  13982. geometry.center();
  13983. var pos = geometry.attributes.position.array;
  13984. // the boundingBox should go from (-1, -1, -1) to (4, 4, 4) so it has a size of (5, 5, 5)
  13985. // after centering it the vertices should be placed between (-2.5, -2.5, -2.5) and (2.5, 2.5, 2.5)
  13986. assert.ok( pos[ 0 ] === - 2.5 && pos[ 1 ] === - 2.5 && pos[ 2 ] === - 2.5 &&
  13987. pos[ 3 ] === - 0.5 && pos[ 4 ] === - 0.5 && pos[ 5 ] === - 0.5 &&
  13988. pos[ 6 ] === 2.5 && pos[ 7 ] === 2.5 && pos[ 8 ] === 2.5, "vertices were replaced by boundingBox dimensions" );
  13989. } );
  13990. QUnit.test( "setFromObject", ( assert ) => {
  13991. var lineGeo = new Geometry();
  13992. lineGeo.vertices.push(
  13993. new Vector3( - 10, 0, 0 ),
  13994. new Vector3( 0, 10, 0 ),
  13995. new Vector3( 10, 0, 0 )
  13996. );
  13997. lineGeo.colors.push(
  13998. new Color( 1, 0, 0 ),
  13999. new Color( 0, 1, 0 ),
  14000. new Color( 0, 0, 1 )
  14001. );
  14002. var line = new LineSegments( lineGeo, null );
  14003. var geometry = new BufferGeometry().setFromObject( line );
  14004. var pos = geometry.attributes.position.array;
  14005. var col = geometry.attributes.color.array;
  14006. var v = lineGeo.vertices;
  14007. var c = lineGeo.colors;
  14008. assert.ok(
  14009. // position exists
  14010. pos !== undefined &&
  14011. // vertex arrays have the same size
  14012. v.length * 3 === pos.length &&
  14013. // there are three complete vertices (each vertex contains three values)
  14014. geometry.attributes.position.count === 3 &&
  14015. // check if both arrays contains the same data
  14016. pos[ 0 ] === v[ 0 ].x && pos[ 1 ] === v[ 0 ].y && pos[ 2 ] === v[ 0 ].z &&
  14017. pos[ 3 ] === v[ 1 ].x && pos[ 4 ] === v[ 1 ].y && pos[ 5 ] === v[ 1 ].z &&
  14018. pos[ 6 ] === v[ 2 ].x && pos[ 7 ] === v[ 2 ].y && pos[ 8 ] === v[ 2 ].z
  14019. , "positions are equal" );
  14020. assert.ok(
  14021. // color exists
  14022. col !== undefined &&
  14023. // color arrays have the same size
  14024. c.length * 3 === col.length &&
  14025. // there are three complete colors (each color contains three values)
  14026. geometry.attributes.color.count === 3 &&
  14027. // check if both arrays contains the same data
  14028. col[ 0 ] === c[ 0 ].r && col[ 1 ] === c[ 0 ].g && col[ 2 ] === c[ 0 ].b &&
  14029. col[ 3 ] === c[ 1 ].r && col[ 4 ] === c[ 1 ].g && col[ 5 ] === c[ 1 ].b &&
  14030. col[ 6 ] === c[ 2 ].r && col[ 7 ] === c[ 2 ].g && col[ 8 ] === c[ 2 ].b
  14031. , "colors are equal" );
  14032. } );
  14033. QUnit.test( "setFromObject (more)", ( assert ) => {
  14034. var lineGeo = new Geometry();
  14035. lineGeo.vertices.push(
  14036. new Vector3( - 10, 0, 0 ),
  14037. new Vector3( 0, 10, 0 ),
  14038. new Vector3( 10, 0, 0 )
  14039. );
  14040. lineGeo.colors.push(
  14041. new Color( 1, 0, 0 ),
  14042. new Color( 0, 1, 0 ),
  14043. new Color( 0, 0, 1 )
  14044. );
  14045. lineGeo.computeBoundingBox();
  14046. lineGeo.computeBoundingSphere();
  14047. var line = new LineSegments( lineGeo );
  14048. var geometry = new BufferGeometry().setFromObject( line );
  14049. assert.ok( geometry.boundingBox.equals( lineGeo.boundingBox ), "BoundingBox was set correctly" );
  14050. assert.ok( geometry.boundingSphere.equals( lineGeo.boundingSphere ), "BoundingSphere was set correctly" );
  14051. var pos = geometry.attributes.position.array;
  14052. var col = geometry.attributes.color.array;
  14053. var v = lineGeo.vertices;
  14054. var c = lineGeo.colors;
  14055. // adapted from setFromObject QUnit.test (way up)
  14056. assert.notStrictEqual( pos, undefined, "Position attribute exists" );
  14057. assert.strictEqual( v.length * 3, pos.length, "Vertex arrays have the same size" );
  14058. assert.strictEqual( geometry.attributes.position.count, 3, "Correct number of vertices" );
  14059. assert.ok( comparePositions( pos, v ), "Positions are identical" );
  14060. assert.notStrictEqual( col, undefined, "Color attribute exists" );
  14061. assert.strictEqual( c.length * 3, col.length, "Color arrays have the same size" );
  14062. assert.strictEqual( geometry.attributes.color.count, 3, "Correct number of colors" );
  14063. assert.ok( compareColors( col, c ), "Colors are identical" );
  14064. // setFromObject with a Mesh as object
  14065. lineGeo.faces.push( new Face3( 0, 1, 2 ) );
  14066. var lineMesh = new Mesh( lineGeo );
  14067. var geometry = new BufferGeometry().setFromObject( lineMesh );
  14068. // no colors
  14069. var pos = geometry.attributes.position.array;
  14070. var v = lineGeo.vertices;
  14071. assert.notStrictEqual( pos, undefined, "Mesh: position attribute exists" );
  14072. assert.strictEqual( v.length * 3, pos.length, "Mesh: vertex arrays have the same size" );
  14073. assert.strictEqual( geometry.attributes.position.count, 3, "Mesh: correct number of vertices" );
  14074. assert.ok( comparePositions( pos, v ), "Mesh: positions are identical" );
  14075. } );
  14076. QUnit.test( "updateFromObject", ( assert ) => {
  14077. var geo = new Geometry();
  14078. geo.vertices.push(
  14079. new Vector3( - 10, 0, 0 ),
  14080. new Vector3( 0, 10, 0 ),
  14081. new Vector3( 10, 0, 0 )
  14082. );
  14083. geo.faces.push( new Face3( 0, 1, 2 ) );
  14084. geo.faces[ 0 ].vertexColors.push(
  14085. new Color( 1, 0, 0 ),
  14086. new Color( 0, 1, 0 ),
  14087. new Color( 0, 0, 1 )
  14088. );
  14089. geo.faceVertexUvs[ 0 ] = [
  14090. [
  14091. new Vector2( 0, 0 ),
  14092. new Vector2( 1, 0 ),
  14093. new Vector2( 1, 1 )
  14094. ]
  14095. ];
  14096. geo.computeFaceNormals();
  14097. geo.computeVertexNormals();
  14098. geo.verticesNeedUpdate = true;
  14099. geo.normalsNeedUpdate = true;
  14100. geo.colorsNeedUpdate = true;
  14101. geo.uvsNeedUpdate = true;
  14102. geo.groupsNeedUpdate = true;
  14103. var mesh = new Mesh( geo );
  14104. var geometry = new BufferGeometry();
  14105. geometry.updateFromObject( mesh ); // first call to create the underlying structure (DirectGeometry)
  14106. geometry.updateFromObject( mesh ); // second time to actually go thru the motions and update
  14107. var pos = geometry.attributes.position.array;
  14108. var col = geometry.attributes.color.array;
  14109. var norm = geometry.attributes.normal.array;
  14110. var uvs = geometry.attributes.uv.array;
  14111. var v = geo.vertices;
  14112. var c = geo.faces[ 0 ].vertexColors;
  14113. var n = geo.faces[ 0 ].vertexNormals;
  14114. var u = geo.faceVertexUvs[ 0 ][ 0 ];
  14115. assert.notStrictEqual( pos, undefined, "Position attribute exists" );
  14116. assert.strictEqual( v.length * 3, pos.length, "Both arrays have the same size" );
  14117. assert.strictEqual( geometry.attributes.position.count, v.length, "Correct number of vertices" );
  14118. assert.ok( comparePositions( pos, v ), "Positions are identical" );
  14119. assert.notStrictEqual( col, undefined, "Color attribute exists" );
  14120. assert.strictEqual( c.length * 3, col.length, "Both arrays have the same size" );
  14121. assert.strictEqual( geometry.attributes.color.count, c.length, "Correct number of colors" );
  14122. assert.ok( compareColors( col, c ), "Colors are identical" );
  14123. assert.notStrictEqual( norm, undefined, "Normal attribute exists" );
  14124. assert.strictEqual( n.length * 3, norm.length, "Both arrays have the same size" );
  14125. assert.strictEqual( geometry.attributes.normal.count, n.length, "Correct number of normals" );
  14126. assert.ok( comparePositions( norm, n ), "Normals are identical" );
  14127. assert.notStrictEqual( uvs, undefined, "UV attribute exists" );
  14128. assert.strictEqual( u.length * 2, uvs.length, "Both arrays have the same size" );
  14129. assert.strictEqual( geometry.attributes.uv.count, u.length, "Correct number of UV coordinates" );
  14130. assert.ok( compareUvs( uvs, u ), "UVs are identical" );
  14131. } );
  14132. QUnit.test( "fromGeometry/fromDirectGeometry", ( assert ) => {
  14133. assert.timeout( 1000 );
  14134. var a = new BufferGeometry();
  14135. // BoxGeometry is a bit too simple but works fine in a pinch
  14136. // var b = new BoxGeometry( 1, 1, 1 );
  14137. // b.mergeVertices();
  14138. // b.computeVertexNormals();
  14139. // b.computeBoundingBox();
  14140. // b.computeBoundingSphere();
  14141. var asyncDone = assert.async(); // tell QUnit we're done with asserts
  14142. var loader = new JSONLoader();
  14143. loader.load( "../../examples/models/skinned/simple/simple.js", function ( modelGeometry ) {
  14144. a.fromGeometry( modelGeometry );
  14145. var attr;
  14146. var geometry = new DirectGeometry().fromGeometry( modelGeometry );
  14147. var positions = new Float32Array( geometry.vertices.length * 3 );
  14148. attr = new BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices );
  14149. assert.ok( bufferAttributeEquals( a.attributes.position, attr ), "Vertices are identical" );
  14150. if ( geometry.normals.length > 0 ) {
  14151. var normals = new Float32Array( geometry.normals.length * 3 );
  14152. attr = new BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals );
  14153. assert.ok( bufferAttributeEquals( a.attributes.normal, attr ), "Normals are identical" );
  14154. }
  14155. if ( geometry.colors.length > 0 ) {
  14156. var colors = new Float32Array( geometry.colors.length * 3 );
  14157. attr = new BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors );
  14158. assert.ok( bufferAttributeEquals( a.attributes.color, attr ), "Colors are identical" );
  14159. }
  14160. if ( geometry.uvs.length > 0 ) {
  14161. var uvs = new Float32Array( geometry.uvs.length * 2 );
  14162. attr = new BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs );
  14163. assert.ok( bufferAttributeEquals( a.attributes.uv, attr ), "UVs are identical" );
  14164. }
  14165. if ( geometry.uvs2.length > 0 ) {
  14166. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  14167. attr = new BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 );
  14168. assert.ok( bufferAttributeEquals( a.attributes.uv2, attr ), "UV2s are identical" );
  14169. }
  14170. if ( geometry.indices.length > 0 ) {
  14171. var TypeArray = arrayMax( geometry.indices ) > 65535 ? Uint32Array : Uint16Array;
  14172. var indices = new TypeArray( geometry.indices.length * 3 );
  14173. attr = new BufferAttribute( indices, 1 ).copyIndicesArray( geometry.indices );
  14174. assert.ok( bufferAttributeEquals( a.indices, attr ), "Indices are identical" );
  14175. }
  14176. // groups
  14177. assert.deepEqual( a.groups, geometry.groups, "Groups are identical" );
  14178. // morphs
  14179. if ( geometry.morphTargets !== undefined ) {
  14180. for ( var name in geometry.morphTargets ) {
  14181. var morphTargets = geometry.morphTargets[ name ];
  14182. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  14183. var morphTarget = morphTargets[ i ];
  14184. attr = new Float32BufferAttribute( morphTarget.length * 3, 3 );
  14185. attr.copyVector3sArray( morphTarget );
  14186. assert.ok(
  14187. bufferAttributeEquals( a.morphAttributes[ name ][ i ], attr ),
  14188. "MorphTargets #" + i + " are identical"
  14189. );
  14190. }
  14191. }
  14192. }
  14193. // skinning
  14194. if ( geometry.skinIndices.length > 0 ) {
  14195. attr = new Float32BufferAttribute( geometry.skinIndices.length * 4, 4 );
  14196. attr.copyVector4sArray( geometry.skinIndices );
  14197. assert.ok( bufferAttributeEquals( a.attributes.skinIndex, attr ), "SkinIndices are identical" );
  14198. }
  14199. if ( geometry.skinWeights.length > 0 ) {
  14200. attr = new Float32BufferAttribute( geometry.skinWeights.length * 4, 4 );
  14201. attr.copyVector4sArray( geometry.skinWeights );
  14202. assert.ok( bufferAttributeEquals( a.attributes.skinWeight, attr ), "SkinWeights are identical" );
  14203. }
  14204. // TODO
  14205. // DirectGeometry doesn't actually copy boundingSphere and boundingBox yet,
  14206. // so they're always null
  14207. if ( geometry.boundingSphere !== null ) {
  14208. assert.ok( a.boundingSphere.equals( geometry.boundingSphere ), "BoundingSphere is identical" );
  14209. }
  14210. if ( geometry.boundingBox !== null ) {
  14211. assert.ok( a.boundingBox.equals( geometry.boundingBox ), "BoundingBox is identical" );
  14212. }
  14213. asyncDone();
  14214. } );
  14215. } );
  14216. QUnit.test( "computeBoundingBox", ( assert ) => {
  14217. var bb = getBBForVertices( [ - 1, - 2, - 3, 13, - 2, - 3.5, - 1, - 20, 0, - 4, 5, 6 ] );
  14218. assert.ok( bb.min.x === - 4 && bb.min.y === - 20 && bb.min.z === - 3.5, "min values are set correctly" );
  14219. assert.ok( bb.max.x === 13 && bb.max.y === 5 && bb.max.z === 6, "max values are set correctly" );
  14220. var bb = getBBForVertices( [ - 1, - 1, - 1 ] );
  14221. assert.ok( bb.min.x === bb.max.x && bb.min.y === bb.max.y && bb.min.z === bb.max.z, "since there is only one vertex, max and min are equal" );
  14222. assert.ok( bb.min.x === - 1 && bb.min.y === - 1 && bb.min.z === - 1, "since there is only one vertex, min and max are this vertex" );
  14223. } );
  14224. QUnit.test( "computeBoundingSphere", ( assert ) => {
  14225. var bs = getBSForVertices( [ - 10, 0, 0, 10, 0, 0 ] );
  14226. assert.ok( bs.radius === ( 10 + 10 ) / 2, "radius is equal to deltaMinMax / 2" );
  14227. assert.ok( bs.center.x === 0 && bs.center.y === 0 && bs.center.y === 0, "bounding sphere is at ( 0, 0, 0 )" );
  14228. var bs = getBSForVertices( [ - 5, 11, - 3, 5, - 11, 3 ] );
  14229. var radius = new Vector3( 5, 11, 3 ).length();
  14230. assert.ok( bs.radius === radius, "radius is equal to directionLength" );
  14231. assert.ok( bs.center.x === 0 && bs.center.y === 0 && bs.center.y === 0, "bounding sphere is at ( 0, 0, 0 )" );
  14232. } );
  14233. QUnit.test( "computeFaceNormals", ( assert ) => {
  14234. assert.ok( false, "everything's gonna be alright" );
  14235. } );
  14236. QUnit.test( "computeVertexNormals", ( assert ) => {
  14237. // get normals for a counter clockwise created triangle
  14238. var normals = getNormalsForVertices( [ - 1, 0, 0, 1, 0, 0, 0, 1, 0 ], assert );
  14239. assert.ok( normals[ 0 ] === 0 && normals[ 1 ] === 0 && normals[ 2 ] === 1,
  14240. "first normal is pointing to screen since the the triangle was created counter clockwise" );
  14241. assert.ok( normals[ 3 ] === 0 && normals[ 4 ] === 0 && normals[ 5 ] === 1,
  14242. "second normal is pointing to screen since the the triangle was created counter clockwise" );
  14243. assert.ok( normals[ 6 ] === 0 && normals[ 7 ] === 0 && normals[ 8 ] === 1,
  14244. "third normal is pointing to screen since the the triangle was created counter clockwise" );
  14245. // get normals for a clockwise created triangle
  14246. var normals = getNormalsForVertices( [ 1, 0, 0, - 1, 0, 0, 0, 1, 0 ], assert );
  14247. assert.ok( normals[ 0 ] === 0 && normals[ 1 ] === 0 && normals[ 2 ] === - 1,
  14248. "first normal is pointing to screen since the the triangle was created clockwise" );
  14249. assert.ok( normals[ 3 ] === 0 && normals[ 4 ] === 0 && normals[ 5 ] === - 1,
  14250. "second normal is pointing to screen since the the triangle was created clockwise" );
  14251. assert.ok( normals[ 6 ] === 0 && normals[ 7 ] === 0 && normals[ 8 ] === - 1,
  14252. "third normal is pointing to screen since the the triangle was created clockwise" );
  14253. var normals = getNormalsForVertices( [ 0, 0, 1, 0, 0, - 1, 1, 1, 0 ], assert );
  14254. // the triangle is rotated by 45 degrees to the right so the normals of the three vertices
  14255. // should point to (1, -1, 0).normalized(). The simplest solution is to check against a normalized
  14256. // vector (1, -1, 0) but you will get calculation errors because of floating calculations so another
  14257. // valid technique is to create a vector which stands in 90 degrees to the normals and calculate the
  14258. // dot product which is the cos of the angle between them. This should be < floating calculation error
  14259. // which can be taken from Number.EPSILON
  14260. var direction = new Vector3( 1, 1, 0 ).normalize(); // a vector which should have 90 degrees difference to normals
  14261. var difference = direction.dot( new Vector3( normals[ 0 ], normals[ 1 ], normals[ 2 ] ) );
  14262. assert.ok( difference < Number.EPSILON, "normal is equal to reference vector" );
  14263. // get normals for a line should be NAN because you need min a triangle to calculate normals
  14264. var normals = getNormalsForVertices( [ 1, 0, 0, - 1, 0, 0 ], assert );
  14265. for ( var i = 0; i < normals.length; i ++ ) {
  14266. assert.ok( ! normals[ i ], "normals can't be calculated which is good" );
  14267. }
  14268. } );
  14269. QUnit.test( "computeVertexNormals (indexed)", ( assert ) => {
  14270. var sqrt = 0.5 * Math.sqrt( 2 );
  14271. var normal = new BufferAttribute( new Float32Array( [
  14272. - 1, 0, 0, - 1, 0, 0, - 1, 0, 0,
  14273. sqrt, sqrt, 0, sqrt, sqrt, 0, sqrt, sqrt, 0,
  14274. - 1, 0, 0
  14275. ] ), 3 );
  14276. var position = new BufferAttribute( new Float32Array( [
  14277. 0.5, 0.5, 0.5, 0.5, 0.5, - 0.5, 0.5, - 0.5, 0.5,
  14278. 0.5, - 0.5, - 0.5, - 0.5, 0.5, - 0.5, - 0.5, 0.5, 0.5,
  14279. - 0.5, - 0.5, - 0.5
  14280. ] ), 3 );
  14281. var index = new BufferAttribute( new Uint16Array( [
  14282. 0, 2, 1, 2, 3, 1, 4, 6, 5, 6, 7, 5
  14283. ] ), 1 );
  14284. var a = new BufferGeometry();
  14285. a.addAttribute( "position", position );
  14286. a.computeVertexNormals();
  14287. assert.ok(
  14288. bufferAttributeEquals( normal, a.getAttribute( "normal" ) ),
  14289. "Regular geometry: first computed normals are correct"
  14290. );
  14291. // a second time to see if the existing normals get properly deleted
  14292. a.computeVertexNormals();
  14293. assert.ok(
  14294. bufferAttributeEquals( normal, a.getAttribute( "normal" ) ),
  14295. "Regular geometry: second computed normals are correct"
  14296. );
  14297. // indexed geometry
  14298. var a = new BufferGeometry();
  14299. a.addAttribute( "position", position );
  14300. a.setIndex( index );
  14301. a.computeVertexNormals();
  14302. assert.ok( bufferAttributeEquals( normal, a.getAttribute( "normal" ) ), "Indexed geometry: computed normals are correct" );
  14303. } );
  14304. QUnit.test( "merge", ( assert ) => {
  14305. var geometry1 = new BufferGeometry();
  14306. geometry1.addAttribute( "attrName", new BufferAttribute( new Float32Array( [ 1, 2, 3, 0, 0, 0 ] ), 3 ) );
  14307. var geometry2 = new BufferGeometry();
  14308. geometry2.addAttribute( "attrName", new BufferAttribute( new Float32Array( [ 4, 5, 6 ] ), 3 ) );
  14309. var attr = geometry1.attributes.attrName.array;
  14310. geometry1.merge( geometry2, 1 );
  14311. // merged array should be 1, 2, 3, 4, 5, 6
  14312. for ( var i = 0; i < attr.length; i ++ ) {
  14313. assert.ok( attr[ i ] === i + 1, "" );
  14314. }
  14315. geometry1.merge( geometry2 );
  14316. assert.ok( attr[ 0 ] === 4 && attr[ 1 ] === 5 && attr[ 2 ] === 6, "copied the 3 attributes without offset" );
  14317. } );
  14318. QUnit.test( "normalizeNormals", ( assert ) => {
  14319. assert.ok( false, "everything's gonna be alright" );
  14320. } );
  14321. QUnit.test( "toNonIndexed", ( assert ) => {
  14322. var geometry = new BufferGeometry();
  14323. var vertices = new Float32Array( [
  14324. 0.5, 0.5, 0.5, 0.5, 0.5, - 0.5, 0.5, - 0.5, 0.5, 0.5, - 0.5, - 0.5
  14325. ] );
  14326. var index = new BufferAttribute( new Uint16Array( [ 0, 2, 1, 2, 3, 1 ] ) );
  14327. var expected = new Float32Array( [
  14328. 0.5, 0.5, 0.5, 0.5, - 0.5, 0.5, 0.5, 0.5, - 0.5,
  14329. 0.5, - 0.5, 0.5, 0.5, - 0.5, - 0.5, 0.5, 0.5, - 0.5
  14330. ] );
  14331. geometry.addAttribute( 'position', new BufferAttribute( vertices, 3 ) );
  14332. geometry.setIndex( index );
  14333. var nonIndexed = geometry.toNonIndexed();
  14334. assert.deepEqual( nonIndexed.getAttribute( "position" ).array, expected, "Expected vertices" );
  14335. } );
  14336. QUnit.test( "toJSON", ( assert ) => {
  14337. var index = new BufferAttribute( new Uint16Array( [ 0, 1, 2, 3 ] ), 1 );
  14338. var attribute1 = new BufferAttribute( new Uint16Array( [ 1, 3, 5, 7 ] ), 1 );
  14339. var a = new BufferGeometry();
  14340. a.name = "JSONQUnit.test";
  14341. // a.parameters = { "placeholder": 0 };
  14342. a.addAttribute( "attribute1", attribute1 );
  14343. a.setIndex( index );
  14344. a.addGroup( 0, 1, 2 );
  14345. a.boundingSphere = new Sphere( new Vector3( x, y, z ), 0.5 );
  14346. var j = a.toJSON();
  14347. var gold = {
  14348. "metadata": {
  14349. "version": 4.5,
  14350. "type": "BufferGeometry",
  14351. "generator": "BufferGeometry.toJSON"
  14352. },
  14353. "uuid": a.uuid,
  14354. "type": "BufferGeometry",
  14355. "name": "JSONQUnit.test",
  14356. "data": {
  14357. "attributes": {
  14358. "attribute1": {
  14359. "itemSize": 1,
  14360. "type": "Uint16Array",
  14361. "array": [ 1, 3, 5, 7 ],
  14362. "normalized": false
  14363. }
  14364. },
  14365. "index": {
  14366. "type": "Uint16Array",
  14367. "array": [ 0, 1, 2, 3 ]
  14368. },
  14369. "groups": [
  14370. {
  14371. "start": 0,
  14372. "count": 1,
  14373. "materialIndex": 2
  14374. }
  14375. ],
  14376. "boundingSphere": {
  14377. "center": [ 2, 3, 4 ],
  14378. "radius": 0.5
  14379. }
  14380. }
  14381. };
  14382. assert.deepEqual( j, gold, "Generated JSON is as expected" );
  14383. } );
  14384. QUnit.test( "clone", ( assert ) => {
  14385. var a = new BufferGeometry();
  14386. a.addAttribute( "attribute1", new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 5, 6 ] ), 3 ) );
  14387. a.addAttribute( "attribute2", new BufferAttribute( new Float32Array( [ 0, 1, 3, 5, 6 ] ), 1 ) );
  14388. a.addGroup( 0, 1, 2 );
  14389. a.computeBoundingBox();
  14390. a.computeBoundingSphere();
  14391. a.setDrawRange( 0, 1 );
  14392. var b = a.clone();
  14393. assert.notEqual( a, b, "A new object was created" );
  14394. assert.notEqual( a.id, b.id, "New object has a different GUID" );
  14395. assert.strictEqual(
  14396. Object.keys( a.attributes ).count, Object.keys( b.attributes ).count,
  14397. "Both objects have the same amount of attributes"
  14398. );
  14399. assert.ok(
  14400. bufferAttributeEquals( a.getAttribute( "attribute1" ), b.getAttribute( "attribute1" ) ),
  14401. "First attributes buffer is identical"
  14402. );
  14403. assert.ok(
  14404. bufferAttributeEquals( a.getAttribute( "attribute2" ), b.getAttribute( "attribute2" ) ),
  14405. "Second attributes buffer is identical"
  14406. );
  14407. assert.deepEqual( a.groups, b.groups, "Groups are identical" );
  14408. assert.ok( a.boundingBox.equals( b.boundingBox ), "BoundingBoxes are equal" );
  14409. assert.ok( a.boundingSphere.equals( b.boundingSphere ), "BoundingSpheres are equal" );
  14410. assert.strictEqual( a.drawRange.start, b.drawRange.start, "DrawRange start is identical" );
  14411. assert.strictEqual( a.drawRange.count, b.drawRange.count, "DrawRange count is identical" );
  14412. } );
  14413. QUnit.test( "copy", ( assert ) => {
  14414. var geometry = new BufferGeometry();
  14415. geometry.addAttribute( "attrName", new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 5, 6 ] ), 3 ) );
  14416. geometry.addAttribute( "attrName2", new BufferAttribute( new Float32Array( [ 0, 1, 3, 5, 6 ] ), 1 ) );
  14417. var copy = new BufferGeometry().copy( geometry );
  14418. assert.ok( copy !== geometry && geometry.id !== copy.id, "new object was created" );
  14419. Object.keys( geometry.attributes ).forEach( function ( key ) {
  14420. var attribute = geometry.attributes[ key ];
  14421. assert.ok( attribute !== undefined, "all attributes where copied" );
  14422. for ( var i = 0; i < attribute.array.length; i ++ ) {
  14423. assert.ok( attribute.array[ i ] === copy.attributes[ key ].array[ i ], "values of the attribute are equal" );
  14424. }
  14425. } );
  14426. } );
  14427. QUnit.test( "dispose", ( assert ) => {
  14428. assert.ok( false, "everything's gonna be alright" );
  14429. } );
  14430. } );
  14431. } );
  14432. /**
  14433. * @author alteredq / http://alteredqualia.com/
  14434. */
  14435. function Clock( autoStart ) {
  14436. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  14437. this.startTime = 0;
  14438. this.oldTime = 0;
  14439. this.elapsedTime = 0;
  14440. this.running = false;
  14441. }
  14442. Object.assign( Clock.prototype, {
  14443. start: function () {
  14444. this.startTime = ( typeof performance === 'undefined' ? Date : performance ).now(); // see #10732
  14445. this.oldTime = this.startTime;
  14446. this.elapsedTime = 0;
  14447. this.running = true;
  14448. },
  14449. stop: function () {
  14450. this.getElapsedTime();
  14451. this.running = false;
  14452. this.autoStart = false;
  14453. },
  14454. getElapsedTime: function () {
  14455. this.getDelta();
  14456. return this.elapsedTime;
  14457. },
  14458. getDelta: function () {
  14459. var diff = 0;
  14460. if ( this.autoStart && ! this.running ) {
  14461. this.start();
  14462. return 0;
  14463. }
  14464. if ( this.running ) {
  14465. var newTime = ( typeof performance === 'undefined' ? Date : performance ).now();
  14466. diff = ( newTime - this.oldTime ) / 1000;
  14467. this.oldTime = newTime;
  14468. this.elapsedTime += diff;
  14469. }
  14470. return diff;
  14471. }
  14472. } );
  14473. /**
  14474. * @author simonThiele / https://github.com/simonThiele
  14475. * @author TristanVALCKE / https://github.com/Itee
  14476. */
  14477. /* global QUnit */
  14478. QUnit.module( 'Core', () => {
  14479. QUnit.module.todo( 'Clock', () => {
  14480. function mockPerformance() {
  14481. self.performance = {
  14482. deltaTime: 0,
  14483. next: function ( delta ) {
  14484. this.deltaTime += delta;
  14485. },
  14486. now: function () {
  14487. return this.deltaTime;
  14488. }
  14489. };
  14490. }
  14491. // INSTANCING
  14492. QUnit.test( "Instancing", ( assert ) => {
  14493. assert.ok( false, "everything's gonna be alright" );
  14494. } );
  14495. // PUBLIC STUFF
  14496. QUnit.test( "start", ( assert ) => {
  14497. assert.ok( false, "everything's gonna be alright" );
  14498. } );
  14499. QUnit.test( "stop", ( assert ) => {
  14500. assert.ok( false, "everything's gonna be alright" );
  14501. } );
  14502. QUnit.test( "getElapsedTime", ( assert ) => {
  14503. assert.ok( false, "everything's gonna be alright" );
  14504. } );
  14505. QUnit.test( "getDelta", ( assert ) => {
  14506. assert.ok( false, "everything's gonna be alright" );
  14507. } );
  14508. // OTHERS
  14509. QUnit.test( "clock with performance", ( assert ) => {
  14510. mockPerformance();
  14511. var clock = new Clock( false );
  14512. clock.start();
  14513. self.performance.next( 123 );
  14514. assert.numEqual( clock.getElapsedTime(), 0.123, "okay" );
  14515. self.performance.next( 100 );
  14516. assert.numEqual( clock.getElapsedTime(), 0.223, "okay" );
  14517. clock.stop();
  14518. self.performance.next( 1000 );
  14519. assert.numEqual( clock.getElapsedTime(), 0.223, "don't update time if the clock was stopped" );
  14520. } );
  14521. } );
  14522. } );
  14523. /**
  14524. * @author moraxy / https://github.com/moraxy
  14525. * @author TristanVALCKE / https://github.com/Itee
  14526. */
  14527. /* global QUnit */
  14528. QUnit.module( 'Core', () => {
  14529. QUnit.module.todo( 'DirectGeometry', () => {
  14530. // INSTANCING
  14531. QUnit.test( "Instancing", ( assert ) => {
  14532. assert.ok( false, "everything's gonna be alright" );
  14533. } );
  14534. // PUBLIC STUFF
  14535. QUnit.test( "computeGroups", ( assert ) => {
  14536. var a = new DirectGeometry();
  14537. var b = new Geometry();
  14538. var expected = [
  14539. { start: 0, materialIndex: 0, count: 3 },
  14540. { start: 3, materialIndex: 1, count: 3 },
  14541. { start: 6, materialIndex: 2, count: 6 }
  14542. ];
  14543. // we only care for materialIndex
  14544. b.faces.push(
  14545. new Face3( 0, 0, 0, undefined, undefined, 0 ),
  14546. new Face3( 0, 0, 0, undefined, undefined, 1 ),
  14547. new Face3( 0, 0, 0, undefined, undefined, 2 ),
  14548. new Face3( 0, 0, 0, undefined, undefined, 2 )
  14549. );
  14550. a.computeGroups( b );
  14551. assert.deepEqual( a.groups, expected, "Groups are as expected" );
  14552. } );
  14553. QUnit.test( "fromGeometry", ( assert ) => {
  14554. assert.timeout( 1000 );
  14555. var a = new DirectGeometry();
  14556. var asyncDone = assert.async(); // tell QUnit when we're done with async stuff
  14557. var loader = new JSONLoader();
  14558. loader.load( "../../examples/models/skinned/simple/simple.js", function ( geometry ) {
  14559. a.fromGeometry( geometry );
  14560. var tmp = new DirectGeometry();
  14561. tmp.computeGroups( geometry );
  14562. assert.deepEqual( a.groups, tmp.groups, "Check groups" );
  14563. var morphTargets = geometry.morphTargets;
  14564. var morphTargetsLength = morphTargets.length;
  14565. var morphTargetsPosition;
  14566. if ( morphTargetsLength > 0 ) {
  14567. morphTargetsPosition = [];
  14568. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  14569. morphTargetsPosition[ i ] = [];
  14570. }
  14571. morphTargets.position = morphTargetsPosition;
  14572. }
  14573. var morphNormals = geometry.morphNormals;
  14574. var morphNormalsLength = morphNormals.length;
  14575. var morphTargetsNormal;
  14576. if ( morphNormalsLength > 0 ) {
  14577. morphTargetsNormal = [];
  14578. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  14579. morphTargetsNormal[ i ] = [];
  14580. }
  14581. morphTargets.normal = morphTargetsNormal;
  14582. }
  14583. var vertices = [];
  14584. var normals = [];
  14585. var colors = [];
  14586. var uvs = [];
  14587. var uvs2 = [];
  14588. var skinIndices = [];
  14589. var skinWeights = [];
  14590. var hasFaceVertexUv = geometry.faceVertexUvs[ 0 ] && geometry.faceVertexUvs[ 0 ].length > 0;
  14591. var hasFaceVertexUv2 = geometry.faceVertexUvs[ 1 ] && geometry.faceVertexUvs[ 1 ].length > 0;
  14592. var hasSkinIndices = geometry.skinIndices.length === geometry.vertices.length;
  14593. var hasSkinWeights = geometry.skinWeights.length === geometry.vertices.length;
  14594. for ( var i = 0; i < geometry.faces.length; i ++ ) {
  14595. var face = geometry.faces[ i ];
  14596. vertices.push(
  14597. geometry.vertices[ face.a ],
  14598. geometry.vertices[ face.b ],
  14599. geometry.vertices[ face.c ]
  14600. );
  14601. var vertexNormals = face.vertexNormals;
  14602. if ( vertexNormals.length === 3 ) {
  14603. normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  14604. } else {
  14605. normals.push( face.normal, face.normal, face.normal );
  14606. }
  14607. var vertexColors = face.vertexColors;
  14608. if ( vertexColors.length === 3 ) {
  14609. colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  14610. } else {
  14611. colors.push( face.color, face.color, face.color );
  14612. }
  14613. if ( hasFaceVertexUv === true ) {
  14614. var vertexUvs = geometry.faceVertexUvs[ 0 ][ i ];
  14615. if ( vertexUvs !== undefined ) {
  14616. uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  14617. } else {
  14618. uvs.push( new Vector2(), new Vector2(), new Vector2() );
  14619. }
  14620. }
  14621. if ( hasFaceVertexUv2 === true ) {
  14622. var vertexUvs = geometry.faceVertexUvs[ 1 ][ i ];
  14623. if ( vertexUvs !== undefined ) {
  14624. uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  14625. } else {
  14626. uvs2.push( new Vector2(), new Vector2(), new Vector2() );
  14627. }
  14628. }
  14629. // morphs
  14630. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  14631. var morphTarget = morphTargets[ j ].vertices;
  14632. morphTargetsPosition[ j ].push(
  14633. morphTarget[ face.a ],
  14634. morphTarget[ face.b ],
  14635. morphTarget[ face.c ]
  14636. );
  14637. }
  14638. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  14639. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  14640. morphTargetsNormal[ j ].push( morphNormal.a, morphNormal.b, morphNormal.c );
  14641. }
  14642. // skins
  14643. if ( hasSkinIndices ) {
  14644. skinIndices.push(
  14645. geometry.skinIndices[ face.a ],
  14646. geometry.skinIndices[ face.b ],
  14647. geometry.skinIndices[ face.c ]
  14648. );
  14649. }
  14650. if ( hasSkinWeights ) {
  14651. skinWeights.push(
  14652. geometry.skinWeights[ face.a ],
  14653. geometry.skinWeights[ face.b ],
  14654. geometry.skinWeights[ face.c ]
  14655. );
  14656. }
  14657. }
  14658. assert.deepEqual( a.vertices, vertices, "Vertices are identical" );
  14659. assert.deepEqual( a.normals, normals, "Normals are identical" );
  14660. assert.deepEqual( a.colors, colors, "Colors are identical" );
  14661. assert.deepEqual( a.uvs, uvs, "UV coordinates are identical" );
  14662. assert.deepEqual( a.uvs2, uvs2, "UV(2) coordinates are identical" );
  14663. assert.deepEqual( a.skinIndices, skinIndices, "SkinIndices are identical" );
  14664. assert.deepEqual( a.skinWeights, skinWeights, "SkinWeights are identical" );
  14665. assert.deepEqual( a.morphTargetsPosition, morphTargetsPosition, "MorphTargets (Position) are identical" );
  14666. assert.deepEqual( a.morphTargetsNormal, morphTargetsNormal, "MorphTargets (Normals) are identical" );
  14667. asyncDone();
  14668. }, onProgress, onError );
  14669. function onProgress() {}
  14670. function onError( error ) {
  14671. console.error( error );
  14672. asyncDone();
  14673. }
  14674. } );
  14675. } );
  14676. } );
  14677. /**
  14678. * @author simonThiele / https://github.com/simonThiele
  14679. * @author TristanVALCKE / https://github.com/Itee
  14680. */
  14681. /* global QUnit */
  14682. QUnit.module( 'Core', () => {
  14683. QUnit.module.todo( 'EventDispatcher', () => {
  14684. // INSTANCING
  14685. QUnit.test( "Instancing", ( assert ) => {
  14686. assert.ok( false, "everything's gonna be alright" );
  14687. } );
  14688. // PUBLIC STUFF
  14689. QUnit.test( "addEventListener", ( assert ) => {
  14690. var eventDispatcher = new EventDispatcher();
  14691. var listener = {};
  14692. eventDispatcher.addEventListener( 'anyType', listener );
  14693. assert.ok( eventDispatcher._listeners.anyType.length === 1, "listener with unknown type was added" );
  14694. assert.ok( eventDispatcher._listeners.anyType[ 0 ] === listener, "listener with unknown type was added" );
  14695. eventDispatcher.addEventListener( 'anyType', listener );
  14696. assert.ok( eventDispatcher._listeners.anyType.length === 1, "can't add one listener twice to same type" );
  14697. assert.ok( eventDispatcher._listeners.anyType[ 0 ] === listener, "listener is still there" );
  14698. } );
  14699. QUnit.test( "hasEventListener", ( assert ) => {
  14700. var eventDispatcher = new EventDispatcher();
  14701. var listener = {};
  14702. eventDispatcher.addEventListener( 'anyType', listener );
  14703. assert.ok( eventDispatcher.hasEventListener( 'anyType', listener ), "listener was found" );
  14704. assert.ok( ! eventDispatcher.hasEventListener( 'anotherType', listener ), "listener was not found which is good" );
  14705. } );
  14706. QUnit.test( "removeEventListener", ( assert ) => {
  14707. var eventDispatcher = new EventDispatcher();
  14708. var listener = {};
  14709. assert.ok( eventDispatcher._listeners === undefined, "there are no listeners by default" );
  14710. eventDispatcher.addEventListener( 'anyType', listener );
  14711. assert.ok( Object.keys( eventDispatcher._listeners ).length === 1 &&
  14712. eventDispatcher._listeners.anyType.length === 1, "if a listener was added, there is a new key" );
  14713. eventDispatcher.removeEventListener( 'anyType', listener );
  14714. assert.ok( eventDispatcher._listeners.anyType.length === 0, "listener was deleted" );
  14715. eventDispatcher.removeEventListener( 'unknownType', listener );
  14716. assert.ok( eventDispatcher._listeners.unknownType === undefined, "unknown types will be ignored" );
  14717. eventDispatcher.removeEventListener( 'anyType', undefined );
  14718. assert.ok( eventDispatcher._listeners.anyType.length === 0, "undefined listeners are ignored" );
  14719. } );
  14720. QUnit.test( "dispatchEvent", ( assert ) => {
  14721. var eventDispatcher = new EventDispatcher();
  14722. var callCount = 0;
  14723. var listener = function () {
  14724. callCount ++;
  14725. };
  14726. eventDispatcher.addEventListener( 'anyType', listener );
  14727. assert.ok( callCount === 0, "no event, no call" );
  14728. eventDispatcher.dispatchEvent( { type: 'anyType' } );
  14729. assert.ok( callCount === 1, "one event, one call" );
  14730. eventDispatcher.dispatchEvent( { type: 'anyType' } );
  14731. assert.ok( callCount === 2, "two events, two calls" );
  14732. } );
  14733. } );
  14734. } );
  14735. /**
  14736. * @author simonThiele / https://github.com/simonThiele
  14737. * @author TristanVALCKE / https://github.com/Itee
  14738. */
  14739. /* global QUnit */
  14740. QUnit.module( 'Core', () => {
  14741. QUnit.module.todo( 'Face3', () => {
  14742. // INSTANCING
  14743. QUnit.test( "Instancing", ( assert ) => {
  14744. assert.ok( false, "everything's gonna be alright" );
  14745. } );
  14746. // PUBLIC STUFF
  14747. QUnit.test( "copy", ( assert ) => {
  14748. var instance = new Face3( 0, 1, 2, new Vector3( 0, 1, 0 ), new Color( 0.25, 0.5, 0.75 ), 2 );
  14749. var copiedInstance = instance.copy( instance );
  14750. checkCopy( copiedInstance, assert );
  14751. checkVertexAndColors( copiedInstance, assert );
  14752. } );
  14753. QUnit.test( "copy (more)", ( assert ) => {
  14754. var instance = new Face3( 0, 1, 2,
  14755. [ new Vector3( 0, 1, 0 ), new Vector3( 1, 0, 1 ) ],
  14756. [ new Color( 0.25, 0.5, 0.75 ), new Color( 1, 0, 0.4 ) ],
  14757. 2 );
  14758. var copiedInstance = instance.copy( instance );
  14759. checkCopy( copiedInstance, assert );
  14760. checkVertexAndColorArrays( copiedInstance, assert );
  14761. } );
  14762. QUnit.test( "clone", ( assert ) => {
  14763. var instance = new Face3( 0, 1, 2, new Vector3( 0, 1, 0 ), new Color( 0.25, 0.5, 0.75 ), 2 );
  14764. var copiedInstance = instance.clone();
  14765. checkCopy( copiedInstance, assert );
  14766. checkVertexAndColors( copiedInstance, assert );
  14767. } );
  14768. function checkCopy( copiedInstance, assert ) {
  14769. assert.ok( copiedInstance instanceof Face3, "copy created the correct type" );
  14770. assert.ok(
  14771. copiedInstance.a === 0 &&
  14772. copiedInstance.b === 1 &&
  14773. copiedInstance.c === 2 &&
  14774. copiedInstance.materialIndex === 2
  14775. , "properties where copied" );
  14776. }
  14777. function checkVertexAndColors( copiedInstance, assert ) {
  14778. assert.ok(
  14779. copiedInstance.normal.x === 0 && copiedInstance.normal.y === 1 && copiedInstance.normal.z === 0 &&
  14780. copiedInstance.color.r === 0.25 && copiedInstance.color.g === 0.5 && copiedInstance.color.b === 0.75
  14781. , "properties where copied" );
  14782. }
  14783. function checkVertexAndColorArrays( copiedInstance, assert ) {
  14784. assert.ok(
  14785. copiedInstance.vertexNormals[ 0 ].x === 0 && copiedInstance.vertexNormals[ 0 ].y === 1 && copiedInstance.vertexNormals[ 0 ].z === 0 &&
  14786. copiedInstance.vertexNormals[ 1 ].x === 1 && copiedInstance.vertexNormals[ 1 ].y === 0 && copiedInstance.vertexNormals[ 1 ].z === 1 &&
  14787. copiedInstance.vertexColors[ 0 ].r === 0.25 && copiedInstance.vertexColors[ 0 ].g === 0.5 && copiedInstance.vertexColors[ 0 ].b === 0.75 &&
  14788. copiedInstance.vertexColors[ 1 ].r === 1 && copiedInstance.vertexColors[ 1 ].g === 0 && copiedInstance.vertexColors[ 1 ].b === 0.4
  14789. , "properties where copied" );
  14790. }
  14791. } );
  14792. } );
  14793. /**
  14794. * @author clockworkgeek / https://github.com/clockworkgeek
  14795. * @author timothypratley / https://github.com/timothypratley
  14796. * @author WestLangley / http://github.com/WestLangley
  14797. * @author Mugen87 / https://github.com/Mugen87
  14798. */
  14799. function PolyhedronGeometry( vertices, indices, radius, detail ) {
  14800. Geometry.call( this );
  14801. this.type = 'PolyhedronGeometry';
  14802. this.parameters = {
  14803. vertices: vertices,
  14804. indices: indices,
  14805. radius: radius,
  14806. detail: detail
  14807. };
  14808. this.fromBufferGeometry( new PolyhedronBufferGeometry( vertices, indices, radius, detail ) );
  14809. this.mergeVertices();
  14810. }
  14811. PolyhedronGeometry.prototype = Object.create( Geometry.prototype );
  14812. PolyhedronGeometry.prototype.constructor = PolyhedronGeometry;
  14813. // PolyhedronBufferGeometry
  14814. function PolyhedronBufferGeometry( vertices, indices, radius, detail ) {
  14815. BufferGeometry.call( this );
  14816. this.type = 'PolyhedronBufferGeometry';
  14817. this.parameters = {
  14818. vertices: vertices,
  14819. indices: indices,
  14820. radius: radius,
  14821. detail: detail
  14822. };
  14823. radius = radius || 1;
  14824. detail = detail || 0;
  14825. // default buffer data
  14826. var vertexBuffer = [];
  14827. var uvBuffer = [];
  14828. // the subdivision creates the vertex buffer data
  14829. subdivide( detail );
  14830. // all vertices should lie on a conceptual sphere with a given radius
  14831. appplyRadius( radius );
  14832. // finally, create the uv data
  14833. generateUVs();
  14834. // build non-indexed geometry
  14835. this.addAttribute( 'position', new Float32BufferAttribute( vertexBuffer, 3 ) );
  14836. this.addAttribute( 'normal', new Float32BufferAttribute( vertexBuffer.slice(), 3 ) );
  14837. this.addAttribute( 'uv', new Float32BufferAttribute( uvBuffer, 2 ) );
  14838. if ( detail === 0 ) {
  14839. this.computeVertexNormals(); // flat normals
  14840. } else {
  14841. this.normalizeNormals(); // smooth normals
  14842. }
  14843. // helper functions
  14844. function subdivide( detail ) {
  14845. var a = new Vector3();
  14846. var b = new Vector3();
  14847. var c = new Vector3();
  14848. // iterate over all faces and apply a subdivison with the given detail value
  14849. for ( var i = 0; i < indices.length; i += 3 ) {
  14850. // get the vertices of the face
  14851. getVertexByIndex( indices[ i + 0 ], a );
  14852. getVertexByIndex( indices[ i + 1 ], b );
  14853. getVertexByIndex( indices[ i + 2 ], c );
  14854. // perform subdivision
  14855. subdivideFace( a, b, c, detail );
  14856. }
  14857. }
  14858. function subdivideFace( a, b, c, detail ) {
  14859. var cols = Math.pow( 2, detail );
  14860. // we use this multidimensional array as a data structure for creating the subdivision
  14861. var v = [];
  14862. var i, j;
  14863. // construct all of the vertices for this subdivision
  14864. for ( i = 0; i <= cols; i ++ ) {
  14865. v[ i ] = [];
  14866. var aj = a.clone().lerp( c, i / cols );
  14867. var bj = b.clone().lerp( c, i / cols );
  14868. var rows = cols - i;
  14869. for ( j = 0; j <= rows; j ++ ) {
  14870. if ( j === 0 && i === cols ) {
  14871. v[ i ][ j ] = aj;
  14872. } else {
  14873. v[ i ][ j ] = aj.clone().lerp( bj, j / rows );
  14874. }
  14875. }
  14876. }
  14877. // construct all of the faces
  14878. for ( i = 0; i < cols; i ++ ) {
  14879. for ( j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  14880. var k = Math.floor( j / 2 );
  14881. if ( j % 2 === 0 ) {
  14882. pushVertex( v[ i ][ k + 1 ] );
  14883. pushVertex( v[ i + 1 ][ k ] );
  14884. pushVertex( v[ i ][ k ] );
  14885. } else {
  14886. pushVertex( v[ i ][ k + 1 ] );
  14887. pushVertex( v[ i + 1 ][ k + 1 ] );
  14888. pushVertex( v[ i + 1 ][ k ] );
  14889. }
  14890. }
  14891. }
  14892. }
  14893. function appplyRadius( radius ) {
  14894. var vertex = new Vector3();
  14895. // iterate over the entire buffer and apply the radius to each vertex
  14896. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  14897. vertex.x = vertexBuffer[ i + 0 ];
  14898. vertex.y = vertexBuffer[ i + 1 ];
  14899. vertex.z = vertexBuffer[ i + 2 ];
  14900. vertex.normalize().multiplyScalar( radius );
  14901. vertexBuffer[ i + 0 ] = vertex.x;
  14902. vertexBuffer[ i + 1 ] = vertex.y;
  14903. vertexBuffer[ i + 2 ] = vertex.z;
  14904. }
  14905. }
  14906. function generateUVs() {
  14907. var vertex = new Vector3();
  14908. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  14909. vertex.x = vertexBuffer[ i + 0 ];
  14910. vertex.y = vertexBuffer[ i + 1 ];
  14911. vertex.z = vertexBuffer[ i + 2 ];
  14912. var u = azimuth( vertex ) / 2 / Math.PI + 0.5;
  14913. var v = inclination( vertex ) / Math.PI + 0.5;
  14914. uvBuffer.push( u, 1 - v );
  14915. }
  14916. correctUVs();
  14917. correctSeam();
  14918. }
  14919. function correctSeam() {
  14920. // handle case when face straddles the seam, see #3269
  14921. for ( var i = 0; i < uvBuffer.length; i += 6 ) {
  14922. // uv data of a single face
  14923. var x0 = uvBuffer[ i + 0 ];
  14924. var x1 = uvBuffer[ i + 2 ];
  14925. var x2 = uvBuffer[ i + 4 ];
  14926. var max = Math.max( x0, x1, x2 );
  14927. var min = Math.min( x0, x1, x2 );
  14928. // 0.9 is somewhat arbitrary
  14929. if ( max > 0.9 && min < 0.1 ) {
  14930. if ( x0 < 0.2 ) uvBuffer[ i + 0 ] += 1;
  14931. if ( x1 < 0.2 ) uvBuffer[ i + 2 ] += 1;
  14932. if ( x2 < 0.2 ) uvBuffer[ i + 4 ] += 1;
  14933. }
  14934. }
  14935. }
  14936. function pushVertex( vertex ) {
  14937. vertexBuffer.push( vertex.x, vertex.y, vertex.z );
  14938. }
  14939. function getVertexByIndex( index, vertex ) {
  14940. var stride = index * 3;
  14941. vertex.x = vertices[ stride + 0 ];
  14942. vertex.y = vertices[ stride + 1 ];
  14943. vertex.z = vertices[ stride + 2 ];
  14944. }
  14945. function correctUVs() {
  14946. var a = new Vector3();
  14947. var b = new Vector3();
  14948. var c = new Vector3();
  14949. var centroid = new Vector3();
  14950. var uvA = new Vector2();
  14951. var uvB = new Vector2();
  14952. var uvC = new Vector2();
  14953. for ( var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6 ) {
  14954. a.set( vertexBuffer[ i + 0 ], vertexBuffer[ i + 1 ], vertexBuffer[ i + 2 ] );
  14955. b.set( vertexBuffer[ i + 3 ], vertexBuffer[ i + 4 ], vertexBuffer[ i + 5 ] );
  14956. c.set( vertexBuffer[ i + 6 ], vertexBuffer[ i + 7 ], vertexBuffer[ i + 8 ] );
  14957. uvA.set( uvBuffer[ j + 0 ], uvBuffer[ j + 1 ] );
  14958. uvB.set( uvBuffer[ j + 2 ], uvBuffer[ j + 3 ] );
  14959. uvC.set( uvBuffer[ j + 4 ], uvBuffer[ j + 5 ] );
  14960. centroid.copy( a ).add( b ).add( c ).divideScalar( 3 );
  14961. var azi = azimuth( centroid );
  14962. correctUV( uvA, j + 0, a, azi );
  14963. correctUV( uvB, j + 2, b, azi );
  14964. correctUV( uvC, j + 4, c, azi );
  14965. }
  14966. }
  14967. function correctUV( uv, stride, vector, azimuth ) {
  14968. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) {
  14969. uvBuffer[ stride ] = uv.x - 1;
  14970. }
  14971. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) {
  14972. uvBuffer[ stride ] = azimuth / 2 / Math.PI + 0.5;
  14973. }
  14974. }
  14975. // Angle around the Y axis, counter-clockwise when looking from above.
  14976. function azimuth( vector ) {
  14977. return Math.atan2( vector.z, - vector.x );
  14978. }
  14979. // Angle above the XZ plane.
  14980. function inclination( vector ) {
  14981. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  14982. }
  14983. }
  14984. PolyhedronBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  14985. PolyhedronBufferGeometry.prototype.constructor = PolyhedronBufferGeometry;
  14986. /**
  14987. * @author Abe Pazos / https://hamoid.com
  14988. * @author Mugen87 / https://github.com/Mugen87
  14989. */
  14990. function DodecahedronGeometry( radius, detail ) {
  14991. Geometry.call( this );
  14992. this.type = 'DodecahedronGeometry';
  14993. this.parameters = {
  14994. radius: radius,
  14995. detail: detail
  14996. };
  14997. this.fromBufferGeometry( new DodecahedronBufferGeometry( radius, detail ) );
  14998. this.mergeVertices();
  14999. }
  15000. DodecahedronGeometry.prototype = Object.create( Geometry.prototype );
  15001. DodecahedronGeometry.prototype.constructor = DodecahedronGeometry;
  15002. // DodecahedronBufferGeometry
  15003. function DodecahedronBufferGeometry( radius, detail ) {
  15004. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  15005. var r = 1 / t;
  15006. var vertices = [
  15007. // (±1, ±1, ±1)
  15008. - 1, - 1, - 1, - 1, - 1, 1,
  15009. - 1, 1, - 1, - 1, 1, 1,
  15010. 1, - 1, - 1, 1, - 1, 1,
  15011. 1, 1, - 1, 1, 1, 1,
  15012. // (0, ±1/φ, ±φ)
  15013. 0, - r, - t, 0, - r, t,
  15014. 0, r, - t, 0, r, t,
  15015. // (±1/φ, ±φ, 0)
  15016. - r, - t, 0, - r, t, 0,
  15017. r, - t, 0, r, t, 0,
  15018. // (±φ, 0, ±1/φ)
  15019. - t, 0, - r, t, 0, - r,
  15020. - t, 0, r, t, 0, r
  15021. ];
  15022. var indices = [
  15023. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  15024. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  15025. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  15026. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  15027. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  15028. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  15029. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  15030. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  15031. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  15032. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  15033. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  15034. 1, 12, 14, 1, 14, 5, 1, 5, 9
  15035. ];
  15036. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  15037. this.type = 'DodecahedronBufferGeometry';
  15038. this.parameters = {
  15039. radius: radius,
  15040. detail: detail
  15041. };
  15042. }
  15043. DodecahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  15044. DodecahedronBufferGeometry.prototype.constructor = DodecahedronBufferGeometry;
  15045. /**
  15046. * @author simonThiele / https://github.com/simonThiele
  15047. */
  15048. /* global QUnit */
  15049. function getGeometryByParams( x1, y1, z1, x2, y2, z2, x3, y3, z3 ) {
  15050. var geometry = new Geometry();
  15051. // a triangle
  15052. geometry.vertices = [
  15053. new Vector3( x1, y1, z1 ),
  15054. new Vector3( x2, y2, z2 ),
  15055. new Vector3( x3, y3, z3 )
  15056. ];
  15057. return geometry;
  15058. }
  15059. function getGeometry() {
  15060. return getGeometryByParams( - 0.5, 0, 0, 0.5, 0, 0, 0, 1, 0 );
  15061. }
  15062. QUnit.module( 'Core', () => {
  15063. QUnit.module.todo( 'Geometry', () => {
  15064. // INHERITANCE
  15065. QUnit.test( "Extending", ( assert ) => {
  15066. assert.ok( false, "everything's gonna be alright" );
  15067. } );
  15068. // INSTANCING
  15069. QUnit.test( "Instancing", ( assert ) => {
  15070. assert.ok( false, "everything's gonna be alright" );
  15071. } );
  15072. // PUBLIC STUFF
  15073. QUnit.test( "isGeometry", ( assert ) => {
  15074. assert.ok( false, "everything's gonna be alright" );
  15075. } );
  15076. QUnit.test( "applyMatrix", ( assert ) => {
  15077. var geometry = getGeometry();
  15078. geometry.faces.push( new Face3( 0, 1, 2 ) );
  15079. var m = new Matrix4();
  15080. var expectedVerts = [
  15081. new Vector3( 1.5, 3, 4 ),
  15082. new Vector3( 2.5, 3, 4 ),
  15083. new Vector3( 2, 3, 5 )
  15084. ];
  15085. var v0, v1, v2;
  15086. m.makeRotationX( Math.PI / 2 );
  15087. m.setPosition( new Vector3( x, y, z ) );
  15088. geometry.applyMatrix( m );
  15089. v0 = geometry.vertices[ 0 ];
  15090. v1 = geometry.vertices[ 1 ];
  15091. v2 = geometry.vertices[ 2 ];
  15092. assert.ok(
  15093. Math.abs( v0.x - expectedVerts[ 0 ].x ) <= eps &&
  15094. Math.abs( v0.y - expectedVerts[ 0 ].y ) <= eps &&
  15095. Math.abs( v0.z - expectedVerts[ 0 ].z ) <= eps,
  15096. "First vertex is as expected"
  15097. );
  15098. assert.ok(
  15099. Math.abs( v1.x - expectedVerts[ 1 ].x ) <= eps &&
  15100. Math.abs( v1.y - expectedVerts[ 1 ].y ) <= eps &&
  15101. Math.abs( v1.z - expectedVerts[ 1 ].z ) <= eps,
  15102. "Second vertex is as expected"
  15103. );
  15104. assert.ok(
  15105. Math.abs( v2.x - expectedVerts[ 2 ].x ) <= eps &&
  15106. Math.abs( v2.y - expectedVerts[ 2 ].y ) <= eps &&
  15107. Math.abs( v2.z - expectedVerts[ 2 ].z ) <= eps,
  15108. "Third vertex is as expected"
  15109. );
  15110. } );
  15111. QUnit.test( "rotateX", ( assert ) => {
  15112. var geometry = getGeometry();
  15113. var matrix = new Matrix4();
  15114. matrix.makeRotationX( Math.PI / 2 ); // 90 degree
  15115. geometry.applyMatrix( matrix );
  15116. var v0 = geometry.vertices[ 0 ], v1 = geometry.vertices[ 1 ], v2 = geometry.vertices[ 2 ];
  15117. assert.ok( v0.x === - 0.5 && v0.y === 0 && v0.z === 0, "first vertex was rotated" );
  15118. assert.ok( v1.x === 0.5 && v1.y === 0 && v1.z === 0, "second vertex was rotated" );
  15119. assert.ok( v2.x === 0 && v2.y < Number.EPSILON && v2.z === 1, "third vertex was rotated" );
  15120. } );
  15121. QUnit.test( "rotateY", ( assert ) => {
  15122. var geometry = getGeometry();
  15123. var matrix = new Matrix4();
  15124. matrix.makeRotationY( Math.PI ); // 180 degrees
  15125. geometry.applyMatrix( matrix );
  15126. var v0 = geometry.vertices[ 0 ], v1 = geometry.vertices[ 1 ], v2 = geometry.vertices[ 2 ];
  15127. assert.ok( v0.x === 0.5 && v0.y === 0 && v0.z < Number.EPSILON, "first vertex was rotated" );
  15128. assert.ok( v1.x === - 0.5 && v1.y === 0 && v1.z < Number.EPSILON, "second vertex was rotated" );
  15129. assert.ok( v2.x === 0 && v2.y === 1 && v2.z === 0, "third vertex was rotated" );
  15130. } );
  15131. QUnit.test( "rotateZ", ( assert ) => {
  15132. var geometry = getGeometry();
  15133. var matrix = new Matrix4();
  15134. matrix.makeRotationZ( Math.PI / 2 * 3 ); // 270 degrees
  15135. geometry.applyMatrix( matrix );
  15136. var v0 = geometry.vertices[ 0 ], v1 = geometry.vertices[ 1 ], v2 = geometry.vertices[ 2 ];
  15137. assert.ok( v0.x < Number.EPSILON && v0.y === 0.5 && v0.z === 0, "first vertex was rotated" );
  15138. assert.ok( v1.x < Number.EPSILON && v1.y === - 0.5 && v1.z === 0, "second vertex was rotated" );
  15139. assert.ok( v2.x === 1 && v2.y < Number.EPSILON && v2.z === 0, "third vertex was rotated" );
  15140. } );
  15141. QUnit.test( "translate", ( assert ) => {
  15142. var a = getGeometry();
  15143. var expected = [
  15144. new Vector3( - 2.5, 3, - 4 ),
  15145. new Vector3( - 1.5, 3, - 4 ),
  15146. new Vector3( - 2, 4, - 4 )
  15147. ];
  15148. var v;
  15149. a.translate( - x, y, - z );
  15150. for ( var i = 0; i < a.vertices.length; i ++ ) {
  15151. v = a.vertices[ i ];
  15152. assert.ok(
  15153. Math.abs( v.x - expected[ i ].x ) <= eps &&
  15154. Math.abs( v.y - expected[ i ].y ) <= eps &&
  15155. Math.abs( v.z - expected[ i ].z ) <= eps,
  15156. "Vertex #" + i + " was translated as expected"
  15157. );
  15158. }
  15159. } );
  15160. QUnit.test( "scale", ( assert ) => {
  15161. var a = getGeometry();
  15162. var expected = [
  15163. new Vector3( - 1, 0, 0 ),
  15164. new Vector3( 1, 0, 0 ),
  15165. new Vector3( 0, 3, 0 )
  15166. ];
  15167. var v;
  15168. a.scale( 2, 3, 4 );
  15169. for ( var i = 0; i < a.vertices.length; i ++ ) {
  15170. v = a.vertices[ i ];
  15171. assert.ok(
  15172. Math.abs( v.x - expected[ i ].x ) <= eps &&
  15173. Math.abs( v.y - expected[ i ].y ) <= eps &&
  15174. Math.abs( v.z - expected[ i ].z ) <= eps,
  15175. "Vertex #" + i + " was scaled as expected"
  15176. );
  15177. }
  15178. } );
  15179. QUnit.test( "lookAt", ( assert ) => {
  15180. var a = getGeometry();
  15181. var expected = [
  15182. new Vector3( - 0.5, 0, 0 ),
  15183. new Vector3( 0.5, 0, 0 ),
  15184. new Vector3( 0, 0.5 * Math.sqrt( 2 ), 0.5 * Math.sqrt( 2 ) )
  15185. ];
  15186. a.lookAt( new Vector3( 0, - 1, 1 ) );
  15187. for ( var i = 0; i < a.vertices.length; i ++ ) {
  15188. var v = a.vertices[ i ];
  15189. assert.ok(
  15190. Math.abs( v.x - expected[ i ].x ) <= eps &&
  15191. Math.abs( v.y - expected[ i ].y ) <= eps &&
  15192. Math.abs( v.z - expected[ i ].z ) <= eps,
  15193. "Vertex #" + i + " was adjusted as expected"
  15194. );
  15195. }
  15196. } );
  15197. QUnit.test( "fromBufferGeometry", ( assert ) => {
  15198. var bufferGeometry = new BufferGeometry();
  15199. bufferGeometry.addAttribute( 'position', new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ] ), 3 ) );
  15200. bufferGeometry.addAttribute( 'color', new BufferAttribute( new Float32Array( [ 0, 0, 0, 0.5, 0.5, 0.5, 1, 1, 1 ] ), 3 ) );
  15201. bufferGeometry.addAttribute( 'normal', new BufferAttribute( new Float32Array( [ 0, 1, 0, 1, 0, 1, 1, 1, 0 ] ), 3 ) );
  15202. bufferGeometry.addAttribute( 'uv', new BufferAttribute( new Float32Array( [ 0, 0, 0, 1, 1, 1 ] ), 2 ) );
  15203. bufferGeometry.addAttribute( 'uv2', new BufferAttribute( new Float32Array( [ 0, 0, 0, 1, 1, 1 ] ), 2 ) );
  15204. var geometry = new Geometry().fromBufferGeometry( bufferGeometry );
  15205. var colors = geometry.colors;
  15206. assert.ok(
  15207. colors[ 0 ].r === 0 && colors[ 0 ].g === 0 && colors[ 0 ].b === 0 &&
  15208. colors[ 1 ].r === 0.5 && colors[ 1 ].g === 0.5 && colors[ 1 ].b === 0.5 &&
  15209. colors[ 2 ].r === 1 && colors[ 2 ].g === 1 && colors[ 2 ].b === 1
  15210. , "colors were created well" );
  15211. var vertices = geometry.vertices;
  15212. assert.ok(
  15213. vertices[ 0 ].x === 1 && vertices[ 0 ].y === 2 && vertices[ 0 ].z === 3 &&
  15214. vertices[ 1 ].x === 4 && vertices[ 1 ].y === 5 && vertices[ 1 ].z === 6 &&
  15215. vertices[ 2 ].x === 7 && vertices[ 2 ].y === 8 && vertices[ 2 ].z === 9
  15216. , "vertices were created well" );
  15217. var vNormals = geometry.faces[ 0 ].vertexNormals;
  15218. assert.ok(
  15219. vNormals[ 0 ].x === 0 && vNormals[ 0 ].y === 1 && vNormals[ 0 ].z === 0 &&
  15220. vNormals[ 1 ].x === 1 && vNormals[ 1 ].y === 0 && vNormals[ 1 ].z === 1 &&
  15221. vNormals[ 2 ].x === 1 && vNormals[ 2 ].y === 1 && vNormals[ 2 ].z === 0
  15222. , "vertex normals were created well" );
  15223. } );
  15224. QUnit.test( "center", ( assert ) => {
  15225. assert.ok( false, "everything's gonna be alright" );
  15226. } );
  15227. QUnit.test( "normalize", ( assert ) => {
  15228. var geometry = getGeometry();
  15229. geometry.computeLineDistances();
  15230. var distances = geometry.lineDistances;
  15231. assert.ok( distances[ 0 ] === 0, "distance to the 1st point is 0" );
  15232. assert.ok( distances[ 1 ] === 1 + distances[ 0 ], "distance from the 1st to the 2nd is sqrt(2nd - 1st) + distance - 1" );
  15233. assert.ok( distances[ 2 ] === Math.sqrt( 0.5 * 0.5 + 1 ) + distances[ 1 ], "distance from the 1st to the 3nd is sqrt(3rd - 2nd) + distance - 1" );
  15234. } );
  15235. QUnit.test( "normalize (actual)", ( assert ) => {
  15236. var a = getGeometry();
  15237. var sqrt = 0.5 * Math.sqrt( 2 );
  15238. var expected = [
  15239. new Vector3( - sqrt, - sqrt, 0 ),
  15240. new Vector3( sqrt, - sqrt, 0 ),
  15241. new Vector3( 0, sqrt, 0 )
  15242. ];
  15243. var v;
  15244. a.normalize();
  15245. for ( var i = 0; i < a.vertices.length; i ++ ) {
  15246. v = a.vertices[ i ];
  15247. assert.ok(
  15248. Math.abs( v.x - expected[ i ].x ) <= eps &&
  15249. Math.abs( v.y - expected[ i ].y ) <= eps &&
  15250. Math.abs( v.z - expected[ i ].z ) <= eps,
  15251. "Vertex #" + i + " was normalized as expected"
  15252. );
  15253. }
  15254. } );
  15255. QUnit.test( "computeFaceNormals", ( assert ) => {
  15256. assert.ok( false, "everything's gonna be alright" );
  15257. } );
  15258. QUnit.test( "computeVertexNormals", ( assert ) => {
  15259. assert.ok( false, "everything's gonna be alright" );
  15260. } );
  15261. QUnit.test( "computeFlatVertexNormals", ( assert ) => {
  15262. assert.ok( false, "everything's gonna be alright" );
  15263. } );
  15264. QUnit.test( "computeMorphNormals", ( assert ) => {
  15265. assert.ok( false, "everything's gonna be alright" );
  15266. } );
  15267. QUnit.test( "computeLineDistances", ( assert ) => {
  15268. assert.ok( false, "everything's gonna be alright" );
  15269. } );
  15270. QUnit.test( "computeBoundingBox", ( assert ) => {
  15271. var a = new DodecahedronGeometry();
  15272. a.computeBoundingBox();
  15273. assert.strictEqual( a.boundingBox.isEmpty(), false, "Bounding box isn't empty" );
  15274. var allIn = true;
  15275. for ( var i = 0; i < a.vertices.length; i ++ ) {
  15276. if ( ! a.boundingBox.containsPoint( a.vertices[ i ] ) ) {
  15277. allIn = false;
  15278. }
  15279. }
  15280. assert.strictEqual( allIn, true, "All vertices are inside the box" );
  15281. } );
  15282. QUnit.test( "computeBoundingSphere", ( assert ) => {
  15283. var a = new DodecahedronGeometry();
  15284. a.computeBoundingSphere();
  15285. var allIn = true;
  15286. for ( var i = 0; i < a.vertices.length; i ++ ) {
  15287. if ( ! a.boundingSphere.containsPoint( a.vertices[ i ] ) ) {
  15288. allIn = false;
  15289. }
  15290. }
  15291. assert.strictEqual( allIn, true, "All vertices are inside the bounding sphere" );
  15292. } );
  15293. QUnit.test( "merge", ( assert ) => {
  15294. assert.ok( false, "everything's gonna be alright" );
  15295. } );
  15296. QUnit.test( "mergeMesh", ( assert ) => {
  15297. assert.ok( false, "everything's gonna be alright" );
  15298. } );
  15299. QUnit.test( "mergeVertices", ( assert ) => {
  15300. var a = new Geometry();
  15301. var b = new BoxBufferGeometry( 1, 1, 1 );
  15302. var verts, faces, removed;
  15303. a.fromBufferGeometry( b );
  15304. removed = a.mergeVertices();
  15305. verts = a.vertices.length;
  15306. faces = a.faces.length;
  15307. assert.strictEqual( removed, 16, "Removed the expected number of vertices" );
  15308. assert.strictEqual( verts, 8, "Minimum number of vertices remaining" );
  15309. assert.strictEqual( faces, 12, "Minimum number of faces remaining" );
  15310. } );
  15311. QUnit.test( "sortFacesByMaterialIndex", ( assert ) => {
  15312. var box = new BoxBufferGeometry( 1, 1, 1 );
  15313. var a = new Geometry().fromBufferGeometry( box );
  15314. var expected = [ 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 ];
  15315. a.faces.reverse(); // a bit too simple probably, still missing stuff like checking new UVs
  15316. a.sortFacesByMaterialIndex();
  15317. var indices = [];
  15318. for ( var i = 0; i < a.faces.length; i ++ ) {
  15319. indices.push( a.faces[ i ].materialIndex );
  15320. }
  15321. assert.deepEqual( indices, expected, "Faces in correct order" );
  15322. } );
  15323. QUnit.test( "toJSON", ( assert ) => {
  15324. var a = getGeometry();
  15325. var gold = {
  15326. "metadata": {
  15327. "version": 4.5,
  15328. "type": "Geometry",
  15329. "generator": "Geometry.toJSON"
  15330. },
  15331. "uuid": null,
  15332. "type": "Geometry",
  15333. "data": {
  15334. "vertices": [ - 0.5, 0, 0, 0.5, 0, 0, 0, 1, 0 ],
  15335. "normals": [ 0, 0, 1 ],
  15336. "faces": [ 50, 0, 1, 2, 0, 0, 0, 0, 0 ]
  15337. }
  15338. };
  15339. var json;
  15340. a.faces.push( new Face3( 0, 1, 2 ) );
  15341. a.computeFaceNormals();
  15342. a.computeVertexNormals();
  15343. json = a.toJSON();
  15344. json.uuid = null;
  15345. assert.deepEqual( json, gold, "Generated JSON is as expected" );
  15346. } );
  15347. QUnit.test( "clone", ( assert ) => {
  15348. assert.ok( false, "everything's gonna be alright" );
  15349. } );
  15350. QUnit.test( "copy", ( assert ) => {
  15351. assert.ok( false, "everything's gonna be alright" );
  15352. } );
  15353. QUnit.test( "dispose", ( assert ) => {
  15354. assert.ok( false, "everything's gonna be alright" );
  15355. } );
  15356. } );
  15357. } );
  15358. function InstancedBufferAttribute( array, itemSize, meshPerAttribute ) {
  15359. BufferAttribute.call( this, array, itemSize );
  15360. this.meshPerAttribute = meshPerAttribute || 1;
  15361. }
  15362. InstancedBufferAttribute.prototype = Object.assign( Object.create( BufferAttribute.prototype ), {
  15363. constructor: InstancedBufferAttribute,
  15364. isInstancedBufferAttribute: true,
  15365. copy: function ( source ) {
  15366. BufferAttribute.prototype.copy.call( this, source );
  15367. this.meshPerAttribute = source.meshPerAttribute;
  15368. return this;
  15369. }
  15370. } );
  15371. /**
  15372. * @author simonThiele / https://github.com/simonThiele
  15373. */
  15374. /* global QUnit */
  15375. QUnit.module( 'Core', () => {
  15376. QUnit.module.todo( 'InstancedBufferAttribute', () => {
  15377. // INHERITANCE
  15378. QUnit.test( "Extending", ( assert ) => {
  15379. assert.ok( false, "everything's gonna be alright" );
  15380. } );
  15381. // INSTANCING
  15382. QUnit.test( "Instancing", ( assert ) => {
  15383. var instance = new InstancedBufferAttribute( new Float32Array( 10 ), 2 );
  15384. assert.ok( instance.meshPerAttribute === 1, "ok" );
  15385. var instance = new InstancedBufferAttribute( new Float32Array( 10 ), 2, 123 );
  15386. assert.ok( instance.meshPerAttribute === 123, "ok" );
  15387. } );
  15388. // PUBLIC STUFF
  15389. QUnit.test( "copy", ( assert ) => {
  15390. var array = new Float32Array( [ 1, 2, 3, 7, 8, 9 ] );
  15391. var instance = new InstancedBufferAttribute( array, 2, 123 );
  15392. var copiedInstance = instance.copy( instance );
  15393. assert.ok( copiedInstance instanceof InstancedBufferAttribute, "the clone has the correct type" );
  15394. assert.ok( copiedInstance.itemSize === 2, "itemSize was copied" );
  15395. assert.ok( copiedInstance.meshPerAttribute === 123, "meshPerAttribute was copied" );
  15396. for ( var i = 0; i < array.length; i ++ ) {
  15397. assert.ok( copiedInstance.array[ i ] === array[ i ], "array was copied" );
  15398. }
  15399. } );
  15400. } );
  15401. } );
  15402. function InstancedBufferGeometry() {
  15403. BufferGeometry.call( this );
  15404. this.type = 'InstancedBufferGeometry';
  15405. this.maxInstancedCount = undefined;
  15406. }
  15407. InstancedBufferGeometry.prototype = Object.assign( Object.create( BufferGeometry.prototype ), {
  15408. constructor: InstancedBufferGeometry,
  15409. isInstancedBufferGeometry: true,
  15410. copy: function ( source ) {
  15411. BufferGeometry.prototype.copy.call( this, source );
  15412. this.maxInstancedCount = source.maxInstancedCount;
  15413. return this;
  15414. },
  15415. clone: function () {
  15416. return new this.constructor().copy( this );
  15417. }
  15418. } );
  15419. /**
  15420. * @author simonThiele / https://github.com/simonThiele
  15421. */
  15422. /* global QUnit */
  15423. QUnit.module( 'Core', () => {
  15424. QUnit.module.todo( 'InstancedBufferGeometry', () => {
  15425. function createClonableMock() {
  15426. return {
  15427. callCount: 0,
  15428. clone: function () {
  15429. this.callCount ++;
  15430. return this;
  15431. }
  15432. };
  15433. }
  15434. // INHERITANCE
  15435. QUnit.test( "Extending", ( assert ) => {
  15436. assert.ok( false, "everything's gonna be alright" );
  15437. } );
  15438. // INSTANCING
  15439. QUnit.test( "Instancing", ( assert ) => {
  15440. assert.ok( false, "everything's gonna be alright" );
  15441. } );
  15442. // PUBLIC STUFF
  15443. QUnit.test( "copy", ( assert ) => {
  15444. var instanceMock1 = {};
  15445. var instanceMock2 = {};
  15446. var indexMock = createClonableMock();
  15447. var defaultAttribute1 = new BufferAttribute( new Float32Array( [ 1 ] ) );
  15448. var defaultAttribute2 = new BufferAttribute( new Float32Array( [ 2 ] ) );
  15449. var instance = new InstancedBufferGeometry();
  15450. instance.addGroup( 0, 10, instanceMock1 );
  15451. instance.addGroup( 10, 5, instanceMock2 );
  15452. instance.setIndex( indexMock );
  15453. instance.addAttribute( 'defaultAttribute1', defaultAttribute1 );
  15454. instance.addAttribute( 'defaultAttribute2', defaultAttribute2 );
  15455. var copiedInstance = new InstancedBufferGeometry().copy( instance );
  15456. assert.ok( copiedInstance instanceof InstancedBufferGeometry, "the clone has the correct type" );
  15457. assert.equal( copiedInstance.index, indexMock, "index was copied" );
  15458. assert.equal( copiedInstance.index.callCount, 1, "index.clone was called once" );
  15459. assert.ok( copiedInstance.attributes[ 'defaultAttribute1' ] instanceof BufferAttribute, "attribute was created" );
  15460. assert.deepEqual( copiedInstance.attributes[ 'defaultAttribute1' ].array, defaultAttribute1.array, "attribute was copied" );
  15461. assert.deepEqual( copiedInstance.attributes[ 'defaultAttribute2' ].array, defaultAttribute2.array, "attribute was copied" );
  15462. assert.equal( copiedInstance.groups[ 0 ].start, 0, "group was copied" );
  15463. assert.equal( copiedInstance.groups[ 0 ].count, 10, "group was copied" );
  15464. assert.equal( copiedInstance.groups[ 0 ].materialIndex, instanceMock1, "group was copied" );
  15465. assert.equal( copiedInstance.groups[ 1 ].start, 10, "group was copied" );
  15466. assert.equal( copiedInstance.groups[ 1 ].count, 5, "group was copied" );
  15467. assert.equal( copiedInstance.groups[ 1 ].materialIndex, instanceMock2, "group was copied" );
  15468. } );
  15469. QUnit.test( "clone", ( assert ) => {
  15470. assert.ok( false, "everything's gonna be alright" );
  15471. } );
  15472. } );
  15473. } );
  15474. function InterleavedBuffer( array, stride ) {
  15475. this.uuid = _Math.generateUUID();
  15476. this.array = array;
  15477. this.stride = stride;
  15478. this.count = array !== undefined ? array.length / stride : 0;
  15479. this.dynamic = false;
  15480. this.updateRange = { offset: 0, count: - 1 };
  15481. this.onUploadCallback = function () {};
  15482. this.version = 0;
  15483. }
  15484. Object.defineProperty( InterleavedBuffer.prototype, 'needsUpdate', {
  15485. set: function ( value ) {
  15486. if ( value === true ) this.version ++;
  15487. }
  15488. } );
  15489. Object.assign( InterleavedBuffer.prototype, {
  15490. isInterleavedBuffer: true,
  15491. setArray: function ( array ) {
  15492. if ( Array.isArray( array ) ) {
  15493. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  15494. }
  15495. this.count = array !== undefined ? array.length / this.stride : 0;
  15496. this.array = array;
  15497. },
  15498. setDynamic: function ( value ) {
  15499. this.dynamic = value;
  15500. return this;
  15501. },
  15502. copy: function ( source ) {
  15503. this.array = new source.array.constructor( source.array );
  15504. this.count = source.count;
  15505. this.stride = source.stride;
  15506. this.dynamic = source.dynamic;
  15507. return this;
  15508. },
  15509. copyAt: function ( index1, attribute, index2 ) {
  15510. index1 *= this.stride;
  15511. index2 *= attribute.stride;
  15512. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  15513. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  15514. }
  15515. return this;
  15516. },
  15517. set: function ( value, offset ) {
  15518. if ( offset === undefined ) offset = 0;
  15519. this.array.set( value, offset );
  15520. return this;
  15521. },
  15522. clone: function () {
  15523. return new this.constructor().copy( this );
  15524. },
  15525. onUpload: function ( callback ) {
  15526. this.onUploadCallback = callback;
  15527. return this;
  15528. }
  15529. } );
  15530. function InstancedInterleavedBuffer( array, stride, meshPerAttribute ) {
  15531. InterleavedBuffer.call( this, array, stride );
  15532. this.meshPerAttribute = meshPerAttribute || 1;
  15533. }
  15534. InstancedInterleavedBuffer.prototype = Object.assign( Object.create( InterleavedBuffer.prototype ), {
  15535. constructor: InstancedInterleavedBuffer,
  15536. isInstancedInterleavedBuffer: true,
  15537. copy: function ( source ) {
  15538. InterleavedBuffer.prototype.copy.call( this, source );
  15539. this.meshPerAttribute = source.meshPerAttribute;
  15540. return this;
  15541. }
  15542. } );
  15543. /**
  15544. * @author simonThiele / https://github.com/simonThiele
  15545. */
  15546. /* global QUnit */
  15547. QUnit.module( 'Core', () => {
  15548. QUnit.module.todo( 'InstancedInterleavedBuffer', () => {
  15549. // INHERITANCE
  15550. QUnit.test( "Extending", ( assert ) => {
  15551. assert.ok( false, "everything's gonna be alright" );
  15552. } );
  15553. // INSTANCING
  15554. QUnit.test( "Instancing", ( assert ) => {
  15555. var array = new Float32Array( [ 1, 2, 3, 7, 8, 9 ] );
  15556. var instance = new InstancedInterleavedBuffer( array, 3 );
  15557. assert.ok( instance.meshPerAttribute === 1, "ok" );
  15558. } );
  15559. // PUBLIC STUFF
  15560. QUnit.test( "isInstancedInterleavedBuffer", ( assert ) => {
  15561. assert.ok( false, "everything's gonna be alright" );
  15562. } );
  15563. QUnit.test( "copy", ( assert ) => {
  15564. var array = new Float32Array( [ 1, 2, 3, 7, 8, 9 ] );
  15565. var instance = new InstancedInterleavedBuffer( array, 3 );
  15566. var copiedInstance = instance.copy( instance );
  15567. assert.ok( copiedInstance.meshPerAttribute === 1, "additional attribute was copied" );
  15568. } );
  15569. } );
  15570. } );
  15571. /**
  15572. * @author simonThiele / https://github.com/simonThiele
  15573. */
  15574. /* global QUnit */
  15575. QUnit.module( 'Core', () => {
  15576. QUnit.module.todo( 'InterleavedBuffer', () => {
  15577. function checkInstanceAgainstCopy( instance, copiedInstance, assert ) {
  15578. assert.ok( copiedInstance instanceof InterleavedBuffer, "the clone has the correct type" );
  15579. for ( var i = 0; i < instance.array.length; i ++ ) {
  15580. assert.ok( copiedInstance.array[ i ] === instance.array[ i ], "array was copied" );
  15581. }
  15582. assert.ok( copiedInstance.stride === instance.stride, "stride was copied" );
  15583. assert.ok( copiedInstance.dynamic === true, "dynamic was copied" );
  15584. }
  15585. // INSTANCING
  15586. QUnit.test( "Instancing", ( assert ) => {
  15587. assert.ok( false, "everything's gonna be alright" );
  15588. } );
  15589. // PROPERTIES
  15590. QUnit.test( "needsUpdate", ( assert ) => {
  15591. var a = new InterleavedBuffer( new Float32Array( [ 1, 2, 3, 4 ], 2 ) );
  15592. a.needsUpdate = true;
  15593. assert.strictEqual( a.version, 1, "Check version increased" );
  15594. } );
  15595. // PUBLIC STUFF
  15596. QUnit.test( "isInterleavedBuffer", ( assert ) => {
  15597. assert.ok( false, "everything's gonna be alright" );
  15598. } );
  15599. QUnit.test( "setArray", ( assert ) => {
  15600. var f32a = new Float32Array( [ 1, 2, 3, 4 ] );
  15601. var f32b = new Float32Array( [] );
  15602. var a = new InterleavedBuffer( f32a, 2, false );
  15603. a.setArray( f32a );
  15604. assert.strictEqual( a.count, 2, "Check item count for non-empty array" );
  15605. assert.strictEqual( a.array, f32a, "Check array itself" );
  15606. a.setArray( f32b );
  15607. assert.strictEqual( a.count, 0, "Check item count for empty array" );
  15608. assert.strictEqual( a.array, f32b, "Check array itself" );
  15609. assert.throws(
  15610. function () {
  15611. a.setArray( [ 1, 2, 3, 4 ] );
  15612. },
  15613. /array should be a Typed Array/,
  15614. "Calling setArray with a non-typed array throws Error"
  15615. );
  15616. } );
  15617. QUnit.test( "setDynamic", ( assert ) => {
  15618. assert.ok( false, "everything's gonna be alright" );
  15619. } );
  15620. QUnit.test( "copy", ( assert ) => {
  15621. var array = new Float32Array( [ 1, 2, 3, 7, 8, 9 ] );
  15622. var instance = new InterleavedBuffer( array, 3 );
  15623. instance.setDynamic( true );
  15624. checkInstanceAgainstCopy( instance, instance.copy( instance ), assert );
  15625. } );
  15626. QUnit.test( "copyAt", ( assert ) => {
  15627. var a = new InterleavedBuffer( new Float32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ] ), 3 );
  15628. var b = new InterleavedBuffer( new Float32Array( 9 ), 3 );
  15629. var expected = new Float32Array( [ 4, 5, 6, 7, 8, 9, 1, 2, 3 ] );
  15630. b.copyAt( 1, a, 2 );
  15631. b.copyAt( 0, a, 1 );
  15632. b.copyAt( 2, a, 0 );
  15633. assert.deepEqual( b.array, expected, "Check the right values were replaced" );
  15634. } );
  15635. QUnit.test( "set", ( assert ) => {
  15636. var instance = new InterleavedBuffer( new Float32Array( [ 1, 2, 3, 7, 8, 9 ] ), 3 );
  15637. instance.set( [ 0, - 1 ] );
  15638. assert.ok( instance.array[ 0 ] === 0 && instance.array[ 1 ] === - 1, "replace at first by default" );
  15639. } );
  15640. QUnit.test( "clone", ( assert ) => {
  15641. var array = new Float32Array( [ 1, 2, 3, 7, 8, 9 ] );
  15642. var instance = new InterleavedBuffer( array, 3 );
  15643. instance.setDynamic( true );
  15644. checkInstanceAgainstCopy( instance, instance.clone(), assert );
  15645. } );
  15646. QUnit.test( "onUpload", ( assert ) => {
  15647. var a = new InterleavedBuffer();
  15648. var func = function () { };
  15649. a.onUpload( func );
  15650. assert.strictEqual( a.onUploadCallback, func, "Check callback was set properly" );
  15651. } );
  15652. // OTHERS
  15653. QUnit.test( "count", ( assert ) => {
  15654. var instance = new InterleavedBuffer( new Float32Array( [ 1, 2, 3, 7, 8, 9 ] ), 3 );
  15655. assert.equal( instance.count, 2, "count is calculated via array length / stride" );
  15656. } );
  15657. } );
  15658. } );
  15659. function InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, normalized ) {
  15660. this.uuid = _Math.generateUUID();
  15661. this.data = interleavedBuffer;
  15662. this.itemSize = itemSize;
  15663. this.offset = offset;
  15664. this.normalized = normalized === true;
  15665. }
  15666. Object.defineProperties( InterleavedBufferAttribute.prototype, {
  15667. count: {
  15668. get: function () {
  15669. return this.data.count;
  15670. }
  15671. },
  15672. array: {
  15673. get: function () {
  15674. return this.data.array;
  15675. }
  15676. }
  15677. } );
  15678. Object.assign( InterleavedBufferAttribute.prototype, {
  15679. isInterleavedBufferAttribute: true,
  15680. setX: function ( index, x ) {
  15681. this.data.array[ index * this.data.stride + this.offset ] = x;
  15682. return this;
  15683. },
  15684. setY: function ( index, y ) {
  15685. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  15686. return this;
  15687. },
  15688. setZ: function ( index, z ) {
  15689. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  15690. return this;
  15691. },
  15692. setW: function ( index, w ) {
  15693. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  15694. return this;
  15695. },
  15696. getX: function ( index ) {
  15697. return this.data.array[ index * this.data.stride + this.offset ];
  15698. },
  15699. getY: function ( index ) {
  15700. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  15701. },
  15702. getZ: function ( index ) {
  15703. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  15704. },
  15705. getW: function ( index ) {
  15706. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  15707. },
  15708. setXY: function ( index, x, y ) {
  15709. index = index * this.data.stride + this.offset;
  15710. this.data.array[ index + 0 ] = x;
  15711. this.data.array[ index + 1 ] = y;
  15712. return this;
  15713. },
  15714. setXYZ: function ( index, x, y, z ) {
  15715. index = index * this.data.stride + this.offset;
  15716. this.data.array[ index + 0 ] = x;
  15717. this.data.array[ index + 1 ] = y;
  15718. this.data.array[ index + 2 ] = z;
  15719. return this;
  15720. },
  15721. setXYZW: function ( index, x, y, z, w ) {
  15722. index = index * this.data.stride + this.offset;
  15723. this.data.array[ index + 0 ] = x;
  15724. this.data.array[ index + 1 ] = y;
  15725. this.data.array[ index + 2 ] = z;
  15726. this.data.array[ index + 3 ] = w;
  15727. return this;
  15728. }
  15729. } );
  15730. /**
  15731. * @author simonThiele / https://github.com/simonThiele
  15732. * @author TristanVALCKE / https://github.com/Itee
  15733. */
  15734. /* global QUnit */
  15735. QUnit.module( 'Core', () => {
  15736. QUnit.module.todo( 'InterleavedBufferAttribute', () => {
  15737. // INSTANCING
  15738. QUnit.test( "Instancing", ( assert ) => {
  15739. assert.ok( false, "everything's gonna be alright" );
  15740. } );
  15741. // PROPERTIES
  15742. QUnit.test( "count", ( assert ) => {
  15743. var buffer = new InterleavedBuffer( new Float32Array( [ 1, 2, 3, 7, 8, 9 ] ), 3 );
  15744. var instance = new InterleavedBufferAttribute( buffer, 2, 0 );
  15745. assert.ok( instance.count === 2, "count is calculated via array length / stride" );
  15746. } );
  15747. QUnit.test( "array", ( assert ) => {
  15748. assert.ok( false, "everything's gonna be alright" );
  15749. } );
  15750. // PUBLIC STUFF
  15751. // setY, setZ and setW are calculated in the same way so not QUnit.testing this
  15752. // TODO: ( you can't be sure that will be the case in future, or a mistake was introduce in one off them ! )
  15753. QUnit.test( "setX", ( assert ) => {
  15754. var buffer = new InterleavedBuffer( new Float32Array( [ 1, 2, 3, 7, 8, 9 ] ), 3 );
  15755. var instance = new InterleavedBufferAttribute( buffer, 2, 0 );
  15756. instance.setX( 0, 123 );
  15757. instance.setX( 1, 321 );
  15758. assert.ok( instance.data.array[ 0 ] === 123 &&
  15759. instance.data.array[ 3 ] === 321, "x was calculated correct based on index and default offset" );
  15760. var buffer = new InterleavedBuffer( new Float32Array( [ 1, 2, 3, 7, 8, 9 ] ), 3 );
  15761. var instance = new InterleavedBufferAttribute( buffer, 2, 1 );
  15762. instance.setX( 0, 123 );
  15763. instance.setX( 1, 321 );
  15764. // the offset was defined as 1, so go one step futher in the array
  15765. assert.ok( instance.data.array[ 1 ] === 123 &&
  15766. instance.data.array[ 4 ] === 321, "x was calculated correct based on index and default offset" );
  15767. } );
  15768. QUnit.test( "setY", ( assert ) => {
  15769. assert.ok( false, "everything's gonna be alright" );
  15770. } );
  15771. QUnit.test( "setZ", ( assert ) => {
  15772. assert.ok( false, "everything's gonna be alright" );
  15773. } );
  15774. QUnit.test( "setW", ( assert ) => {
  15775. assert.ok( false, "everything's gonna be alright" );
  15776. } );
  15777. QUnit.test( "getX", ( assert ) => {
  15778. assert.ok( false, "everything's gonna be alright" );
  15779. } );
  15780. QUnit.test( "getY", ( assert ) => {
  15781. assert.ok( false, "everything's gonna be alright" );
  15782. } );
  15783. QUnit.test( "getZ", ( assert ) => {
  15784. assert.ok( false, "everything's gonna be alright" );
  15785. } );
  15786. QUnit.test( "getW", ( assert ) => {
  15787. assert.ok( false, "everything's gonna be alright" );
  15788. } );
  15789. QUnit.test( "setXY", ( assert ) => {
  15790. assert.ok( false, "everything's gonna be alright" );
  15791. } );
  15792. QUnit.test( "setXYZ", ( assert ) => {
  15793. assert.ok( false, "everything's gonna be alright" );
  15794. } );
  15795. QUnit.test( "setXYZW", ( assert ) => {
  15796. assert.ok( false, "everything's gonna be alright" );
  15797. } );
  15798. } );
  15799. } );
  15800. /**
  15801. * @author moraxy / https://github.com/moraxy
  15802. */
  15803. /* global QUnit */
  15804. QUnit.module( 'Core', () => {
  15805. QUnit.module.todo( 'Layers', () => {
  15806. // INSTANCING
  15807. QUnit.test( "Instancing", ( assert ) => {
  15808. assert.ok( false, "everything's gonna be alright" );
  15809. } );
  15810. // PUBLIC STUFF
  15811. QUnit.test( "set", ( assert ) => {
  15812. var a = new Layers();
  15813. a.set( 0 );
  15814. assert.strictEqual( a.mask, 1, "Set channel 0" );
  15815. a.set( 1 );
  15816. assert.strictEqual( a.mask, 2, "Set channel 1" );
  15817. a.set( 2 );
  15818. assert.strictEqual( a.mask, 4, "Set channel 2" );
  15819. } );
  15820. QUnit.test( "enable", ( assert ) => {
  15821. var a = new Layers();
  15822. a.set( 0 );
  15823. a.enable( 0 );
  15824. assert.strictEqual( a.mask, 1, "Enable channel 0 with mask 0" );
  15825. a.set( 0 );
  15826. a.enable( 1 );
  15827. assert.strictEqual( a.mask, 3, "Enable channel 1 with mask 0" );
  15828. a.set( 1 );
  15829. a.enable( 0 );
  15830. assert.strictEqual( a.mask, 3, "Enable channel 0 with mask 1" );
  15831. a.set( 1 );
  15832. a.enable( 1 );
  15833. assert.strictEqual( a.mask, 2, "Enable channel 1 with mask 1" );
  15834. } );
  15835. QUnit.test( "toggle", ( assert ) => {
  15836. var a = new Layers();
  15837. a.set( 0 );
  15838. a.toggle( 0 );
  15839. assert.strictEqual( a.mask, 0, "Toggle channel 0 with mask 0" );
  15840. a.set( 0 );
  15841. a.toggle( 1 );
  15842. assert.strictEqual( a.mask, 3, "Toggle channel 1 with mask 0" );
  15843. a.set( 1 );
  15844. a.toggle( 0 );
  15845. assert.strictEqual( a.mask, 3, "Toggle channel 0 with mask 1" );
  15846. a.set( 1 );
  15847. a.toggle( 1 );
  15848. assert.strictEqual( a.mask, 0, "Toggle channel 1 with mask 1" );
  15849. } );
  15850. QUnit.test( "disable", ( assert ) => {
  15851. var a = new Layers();
  15852. a.set( 0 );
  15853. a.disable( 0 );
  15854. assert.strictEqual( a.mask, 0, "Disable channel 0 with mask 0" );
  15855. a.set( 0 );
  15856. a.disable( 1 );
  15857. assert.strictEqual( a.mask, 1, "Disable channel 1 with mask 0" );
  15858. a.set( 1 );
  15859. a.disable( 0 );
  15860. assert.strictEqual( a.mask, 2, "Disable channel 0 with mask 1" );
  15861. a.set( 1 );
  15862. a.disable( 1 );
  15863. assert.strictEqual( a.mask, 0, "Disable channel 1 with mask 1" );
  15864. } );
  15865. QUnit.test( "test", ( assert ) => {
  15866. var a = new Layers();
  15867. var b = new Layers();
  15868. assert.ok( a.test( b ), "Start out true" );
  15869. a.set( 1 );
  15870. assert.notOk( a.test( b ), "Set channel 1 in a and fail the QUnit.test" );
  15871. b.toggle( 1 );
  15872. assert.ok( a.test( b ), "Toggle channel 1 in b and pass again" );
  15873. } );
  15874. } );
  15875. } );
  15876. /**
  15877. * @author simonThiele / https://github.com/simonThiele
  15878. * @author TristanVALCKE / https://github.com/Itee
  15879. */
  15880. /* global QUnit */
  15881. QUnit.module( 'Core', () => {
  15882. QUnit.module.todo( 'Object3D', () => {
  15883. var RadToDeg = 180 / Math.PI;
  15884. var eulerEquals = function ( a, b, tolerance ) {
  15885. tolerance = tolerance || 0.0001;
  15886. if ( a.order != b.order ) {
  15887. return false;
  15888. }
  15889. return (
  15890. Math.abs( a.x - b.x ) <= tolerance &&
  15891. Math.abs( a.y - b.y ) <= tolerance &&
  15892. Math.abs( a.z - b.z ) <= tolerance
  15893. );
  15894. };
  15895. // INHERITANCE
  15896. QUnit.test( "Extending", ( assert ) => {
  15897. assert.ok( false, "everything's gonna be alright" );
  15898. } );
  15899. // INSTANCING
  15900. QUnit.test( "Instancing", ( assert ) => {
  15901. assert.ok( false, "everything's gonna be alright" );
  15902. } );
  15903. // STATIC STUFF
  15904. QUnit.test( "DefaultUp", ( assert ) => {
  15905. assert.ok( false, "everything's gonna be alright" );
  15906. } );
  15907. QUnit.test( "DefaultMatrixAutoUpdate", ( assert ) => {
  15908. assert.ok( false, "everything's gonna be alright" );
  15909. } );
  15910. // PUBLIC STUFF
  15911. QUnit.test( "isObject3D", ( assert ) => {
  15912. assert.ok( false, "everything's gonna be alright" );
  15913. } );
  15914. QUnit.test( "onBeforeRender", ( assert ) => {
  15915. assert.ok( false, "everything's gonna be alright" );
  15916. } );
  15917. QUnit.test( "onAfterRender", ( assert ) => {
  15918. assert.ok( false, "everything's gonna be alright" );
  15919. } );
  15920. QUnit.test( "applyMatrix", ( assert ) => {
  15921. var a = new Object3D();
  15922. var m = new Matrix4();
  15923. var expectedPos = new Vector3( x, y, z );
  15924. var expectedQuat = new Quaternion( 0.5 * Math.sqrt( 2 ), 0, 0, 0.5 * Math.sqrt( 2 ) );
  15925. m.makeRotationX( Math.PI / 2 );
  15926. m.setPosition( new Vector3( x, y, z ) );
  15927. a.applyMatrix( m );
  15928. assert.deepEqual( a.position, expectedPos, "Position has the expected values" );
  15929. assert.ok(
  15930. Math.abs( a.quaternion.x - expectedQuat.x ) <= eps &&
  15931. Math.abs( a.quaternion.y - expectedQuat.y ) <= eps &&
  15932. Math.abs( a.quaternion.z - expectedQuat.z ) <= eps,
  15933. "Quaternion has the expected values"
  15934. );
  15935. } );
  15936. QUnit.test( "applyQuaternion", ( assert ) => {
  15937. var a = new Object3D();
  15938. var sqrt = 0.5 * Math.sqrt( 2 );
  15939. var quat = new Quaternion( 0, sqrt, 0, sqrt );
  15940. var expected = new Quaternion( sqrt / 2, sqrt / 2, 0, 0 );
  15941. a.quaternion.set( 0.25, 0.25, 0.25, 0.25 );
  15942. a.applyQuaternion( quat );
  15943. assert.ok(
  15944. Math.abs( a.quaternion.x - expected.x ) <= eps &&
  15945. Math.abs( a.quaternion.y - expected.y ) <= eps &&
  15946. Math.abs( a.quaternion.z - expected.z ) <= eps,
  15947. "Quaternion has the expected values"
  15948. );
  15949. } );
  15950. QUnit.test( "setRotationFromAxisAngle", ( assert ) => {
  15951. var a = new Object3D();
  15952. var axis = new Vector3( 0, 1, 0 );
  15953. var angle = Math.PI;
  15954. var expected = new Euler( - Math.PI, 0, - Math.PI );
  15955. a.setRotationFromAxisAngle( axis, angle );
  15956. assert.ok( eulerEquals( a.getWorldRotation(), expected ), "Correct values after rotation" );
  15957. axis.set( 1, 0, 0 );
  15958. var angle = 0;
  15959. expected.set( 0, 0, 0 );
  15960. a.setRotationFromAxisAngle( axis, angle );
  15961. assert.ok( eulerEquals( a.getWorldRotation(), expected ), "Correct values after zeroing" );
  15962. } );
  15963. QUnit.test( "setRotationFromEuler", ( assert ) => {
  15964. var a = new Object3D();
  15965. var rotation = new Euler( ( 45 / RadToDeg ), 0, Math.PI );
  15966. var expected = rotation.clone(); // bit obvious
  15967. a.setRotationFromEuler( rotation );
  15968. assert.ok( eulerEquals( a.getWorldRotation(), expected ), "Correct values after rotation" );
  15969. } );
  15970. QUnit.test( "setRotationFromMatrix", ( assert ) => {
  15971. var a = new Object3D();
  15972. var m = new Matrix4();
  15973. var eye = new Vector3( 0, 0, 0 );
  15974. var target = new Vector3( 0, 1, - 1 );
  15975. var up = new Vector3( 0, 1, 0 );
  15976. m.lookAt( eye, target, up );
  15977. a.setRotationFromMatrix( m );
  15978. assert.numEqual( a.getWorldRotation().x * RadToDeg, 45, "Correct rotation angle" );
  15979. } );
  15980. QUnit.test( "setRotationFromQuaternion", ( assert ) => {
  15981. var a = new Object3D();
  15982. var rotation = new Quaternion().setFromEuler( new Euler( Math.PI, 0, - Math.PI ) );
  15983. var expected = new Euler( Math.PI, 0, - Math.PI );
  15984. a.setRotationFromQuaternion( rotation );
  15985. assert.ok( eulerEquals( a.getWorldRotation(), expected ), "Correct values after rotation" );
  15986. } );
  15987. QUnit.test( "rotateOnAxis", ( assert ) => {
  15988. assert.ok( false, "everything's gonna be alright" );
  15989. } );
  15990. QUnit.test( "rotateOnWorldAxis", ( assert ) => {
  15991. assert.ok( false, "everything's gonna be alright" );
  15992. } );
  15993. QUnit.test( "rotateX", ( assert ) => {
  15994. var obj = new Object3D();
  15995. var angleInRad = 1.562;
  15996. obj.rotateX( angleInRad );
  15997. assert.numEqual( obj.rotation.x, angleInRad, "x is equal" );
  15998. } );
  15999. QUnit.test( "rotateY", ( assert ) => {
  16000. var obj = new Object3D();
  16001. var angleInRad = - 0.346;
  16002. obj.rotateY( angleInRad );
  16003. assert.numEqual( obj.rotation.y, angleInRad, "y is equal" );
  16004. } );
  16005. QUnit.test( "rotateZ", ( assert ) => {
  16006. var obj = new Object3D();
  16007. var angleInRad = 1;
  16008. obj.rotateZ( angleInRad );
  16009. assert.numEqual( obj.rotation.z, angleInRad, "z is equal" );
  16010. } );
  16011. QUnit.test( "translateOnAxis", ( assert ) => {
  16012. var obj = new Object3D();
  16013. obj.translateOnAxis( new Vector3( 1, 0, 0 ), 1 );
  16014. obj.translateOnAxis( new Vector3( 0, 1, 0 ), 1.23 );
  16015. obj.translateOnAxis( new Vector3( 0, 0, 1 ), - 4.56 );
  16016. assert.propEqual( obj.position, {
  16017. x: 1,
  16018. y: 1.23,
  16019. z: - 4.56
  16020. } );
  16021. } );
  16022. QUnit.test( "translateX", ( assert ) => {
  16023. var obj = new Object3D();
  16024. obj.translateX( 1.234 );
  16025. assert.numEqual( obj.position.x, 1.234, "x is equal" );
  16026. } );
  16027. QUnit.test( "translateY", ( assert ) => {
  16028. var obj = new Object3D();
  16029. obj.translateY( 1.234 );
  16030. assert.numEqual( obj.position.y, 1.234, "y is equal" );
  16031. } );
  16032. QUnit.test( "translateZ", ( assert ) => {
  16033. var obj = new Object3D();
  16034. obj.translateZ( 1.234 );
  16035. assert.numEqual( obj.position.z, 1.234, "z is equal" );
  16036. } );
  16037. QUnit.test( "localToWorld", ( assert ) => {
  16038. assert.ok( false, "everything's gonna be alright" );
  16039. } );
  16040. QUnit.test( "worldToLocal", ( assert ) => {
  16041. assert.ok( false, "everything's gonna be alright" );
  16042. } );
  16043. QUnit.test( "lookAt", ( assert ) => {
  16044. var obj = new Object3D();
  16045. obj.lookAt( new Vector3( 0, - 1, 1 ) );
  16046. assert.numEqual( obj.rotation.x * RadToDeg, 45, "x is equal" );
  16047. } );
  16048. QUnit.test( "add/remove", ( assert ) => {
  16049. var a = new Object3D();
  16050. var child1 = new Object3D();
  16051. var child2 = new Object3D();
  16052. assert.strictEqual( a.children.length, 0, "Starts with no children" );
  16053. a.add( child1 );
  16054. assert.strictEqual( a.children.length, 1, "The first child was added" );
  16055. assert.strictEqual( a.children[ 0 ], child1, "It's the right one" );
  16056. a.add( child2 );
  16057. assert.strictEqual( a.children.length, 2, "The second child was added" );
  16058. assert.strictEqual( a.children[ 1 ], child2, "It's the right one" );
  16059. assert.strictEqual( a.children[ 0 ], child1, "The first one is still there" );
  16060. a.remove( child1 );
  16061. assert.strictEqual( a.children.length, 1, "The first child was removed" );
  16062. assert.strictEqual( a.children[ 0 ], child2, "The second one is still there" );
  16063. a.add( child1 );
  16064. a.remove( child1, child2 );
  16065. assert.strictEqual( a.children.length, 0, "Both children were removed at once" );
  16066. child1.add( child2 );
  16067. assert.strictEqual( child1.children.length, 1, "The second child was added to the first one" );
  16068. a.add( child2 );
  16069. assert.strictEqual( a.children.length, 1, "The second one was added to the parent (no remove)" );
  16070. assert.strictEqual( a.children[ 0 ], child2, "The second one is now the parent's child again" );
  16071. assert.strictEqual( child1.children.length, 0, "The first one no longer has any children" );
  16072. } );
  16073. QUnit.test( "getObjectById/getObjectByName/getObjectByProperty", ( assert ) => {
  16074. var parent = new Object3D();
  16075. var childName = new Object3D();
  16076. var childId = new Object3D(); // id = parent.id + 2
  16077. var childNothing = new Object3D();
  16078. parent.prop = true;
  16079. childName.name = "foo";
  16080. parent.add( childName, childId, childNothing );
  16081. assert.strictEqual( parent.getObjectByProperty( 'prop', true ), parent, "Get parent by its own property" );
  16082. assert.strictEqual( parent.getObjectByName( "foo" ), childName, "Get child by name" );
  16083. assert.strictEqual( parent.getObjectById( parent.id + 2 ), childId, "Get child by Id" );
  16084. assert.strictEqual(
  16085. parent.getObjectByProperty( 'no-property', 'no-value' ), undefined,
  16086. "Unknown property results in undefined"
  16087. );
  16088. } );
  16089. QUnit.test( "getWorldPosition", ( assert ) => {
  16090. var a = new Object3D();
  16091. var b = new Object3D();
  16092. var expectedSingle = new Vector3( x, y, z );
  16093. var expectedParent = new Vector3( x, y, 0 );
  16094. var expectedChild = new Vector3( x, y, 7 + ( z - z ) );
  16095. a.translateX( x );
  16096. a.translateY( y );
  16097. a.translateZ( z );
  16098. assert.deepEqual(
  16099. a.getWorldPosition(), expectedSingle,
  16100. "WorldPosition as expected for single object"
  16101. );
  16102. // translate child and then parent
  16103. b.translateZ( 7 );
  16104. a.add( b );
  16105. a.translateZ( - z );
  16106. assert.deepEqual( a.getWorldPosition(), expectedParent, "WorldPosition as expected for parent" );
  16107. assert.deepEqual( b.getWorldPosition(), expectedChild, "WorldPosition as expected for child" );
  16108. } );
  16109. QUnit.test( "getWorldQuaternion", ( assert ) => {
  16110. assert.ok( false, "everything's gonna be alright" );
  16111. } );
  16112. QUnit.test( "getWorldRotation", ( assert ) => {
  16113. var obj = new Object3D();
  16114. obj.lookAt( new Vector3( 0, - 1, 1 ) );
  16115. assert.numEqual( obj.getWorldRotation().x * RadToDeg, 45, "x is equal" );
  16116. obj.lookAt( new Vector3( 1, 0, 0 ) );
  16117. assert.numEqual( obj.getWorldRotation().y * RadToDeg, 90, "y is equal" );
  16118. } );
  16119. QUnit.test( "getWorldScale", ( assert ) => {
  16120. var a = new Object3D();
  16121. var m = new Matrix4().makeScale( x, y, z );
  16122. var expected = new Vector3( x, y, z );
  16123. a.applyMatrix( m );
  16124. assert.deepEqual( a.getWorldScale(), expected, "WorldScale as expected" );
  16125. } );
  16126. QUnit.test( "getWorldDirection", ( assert ) => {
  16127. var a = new Object3D();
  16128. var expected = new Vector3( 0, - 0.5 * Math.sqrt( 2 ), 0.5 * Math.sqrt( 2 ) );
  16129. var dir;
  16130. a.lookAt( new Vector3( 0, - 1, 1 ) );
  16131. dir = a.getWorldDirection();
  16132. assert.ok(
  16133. Math.abs( dir.x - expected.x ) <= eps &&
  16134. Math.abs( dir.y - expected.y ) <= eps &&
  16135. Math.abs( dir.z - expected.z ) <= eps,
  16136. "Direction has the expected values"
  16137. );
  16138. } );
  16139. QUnit.test( "raycast", ( assert ) => {
  16140. assert.ok( false, "everything's gonna be alright" );
  16141. } );
  16142. QUnit.test( "traverse/traverseVisible/traverseAncestors", ( assert ) => {
  16143. var a = new Object3D();
  16144. var b = new Object3D();
  16145. var c = new Object3D();
  16146. var d = new Object3D();
  16147. var names = [];
  16148. var expectedNormal = [ "parent", "child", "childchild 1", "childchild 2" ];
  16149. var expectedVisible = [ "parent", "child", "childchild 2" ];
  16150. var expectedAncestors = [ "child", "parent" ];
  16151. a.name = "parent";
  16152. b.name = "child";
  16153. c.name = "childchild 1";
  16154. c.visible = false;
  16155. d.name = "childchild 2";
  16156. b.add( c );
  16157. b.add( d );
  16158. a.add( b );
  16159. a.traverse( function ( obj ) {
  16160. names.push( obj.name );
  16161. } );
  16162. assert.deepEqual( names, expectedNormal, "Traversed objects in expected order" );
  16163. var names = [];
  16164. a.traverseVisible( function ( obj ) {
  16165. names.push( obj.name );
  16166. } );
  16167. assert.deepEqual( names, expectedVisible, "Traversed visible objects in expected order" );
  16168. var names = [];
  16169. c.traverseAncestors( function ( obj ) {
  16170. names.push( obj.name );
  16171. } );
  16172. assert.deepEqual( names, expectedAncestors, "Traversed ancestors in expected order" );
  16173. } );
  16174. QUnit.test( "updateMatrix", ( assert ) => {
  16175. assert.ok( false, "everything's gonna be alright" );
  16176. } );
  16177. QUnit.test( "updateMatrixWorld", ( assert ) => {
  16178. assert.ok( false, "everything's gonna be alright" );
  16179. } );
  16180. QUnit.test( "toJSON", ( assert ) => {
  16181. var a = new Object3D();
  16182. var child = new Object3D();
  16183. var childChild = new Object3D();
  16184. a.name = "a's name";
  16185. a.matrix.set( 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 );
  16186. a.visible = false;
  16187. a.castShadow = true;
  16188. a.receiveShadow = true;
  16189. a.userData[ "foo" ] = "bar";
  16190. child.uuid = "5D4E9AE8-DA61-4912-A575-71A5BE3D72CD";
  16191. childChild.uuid = "B43854B3-E970-4E85-BD41-AAF8D7BFA189";
  16192. child.add( childChild );
  16193. a.add( child );
  16194. var gold = {
  16195. "metadata": {
  16196. "version": 4.5,
  16197. "type": "Object",
  16198. "generator": "Object3D.toJSON"
  16199. },
  16200. "object": {
  16201. "uuid": "0A1E4F43-CB5B-4097-8F82-DC2969C0B8C2",
  16202. "type": "Object3D",
  16203. "name": "a's name",
  16204. "castShadow": true,
  16205. "receiveShadow": true,
  16206. "visible": false,
  16207. "userData": { "foo": "bar" },
  16208. "matrix": [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ],
  16209. "children": [
  16210. {
  16211. "uuid": "5D4E9AE8-DA61-4912-A575-71A5BE3D72CD",
  16212. "type": "Object3D",
  16213. "matrix": [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ],
  16214. "children": [
  16215. {
  16216. "uuid": "B43854B3-E970-4E85-BD41-AAF8D7BFA189",
  16217. "type": "Object3D",
  16218. "matrix": [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]
  16219. }
  16220. ]
  16221. }
  16222. ]
  16223. }
  16224. };
  16225. // hacks
  16226. var out = a.toJSON();
  16227. out.object.uuid = "0A1E4F43-CB5B-4097-8F82-DC2969C0B8C2";
  16228. assert.deepEqual( out, gold, "JSON is as expected" );
  16229. } );
  16230. QUnit.test( "clone", ( assert ) => {
  16231. var a;
  16232. var b = new Object3D();
  16233. assert.strictEqual( a, undefined, "Undefined pre-clone()" );
  16234. a = b.clone();
  16235. assert.notStrictEqual( a, b, "Defined but seperate instances post-clone()" );
  16236. a.uuid = b.uuid;
  16237. assert.deepEqual( a, b, "But identical properties" );
  16238. } );
  16239. QUnit.test( "copy", ( assert ) => {
  16240. var a = new Object3D();
  16241. var b = new Object3D();
  16242. var child = new Object3D();
  16243. var childChild = new Object3D();
  16244. a.name = "original";
  16245. b.name = "to-be-copied";
  16246. b.position.set( x, y, z );
  16247. b.quaternion.set( x, y, z, w );
  16248. b.scale.set( 2, 3, 4 );
  16249. // bogus QUnit.test values
  16250. b.matrix.set( 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 );
  16251. b.matrixWorld.set( 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 );
  16252. b.matrixAutoUpdate = false;
  16253. b.matrixWorldNeedsUpdate = true;
  16254. b.layers.mask = 2;
  16255. b.visible = false;
  16256. b.castShadow = true;
  16257. b.receiveShadow = true;
  16258. b.frustumCulled = false;
  16259. b.renderOrder = 1;
  16260. b.userData[ "foo" ] = "bar";
  16261. child.add( childChild );
  16262. b.add( child );
  16263. assert.notDeepEqual( a, b, "Objects are not equal pre-copy()" );
  16264. a.copy( b, true );
  16265. // check they're all unique instances
  16266. assert.ok(
  16267. a.uuid !== b.uuid &&
  16268. a.children[ 0 ].uuid !== b.children[ 0 ].uuid &&
  16269. a.children[ 0 ].children[ 0 ].uuid !== b.children[ 0 ].children[ 0 ].uuid,
  16270. "UUIDs are all different"
  16271. );
  16272. // and now fix that
  16273. a.uuid = b.uuid;
  16274. a.children[ 0 ].uuid = b.children[ 0 ].uuid;
  16275. a.children[ 0 ].children[ 0 ].uuid = b.children[ 0 ].children[ 0 ].uuid;
  16276. assert.deepEqual( a, b, "Objects are equal post-copy()" );
  16277. } );
  16278. } );
  16279. } );
  16280. function Raycaster( origin, direction, near, far ) {
  16281. this.ray = new Ray( origin, direction );
  16282. // direction is assumed to be normalized (for accurate distance calculations)
  16283. this.near = near || 0;
  16284. this.far = far || Infinity;
  16285. this.params = {
  16286. Mesh: {},
  16287. Line: {},
  16288. LOD: {},
  16289. Points: { threshold: 1 },
  16290. Sprite: {}
  16291. };
  16292. Object.defineProperties( this.params, {
  16293. PointCloud: {
  16294. get: function () {
  16295. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  16296. return this.Points;
  16297. }
  16298. }
  16299. } );
  16300. }
  16301. function ascSort( a, b ) {
  16302. return a.distance - b.distance;
  16303. }
  16304. function intersectObject( object, raycaster, intersects, recursive ) {
  16305. if ( object.visible === false ) return;
  16306. object.raycast( raycaster, intersects );
  16307. if ( recursive === true ) {
  16308. var children = object.children;
  16309. for ( var i = 0, l = children.length; i < l; i ++ ) {
  16310. intersectObject( children[ i ], raycaster, intersects, true );
  16311. }
  16312. }
  16313. }
  16314. Object.assign( Raycaster.prototype, {
  16315. linePrecision: 1,
  16316. set: function ( origin, direction ) {
  16317. // direction is assumed to be normalized (for accurate distance calculations)
  16318. this.ray.set( origin, direction );
  16319. },
  16320. setFromCamera: function ( coords, camera ) {
  16321. if ( ( camera && camera.isPerspectiveCamera ) ) {
  16322. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  16323. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  16324. } else if ( ( camera && camera.isOrthographicCamera ) ) {
  16325. this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
  16326. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  16327. } else {
  16328. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  16329. }
  16330. },
  16331. intersectObject: function ( object, recursive ) {
  16332. var intersects = [];
  16333. intersectObject( object, this, intersects, recursive );
  16334. intersects.sort( ascSort );
  16335. return intersects;
  16336. },
  16337. intersectObjects: function ( objects, recursive ) {
  16338. var intersects = [];
  16339. if ( Array.isArray( objects ) === false ) {
  16340. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  16341. return intersects;
  16342. }
  16343. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  16344. intersectObject( objects[ i ], this, intersects, recursive );
  16345. }
  16346. intersects.sort( ascSort );
  16347. return intersects;
  16348. }
  16349. } );
  16350. /**
  16351. * @author mrdoob / http://mrdoob.com/
  16352. * @author benaadams / https://twitter.com/ben_a_adams
  16353. * @author Mugen87 / https://github.com/Mugen87
  16354. */
  16355. function SphereGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  16356. Geometry.call( this );
  16357. this.type = 'SphereGeometry';
  16358. this.parameters = {
  16359. radius: radius,
  16360. widthSegments: widthSegments,
  16361. heightSegments: heightSegments,
  16362. phiStart: phiStart,
  16363. phiLength: phiLength,
  16364. thetaStart: thetaStart,
  16365. thetaLength: thetaLength
  16366. };
  16367. this.fromBufferGeometry( new SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
  16368. this.mergeVertices();
  16369. }
  16370. SphereGeometry.prototype = Object.create( Geometry.prototype );
  16371. SphereGeometry.prototype.constructor = SphereGeometry;
  16372. // SphereBufferGeometry
  16373. function SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  16374. BufferGeometry.call( this );
  16375. this.type = 'SphereBufferGeometry';
  16376. this.parameters = {
  16377. radius: radius,
  16378. widthSegments: widthSegments,
  16379. heightSegments: heightSegments,
  16380. phiStart: phiStart,
  16381. phiLength: phiLength,
  16382. thetaStart: thetaStart,
  16383. thetaLength: thetaLength
  16384. };
  16385. radius = radius || 1;
  16386. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  16387. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  16388. phiStart = phiStart !== undefined ? phiStart : 0;
  16389. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  16390. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  16391. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  16392. var thetaEnd = thetaStart + thetaLength;
  16393. var ix, iy;
  16394. var index = 0;
  16395. var grid = [];
  16396. var vertex = new Vector3();
  16397. var normal = new Vector3();
  16398. // buffers
  16399. var indices = [];
  16400. var vertices = [];
  16401. var normals = [];
  16402. var uvs = [];
  16403. // generate vertices, normals and uvs
  16404. for ( iy = 0; iy <= heightSegments; iy ++ ) {
  16405. var verticesRow = [];
  16406. var v = iy / heightSegments;
  16407. for ( ix = 0; ix <= widthSegments; ix ++ ) {
  16408. var u = ix / widthSegments;
  16409. // vertex
  16410. vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  16411. vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
  16412. vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  16413. vertices.push( vertex.x, vertex.y, vertex.z );
  16414. // normal
  16415. normal.set( vertex.x, vertex.y, vertex.z ).normalize();
  16416. normals.push( normal.x, normal.y, normal.z );
  16417. // uv
  16418. uvs.push( u, 1 - v );
  16419. verticesRow.push( index ++ );
  16420. }
  16421. grid.push( verticesRow );
  16422. }
  16423. // indices
  16424. for ( iy = 0; iy < heightSegments; iy ++ ) {
  16425. for ( ix = 0; ix < widthSegments; ix ++ ) {
  16426. var a = grid[ iy ][ ix + 1 ];
  16427. var b = grid[ iy ][ ix ];
  16428. var c = grid[ iy + 1 ][ ix ];
  16429. var d = grid[ iy + 1 ][ ix + 1 ];
  16430. if ( iy !== 0 || thetaStart > 0 ) indices.push( a, b, d );
  16431. if ( iy !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( b, c, d );
  16432. }
  16433. }
  16434. // build geometry
  16435. this.setIndex( indices );
  16436. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16437. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16438. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16439. }
  16440. SphereBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16441. SphereBufferGeometry.prototype.constructor = SphereBufferGeometry;
  16442. /**
  16443. * @author simonThiele / https://github.com/simonThiele
  16444. */
  16445. /* global QUnit */
  16446. function checkRayDirectionAgainstReferenceVector( rayDirection, refVector, assert ) {
  16447. assert.ok( refVector.x - rayDirection.x <= Number.EPSILON && refVector.y - rayDirection.y <= Number.EPSILON && refVector.z - rayDirection.z <= Number.EPSILON, "camera is pointing to" +
  16448. " the same direction as expected" );
  16449. }
  16450. function getRaycaster() {
  16451. return new Raycaster(
  16452. new Vector3( 0, 0, 0 ),
  16453. new Vector3( 0, 0, - 1 ),
  16454. 1,
  16455. 100
  16456. );
  16457. }
  16458. function getObjectsToCheck() {
  16459. var objects = [];
  16460. var sphere1 = getSphere();
  16461. sphere1.position.set( 0, 0, - 10 );
  16462. sphere1.name = 1;
  16463. objects.push( sphere1 );
  16464. var sphere11 = getSphere();
  16465. sphere11.position.set( 0, 0, 1 );
  16466. sphere11.name = 11;
  16467. sphere1.add( sphere11 );
  16468. var sphere12 = getSphere();
  16469. sphere12.position.set( 0, 0, - 1 );
  16470. sphere12.name = 12;
  16471. sphere1.add( sphere12 );
  16472. var sphere2 = getSphere();
  16473. sphere2.position.set( - 5, 0, - 5 );
  16474. sphere2.name = 2;
  16475. objects.push( sphere2 );
  16476. for ( var i = 0; i < objects.length; i ++ ) {
  16477. objects[ i ].updateMatrixWorld();
  16478. }
  16479. return objects;
  16480. }
  16481. function getSphere() {
  16482. return new Mesh( new SphereGeometry( 1, 100, 100 ) );
  16483. }
  16484. QUnit.module( 'Core', () => {
  16485. QUnit.module.todo( 'Raycaster', () => {
  16486. // INSTANCING
  16487. QUnit.test( "Instancing", ( assert ) => {
  16488. assert.ok( false, "everything's gonna be alright" );
  16489. } );
  16490. // PUBLIC STUFF
  16491. QUnit.test( "linePrecision", ( assert ) => {
  16492. assert.ok( false, "everything's gonna be alright" );
  16493. } );
  16494. QUnit.test( "set", ( assert ) => {
  16495. var origin = new Vector3( 0, 0, 0 );
  16496. var direction = new Vector3( 0, 0, - 1 );
  16497. var a = new Raycaster( origin.clone(), direction.clone() );
  16498. assert.deepEqual( a.ray.origin, origin, "Origin is correct" );
  16499. assert.deepEqual( a.ray.direction, direction, "Direction is correct" );
  16500. origin.set( 1, 1, 1 );
  16501. direction.set( - 1, 0, 0 );
  16502. a.set( origin, direction );
  16503. assert.deepEqual( a.ray.origin, origin, "Origin was set correctly" );
  16504. assert.deepEqual( a.ray.direction, direction, "Direction was set correctly" );
  16505. } );
  16506. QUnit.test( "setFromCamera (Perspective)", ( assert ) => {
  16507. var raycaster = new Raycaster();
  16508. var rayDirection = raycaster.ray.direction;
  16509. var camera = new PerspectiveCamera( 90, 1, 1, 1000 );
  16510. raycaster.setFromCamera( {
  16511. x: 0,
  16512. y: 0
  16513. }, camera );
  16514. assert.ok( rayDirection.x === 0, rayDirection.y === 0, rayDirection.z === - 1,
  16515. "camera is looking straight to -z and so does the ray in the middle of the screen" );
  16516. var step = 0.1;
  16517. for ( var x = - 1; x <= 1; x += step ) {
  16518. for ( var y = - 1; y <= 1; y += step ) {
  16519. raycaster.setFromCamera( {
  16520. x,
  16521. y
  16522. }, camera );
  16523. var refVector = new Vector3( x, y, - 1 ).normalize();
  16524. checkRayDirectionAgainstReferenceVector( rayDirection, refVector, assert );
  16525. }
  16526. }
  16527. } );
  16528. QUnit.test( "setFromCamera (Orthographic)", ( assert ) => {
  16529. var raycaster = new Raycaster();
  16530. var rayOrigin = raycaster.ray.origin;
  16531. var rayDirection = raycaster.ray.direction;
  16532. var camera = new OrthographicCamera( - 1, 1, 1, - 1, 0, 1000 );
  16533. var expectedOrigin = new Vector3( 0, 0, 0 );
  16534. var expectedDirection = new Vector3( 0, 0, - 1 );
  16535. raycaster.setFromCamera( {
  16536. x: 0,
  16537. y: 0
  16538. }, camera );
  16539. assert.deepEqual( rayOrigin, expectedOrigin, "Ray origin has the right coordinates" );
  16540. assert.deepEqual( rayDirection, expectedDirection, "Camera and Ray are pointing towards -z" );
  16541. } );
  16542. QUnit.test( "intersectObject", ( assert ) => {
  16543. var raycaster = getRaycaster();
  16544. var objectsToCheck = getObjectsToCheck();
  16545. assert.ok( raycaster.intersectObject( objectsToCheck[ 0 ] ).length === 1,
  16546. "no recursive search should lead to one hit" );
  16547. assert.ok( raycaster.intersectObject( objectsToCheck[ 0 ], true ).length === 3,
  16548. "recursive search should lead to three hits" );
  16549. var intersections = raycaster.intersectObject( objectsToCheck[ 0 ], true );
  16550. for ( var i = 0; i < intersections.length - 1; i ++ ) {
  16551. assert.ok( intersections[ i ].distance <= intersections[ i + 1 ].distance, "intersections are sorted" );
  16552. }
  16553. } );
  16554. QUnit.test( "intersectObjects", ( assert ) => {
  16555. var raycaster = getRaycaster();
  16556. var objectsToCheck = getObjectsToCheck();
  16557. assert.ok( raycaster.intersectObjects( objectsToCheck ).length === 1,
  16558. "no recursive search should lead to one hit" );
  16559. assert.ok( raycaster.intersectObjects( objectsToCheck, true ).length === 3,
  16560. "recursive search should lead to three hits" );
  16561. var intersections = raycaster.intersectObjects( objectsToCheck, true );
  16562. for ( var i = 0; i < intersections.length - 1; i ++ ) {
  16563. assert.ok( intersections[ i ].distance <= intersections[ i + 1 ].distance, "intersections are sorted" );
  16564. }
  16565. } );
  16566. } );
  16567. } );
  16568. /**
  16569. * @author mrdoob / http://mrdoob.com/
  16570. */
  16571. function Uniform( value ) {
  16572. if ( typeof value === 'string' ) {
  16573. console.warn( 'THREE.Uniform: Type parameter is no longer needed.' );
  16574. value = arguments[ 1 ];
  16575. }
  16576. this.value = value;
  16577. }
  16578. Uniform.prototype.clone = function () {
  16579. return new Uniform( this.value.clone === undefined ? this.value : this.value.clone() );
  16580. };
  16581. /**
  16582. * @author moraxy / https://github.com/moraxy
  16583. */
  16584. /* global QUnit */
  16585. QUnit.module( 'Core', () => {
  16586. QUnit.module.todo( 'Uniform', () => {
  16587. // INSTANCING
  16588. QUnit.test( "Instancing", ( assert ) => {
  16589. var a;
  16590. var b = new Vector3( x, y, z );
  16591. a = new Uniform( 5 );
  16592. assert.strictEqual( a.value, 5, "New constructor works with simple values" );
  16593. a = new Uniform( b );
  16594. assert.ok( a.value.equals( b ), "New constructor works with complex values" );
  16595. } );
  16596. // PUBLIC STUFF
  16597. QUnit.test( "clone", ( assert ) => {
  16598. var a = new Uniform( 23 );
  16599. var b = a.clone();
  16600. assert.strictEqual( b.value, a.value, "clone() with simple values works" );
  16601. var a = new Uniform( new Vector3( 1, 2, 3 ) );
  16602. var b = a.clone();
  16603. assert.ok( b.value.equals( a.value ), "clone() with complex values works" );
  16604. } );
  16605. } );
  16606. } );
  16607. function Group() {
  16608. Object3D.call( this );
  16609. this.type = 'Group';
  16610. }
  16611. Group.prototype = Object.assign( Object.create( Object3D.prototype ), {
  16612. constructor: Group
  16613. } );
  16614. /**
  16615. * @author TristanVALCKE / https://github.com/Itee
  16616. */
  16617. /* global QUnit */
  16618. QUnit.module.todo( 'Extras', () => {
  16619. QUnit.module.todo( 'SceneUtils', () => {
  16620. // PUBLIC STUFF
  16621. QUnit.test( "createMultiMaterialObject", ( assert ) => {
  16622. assert.ok( false, "everything's gonna be alright" );
  16623. } );
  16624. QUnit.test( "detach", ( assert ) => {
  16625. assert.ok( false, "everything's gonna be alright" );
  16626. } );
  16627. QUnit.test( "attach", ( assert ) => {
  16628. assert.ok( false, "everything's gonna be alright" );
  16629. } );
  16630. } );
  16631. } );
  16632. /**
  16633. * @author zz85 / http://www.lab4games.net/zz85/blog
  16634. */
  16635. var ShapeUtils = {
  16636. // calculate area of the contour polygon
  16637. area: function ( contour ) {
  16638. var n = contour.length;
  16639. var a = 0.0;
  16640. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  16641. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  16642. }
  16643. return a * 0.5;
  16644. },
  16645. triangulate: ( function () {
  16646. /**
  16647. * This code is a quick port of code written in C++ which was submitted to
  16648. * flipcode.com by John W. Ratcliff // July 22, 2000
  16649. * See original code and more information here:
  16650. * http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml
  16651. *
  16652. * ported to actionscript by Zevan Rosser
  16653. * www.actionsnippet.com
  16654. *
  16655. * ported to javascript by Joshua Koo
  16656. * http://www.lab4games.net/zz85/blog
  16657. *
  16658. */
  16659. function snip( contour, u, v, w, n, verts ) {
  16660. var p;
  16661. var ax, ay, bx, by;
  16662. var cx, cy, px, py;
  16663. ax = contour[ verts[ u ] ].x;
  16664. ay = contour[ verts[ u ] ].y;
  16665. bx = contour[ verts[ v ] ].x;
  16666. by = contour[ verts[ v ] ].y;
  16667. cx = contour[ verts[ w ] ].x;
  16668. cy = contour[ verts[ w ] ].y;
  16669. if ( ( bx - ax ) * ( cy - ay ) - ( by - ay ) * ( cx - ax ) <= 0 ) return false;
  16670. var aX, aY, bX, bY, cX, cY;
  16671. var apx, apy, bpx, bpy, cpx, cpy;
  16672. var cCROSSap, bCROSScp, aCROSSbp;
  16673. aX = cx - bx; aY = cy - by;
  16674. bX = ax - cx; bY = ay - cy;
  16675. cX = bx - ax; cY = by - ay;
  16676. for ( p = 0; p < n; p ++ ) {
  16677. px = contour[ verts[ p ] ].x;
  16678. py = contour[ verts[ p ] ].y;
  16679. if ( ( ( px === ax ) && ( py === ay ) ) ||
  16680. ( ( px === bx ) && ( py === by ) ) ||
  16681. ( ( px === cx ) && ( py === cy ) ) ) continue;
  16682. apx = px - ax; apy = py - ay;
  16683. bpx = px - bx; bpy = py - by;
  16684. cpx = px - cx; cpy = py - cy;
  16685. // see if p is inside triangle abc
  16686. aCROSSbp = aX * bpy - aY * bpx;
  16687. cCROSSap = cX * apy - cY * apx;
  16688. bCROSScp = bX * cpy - bY * cpx;
  16689. if ( ( aCROSSbp >= - Number.EPSILON ) && ( bCROSScp >= - Number.EPSILON ) && ( cCROSSap >= - Number.EPSILON ) ) return false;
  16690. }
  16691. return true;
  16692. }
  16693. // takes in an contour array and returns
  16694. return function triangulate( contour, indices ) {
  16695. var n = contour.length;
  16696. if ( n < 3 ) return null;
  16697. var result = [],
  16698. verts = [],
  16699. vertIndices = [];
  16700. /* we want a counter-clockwise polygon in verts */
  16701. var u, v, w;
  16702. if ( ShapeUtils.area( contour ) > 0.0 ) {
  16703. for ( v = 0; v < n; v ++ ) verts[ v ] = v;
  16704. } else {
  16705. for ( v = 0; v < n; v ++ ) verts[ v ] = ( n - 1 ) - v;
  16706. }
  16707. var nv = n;
  16708. /* remove nv - 2 vertices, creating 1 triangle every time */
  16709. var count = 2 * nv; /* error detection */
  16710. for ( v = nv - 1; nv > 2; ) {
  16711. /* if we loop, it is probably a non-simple polygon */
  16712. if ( ( count -- ) <= 0 ) {
  16713. //** Triangulate: ERROR - probable bad polygon!
  16714. //throw ( "Warning, unable to triangulate polygon!" );
  16715. //return null;
  16716. // Sometimes warning is fine, especially polygons are triangulated in reverse.
  16717. console.warn( 'THREE.ShapeUtils: Unable to triangulate polygon! in triangulate()' );
  16718. if ( indices ) return vertIndices;
  16719. return result;
  16720. }
  16721. /* three consecutive vertices in current polygon, <u,v,w> */
  16722. u = v; if ( nv <= u ) u = 0; /* previous */
  16723. v = u + 1; if ( nv <= v ) v = 0; /* new v */
  16724. w = v + 1; if ( nv <= w ) w = 0; /* next */
  16725. if ( snip( contour, u, v, w, nv, verts ) ) {
  16726. var a, b, c, s, t;
  16727. /* true names of the vertices */
  16728. a = verts[ u ];
  16729. b = verts[ v ];
  16730. c = verts[ w ];
  16731. /* output Triangle */
  16732. result.push( [ contour[ a ],
  16733. contour[ b ],
  16734. contour[ c ] ] );
  16735. vertIndices.push( [ verts[ u ], verts[ v ], verts[ w ] ] );
  16736. /* remove v from the remaining polygon */
  16737. for ( s = v, t = v + 1; t < nv; s ++, t ++ ) {
  16738. verts[ s ] = verts[ t ];
  16739. }
  16740. nv --;
  16741. /* reset error detection counter */
  16742. count = 2 * nv;
  16743. }
  16744. }
  16745. if ( indices ) return vertIndices;
  16746. return result;
  16747. };
  16748. } )(),
  16749. triangulateShape: function ( contour, holes ) {
  16750. function removeDupEndPts( points ) {
  16751. var l = points.length;
  16752. if ( l > 2 && points[ l - 1 ].equals( points[ 0 ] ) ) {
  16753. points.pop();
  16754. }
  16755. }
  16756. removeDupEndPts( contour );
  16757. holes.forEach( removeDupEndPts );
  16758. function point_in_segment_2D_colin( inSegPt1, inSegPt2, inOtherPt ) {
  16759. // inOtherPt needs to be collinear to the inSegment
  16760. if ( inSegPt1.x !== inSegPt2.x ) {
  16761. if ( inSegPt1.x < inSegPt2.x ) {
  16762. return ( ( inSegPt1.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt2.x ) );
  16763. } else {
  16764. return ( ( inSegPt2.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt1.x ) );
  16765. }
  16766. } else {
  16767. if ( inSegPt1.y < inSegPt2.y ) {
  16768. return ( ( inSegPt1.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt2.y ) );
  16769. } else {
  16770. return ( ( inSegPt2.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt1.y ) );
  16771. }
  16772. }
  16773. }
  16774. function intersect_segments_2D( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1, inSeg2Pt2, inExcludeAdjacentSegs ) {
  16775. var seg1dx = inSeg1Pt2.x - inSeg1Pt1.x, seg1dy = inSeg1Pt2.y - inSeg1Pt1.y;
  16776. var seg2dx = inSeg2Pt2.x - inSeg2Pt1.x, seg2dy = inSeg2Pt2.y - inSeg2Pt1.y;
  16777. var seg1seg2dx = inSeg1Pt1.x - inSeg2Pt1.x;
  16778. var seg1seg2dy = inSeg1Pt1.y - inSeg2Pt1.y;
  16779. var limit = seg1dy * seg2dx - seg1dx * seg2dy;
  16780. var perpSeg1 = seg1dy * seg1seg2dx - seg1dx * seg1seg2dy;
  16781. if ( Math.abs( limit ) > Number.EPSILON ) {
  16782. // not parallel
  16783. var perpSeg2;
  16784. if ( limit > 0 ) {
  16785. if ( ( perpSeg1 < 0 ) || ( perpSeg1 > limit ) ) return [];
  16786. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  16787. if ( ( perpSeg2 < 0 ) || ( perpSeg2 > limit ) ) return [];
  16788. } else {
  16789. if ( ( perpSeg1 > 0 ) || ( perpSeg1 < limit ) ) return [];
  16790. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  16791. if ( ( perpSeg2 > 0 ) || ( perpSeg2 < limit ) ) return [];
  16792. }
  16793. // i.e. to reduce rounding errors
  16794. // intersection at endpoint of segment#1?
  16795. if ( perpSeg2 === 0 ) {
  16796. if ( ( inExcludeAdjacentSegs ) &&
  16797. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  16798. return [ inSeg1Pt1 ];
  16799. }
  16800. if ( perpSeg2 === limit ) {
  16801. if ( ( inExcludeAdjacentSegs ) &&
  16802. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  16803. return [ inSeg1Pt2 ];
  16804. }
  16805. // intersection at endpoint of segment#2?
  16806. if ( perpSeg1 === 0 ) return [ inSeg2Pt1 ];
  16807. if ( perpSeg1 === limit ) return [ inSeg2Pt2 ];
  16808. // return real intersection point
  16809. var factorSeg1 = perpSeg2 / limit;
  16810. return [ { x: inSeg1Pt1.x + factorSeg1 * seg1dx, y: inSeg1Pt1.y + factorSeg1 * seg1dy } ];
  16811. } else {
  16812. // parallel or collinear
  16813. if ( ( perpSeg1 !== 0 ) ||
  16814. ( seg2dy * seg1seg2dx !== seg2dx * seg1seg2dy ) ) return [];
  16815. // they are collinear or degenerate
  16816. var seg1Pt = ( ( seg1dx === 0 ) && ( seg1dy === 0 ) ); // segment1 is just a point?
  16817. var seg2Pt = ( ( seg2dx === 0 ) && ( seg2dy === 0 ) ); // segment2 is just a point?
  16818. // both segments are points
  16819. if ( seg1Pt && seg2Pt ) {
  16820. if ( ( inSeg1Pt1.x !== inSeg2Pt1.x ) ||
  16821. ( inSeg1Pt1.y !== inSeg2Pt1.y ) ) return []; // they are distinct points
  16822. return [ inSeg1Pt1 ]; // they are the same point
  16823. }
  16824. // segment#1 is a single point
  16825. if ( seg1Pt ) {
  16826. if ( ! point_in_segment_2D_colin( inSeg2Pt1, inSeg2Pt2, inSeg1Pt1 ) ) return []; // but not in segment#2
  16827. return [ inSeg1Pt1 ];
  16828. }
  16829. // segment#2 is a single point
  16830. if ( seg2Pt ) {
  16831. if ( ! point_in_segment_2D_colin( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1 ) ) return []; // but not in segment#1
  16832. return [ inSeg2Pt1 ];
  16833. }
  16834. // they are collinear segments, which might overlap
  16835. var seg1min, seg1max, seg1minVal, seg1maxVal;
  16836. var seg2min, seg2max, seg2minVal, seg2maxVal;
  16837. if ( seg1dx !== 0 ) {
  16838. // the segments are NOT on a vertical line
  16839. if ( inSeg1Pt1.x < inSeg1Pt2.x ) {
  16840. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.x;
  16841. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.x;
  16842. } else {
  16843. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.x;
  16844. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.x;
  16845. }
  16846. if ( inSeg2Pt1.x < inSeg2Pt2.x ) {
  16847. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.x;
  16848. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.x;
  16849. } else {
  16850. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.x;
  16851. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.x;
  16852. }
  16853. } else {
  16854. // the segments are on a vertical line
  16855. if ( inSeg1Pt1.y < inSeg1Pt2.y ) {
  16856. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.y;
  16857. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.y;
  16858. } else {
  16859. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.y;
  16860. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.y;
  16861. }
  16862. if ( inSeg2Pt1.y < inSeg2Pt2.y ) {
  16863. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.y;
  16864. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.y;
  16865. } else {
  16866. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.y;
  16867. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.y;
  16868. }
  16869. }
  16870. if ( seg1minVal <= seg2minVal ) {
  16871. if ( seg1maxVal < seg2minVal ) return [];
  16872. if ( seg1maxVal === seg2minVal ) {
  16873. if ( inExcludeAdjacentSegs ) return [];
  16874. return [ seg2min ];
  16875. }
  16876. if ( seg1maxVal <= seg2maxVal ) return [ seg2min, seg1max ];
  16877. return [ seg2min, seg2max ];
  16878. } else {
  16879. if ( seg1minVal > seg2maxVal ) return [];
  16880. if ( seg1minVal === seg2maxVal ) {
  16881. if ( inExcludeAdjacentSegs ) return [];
  16882. return [ seg1min ];
  16883. }
  16884. if ( seg1maxVal <= seg2maxVal ) return [ seg1min, seg1max ];
  16885. return [ seg1min, seg2max ];
  16886. }
  16887. }
  16888. }
  16889. function isPointInsideAngle( inVertex, inLegFromPt, inLegToPt, inOtherPt ) {
  16890. // The order of legs is important
  16891. // translation of all points, so that Vertex is at (0,0)
  16892. var legFromPtX = inLegFromPt.x - inVertex.x, legFromPtY = inLegFromPt.y - inVertex.y;
  16893. var legToPtX = inLegToPt.x - inVertex.x, legToPtY = inLegToPt.y - inVertex.y;
  16894. var otherPtX = inOtherPt.x - inVertex.x, otherPtY = inOtherPt.y - inVertex.y;
  16895. // main angle >0: < 180 deg.; 0: 180 deg.; <0: > 180 deg.
  16896. var from2toAngle = legFromPtX * legToPtY - legFromPtY * legToPtX;
  16897. var from2otherAngle = legFromPtX * otherPtY - legFromPtY * otherPtX;
  16898. if ( Math.abs( from2toAngle ) > Number.EPSILON ) {
  16899. // angle != 180 deg.
  16900. var other2toAngle = otherPtX * legToPtY - otherPtY * legToPtX;
  16901. // console.log( "from2to: " + from2toAngle + ", from2other: " + from2otherAngle + ", other2to: " + other2toAngle );
  16902. if ( from2toAngle > 0 ) {
  16903. // main angle < 180 deg.
  16904. return ( ( from2otherAngle >= 0 ) && ( other2toAngle >= 0 ) );
  16905. } else {
  16906. // main angle > 180 deg.
  16907. return ( ( from2otherAngle >= 0 ) || ( other2toAngle >= 0 ) );
  16908. }
  16909. } else {
  16910. // angle == 180 deg.
  16911. // console.log( "from2to: 180 deg., from2other: " + from2otherAngle );
  16912. return ( from2otherAngle > 0 );
  16913. }
  16914. }
  16915. function removeHoles( contour, holes ) {
  16916. var shape = contour.concat(); // work on this shape
  16917. var hole;
  16918. function isCutLineInsideAngles( inShapeIdx, inHoleIdx ) {
  16919. // Check if hole point lies within angle around shape point
  16920. var lastShapeIdx = shape.length - 1;
  16921. var prevShapeIdx = inShapeIdx - 1;
  16922. if ( prevShapeIdx < 0 ) prevShapeIdx = lastShapeIdx;
  16923. var nextShapeIdx = inShapeIdx + 1;
  16924. if ( nextShapeIdx > lastShapeIdx ) nextShapeIdx = 0;
  16925. var insideAngle = isPointInsideAngle( shape[ inShapeIdx ], shape[ prevShapeIdx ], shape[ nextShapeIdx ], hole[ inHoleIdx ] );
  16926. if ( ! insideAngle ) {
  16927. // console.log( "Vertex (Shape): " + inShapeIdx + ", Point: " + hole[inHoleIdx].x + "/" + hole[inHoleIdx].y );
  16928. return false;
  16929. }
  16930. // Check if shape point lies within angle around hole point
  16931. var lastHoleIdx = hole.length - 1;
  16932. var prevHoleIdx = inHoleIdx - 1;
  16933. if ( prevHoleIdx < 0 ) prevHoleIdx = lastHoleIdx;
  16934. var nextHoleIdx = inHoleIdx + 1;
  16935. if ( nextHoleIdx > lastHoleIdx ) nextHoleIdx = 0;
  16936. insideAngle = isPointInsideAngle( hole[ inHoleIdx ], hole[ prevHoleIdx ], hole[ nextHoleIdx ], shape[ inShapeIdx ] );
  16937. if ( ! insideAngle ) {
  16938. // console.log( "Vertex (Hole): " + inHoleIdx + ", Point: " + shape[inShapeIdx].x + "/" + shape[inShapeIdx].y );
  16939. return false;
  16940. }
  16941. return true;
  16942. }
  16943. function intersectsShapeEdge( inShapePt, inHolePt ) {
  16944. // checks for intersections with shape edges
  16945. var sIdx, nextIdx, intersection;
  16946. for ( sIdx = 0; sIdx < shape.length; sIdx ++ ) {
  16947. nextIdx = sIdx + 1; nextIdx %= shape.length;
  16948. intersection = intersect_segments_2D( inShapePt, inHolePt, shape[ sIdx ], shape[ nextIdx ], true );
  16949. if ( intersection.length > 0 ) return true;
  16950. }
  16951. return false;
  16952. }
  16953. var indepHoles = [];
  16954. function intersectsHoleEdge( inShapePt, inHolePt ) {
  16955. // checks for intersections with hole edges
  16956. var ihIdx, chkHole,
  16957. hIdx, nextIdx, intersection;
  16958. for ( ihIdx = 0; ihIdx < indepHoles.length; ihIdx ++ ) {
  16959. chkHole = holes[ indepHoles[ ihIdx ] ];
  16960. for ( hIdx = 0; hIdx < chkHole.length; hIdx ++ ) {
  16961. nextIdx = hIdx + 1; nextIdx %= chkHole.length;
  16962. intersection = intersect_segments_2D( inShapePt, inHolePt, chkHole[ hIdx ], chkHole[ nextIdx ], true );
  16963. if ( intersection.length > 0 ) return true;
  16964. }
  16965. }
  16966. return false;
  16967. }
  16968. var holeIndex, shapeIndex,
  16969. shapePt, holePt,
  16970. holeIdx, cutKey, failedCuts = [],
  16971. tmpShape1, tmpShape2,
  16972. tmpHole1, tmpHole2;
  16973. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  16974. indepHoles.push( h );
  16975. }
  16976. var minShapeIndex = 0;
  16977. var counter = indepHoles.length * 2;
  16978. while ( indepHoles.length > 0 ) {
  16979. counter --;
  16980. if ( counter < 0 ) {
  16981. console.log( 'THREE.ShapeUtils: Infinite Loop! Holes left:" + indepHoles.length + ", Probably Hole outside Shape!' );
  16982. break;
  16983. }
  16984. // search for shape-vertex and hole-vertex,
  16985. // which can be connected without intersections
  16986. for ( shapeIndex = minShapeIndex; shapeIndex < shape.length; shapeIndex ++ ) {
  16987. shapePt = shape[ shapeIndex ];
  16988. holeIndex = - 1;
  16989. // search for hole which can be reached without intersections
  16990. for ( var h = 0; h < indepHoles.length; h ++ ) {
  16991. holeIdx = indepHoles[ h ];
  16992. // prevent multiple checks
  16993. cutKey = shapePt.x + ':' + shapePt.y + ':' + holeIdx;
  16994. if ( failedCuts[ cutKey ] !== undefined ) continue;
  16995. hole = holes[ holeIdx ];
  16996. for ( var h2 = 0; h2 < hole.length; h2 ++ ) {
  16997. holePt = hole[ h2 ];
  16998. if ( ! isCutLineInsideAngles( shapeIndex, h2 ) ) continue;
  16999. if ( intersectsShapeEdge( shapePt, holePt ) ) continue;
  17000. if ( intersectsHoleEdge( shapePt, holePt ) ) continue;
  17001. holeIndex = h2;
  17002. indepHoles.splice( h, 1 );
  17003. tmpShape1 = shape.slice( 0, shapeIndex + 1 );
  17004. tmpShape2 = shape.slice( shapeIndex );
  17005. tmpHole1 = hole.slice( holeIndex );
  17006. tmpHole2 = hole.slice( 0, holeIndex + 1 );
  17007. shape = tmpShape1.concat( tmpHole1 ).concat( tmpHole2 ).concat( tmpShape2 );
  17008. minShapeIndex = shapeIndex;
  17009. // Debug only, to show the selected cuts
  17010. // glob_CutLines.push( [ shapePt, holePt ] );
  17011. break;
  17012. }
  17013. if ( holeIndex >= 0 ) break; // hole-vertex found
  17014. failedCuts[ cutKey ] = true; // remember failure
  17015. }
  17016. if ( holeIndex >= 0 ) break; // hole-vertex found
  17017. }
  17018. }
  17019. return shape; /* shape with no holes */
  17020. }
  17021. var i, il, f, face,
  17022. key, index,
  17023. allPointsMap = {};
  17024. // To maintain reference to old shape, one must match coordinates, or offset the indices from original arrays. It's probably easier to do the first.
  17025. var allpoints = contour.concat();
  17026. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  17027. Array.prototype.push.apply( allpoints, holes[ h ] );
  17028. }
  17029. //console.log( "allpoints",allpoints, allpoints.length );
  17030. // prepare all points map
  17031. for ( i = 0, il = allpoints.length; i < il; i ++ ) {
  17032. key = allpoints[ i ].x + ':' + allpoints[ i ].y;
  17033. if ( allPointsMap[ key ] !== undefined ) {
  17034. console.warn( 'THREE.ShapeUtils: Duplicate point', key, i );
  17035. }
  17036. allPointsMap[ key ] = i;
  17037. }
  17038. // remove holes by cutting paths to holes and adding them to the shape
  17039. var shapeWithoutHoles = removeHoles( contour, holes );
  17040. var triangles = ShapeUtils.triangulate( shapeWithoutHoles, false ); // True returns indices for points of spooled shape
  17041. //console.log( "triangles",triangles, triangles.length );
  17042. // check all face vertices against all points map
  17043. for ( i = 0, il = triangles.length; i < il; i ++ ) {
  17044. face = triangles[ i ];
  17045. for ( f = 0; f < 3; f ++ ) {
  17046. key = face[ f ].x + ':' + face[ f ].y;
  17047. index = allPointsMap[ key ];
  17048. if ( index !== undefined ) {
  17049. face[ f ] = index;
  17050. }
  17051. }
  17052. }
  17053. return triangles.concat();
  17054. },
  17055. isClockWise: function ( pts ) {
  17056. return ShapeUtils.area( pts ) < 0;
  17057. }
  17058. };
  17059. /**
  17060. * @author TristanVALCKE / https://github.com/Itee
  17061. */
  17062. /* global QUnit */
  17063. QUnit.module( 'Extras', () => {
  17064. QUnit.module.todo( 'ShapeUtils', () => {
  17065. // PUBLIC STUFF
  17066. QUnit.test( "area", ( assert ) => {
  17067. assert.ok( false, "everything's gonna be alright" );
  17068. } );
  17069. QUnit.test( "triangulate", ( assert ) => {
  17070. assert.ok( false, "everything's gonna be alright" );
  17071. } );
  17072. QUnit.test( "triangulateShape", ( assert ) => {
  17073. assert.ok( false, "everything's gonna be alright" );
  17074. } );
  17075. QUnit.test( "isClockWise", ( assert ) => {
  17076. assert.ok( false, "everything's gonna be alright" );
  17077. } );
  17078. } );
  17079. } );
  17080. function Curve() {
  17081. this.type = 'Curve';
  17082. this.arcLengthDivisions = 200;
  17083. }
  17084. Object.assign( Curve.prototype, {
  17085. // Virtual base class method to overwrite and implement in subclasses
  17086. // - t [0 .. 1]
  17087. getPoint: function ( /* t, optionalTarget */ ) {
  17088. console.warn( 'THREE.Curve: .getPoint() not implemented.' );
  17089. return null;
  17090. },
  17091. // Get point at relative position in curve according to arc length
  17092. // - u [0 .. 1]
  17093. getPointAt: function ( u, optionalTarget ) {
  17094. var t = this.getUtoTmapping( u );
  17095. return this.getPoint( t, optionalTarget );
  17096. },
  17097. // Get sequence of points using getPoint( t )
  17098. getPoints: function ( divisions ) {
  17099. if ( divisions === undefined ) divisions = 5;
  17100. var points = [];
  17101. for ( var d = 0; d <= divisions; d ++ ) {
  17102. points.push( this.getPoint( d / divisions ) );
  17103. }
  17104. return points;
  17105. },
  17106. // Get sequence of points using getPointAt( u )
  17107. getSpacedPoints: function ( divisions ) {
  17108. if ( divisions === undefined ) divisions = 5;
  17109. var points = [];
  17110. for ( var d = 0; d <= divisions; d ++ ) {
  17111. points.push( this.getPointAt( d / divisions ) );
  17112. }
  17113. return points;
  17114. },
  17115. // Get total curve arc length
  17116. getLength: function () {
  17117. var lengths = this.getLengths();
  17118. return lengths[ lengths.length - 1 ];
  17119. },
  17120. // Get list of cumulative segment lengths
  17121. getLengths: function ( divisions ) {
  17122. if ( divisions === undefined ) divisions = this.arcLengthDivisions;
  17123. if ( this.cacheArcLengths &&
  17124. ( this.cacheArcLengths.length === divisions + 1 ) &&
  17125. ! this.needsUpdate ) {
  17126. return this.cacheArcLengths;
  17127. }
  17128. this.needsUpdate = false;
  17129. var cache = [];
  17130. var current, last = this.getPoint( 0 );
  17131. var p, sum = 0;
  17132. cache.push( 0 );
  17133. for ( p = 1; p <= divisions; p ++ ) {
  17134. current = this.getPoint( p / divisions );
  17135. sum += current.distanceTo( last );
  17136. cache.push( sum );
  17137. last = current;
  17138. }
  17139. this.cacheArcLengths = cache;
  17140. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  17141. },
  17142. updateArcLengths: function () {
  17143. this.needsUpdate = true;
  17144. this.getLengths();
  17145. },
  17146. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  17147. getUtoTmapping: function ( u, distance ) {
  17148. var arcLengths = this.getLengths();
  17149. var i = 0, il = arcLengths.length;
  17150. var targetArcLength; // The targeted u distance value to get
  17151. if ( distance ) {
  17152. targetArcLength = distance;
  17153. } else {
  17154. targetArcLength = u * arcLengths[ il - 1 ];
  17155. }
  17156. // binary search for the index with largest value smaller than target u distance
  17157. var low = 0, high = il - 1, comparison;
  17158. while ( low <= high ) {
  17159. i = Math.floor( low + ( high - low ) / 2 ); // less likely to overflow, though probably not issue here, JS doesn't really have integers, all numbers are floats
  17160. comparison = arcLengths[ i ] - targetArcLength;
  17161. if ( comparison < 0 ) {
  17162. low = i + 1;
  17163. } else if ( comparison > 0 ) {
  17164. high = i - 1;
  17165. } else {
  17166. high = i;
  17167. break;
  17168. // DONE
  17169. }
  17170. }
  17171. i = high;
  17172. if ( arcLengths[ i ] === targetArcLength ) {
  17173. return i / ( il - 1 );
  17174. }
  17175. // we could get finer grain at lengths, or use simple interpolation between two points
  17176. var lengthBefore = arcLengths[ i ];
  17177. var lengthAfter = arcLengths[ i + 1 ];
  17178. var segmentLength = lengthAfter - lengthBefore;
  17179. // determine where we are between the 'before' and 'after' points
  17180. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  17181. // add that fractional amount to t
  17182. var t = ( i + segmentFraction ) / ( il - 1 );
  17183. return t;
  17184. },
  17185. // Returns a unit vector tangent at t
  17186. // In case any sub curve does not implement its tangent derivation,
  17187. // 2 points a small delta apart will be used to find its gradient
  17188. // which seems to give a reasonable approximation
  17189. getTangent: function ( t ) {
  17190. var delta = 0.0001;
  17191. var t1 = t - delta;
  17192. var t2 = t + delta;
  17193. // Capping in case of danger
  17194. if ( t1 < 0 ) t1 = 0;
  17195. if ( t2 > 1 ) t2 = 1;
  17196. var pt1 = this.getPoint( t1 );
  17197. var pt2 = this.getPoint( t2 );
  17198. var vec = pt2.clone().sub( pt1 );
  17199. return vec.normalize();
  17200. },
  17201. getTangentAt: function ( u ) {
  17202. var t = this.getUtoTmapping( u );
  17203. return this.getTangent( t );
  17204. },
  17205. computeFrenetFrames: function ( segments, closed ) {
  17206. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  17207. var normal = new Vector3();
  17208. var tangents = [];
  17209. var normals = [];
  17210. var binormals = [];
  17211. var vec = new Vector3();
  17212. var mat = new Matrix4();
  17213. var i, u, theta;
  17214. // compute the tangent vectors for each segment on the curve
  17215. for ( i = 0; i <= segments; i ++ ) {
  17216. u = i / segments;
  17217. tangents[ i ] = this.getTangentAt( u );
  17218. tangents[ i ].normalize();
  17219. }
  17220. // select an initial normal vector perpendicular to the first tangent vector,
  17221. // and in the direction of the minimum tangent xyz component
  17222. normals[ 0 ] = new Vector3();
  17223. binormals[ 0 ] = new Vector3();
  17224. var min = Number.MAX_VALUE;
  17225. var tx = Math.abs( tangents[ 0 ].x );
  17226. var ty = Math.abs( tangents[ 0 ].y );
  17227. var tz = Math.abs( tangents[ 0 ].z );
  17228. if ( tx <= min ) {
  17229. min = tx;
  17230. normal.set( 1, 0, 0 );
  17231. }
  17232. if ( ty <= min ) {
  17233. min = ty;
  17234. normal.set( 0, 1, 0 );
  17235. }
  17236. if ( tz <= min ) {
  17237. normal.set( 0, 0, 1 );
  17238. }
  17239. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  17240. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  17241. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  17242. // compute the slowly-varying normal and binormal vectors for each segment on the curve
  17243. for ( i = 1; i <= segments; i ++ ) {
  17244. normals[ i ] = normals[ i - 1 ].clone();
  17245. binormals[ i ] = binormals[ i - 1 ].clone();
  17246. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  17247. if ( vec.length() > Number.EPSILON ) {
  17248. vec.normalize();
  17249. theta = Math.acos( _Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  17250. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  17251. }
  17252. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  17253. }
  17254. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  17255. if ( closed === true ) {
  17256. theta = Math.acos( _Math.clamp( normals[ 0 ].dot( normals[ segments ] ), - 1, 1 ) );
  17257. theta /= segments;
  17258. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ segments ] ) ) > 0 ) {
  17259. theta = - theta;
  17260. }
  17261. for ( i = 1; i <= segments; i ++ ) {
  17262. // twist a little...
  17263. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  17264. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  17265. }
  17266. }
  17267. return {
  17268. tangents: tangents,
  17269. normals: normals,
  17270. binormals: binormals
  17271. };
  17272. },
  17273. clone: function () {
  17274. return new this.constructor().copy( this );
  17275. },
  17276. copy: function ( source ) {
  17277. this.arcLengthDivisions = source.arcLengthDivisions;
  17278. return this;
  17279. }
  17280. } );
  17281. /**
  17282. * @author TristanVALCKE / https://github.com/Itee
  17283. */
  17284. /* global QUnit */
  17285. QUnit.module( 'Extras', () => {
  17286. QUnit.module( 'Core', () => {
  17287. QUnit.module.todo( 'Curve', () => {
  17288. // INSTANCING
  17289. QUnit.test( "Instancing", ( assert ) => {
  17290. assert.ok( false, "everything's gonna be alright" );
  17291. } );
  17292. // PUBLIC STUFF
  17293. QUnit.test( "getPoint", ( assert ) => {
  17294. assert.ok( false, "everything's gonna be alright" );
  17295. } );
  17296. QUnit.test( "getPointAt", ( assert ) => {
  17297. assert.ok( false, "everything's gonna be alright" );
  17298. } );
  17299. QUnit.test( "getPoints", ( assert ) => {
  17300. assert.ok( false, "everything's gonna be alright" );
  17301. } );
  17302. QUnit.test( "getSpacedPoints", ( assert ) => {
  17303. assert.ok( false, "everything's gonna be alright" );
  17304. } );
  17305. QUnit.test( "getLength", ( assert ) => {
  17306. assert.ok( false, "everything's gonna be alright" );
  17307. } );
  17308. QUnit.test( "getLengths", ( assert ) => {
  17309. assert.ok( false, "everything's gonna be alright" );
  17310. } );
  17311. QUnit.test( "updateArcLengths", ( assert ) => {
  17312. assert.ok( false, "everything's gonna be alright" );
  17313. } );
  17314. QUnit.test( "getUtoTmapping", ( assert ) => {
  17315. assert.ok( false, "everything's gonna be alright" );
  17316. } );
  17317. QUnit.test( "getTangent", ( assert ) => {
  17318. assert.ok( false, "everything's gonna be alright" );
  17319. } );
  17320. QUnit.test( "getTangentAt", ( assert ) => {
  17321. assert.ok( false, "everything's gonna be alright" );
  17322. } );
  17323. QUnit.test( "computeFrenetFrames", ( assert ) => {
  17324. assert.ok( false, "everything's gonna be alright" );
  17325. } );
  17326. } );
  17327. } );
  17328. } );
  17329. function LineCurve( v1, v2 ) {
  17330. Curve.call( this );
  17331. this.type = 'LineCurve';
  17332. this.v1 = v1 || new Vector2();
  17333. this.v2 = v2 || new Vector2();
  17334. }
  17335. LineCurve.prototype = Object.create( Curve.prototype );
  17336. LineCurve.prototype.constructor = LineCurve;
  17337. LineCurve.prototype.isLineCurve = true;
  17338. LineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  17339. var point = optionalTarget || new Vector2();
  17340. if ( t === 1 ) {
  17341. point.copy( this.v2 );
  17342. } else {
  17343. point.copy( this.v2 ).sub( this.v1 );
  17344. point.multiplyScalar( t ).add( this.v1 );
  17345. }
  17346. return point;
  17347. };
  17348. // Line curve is linear, so we can overwrite default getPointAt
  17349. LineCurve.prototype.getPointAt = function ( u, optionalTarget ) {
  17350. return this.getPoint( u, optionalTarget );
  17351. };
  17352. LineCurve.prototype.getTangent = function ( /* t */ ) {
  17353. var tangent = this.v2.clone().sub( this.v1 );
  17354. return tangent.normalize();
  17355. };
  17356. LineCurve.prototype.copy = function ( source ) {
  17357. Curve.prototype.copy.call( this, source );
  17358. this.v1.copy( source.v1 );
  17359. this.v2.copy( source.v2 );
  17360. return this;
  17361. };
  17362. function CurvePath() {
  17363. Curve.call( this );
  17364. this.type = 'CurvePath';
  17365. this.curves = [];
  17366. this.autoClose = false; // Automatically closes the path
  17367. }
  17368. CurvePath.prototype = Object.assign( Object.create( Curve.prototype ), {
  17369. constructor: CurvePath,
  17370. add: function ( curve ) {
  17371. this.curves.push( curve );
  17372. },
  17373. closePath: function () {
  17374. // Add a line curve if start and end of lines are not connected
  17375. var startPoint = this.curves[ 0 ].getPoint( 0 );
  17376. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  17377. if ( ! startPoint.equals( endPoint ) ) {
  17378. this.curves.push( new LineCurve( endPoint, startPoint ) );
  17379. }
  17380. },
  17381. // To get accurate point with reference to
  17382. // entire path distance at time t,
  17383. // following has to be done:
  17384. // 1. Length of each sub path have to be known
  17385. // 2. Locate and identify type of curve
  17386. // 3. Get t for the curve
  17387. // 4. Return curve.getPointAt(t')
  17388. getPoint: function ( t ) {
  17389. var d = t * this.getLength();
  17390. var curveLengths = this.getCurveLengths();
  17391. var i = 0;
  17392. // To think about boundaries points.
  17393. while ( i < curveLengths.length ) {
  17394. if ( curveLengths[ i ] >= d ) {
  17395. var diff = curveLengths[ i ] - d;
  17396. var curve = this.curves[ i ];
  17397. var segmentLength = curve.getLength();
  17398. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  17399. return curve.getPointAt( u );
  17400. }
  17401. i ++;
  17402. }
  17403. return null;
  17404. // loop where sum != 0, sum > d , sum+1 <d
  17405. },
  17406. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  17407. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  17408. // getPoint() depends on getLength
  17409. getLength: function () {
  17410. var lens = this.getCurveLengths();
  17411. return lens[ lens.length - 1 ];
  17412. },
  17413. // cacheLengths must be recalculated.
  17414. updateArcLengths: function () {
  17415. this.needsUpdate = true;
  17416. this.cacheLengths = null;
  17417. this.getCurveLengths();
  17418. },
  17419. // Compute lengths and cache them
  17420. // We cannot overwrite getLengths() because UtoT mapping uses it.
  17421. getCurveLengths: function () {
  17422. // We use cache values if curves and cache array are same length
  17423. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  17424. return this.cacheLengths;
  17425. }
  17426. // Get length of sub-curve
  17427. // Push sums into cached array
  17428. var lengths = [], sums = 0;
  17429. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  17430. sums += this.curves[ i ].getLength();
  17431. lengths.push( sums );
  17432. }
  17433. this.cacheLengths = lengths;
  17434. return lengths;
  17435. },
  17436. getSpacedPoints: function ( divisions ) {
  17437. if ( divisions === undefined ) divisions = 40;
  17438. var points = [];
  17439. for ( var i = 0; i <= divisions; i ++ ) {
  17440. points.push( this.getPoint( i / divisions ) );
  17441. }
  17442. if ( this.autoClose ) {
  17443. points.push( points[ 0 ] );
  17444. }
  17445. return points;
  17446. },
  17447. getPoints: function ( divisions ) {
  17448. divisions = divisions || 12;
  17449. var points = [], last;
  17450. for ( var i = 0, curves = this.curves; i < curves.length; i ++ ) {
  17451. var curve = curves[ i ];
  17452. var resolution = ( curve && curve.isEllipseCurve ) ? divisions * 2
  17453. : ( curve && curve.isLineCurve ) ? 1
  17454. : ( curve && curve.isSplineCurve ) ? divisions * curve.points.length
  17455. : divisions;
  17456. var pts = curve.getPoints( resolution );
  17457. for ( var j = 0; j < pts.length; j ++ ) {
  17458. var point = pts[ j ];
  17459. if ( last && last.equals( point ) ) continue; // ensures no consecutive points are duplicates
  17460. points.push( point );
  17461. last = point;
  17462. }
  17463. }
  17464. if ( this.autoClose && points.length > 1 && ! points[ points.length - 1 ].equals( points[ 0 ] ) ) {
  17465. points.push( points[ 0 ] );
  17466. }
  17467. return points;
  17468. }
  17469. } );
  17470. /**
  17471. * @author TristanVALCKE / https://github.com/Itee
  17472. */
  17473. /* global QUnit */
  17474. QUnit.module( 'Extras', () => {
  17475. QUnit.module( 'Core', () => {
  17476. QUnit.module.todo( 'CurvePath', () => {
  17477. // INHERITANCE
  17478. QUnit.test( "Extending", ( assert ) => {
  17479. assert.ok( false, "everything's gonna be alright" );
  17480. } );
  17481. // INSTANCING
  17482. QUnit.test( "Instancing", ( assert ) => {
  17483. assert.ok( false, "everything's gonna be alright" );
  17484. } );
  17485. // PUBLIC STUFF
  17486. QUnit.test( "add", ( assert ) => {
  17487. assert.ok( false, "everything's gonna be alright" );
  17488. } );
  17489. QUnit.test( "closePath", ( assert ) => {
  17490. assert.ok( false, "everything's gonna be alright" );
  17491. } );
  17492. QUnit.test( "getPoint", ( assert ) => {
  17493. assert.ok( false, "everything's gonna be alright" );
  17494. } );
  17495. QUnit.test( "getLength", ( assert ) => {
  17496. assert.ok( false, "everything's gonna be alright" );
  17497. } );
  17498. QUnit.test( "updateArcLengths", ( assert ) => {
  17499. assert.ok( false, "everything's gonna be alright" );
  17500. } );
  17501. QUnit.test( "getCurveLengths", ( assert ) => {
  17502. assert.ok( false, "everything's gonna be alright" );
  17503. } );
  17504. QUnit.test( "getSpacedPoints", ( assert ) => {
  17505. assert.ok( false, "everything's gonna be alright" );
  17506. } );
  17507. QUnit.test( "getPoints", ( assert ) => {
  17508. assert.ok( false, "everything's gonna be alright" );
  17509. } );
  17510. QUnit.test( "createPointsGeometry", ( assert ) => {
  17511. assert.ok( false, "everything's gonna be alright" );
  17512. } );
  17513. QUnit.test( "createSpacedPointsGeometry", ( assert ) => {
  17514. assert.ok( false, "everything's gonna be alright" );
  17515. } );
  17516. QUnit.test( "createGeometry", ( assert ) => {
  17517. assert.ok( false, "everything's gonna be alright" );
  17518. } );
  17519. } );
  17520. } );
  17521. } );
  17522. /**
  17523. * @author zz85 / http://www.lab4games.net/zz85/blog
  17524. *
  17525. * Bezier Curves formulas obtained from
  17526. * http://en.wikipedia.org/wiki/Bézier_curve
  17527. */
  17528. function CatmullRom( t, p0, p1, p2, p3 ) {
  17529. var v0 = ( p2 - p0 ) * 0.5;
  17530. var v1 = ( p3 - p1 ) * 0.5;
  17531. var t2 = t * t;
  17532. var t3 = t * t2;
  17533. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  17534. }
  17535. //
  17536. function QuadraticBezierP0( t, p ) {
  17537. var k = 1 - t;
  17538. return k * k * p;
  17539. }
  17540. function QuadraticBezierP1( t, p ) {
  17541. return 2 * ( 1 - t ) * t * p;
  17542. }
  17543. function QuadraticBezierP2( t, p ) {
  17544. return t * t * p;
  17545. }
  17546. function QuadraticBezier( t, p0, p1, p2 ) {
  17547. return QuadraticBezierP0( t, p0 ) + QuadraticBezierP1( t, p1 ) +
  17548. QuadraticBezierP2( t, p2 );
  17549. }
  17550. //
  17551. function CubicBezierP0( t, p ) {
  17552. var k = 1 - t;
  17553. return k * k * k * p;
  17554. }
  17555. function CubicBezierP1( t, p ) {
  17556. var k = 1 - t;
  17557. return 3 * k * k * t * p;
  17558. }
  17559. function CubicBezierP2( t, p ) {
  17560. return 3 * ( 1 - t ) * t * t * p;
  17561. }
  17562. function CubicBezierP3( t, p ) {
  17563. return t * t * t * p;
  17564. }
  17565. function CubicBezier( t, p0, p1, p2, p3 ) {
  17566. return CubicBezierP0( t, p0 ) + CubicBezierP1( t, p1 ) + CubicBezierP2( t, p2 ) +
  17567. CubicBezierP3( t, p3 );
  17568. }
  17569. function EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  17570. Curve.call( this );
  17571. this.type = 'EllipseCurve';
  17572. this.aX = aX || 0;
  17573. this.aY = aY || 0;
  17574. this.xRadius = xRadius || 1;
  17575. this.yRadius = yRadius || 1;
  17576. this.aStartAngle = aStartAngle || 0;
  17577. this.aEndAngle = aEndAngle || 2 * Math.PI;
  17578. this.aClockwise = aClockwise || false;
  17579. this.aRotation = aRotation || 0;
  17580. }
  17581. EllipseCurve.prototype = Object.create( Curve.prototype );
  17582. EllipseCurve.prototype.constructor = EllipseCurve;
  17583. EllipseCurve.prototype.isEllipseCurve = true;
  17584. EllipseCurve.prototype.getPoint = function ( t, optionalTarget ) {
  17585. var point = optionalTarget || new Vector2();
  17586. var twoPi = Math.PI * 2;
  17587. var deltaAngle = this.aEndAngle - this.aStartAngle;
  17588. var samePoints = Math.abs( deltaAngle ) < Number.EPSILON;
  17589. // ensures that deltaAngle is 0 .. 2 PI
  17590. while ( deltaAngle < 0 ) deltaAngle += twoPi;
  17591. while ( deltaAngle > twoPi ) deltaAngle -= twoPi;
  17592. if ( deltaAngle < Number.EPSILON ) {
  17593. if ( samePoints ) {
  17594. deltaAngle = 0;
  17595. } else {
  17596. deltaAngle = twoPi;
  17597. }
  17598. }
  17599. if ( this.aClockwise === true && ! samePoints ) {
  17600. if ( deltaAngle === twoPi ) {
  17601. deltaAngle = - twoPi;
  17602. } else {
  17603. deltaAngle = deltaAngle - twoPi;
  17604. }
  17605. }
  17606. var angle = this.aStartAngle + t * deltaAngle;
  17607. var x = this.aX + this.xRadius * Math.cos( angle );
  17608. var y = this.aY + this.yRadius * Math.sin( angle );
  17609. if ( this.aRotation !== 0 ) {
  17610. var cos = Math.cos( this.aRotation );
  17611. var sin = Math.sin( this.aRotation );
  17612. var tx = x - this.aX;
  17613. var ty = y - this.aY;
  17614. // Rotate the point about the center of the ellipse.
  17615. x = tx * cos - ty * sin + this.aX;
  17616. y = tx * sin + ty * cos + this.aY;
  17617. }
  17618. return point.set( x, y );
  17619. };
  17620. EllipseCurve.prototype.copy = function ( source ) {
  17621. Curve.prototype.copy.call( this, source );
  17622. this.aX = source.aX;
  17623. this.aY = source.aY;
  17624. this.xRadius = source.xRadius;
  17625. this.yRadius = source.yRadius;
  17626. this.aStartAngle = source.aStartAngle;
  17627. this.aEndAngle = source.aEndAngle;
  17628. this.aClockwise = source.aClockwise;
  17629. this.aRotation = source.aRotation;
  17630. return this;
  17631. };
  17632. function SplineCurve( points /* array of Vector2 */ ) {
  17633. Curve.call( this );
  17634. this.type = 'SplineCurve';
  17635. this.points = points || [];
  17636. }
  17637. SplineCurve.prototype = Object.create( Curve.prototype );
  17638. SplineCurve.prototype.constructor = SplineCurve;
  17639. SplineCurve.prototype.isSplineCurve = true;
  17640. SplineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  17641. var point = optionalTarget || new Vector2();
  17642. var points = this.points;
  17643. var p = ( points.length - 1 ) * t;
  17644. var intPoint = Math.floor( p );
  17645. var weight = p - intPoint;
  17646. var p0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  17647. var p1 = points[ intPoint ];
  17648. var p2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  17649. var p3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  17650. point.set(
  17651. CatmullRom( weight, p0.x, p1.x, p2.x, p3.x ),
  17652. CatmullRom( weight, p0.y, p1.y, p2.y, p3.y )
  17653. );
  17654. return point;
  17655. };
  17656. SplineCurve.prototype.copy = function ( source ) {
  17657. Curve.prototype.copy.call( this, source );
  17658. this.points = [];
  17659. for ( var i = 0, l = source.points.length; i < l; i ++ ) {
  17660. var point = source.points[ i ];
  17661. this.points.push( point.clone() );
  17662. }
  17663. return this;
  17664. };
  17665. function CubicBezierCurve( v0, v1, v2, v3 ) {
  17666. Curve.call( this );
  17667. this.type = 'CubicBezierCurve';
  17668. this.v0 = v0 || new Vector2();
  17669. this.v1 = v1 || new Vector2();
  17670. this.v2 = v2 || new Vector2();
  17671. this.v3 = v3 || new Vector2();
  17672. }
  17673. CubicBezierCurve.prototype = Object.create( Curve.prototype );
  17674. CubicBezierCurve.prototype.constructor = CubicBezierCurve;
  17675. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  17676. CubicBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  17677. var point = optionalTarget || new Vector2();
  17678. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  17679. point.set(
  17680. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  17681. CubicBezier( t, v0.y, v1.y, v2.y, v3.y )
  17682. );
  17683. return point;
  17684. };
  17685. CubicBezierCurve.prototype.copy = function ( source ) {
  17686. Curve.prototype.copy.call( this, source );
  17687. this.v0.copy( source.v0 );
  17688. this.v1.copy( source.v1 );
  17689. this.v2.copy( source.v2 );
  17690. this.v3.copy( source.v3 );
  17691. return this;
  17692. };
  17693. function QuadraticBezierCurve( v0, v1, v2 ) {
  17694. Curve.call( this );
  17695. this.type = 'QuadraticBezierCurve';
  17696. this.v0 = v0 || new Vector2();
  17697. this.v1 = v1 || new Vector2();
  17698. this.v2 = v2 || new Vector2();
  17699. }
  17700. QuadraticBezierCurve.prototype = Object.create( Curve.prototype );
  17701. QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
  17702. QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
  17703. QuadraticBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  17704. var point = optionalTarget || new Vector2();
  17705. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  17706. point.set(
  17707. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  17708. QuadraticBezier( t, v0.y, v1.y, v2.y )
  17709. );
  17710. return point;
  17711. };
  17712. QuadraticBezierCurve.prototype.copy = function ( source ) {
  17713. Curve.prototype.copy.call( this, source );
  17714. this.v0.copy( source.v0 );
  17715. this.v1.copy( source.v1 );
  17716. this.v2.copy( source.v2 );
  17717. return this;
  17718. };
  17719. var PathPrototype = Object.assign( Object.create( CurvePath.prototype ), {
  17720. fromPoints: function ( vectors ) {
  17721. this.moveTo( vectors[ 0 ].x, vectors[ 0 ].y );
  17722. for ( var i = 1, l = vectors.length; i < l; i ++ ) {
  17723. this.lineTo( vectors[ i ].x, vectors[ i ].y );
  17724. }
  17725. },
  17726. moveTo: function ( x, y ) {
  17727. this.currentPoint.set( x, y ); // TODO consider referencing vectors instead of copying?
  17728. },
  17729. lineTo: function ( x, y ) {
  17730. var curve = new LineCurve( this.currentPoint.clone(), new Vector2( x, y ) );
  17731. this.curves.push( curve );
  17732. this.currentPoint.set( x, y );
  17733. },
  17734. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  17735. var curve = new QuadraticBezierCurve(
  17736. this.currentPoint.clone(),
  17737. new Vector2( aCPx, aCPy ),
  17738. new Vector2( aX, aY )
  17739. );
  17740. this.curves.push( curve );
  17741. this.currentPoint.set( aX, aY );
  17742. },
  17743. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  17744. var curve = new CubicBezierCurve(
  17745. this.currentPoint.clone(),
  17746. new Vector2( aCP1x, aCP1y ),
  17747. new Vector2( aCP2x, aCP2y ),
  17748. new Vector2( aX, aY )
  17749. );
  17750. this.curves.push( curve );
  17751. this.currentPoint.set( aX, aY );
  17752. },
  17753. splineThru: function ( pts /*Array of Vector*/ ) {
  17754. var npts = [ this.currentPoint.clone() ].concat( pts );
  17755. var curve = new SplineCurve( npts );
  17756. this.curves.push( curve );
  17757. this.currentPoint.copy( pts[ pts.length - 1 ] );
  17758. },
  17759. arc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  17760. var x0 = this.currentPoint.x;
  17761. var y0 = this.currentPoint.y;
  17762. this.absarc( aX + x0, aY + y0, aRadius,
  17763. aStartAngle, aEndAngle, aClockwise );
  17764. },
  17765. absarc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  17766. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  17767. },
  17768. ellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  17769. var x0 = this.currentPoint.x;
  17770. var y0 = this.currentPoint.y;
  17771. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  17772. },
  17773. absellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  17774. var curve = new EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  17775. if ( this.curves.length > 0 ) {
  17776. // if a previous curve is present, attempt to join
  17777. var firstPoint = curve.getPoint( 0 );
  17778. if ( ! firstPoint.equals( this.currentPoint ) ) {
  17779. this.lineTo( firstPoint.x, firstPoint.y );
  17780. }
  17781. }
  17782. this.curves.push( curve );
  17783. var lastPoint = curve.getPoint( 1 );
  17784. this.currentPoint.copy( lastPoint );
  17785. }
  17786. } );
  17787. /**
  17788. * @author zz85 / http://www.lab4games.net/zz85/blog
  17789. * Creates free form 2d path using series of points, lines or curves.
  17790. **/
  17791. function Path( points ) {
  17792. CurvePath.call( this );
  17793. this.type = 'Path';
  17794. this.currentPoint = new Vector2();
  17795. if ( points ) {
  17796. this.fromPoints( points );
  17797. }
  17798. }
  17799. Path.prototype = PathPrototype;
  17800. PathPrototype.constructor = Path;
  17801. function Shape() {
  17802. Path.apply( this, arguments );
  17803. this.type = 'Shape';
  17804. this.holes = [];
  17805. }
  17806. Shape.prototype = Object.assign( Object.create( PathPrototype ), {
  17807. constructor: Shape,
  17808. getPointsHoles: function ( divisions ) {
  17809. var holesPts = [];
  17810. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  17811. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  17812. }
  17813. return holesPts;
  17814. },
  17815. // Get points of shape and holes (keypoints based on segments parameter)
  17816. extractAllPoints: function ( divisions ) {
  17817. return {
  17818. shape: this.getPoints( divisions ),
  17819. holes: this.getPointsHoles( divisions )
  17820. };
  17821. },
  17822. extractPoints: function ( divisions ) {
  17823. return this.extractAllPoints( divisions );
  17824. }
  17825. } );
  17826. function ShapePath() {
  17827. this.type = 'ShapePath';
  17828. this.subPaths = [];
  17829. this.currentPath = null;
  17830. }
  17831. Object.assign( ShapePath.prototype, {
  17832. moveTo: function ( x, y ) {
  17833. this.currentPath = new Path();
  17834. this.subPaths.push( this.currentPath );
  17835. this.currentPath.moveTo( x, y );
  17836. },
  17837. lineTo: function ( x, y ) {
  17838. this.currentPath.lineTo( x, y );
  17839. },
  17840. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  17841. this.currentPath.quadraticCurveTo( aCPx, aCPy, aX, aY );
  17842. },
  17843. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  17844. this.currentPath.bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY );
  17845. },
  17846. splineThru: function ( pts ) {
  17847. this.currentPath.splineThru( pts );
  17848. },
  17849. toShapes: function ( isCCW, noHoles ) {
  17850. function toShapesNoHoles( inSubpaths ) {
  17851. var shapes = [];
  17852. for ( var i = 0, l = inSubpaths.length; i < l; i ++ ) {
  17853. var tmpPath = inSubpaths[ i ];
  17854. var tmpShape = new Shape();
  17855. tmpShape.curves = tmpPath.curves;
  17856. shapes.push( tmpShape );
  17857. }
  17858. return shapes;
  17859. }
  17860. function isPointInsidePolygon( inPt, inPolygon ) {
  17861. var polyLen = inPolygon.length;
  17862. // inPt on polygon contour => immediate success or
  17863. // toggling of inside/outside at every single! intersection point of an edge
  17864. // with the horizontal line through inPt, left of inPt
  17865. // not counting lowerY endpoints of edges and whole edges on that line
  17866. var inside = false;
  17867. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  17868. var edgeLowPt = inPolygon[ p ];
  17869. var edgeHighPt = inPolygon[ q ];
  17870. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  17871. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  17872. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  17873. // not parallel
  17874. if ( edgeDy < 0 ) {
  17875. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  17876. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  17877. }
  17878. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  17879. if ( inPt.y === edgeLowPt.y ) {
  17880. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  17881. // continue; // no intersection or edgeLowPt => doesn't count !!!
  17882. } else {
  17883. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  17884. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  17885. if ( perpEdge < 0 ) continue;
  17886. inside = ! inside; // true intersection left of inPt
  17887. }
  17888. } else {
  17889. // parallel or collinear
  17890. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  17891. // edge lies on the same horizontal line as inPt
  17892. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  17893. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  17894. // continue;
  17895. }
  17896. }
  17897. return inside;
  17898. }
  17899. var isClockWise = ShapeUtils.isClockWise;
  17900. var subPaths = this.subPaths;
  17901. if ( subPaths.length === 0 ) return [];
  17902. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  17903. var solid, tmpPath, tmpShape, shapes = [];
  17904. if ( subPaths.length === 1 ) {
  17905. tmpPath = subPaths[ 0 ];
  17906. tmpShape = new Shape();
  17907. tmpShape.curves = tmpPath.curves;
  17908. shapes.push( tmpShape );
  17909. return shapes;
  17910. }
  17911. var holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  17912. holesFirst = isCCW ? ! holesFirst : holesFirst;
  17913. // console.log("Holes first", holesFirst);
  17914. var betterShapeHoles = [];
  17915. var newShapes = [];
  17916. var newShapeHoles = [];
  17917. var mainIdx = 0;
  17918. var tmpPoints;
  17919. newShapes[ mainIdx ] = undefined;
  17920. newShapeHoles[ mainIdx ] = [];
  17921. for ( var i = 0, l = subPaths.length; i < l; i ++ ) {
  17922. tmpPath = subPaths[ i ];
  17923. tmpPoints = tmpPath.getPoints();
  17924. solid = isClockWise( tmpPoints );
  17925. solid = isCCW ? ! solid : solid;
  17926. if ( solid ) {
  17927. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  17928. newShapes[ mainIdx ] = { s: new Shape(), p: tmpPoints };
  17929. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  17930. if ( holesFirst ) mainIdx ++;
  17931. newShapeHoles[ mainIdx ] = [];
  17932. //console.log('cw', i);
  17933. } else {
  17934. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  17935. //console.log('ccw', i);
  17936. }
  17937. }
  17938. // only Holes? -> probably all Shapes with wrong orientation
  17939. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  17940. if ( newShapes.length > 1 ) {
  17941. var ambiguous = false;
  17942. var toChange = [];
  17943. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  17944. betterShapeHoles[ sIdx ] = [];
  17945. }
  17946. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  17947. var sho = newShapeHoles[ sIdx ];
  17948. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  17949. var ho = sho[ hIdx ];
  17950. var hole_unassigned = true;
  17951. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  17952. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  17953. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  17954. if ( hole_unassigned ) {
  17955. hole_unassigned = false;
  17956. betterShapeHoles[ s2Idx ].push( ho );
  17957. } else {
  17958. ambiguous = true;
  17959. }
  17960. }
  17961. }
  17962. if ( hole_unassigned ) {
  17963. betterShapeHoles[ sIdx ].push( ho );
  17964. }
  17965. }
  17966. }
  17967. // console.log("ambiguous: ", ambiguous);
  17968. if ( toChange.length > 0 ) {
  17969. // console.log("to change: ", toChange);
  17970. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  17971. }
  17972. }
  17973. var tmpHoles;
  17974. for ( var i = 0, il = newShapes.length; i < il; i ++ ) {
  17975. tmpShape = newShapes[ i ].s;
  17976. shapes.push( tmpShape );
  17977. tmpHoles = newShapeHoles[ i ];
  17978. for ( var j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  17979. tmpShape.holes.push( tmpHoles[ j ].h );
  17980. }
  17981. }
  17982. //console.log("shape", shapes);
  17983. return shapes;
  17984. }
  17985. } );
  17986. /**
  17987. * @author zz85 / http://www.lab4games.net/zz85/blog
  17988. * @author mrdoob / http://mrdoob.com/
  17989. */
  17990. function Font( data ) {
  17991. this.type = 'Font';
  17992. this.data = data;
  17993. }
  17994. Object.assign( Font.prototype, {
  17995. isFont: true,
  17996. generateShapes: function ( text, size, divisions ) {
  17997. function createPaths( text ) {
  17998. var chars = String( text ).split( '' );
  17999. var scale = size / data.resolution;
  18000. var line_height = ( data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness ) * scale;
  18001. var offsetX = 0, offsetY = 0;
  18002. var paths = [];
  18003. for ( var i = 0; i < chars.length; i ++ ) {
  18004. var char = chars[ i ];
  18005. if ( char === '\n' ) {
  18006. offsetX = 0;
  18007. offsetY -= line_height;
  18008. } else {
  18009. var ret = createPath( char, scale, offsetX, offsetY );
  18010. offsetX += ret.offsetX;
  18011. paths.push( ret.path );
  18012. }
  18013. }
  18014. return paths;
  18015. }
  18016. function createPath( c, scale, offsetX, offsetY ) {
  18017. var glyph = data.glyphs[ c ] || data.glyphs[ '?' ];
  18018. if ( ! glyph ) return;
  18019. var path = new ShapePath();
  18020. var pts = [];
  18021. var x, y, cpx, cpy, cpx0, cpy0, cpx1, cpy1, cpx2, cpy2, laste;
  18022. if ( glyph.o ) {
  18023. var outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  18024. for ( var i = 0, l = outline.length; i < l; ) {
  18025. var action = outline[ i ++ ];
  18026. switch ( action ) {
  18027. case 'm': // moveTo
  18028. x = outline[ i ++ ] * scale + offsetX;
  18029. y = outline[ i ++ ] * scale + offsetY;
  18030. path.moveTo( x, y );
  18031. break;
  18032. case 'l': // lineTo
  18033. x = outline[ i ++ ] * scale + offsetX;
  18034. y = outline[ i ++ ] * scale + offsetY;
  18035. path.lineTo( x, y );
  18036. break;
  18037. case 'q': // quadraticCurveTo
  18038. cpx = outline[ i ++ ] * scale + offsetX;
  18039. cpy = outline[ i ++ ] * scale + offsetY;
  18040. cpx1 = outline[ i ++ ] * scale + offsetX;
  18041. cpy1 = outline[ i ++ ] * scale + offsetY;
  18042. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  18043. laste = pts[ pts.length - 1 ];
  18044. if ( laste ) {
  18045. cpx0 = laste.x;
  18046. cpy0 = laste.y;
  18047. for ( var i2 = 1; i2 <= divisions; i2 ++ ) {
  18048. var t = i2 / divisions;
  18049. QuadraticBezier( t, cpx0, cpx1, cpx );
  18050. QuadraticBezier( t, cpy0, cpy1, cpy );
  18051. }
  18052. }
  18053. break;
  18054. case 'b': // bezierCurveTo
  18055. cpx = outline[ i ++ ] * scale + offsetX;
  18056. cpy = outline[ i ++ ] * scale + offsetY;
  18057. cpx1 = outline[ i ++ ] * scale + offsetX;
  18058. cpy1 = outline[ i ++ ] * scale + offsetY;
  18059. cpx2 = outline[ i ++ ] * scale + offsetX;
  18060. cpy2 = outline[ i ++ ] * scale + offsetY;
  18061. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  18062. laste = pts[ pts.length - 1 ];
  18063. if ( laste ) {
  18064. cpx0 = laste.x;
  18065. cpy0 = laste.y;
  18066. for ( var i2 = 1; i2 <= divisions; i2 ++ ) {
  18067. var t = i2 / divisions;
  18068. CubicBezier( t, cpx0, cpx1, cpx2, cpx );
  18069. CubicBezier( t, cpy0, cpy1, cpy2, cpy );
  18070. }
  18071. }
  18072. break;
  18073. }
  18074. }
  18075. }
  18076. return { offsetX: glyph.ha * scale, path: path };
  18077. }
  18078. //
  18079. if ( size === undefined ) size = 100;
  18080. if ( divisions === undefined ) divisions = 4;
  18081. var data = this.data;
  18082. var paths = createPaths( text );
  18083. var shapes = [];
  18084. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  18085. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  18086. }
  18087. return shapes;
  18088. }
  18089. } );
  18090. /**
  18091. * @author TristanVALCKE / https://github.com/Itee
  18092. */
  18093. /* global QUnit */
  18094. QUnit.module( 'Extras', () => {
  18095. QUnit.module( 'Core', () => {
  18096. QUnit.module.todo( 'Font', () => {
  18097. // INSTANCING
  18098. QUnit.test( "Instancing", ( assert ) => {
  18099. assert.ok( false, "everything's gonna be alright" );
  18100. } );
  18101. // PUBLIC STUFF
  18102. QUnit.test( "isFont", ( assert ) => {
  18103. assert.ok( false, "everything's gonna be alright" );
  18104. } );
  18105. QUnit.test( "generateShapes", ( assert ) => {
  18106. assert.ok( false, "everything's gonna be alright" );
  18107. } );
  18108. } );
  18109. } );
  18110. } );
  18111. /**
  18112. * @author TristanVALCKE / https://github.com/Itee
  18113. */
  18114. /* global QUnit */
  18115. QUnit.module( 'Extras', () => {
  18116. QUnit.module( 'Core', () => {
  18117. QUnit.module.todo( 'Interpolations', () => {
  18118. // PUBLIC STUFF
  18119. QUnit.test( "CatmullRom", ( assert ) => {
  18120. assert.ok( false, "everything's gonna be alright" );
  18121. } );
  18122. QUnit.test( "QuadraticBezier", ( assert ) => {
  18123. assert.ok( false, "everything's gonna be alright" );
  18124. } );
  18125. QUnit.test( "CubicBezier", ( assert ) => {
  18126. assert.ok( false, "everything's gonna be alright" );
  18127. } );
  18128. } );
  18129. } );
  18130. } );
  18131. /**
  18132. * @author TristanVALCKE / https://github.com/Itee
  18133. */
  18134. /* global QUnit */
  18135. QUnit.module( 'Extras', () => {
  18136. QUnit.module( 'Core', () => {
  18137. QUnit.module.todo( 'Path', () => {
  18138. // INSTANCING
  18139. QUnit.test( "Instancing", ( assert ) => {
  18140. assert.ok( false, "everything's gonna be alright" );
  18141. } );
  18142. } );
  18143. } );
  18144. } );
  18145. /**
  18146. * @author TristanVALCKE / https://github.com/Itee
  18147. */
  18148. /* global QUnit */
  18149. QUnit.module( 'Extras', () => {
  18150. QUnit.module( 'Core', () => {
  18151. QUnit.module.todo( 'PathPrototype', () => {
  18152. // INHERITANCE
  18153. QUnit.test( "Extending", ( assert ) => {
  18154. assert.ok( false, "everything's gonna be alright" );
  18155. } );
  18156. // PUBLIC STUFF
  18157. QUnit.test( "fromPoints", ( assert ) => {
  18158. assert.ok( false, "everything's gonna be alright" );
  18159. } );
  18160. QUnit.test( "moveTo", ( assert ) => {
  18161. assert.ok( false, "everything's gonna be alright" );
  18162. } );
  18163. QUnit.test( "lineTo", ( assert ) => {
  18164. assert.ok( false, "everything's gonna be alright" );
  18165. } );
  18166. QUnit.test( "quadraticCurveTo", ( assert ) => {
  18167. assert.ok( false, "everything's gonna be alright" );
  18168. } );
  18169. QUnit.test( "bezierCurveTo", ( assert ) => {
  18170. assert.ok( false, "everything's gonna be alright" );
  18171. } );
  18172. QUnit.test( "splineThru", ( assert ) => {
  18173. assert.ok( false, "everything's gonna be alright" );
  18174. } );
  18175. QUnit.test( "arc", ( assert ) => {
  18176. assert.ok( false, "everything's gonna be alright" );
  18177. } );
  18178. QUnit.test( "absarc", ( assert ) => {
  18179. assert.ok( false, "everything's gonna be alright" );
  18180. } );
  18181. QUnit.test( "ellipse", ( assert ) => {
  18182. assert.ok( false, "everything's gonna be alright" );
  18183. } );
  18184. QUnit.test( "absellipse", ( assert ) => {
  18185. assert.ok( false, "everything's gonna be alright" );
  18186. } );
  18187. } );
  18188. } );
  18189. } );
  18190. /**
  18191. * @author TristanVALCKE / https://github.com/Itee
  18192. */
  18193. /* global QUnit */
  18194. QUnit.module( 'Extras', () => {
  18195. QUnit.module( 'Core', () => {
  18196. QUnit.module.todo( 'Shape', () => {
  18197. // INHERITANCE
  18198. QUnit.test( "Extending", ( assert ) => {
  18199. assert.ok( false, "everything's gonna be alright" );
  18200. } );
  18201. // INSTANCING
  18202. QUnit.test( "Instancing", ( assert ) => {
  18203. assert.ok( false, "everything's gonna be alright" );
  18204. } );
  18205. // PUBLIC STUFF
  18206. QUnit.test( "getPointsHoles", ( assert ) => {
  18207. assert.ok( false, "everything's gonna be alright" );
  18208. } );
  18209. QUnit.test( "extractAllPoints", ( assert ) => {
  18210. assert.ok( false, "everything's gonna be alright" );
  18211. } );
  18212. QUnit.test( "extractPoints", ( assert ) => {
  18213. assert.ok( false, "everything's gonna be alright" );
  18214. } );
  18215. } );
  18216. } );
  18217. } );
  18218. /**
  18219. * @author TristanVALCKE / https://github.com/Itee
  18220. */
  18221. /* global QUnit */
  18222. QUnit.module( 'Extras', () => {
  18223. QUnit.module( 'Core', () => {
  18224. QUnit.module.todo( 'ShapePath', () => {
  18225. // INSTANCING
  18226. QUnit.test( "Instancing", ( assert ) => {
  18227. assert.ok( false, "everything's gonna be alright" );
  18228. } );
  18229. // PUBLIC STUFF
  18230. QUnit.test( "moveTo", ( assert ) => {
  18231. assert.ok( false, "everything's gonna be alright" );
  18232. } );
  18233. QUnit.test( "lineTo", ( assert ) => {
  18234. assert.ok( false, "everything's gonna be alright" );
  18235. } );
  18236. QUnit.test( "quadraticCurveTo", ( assert ) => {
  18237. assert.ok( false, "everything's gonna be alright" );
  18238. } );
  18239. QUnit.test( "bezierCurveTo", ( assert ) => {
  18240. assert.ok( false, "everything's gonna be alright" );
  18241. } );
  18242. QUnit.test( "splineThru", ( assert ) => {
  18243. assert.ok( false, "everything's gonna be alright" );
  18244. } );
  18245. QUnit.test( "toShapes", ( assert ) => {
  18246. assert.ok( false, "everything's gonna be alright" );
  18247. } );
  18248. } );
  18249. } );
  18250. } );
  18251. /**
  18252. * @author TristanVALCKE / https://github.com/Itee
  18253. */
  18254. /* global QUnit */
  18255. QUnit.module( 'Extras', () => {
  18256. QUnit.module( 'Curves', () => {
  18257. QUnit.module.todo( 'ArcCurve', () => {
  18258. // INHERITANCE
  18259. QUnit.test( "Extending", ( assert ) => {
  18260. assert.ok( false, "everything's gonna be alright" );
  18261. } );
  18262. // INSTANCING
  18263. QUnit.test( "Instancing", ( assert ) => {
  18264. assert.ok( false, "everything's gonna be alright" );
  18265. } );
  18266. // PUBLIC STUFF
  18267. QUnit.test( "isArcCurve", ( assert ) => {
  18268. assert.ok( false, "everything's gonna be alright" );
  18269. } );
  18270. } );
  18271. } );
  18272. } );
  18273. function CubicPoly() {
  18274. var c0 = 0, c1 = 0, c2 = 0, c3 = 0;
  18275. /*
  18276. * Compute coefficients for a cubic polynomial
  18277. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  18278. * such that
  18279. * p(0) = x0, p(1) = x1
  18280. * and
  18281. * p'(0) = t0, p'(1) = t1.
  18282. */
  18283. function init( x0, x1, t0, t1 ) {
  18284. c0 = x0;
  18285. c1 = t0;
  18286. c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  18287. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  18288. }
  18289. return {
  18290. initCatmullRom: function ( x0, x1, x2, x3, tension ) {
  18291. init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  18292. },
  18293. initNonuniformCatmullRom: function ( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  18294. // compute tangents when parameterized in [t1,t2]
  18295. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  18296. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  18297. // rescale tangents for parametrization in [0,1]
  18298. t1 *= dt1;
  18299. t2 *= dt1;
  18300. init( x1, x2, t1, t2 );
  18301. },
  18302. calc: function ( t ) {
  18303. var t2 = t * t;
  18304. var t3 = t2 * t;
  18305. return c0 + c1 * t + c2 * t2 + c3 * t3;
  18306. }
  18307. };
  18308. }
  18309. //
  18310. var tmp = new Vector3();
  18311. var px = new CubicPoly();
  18312. var py = new CubicPoly();
  18313. var pz = new CubicPoly();
  18314. function CatmullRomCurve3( points, closed, curveType, tension ) {
  18315. Curve.call( this );
  18316. this.type = 'CatmullRomCurve3';
  18317. this.points = points || [];
  18318. this.closed = closed || false;
  18319. this.curveType = curveType || 'centripetal';
  18320. this.tension = tension || 0.5;
  18321. }
  18322. CatmullRomCurve3.prototype = Object.create( Curve.prototype );
  18323. CatmullRomCurve3.prototype.constructor = CatmullRomCurve3;
  18324. CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
  18325. CatmullRomCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  18326. var point = optionalTarget || new Vector3();
  18327. var points = this.points;
  18328. var l = points.length;
  18329. var p = ( l - ( this.closed ? 0 : 1 ) ) * t;
  18330. var intPoint = Math.floor( p );
  18331. var weight = p - intPoint;
  18332. if ( this.closed ) {
  18333. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / points.length ) + 1 ) * points.length;
  18334. } else if ( weight === 0 && intPoint === l - 1 ) {
  18335. intPoint = l - 2;
  18336. weight = 1;
  18337. }
  18338. var p0, p1, p2, p3; // 4 points
  18339. if ( this.closed || intPoint > 0 ) {
  18340. p0 = points[ ( intPoint - 1 ) % l ];
  18341. } else {
  18342. // extrapolate first point
  18343. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  18344. p0 = tmp;
  18345. }
  18346. p1 = points[ intPoint % l ];
  18347. p2 = points[ ( intPoint + 1 ) % l ];
  18348. if ( this.closed || intPoint + 2 < l ) {
  18349. p3 = points[ ( intPoint + 2 ) % l ];
  18350. } else {
  18351. // extrapolate last point
  18352. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
  18353. p3 = tmp;
  18354. }
  18355. if ( this.curveType === 'centripetal' || this.curveType === 'chordal' ) {
  18356. // init Centripetal / Chordal Catmull-Rom
  18357. var pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  18358. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  18359. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  18360. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  18361. // safety check for repeated points
  18362. if ( dt1 < 1e-4 ) dt1 = 1.0;
  18363. if ( dt0 < 1e-4 ) dt0 = dt1;
  18364. if ( dt2 < 1e-4 ) dt2 = dt1;
  18365. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  18366. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  18367. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  18368. } else if ( this.curveType === 'catmullrom' ) {
  18369. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, this.tension );
  18370. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, this.tension );
  18371. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, this.tension );
  18372. }
  18373. point.set(
  18374. px.calc( weight ),
  18375. py.calc( weight ),
  18376. pz.calc( weight )
  18377. );
  18378. return point;
  18379. };
  18380. CatmullRomCurve3.prototype.copy = function ( source ) {
  18381. Curve.prototype.copy.call( this, source );
  18382. this.points = [];
  18383. for ( var i = 0, l = source.points.length; i < l; i ++ ) {
  18384. var point = source.points[ i ];
  18385. this.points.push( point.clone() );
  18386. }
  18387. this.closed = source.closed;
  18388. this.curveType = source.curveType;
  18389. this.tension = source.tension;
  18390. return this;
  18391. };
  18392. /**
  18393. * @author zz85 / http://joshuakoo.com
  18394. * @author TristanVALCKE / https://github.com/Itee
  18395. */
  18396. /* global QUnit */
  18397. QUnit.module( 'Extras', () => {
  18398. QUnit.module( 'Curves', () => {
  18399. QUnit.module.todo( 'CatmullRomCurve3', () => {
  18400. /* eslint-disable */
  18401. var positions = [
  18402. new Vector3( - 60, - 100, 60 ),
  18403. new Vector3( - 60, 20, 60 ),
  18404. new Vector3( - 60, 120, 60 ),
  18405. new Vector3( 60, 20, - 60 ),
  18406. new Vector3( 60, - 100, - 60 )
  18407. ];
  18408. /* eslint-enable */
  18409. // INHERITANCE
  18410. QUnit.test( "Extending", ( assert ) => {
  18411. assert.ok( false, "everything's gonna be alright" );
  18412. } );
  18413. // INSTANCING
  18414. QUnit.test( "Instancing", ( assert ) => {
  18415. assert.ok( false, "everything's gonna be alright" );
  18416. } );
  18417. // PUBLIC STUFF
  18418. QUnit.test( "isCatmullRomCurve3", ( assert ) => {
  18419. assert.ok( false, "everything's gonna be alright" );
  18420. } );
  18421. QUnit.test( "getPoint", ( assert ) => {
  18422. assert.ok( false, "everything's gonna be alright" );
  18423. } );
  18424. // OTHERS
  18425. QUnit.test( "catmullrom check", ( assert ) => {
  18426. var curve = new CatmullRomCurve3( positions );
  18427. curve.type = 'catmullrom';
  18428. var expectedPoints = [
  18429. new Vector3( - 60, - 100, 60 ),
  18430. new Vector3( - 60, - 51.04, 60 ),
  18431. new Vector3( - 60, - 2.7199999999999998, 60 ),
  18432. new Vector3( - 61.92, 44.48, 61.92 ),
  18433. new Vector3( - 68.64, 95.36000000000001, 68.64 ),
  18434. new Vector3( - 60, 120, 60 ),
  18435. new Vector3( - 14.880000000000017, 95.36000000000001, 14.880000000000017 ),
  18436. new Vector3( 41.75999999999997, 44.48000000000003, - 41.75999999999997 ),
  18437. new Vector3( 67.68, - 2.720000000000023, - 67.68 ),
  18438. new Vector3( 65.75999999999999, - 51.04000000000001, - 65.75999999999999 ),
  18439. new Vector3( 60, - 100, - 60 )
  18440. ];
  18441. var points = curve.getPoints( 10 );
  18442. assert.equal( points.length, expectedPoints.length, 'correct number of points.' );
  18443. points.forEach( function ( point, i ) {
  18444. assert.numEqual( point.x, expectedPoints[ i ].x, 'points[' + i + '].x' );
  18445. assert.numEqual( point.y, expectedPoints[ i ].y, 'points[' + i + '].y' );
  18446. assert.numEqual( point.z, expectedPoints[ i ].z, 'points[' + i + '].z' );
  18447. } );
  18448. } );
  18449. QUnit.test( "chordal basic check", ( assert ) => {
  18450. var curve = new CatmullRomCurve3( positions );
  18451. curve.type = 'chordal';
  18452. var expectedPoints = [
  18453. new Vector3( - 60, - 100, 60 ),
  18454. new Vector3( - 60, - 52, 60 ),
  18455. new Vector3( - 60, - 4, 60 ),
  18456. new Vector3( - 60.656435889910924, 41.62455386421379, 60.656435889910924 ),
  18457. new Vector3( - 62.95396150459915, 87.31049238896205, 62.95396150459915 ),
  18458. new Vector3( - 60, 120, 60 ),
  18459. new Vector3( - 16.302568199486444, 114.1500463116312, 16.302568199486444 ),
  18460. new Vector3( 42.998098664956586, 54.017050116427455, - 42.998098664956586 ),
  18461. new Vector3( 63.542500175682434, - 1.137153397546383, - 63.542500175682434 ),
  18462. new Vector3( 62.65687513176183, - 49.85286504815978, - 62.65687513176183 ),
  18463. new Vector3( 60.00000000000001, - 100, - 60.00000000000001 )
  18464. ];
  18465. var points = curve.getPoints( 10 );
  18466. assert.equal( points.length, expectedPoints.length, 'correct number of points.' );
  18467. points.forEach( function ( point, i ) {
  18468. assert.numEqual( point.x, expectedPoints[ i ].x, 'points[' + i + '].x' );
  18469. assert.numEqual( point.y, expectedPoints[ i ].y, 'points[' + i + '].y' );
  18470. assert.numEqual( point.z, expectedPoints[ i ].z, 'points[' + i + '].z' );
  18471. } );
  18472. } );
  18473. QUnit.test( "centripetal basic check", ( assert ) => {
  18474. var curve = new CatmullRomCurve3( positions );
  18475. curve.type = 'centripetal';
  18476. var expectedPoints = [
  18477. new Vector3( - 60, - 100, 60 ),
  18478. new Vector3( - 60, - 51.47527724919028, 60 ),
  18479. new Vector3( - 60, - 3.300369665587032, 60 ),
  18480. new Vector3( - 61.13836565863938, 42.86306307781241, 61.13836565863938 ),
  18481. new Vector3( - 65.1226454638772, 90.69743905511538, 65.1226454638772 ),
  18482. new Vector3( - 60, 120, 60 ),
  18483. new Vector3( - 15.620412575504497, 103.10790870179872, 15.620412575504497 ),
  18484. new Vector3( 42.384384731047874, 48.35477686933143, - 42.384384731047874 ),
  18485. new Vector3( 65.25545512241153, - 1.646250966068339, - 65.25545512241153 ),
  18486. new Vector3( 63.94159134180865, - 50.234688224551256, - 63.94159134180865 ),
  18487. new Vector3( 59.99999999999999, - 100, - 59.99999999999999 ),
  18488. ];
  18489. var points = curve.getPoints( 10 );
  18490. assert.equal( points.length, expectedPoints.length, 'correct number of points.' );
  18491. points.forEach( function ( point, i ) {
  18492. assert.numEqual( point.x, expectedPoints[ i ].x, 'points[' + i + '].x' );
  18493. assert.numEqual( point.y, expectedPoints[ i ].y, 'points[' + i + '].y' );
  18494. assert.numEqual( point.z, expectedPoints[ i ].z, 'points[' + i + '].z' );
  18495. } );
  18496. } );
  18497. QUnit.test( "closed catmullrom basic check", ( assert ) => {
  18498. var curve = new CatmullRomCurve3( positions );
  18499. curve.type = 'catmullrom';
  18500. curve.closed = true;
  18501. var expectedPoints = [
  18502. new Vector3( - 60, - 100, 60 ),
  18503. new Vector3( - 67.5, - 46.25, 67.5 ),
  18504. new Vector3( - 60, 20, 60 ),
  18505. new Vector3( - 67.5, 83.75, 67.5 ),
  18506. new Vector3( - 60, 120, 60 ),
  18507. new Vector3( 0, 83.75, 0 ),
  18508. new Vector3( 60, 20, - 60 ),
  18509. new Vector3( 75, - 46.25, - 75 ),
  18510. new Vector3( 60, - 100, - 60 ),
  18511. new Vector3( 0, - 115, 0 ),
  18512. new Vector3( - 60, - 100, 60 ),
  18513. ];
  18514. var points = curve.getPoints( 10 );
  18515. assert.equal( points.length, expectedPoints.length, 'correct number of points.' );
  18516. points.forEach( function ( point, i ) {
  18517. assert.numEqual( point.x, expectedPoints[ i ].x, 'points[' + i + '].x' );
  18518. assert.numEqual( point.y, expectedPoints[ i ].y, 'points[' + i + '].y' );
  18519. assert.numEqual( point.z, expectedPoints[ i ].z, 'points[' + i + '].z' );
  18520. } );
  18521. } );
  18522. //
  18523. // curve.type = 'catmullrom'; only from here on
  18524. //
  18525. QUnit.test( "getLength/getLengths", ( assert ) => {
  18526. var curve = new THREE.CatmullRomCurve3( positions );
  18527. curve.type = 'catmullrom';
  18528. var length = curve.getLength();
  18529. var expectedLength = 551.549686276872;
  18530. assert.numEqual( length, expectedLength, "Correct length of curve" );
  18531. var expectedLengths = [
  18532. 0,
  18533. 120,
  18534. 220,
  18535. 416.9771560359221,
  18536. 536.9771560359221
  18537. ];
  18538. var lengths = curve.getLengths( expectedLengths.length - 1 );
  18539. assert.strictEqual( lengths.length, expectedLengths.length, "Correct number of segments" );
  18540. lengths.forEach( function ( segment, i ) {
  18541. assert.numEqual( segment, expectedLengths[ i ], "segment[" + i + "] correct" );
  18542. } );
  18543. } );
  18544. QUnit.test( "getPointAt", ( assert ) => {
  18545. var curve = new THREE.CatmullRomCurve3( positions );
  18546. curve.type = 'catmullrom';
  18547. var expectedPoints = [
  18548. new THREE.Vector3( - 60, - 100, 60 ),
  18549. new THREE.Vector3( - 64.84177333183106, 64.86956465359813, 64.84177333183106 ),
  18550. new THREE.Vector3( - 28.288507045700854, 104.83101184518996, 28.288507045700854 ),
  18551. new THREE.Vector3( 60, - 100, - 60 )
  18552. ];
  18553. var points = [
  18554. curve.getPointAt( 0 ),
  18555. curve.getPointAt( 0.3 ),
  18556. curve.getPointAt( 0.5 ),
  18557. curve.getPointAt( 1 )
  18558. ];
  18559. assert.deepEqual( points, expectedPoints, "Correct points" );
  18560. } );
  18561. QUnit.test( "getTangent/getTangentAt", ( assert ) => {
  18562. var curve = new THREE.CatmullRomCurve3( positions );
  18563. curve.type = 'catmullrom';
  18564. var expectedTangents = [
  18565. new THREE.Vector3( 0, 1, 0 ),
  18566. new THREE.Vector3( - 0.0001090274561657922, 0.9999999881130137, 0.0001090274561657922 ),
  18567. new THREE.Vector3( 0.7071067811865475, - 2.0930381713877622e-13, - 0.7071067811865475 ),
  18568. new THREE.Vector3( 0.43189437062802816, - 0.7917919583070032, - 0.43189437062802816 ),
  18569. new THREE.Vector3( - 0.00019991333100812723, - 0.9999999600346592, 0.00019991333100812723 )
  18570. ];
  18571. var tangents = [
  18572. curve.getTangent( 0 ),
  18573. curve.getTangent( 0.25 ),
  18574. curve.getTangent( 0.5 ),
  18575. curve.getTangent( 0.75 ),
  18576. curve.getTangent( 1 )
  18577. ];
  18578. expectedTangents.forEach( function ( exp, i ) {
  18579. var tangent = tangents[ i ];
  18580. assert.numEqual( tangent.x, exp.x, "getTangent #" + i + ": x correct" );
  18581. assert.numEqual( tangent.y, exp.y, "getTangent #" + i + ": y correct" );
  18582. } );
  18583. //
  18584. var expectedTangents = [
  18585. new THREE.Vector3( 0, 1, 0 ),
  18586. new THREE.Vector3( - 0.10709018822205997, 0.9884651653817284, 0.10709018822205997 ),
  18587. new THREE.Vector3( 0.6396363672964268, - 0.4262987629159402, - 0.6396363672964268 ),
  18588. new THREE.Vector3( 0.5077298411616501, - 0.6960034603275557, - 0.5077298411616501 ),
  18589. new THREE.Vector3( - 0.00019991333100812723, - 0.9999999600346592, 0.00019991333100812723 )
  18590. ];
  18591. var tangents = [
  18592. curve.getTangentAt( 0 ),
  18593. curve.getTangentAt( 0.25 ),
  18594. curve.getTangentAt( 0.5 ),
  18595. curve.getTangentAt( 0.75 ),
  18596. curve.getTangentAt( 1 )
  18597. ];
  18598. expectedTangents.forEach( function ( exp, i ) {
  18599. var tangent = tangents[ i ];
  18600. assert.numEqual( tangent.x, exp.x, "getTangentAt #" + i + ": x correct" );
  18601. assert.numEqual( tangent.y, exp.y, "getTangentAt #" + i + ": y correct" );
  18602. } );
  18603. } );
  18604. QUnit.test( "computeFrenetFrames", ( assert ) => {
  18605. var curve = new THREE.CatmullRomCurve3( positions );
  18606. curve.type = 'catmullrom';
  18607. var expected = {
  18608. binormals: [
  18609. new THREE.Vector3( - 1, 0, 0 ),
  18610. new THREE.Vector3( - 0.28685061854203, 0.6396363672964267, - 0.7131493814579701 ),
  18611. new THREE.Vector3( - 1.9982670528160395e-8, - 0.0001999133310081272, - 0.9999999800173295 )
  18612. ],
  18613. normals: [
  18614. new THREE.Vector3( 0, 0, - 1 ),
  18615. new THREE.Vector3( - 0.7131493814579699, - 0.6396363672964268, - 0.2868506185420297 ),
  18616. new THREE.Vector3( - 0.9999999800173294, 0.00019991333100810582, - 1.99826701852146e-8 )
  18617. ],
  18618. tangents: [
  18619. new THREE.Vector3( 0, 1, 0 ),
  18620. new THREE.Vector3( 0.6396363672964269, - 0.4262987629159403, - 0.6396363672964269 ),
  18621. new THREE.Vector3( - 0.0001999133310081273, - 0.9999999600346594, 0.0001999133310081273 )
  18622. ]
  18623. };
  18624. var frames = curve.computeFrenetFrames( 2, false );
  18625. Object.keys( expected ).forEach( function ( group, i ) {
  18626. expected[ group ].forEach( function ( vec, j ) {
  18627. assert.numEqual( frames[ group ][ j ].x, vec.x, "Frenet frames [" + i + ", " + j + "].x correct" );
  18628. assert.numEqual( frames[ group ][ j ].y, vec.y, "Frenet frames [" + i + ", " + j + "].y correct" );
  18629. assert.numEqual( frames[ group ][ j ].z, vec.z, "Frenet frames [" + i + ", " + j + "].z correct" );
  18630. } );
  18631. } );
  18632. } );
  18633. QUnit.test( "getUtoTmapping", ( assert ) => {
  18634. var curve = new THREE.CatmullRomCurve3( positions );
  18635. curve.type = 'catmullrom';
  18636. var start = curve.getUtoTmapping( 0, 0 );
  18637. var end = curve.getUtoTmapping( 0, curve.getLength() );
  18638. var somewhere = curve.getUtoTmapping( 0.5, 500 );
  18639. var expectedSomewhere = 0.8964116382083199;
  18640. assert.strictEqual( start, 0, "getUtoTmapping( 0, 0 ) is the starting point" );
  18641. assert.strictEqual( end, 1, "getUtoTmapping( 0, length ) is the ending point" );
  18642. assert.numEqual( somewhere, expectedSomewhere, "getUtoTmapping( 0.5, 500 ) is correct" );
  18643. } );
  18644. QUnit.test( "getSpacedPoints", ( assert ) => {
  18645. var curve = new THREE.CatmullRomCurve3( positions );
  18646. curve.type = 'catmullrom';
  18647. var expectedPoints = [
  18648. new THREE.Vector3( - 60, - 100, 60 ),
  18649. new THREE.Vector3( - 60, 10.311489426555056, 60 ),
  18650. new THREE.Vector3( - 65.05889864636504, 117.99691802595966, 65.05889864636504 ),
  18651. new THREE.Vector3( 6.054276900088592, 78.7153118386369, - 6.054276900088592 ),
  18652. new THREE.Vector3( 64.9991491385602, 8.386980812799566, - 64.9991491385602 ),
  18653. new THREE.Vector3( 60, - 100, - 60 )
  18654. ];
  18655. var points = curve.getSpacedPoints();
  18656. assert.strictEqual( points.length, expectedPoints.length, "Correct number of points" );
  18657. assert.deepEqual( points, expectedPoints, "Correct points calculated" );
  18658. } );
  18659. } );
  18660. } );
  18661. } );
  18662. /**
  18663. * @author TristanVALCKE / https://github.com/Itee
  18664. * @author moraxy / https://github.com/moraxy
  18665. */
  18666. /* global QUnit */
  18667. QUnit.module( 'Extras', () => {
  18668. QUnit.module( 'Curves', () => {
  18669. QUnit.module.todo( 'CubicBezierCurve', ( hooks ) => {
  18670. let curve = undefined;
  18671. hooks.before( function () {
  18672. curve = new CubicBezierCurve(
  18673. new Vector2( - 10, 0 ),
  18674. new Vector2( - 5, 15 ),
  18675. new Vector2( 20, 15 ),
  18676. new Vector2( 10, 0 )
  18677. );
  18678. } );
  18679. // INHERITANCE
  18680. QUnit.test( "Extending", ( assert ) => {
  18681. assert.ok( false, "everything's gonna be alright" );
  18682. } );
  18683. // INSTANCING
  18684. QUnit.test( "Instancing", ( assert ) => {
  18685. assert.ok( false, "everything's gonna be alright" );
  18686. } );
  18687. // PUBLIC STUFF
  18688. QUnit.test( "isCubicBezierCurve", ( assert ) => {
  18689. assert.ok( false, "everything's gonna be alright" );
  18690. } );
  18691. QUnit.test( "getPoint", ( assert ) => {
  18692. assert.ok( false, "everything's gonna be alright" );
  18693. } );
  18694. // OTHERS
  18695. QUnit.test( "Simple curve", ( assert ) => {
  18696. var expectedPoints = [
  18697. new Vector2( - 10, 0 ),
  18698. new Vector2( - 3.359375, 8.4375 ),
  18699. new Vector2( 5.625, 11.25 ),
  18700. new Vector2( 11.796875, 8.4375 ),
  18701. new Vector2( 10, 0 )
  18702. ];
  18703. var points = curve.getPoints( expectedPoints.length - 1 );
  18704. assert.strictEqual( points.length, expectedPoints.length, "Correct number of points" );
  18705. assert.deepEqual( points, expectedPoints, "Correct points calculated" );
  18706. // symmetry
  18707. var curveRev = new CubicBezierCurve(
  18708. curve.v3, curve.v2, curve.v1, curve.v0
  18709. );
  18710. var points = curveRev.getPoints( expectedPoints.length - 1 );
  18711. assert.strictEqual( points.length, expectedPoints.length, "Reversed: Correct number of points" );
  18712. assert.deepEqual( points, expectedPoints.reverse(), "Reversed: Correct points curve" );
  18713. } );
  18714. QUnit.test( "getLength/getLengths", ( assert ) => {
  18715. var length = curve.getLength();
  18716. var expectedLength = 36.64630888504102;
  18717. assert.numEqual( length, expectedLength, "Correct length of curve" );
  18718. var expectedLengths = [
  18719. 0,
  18720. 10.737285813492393,
  18721. 20.15159143794633,
  18722. 26.93408340370825,
  18723. 35.56079575637337
  18724. ];
  18725. var lengths = curve.getLengths( expectedLengths.length - 1 );
  18726. assert.strictEqual( lengths.length, expectedLengths.length, "Correct number of segments" );
  18727. lengths.forEach( function ( segment, i ) {
  18728. assert.numEqual( segment, expectedLengths[ i ], "segment[" + i + "] correct" );
  18729. } );
  18730. } );
  18731. QUnit.test( "getPointAt", ( assert ) => {
  18732. var expectedPoints = [
  18733. new Vector2( - 10, 0 ),
  18734. new Vector2( - 3.3188282598022596, 8.463722639089221 ),
  18735. new Vector2( 3.4718554735926617, 11.07899406116314 ),
  18736. new Vector2( 10, 0 )
  18737. ];
  18738. var points = [
  18739. curve.getPointAt( 0 ),
  18740. curve.getPointAt( 0.3 ),
  18741. curve.getPointAt( 0.5 ),
  18742. curve.getPointAt( 1 )
  18743. ];
  18744. assert.deepEqual( points, expectedPoints, "Correct points" );
  18745. } );
  18746. QUnit.test( "getTangent/getTangentAt", ( assert ) => {
  18747. var expectedTangents = [
  18748. new Vector2( 0.316370061632252, 0.9486358543207215 ),
  18749. new Vector2( 0.838961283088303, 0.5441911111721949 ),
  18750. new Vector2( 1, 0 ),
  18751. new Vector2( 0.47628313192245453, - 0.8792919755383518 ),
  18752. new Vector2( - 0.5546041767829665, - 0.8321142992972107 )
  18753. ];
  18754. var tangents = [
  18755. curve.getTangent( 0 ),
  18756. curve.getTangent( 0.25 ),
  18757. curve.getTangent( 0.5 ),
  18758. curve.getTangent( 0.75 ),
  18759. curve.getTangent( 1 )
  18760. ];
  18761. expectedTangents.forEach( function ( exp, i ) {
  18762. var tangent = tangents[ i ];
  18763. assert.numEqual( tangent.x, exp.x, "getTangent #" + i + ": x correct" );
  18764. assert.numEqual( tangent.y, exp.y, "getTangent #" + i + ": y correct" );
  18765. } );
  18766. //
  18767. var expectedTangents = [
  18768. new Vector2( 0.316370061632252, 0.9486358543207215 ),
  18769. new Vector2( 0.7794223085548987, 0.6264988945935596 ),
  18770. new Vector2( 0.988266153082452, 0.15274164681452052 ),
  18771. new Vector2( 0.5004110404199416, - 0.8657879593906534 ),
  18772. new Vector2( - 0.5546041767829665, - 0.8321142992972107 )
  18773. ];
  18774. var tangents = [
  18775. curve.getTangentAt( 0 ),
  18776. curve.getTangentAt( 0.25 ),
  18777. curve.getTangentAt( 0.5 ),
  18778. curve.getTangentAt( 0.75 ),
  18779. curve.getTangentAt( 1 )
  18780. ];
  18781. expectedTangents.forEach( function ( exp, i ) {
  18782. var tangent = tangents[ i ];
  18783. assert.numEqual( tangent.x, exp.x, "getTangentAt #" + i + ": x correct" );
  18784. assert.numEqual( tangent.y, exp.y, "getTangentAt #" + i + ": y correct" );
  18785. } );
  18786. } );
  18787. QUnit.test( "getUtoTmapping", ( assert ) => {
  18788. var start = curve.getUtoTmapping( 0, 0 );
  18789. var end = curve.getUtoTmapping( 0, curve.getLength() );
  18790. var somewhere = curve.getUtoTmapping( 0.5, 1 );
  18791. var expectedSomewhere = 0.02130029182257093;
  18792. assert.strictEqual( start, 0, "getUtoTmapping( 0, 0 ) is the starting point" );
  18793. assert.strictEqual( end, 1, "getUtoTmapping( 0, length ) is the ending point" );
  18794. assert.numEqual( somewhere, expectedSomewhere, "getUtoTmapping( 0.5, 1 ) is correct" );
  18795. } );
  18796. QUnit.test( "getSpacedPoints", ( assert ) => {
  18797. var expectedPoints = [
  18798. new Vector2( - 10, 0 ),
  18799. new Vector2( - 6.16826457740703, 6.17025727295411 ),
  18800. new Vector2( - 0.058874033259857184, 10.1240558653185 ),
  18801. new Vector2( 7.123523032625162, 11.154913869041575 ),
  18802. new Vector2( 12.301846885754463, 6.808865855469985 ),
  18803. new Vector2( 10, 0 )
  18804. ];
  18805. var points = curve.getSpacedPoints();
  18806. assert.strictEqual( points.length, expectedPoints.length, "Correct number of points" );
  18807. assert.deepEqual( points, expectedPoints, "Correct points calculated" );
  18808. } );
  18809. } );
  18810. } );
  18811. } );
  18812. function CubicBezierCurve3( v0, v1, v2, v3 ) {
  18813. Curve.call( this );
  18814. this.type = 'CubicBezierCurve3';
  18815. this.v0 = v0 || new Vector3();
  18816. this.v1 = v1 || new Vector3();
  18817. this.v2 = v2 || new Vector3();
  18818. this.v3 = v3 || new Vector3();
  18819. }
  18820. CubicBezierCurve3.prototype = Object.create( Curve.prototype );
  18821. CubicBezierCurve3.prototype.constructor = CubicBezierCurve3;
  18822. CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
  18823. CubicBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  18824. var point = optionalTarget || new Vector3();
  18825. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  18826. point.set(
  18827. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  18828. CubicBezier( t, v0.y, v1.y, v2.y, v3.y ),
  18829. CubicBezier( t, v0.z, v1.z, v2.z, v3.z )
  18830. );
  18831. return point;
  18832. };
  18833. CubicBezierCurve3.prototype.copy = function ( source ) {
  18834. Curve.prototype.copy.call( this, source );
  18835. this.v0.copy( source.v0 );
  18836. this.v1.copy( source.v1 );
  18837. this.v2.copy( source.v2 );
  18838. this.v3.copy( source.v3 );
  18839. return this;
  18840. };
  18841. /**
  18842. * @author TristanVALCKE / https://github.com/Itee
  18843. * @author moraxy / https://github.com/moraxy
  18844. */
  18845. /* global QUnit */
  18846. QUnit.module( 'Extras', () => {
  18847. QUnit.module( 'Curves', () => {
  18848. QUnit.module.todo( 'CubicBezierCurve3', ( hooks ) => {
  18849. let curve = undefined;
  18850. hooks.before( function () {
  18851. curve = new CubicBezierCurve3(
  18852. new Vector3( - 10, 0, 2 ),
  18853. new Vector3( - 5, 15, 4 ),
  18854. new Vector3( 20, 15, - 5 ),
  18855. new Vector3( 10, 0, 10 )
  18856. );
  18857. } );
  18858. // INHERITANCE
  18859. QUnit.test( "Extending", ( assert ) => {
  18860. assert.ok( false, "everything's gonna be alright" );
  18861. } );
  18862. // INSTANCING
  18863. QUnit.test( "Instancing", ( assert ) => {
  18864. assert.ok( false, "everything's gonna be alright" );
  18865. } );
  18866. // PUBLIC STUFF
  18867. QUnit.test( "isCubicBezierCurve3", ( assert ) => {
  18868. assert.ok( false, "everything's gonna be alright" );
  18869. } );
  18870. QUnit.test( "getPoint", ( assert ) => {
  18871. assert.ok( false, "everything's gonna be alright" );
  18872. } );
  18873. // OTHERS
  18874. QUnit.test( "Simple curve", ( assert ) => {
  18875. var expectedPoints = [
  18876. new Vector3( - 10, 0, 2 ),
  18877. new Vector3( - 3.359375, 8.4375, 1.984375 ),
  18878. new Vector3( 5.625, 11.25, 1.125 ),
  18879. new Vector3( 11.796875, 8.4375, 2.703125 ),
  18880. new Vector3( 10, 0, 10 )
  18881. ];
  18882. var points = curve.getPoints( expectedPoints.length - 1 );
  18883. assert.strictEqual( points.length, expectedPoints.length, "Correct number of points" );
  18884. assert.deepEqual( points, expectedPoints, "Correct points calculated" );
  18885. // symmetry
  18886. var curveRev = new CubicBezierCurve3(
  18887. curve.v3, curve.v2, curve.v1, curve.v0
  18888. );
  18889. points = curveRev.getPoints( expectedPoints.length - 1 );
  18890. assert.strictEqual( points.length, expectedPoints.length, "Reversed: Correct number of points" );
  18891. assert.deepEqual( points, expectedPoints.reverse(), "Reversed: Correct points curve" );
  18892. } );
  18893. QUnit.test( "getLength/getLengths", ( assert ) => {
  18894. var length = curve.getLength();
  18895. var expectedLength = 39.58103024989427;
  18896. assert.numEqual( length, expectedLength, "Correct length of curve" );
  18897. var expectedLengths = [
  18898. 0,
  18899. 10.73729718231036,
  18900. 20.19074500737662,
  18901. 27.154413277853756,
  18902. 38.453287150114214
  18903. ];
  18904. var lengths = curve.getLengths( expectedLengths.length - 1 );
  18905. assert.strictEqual( lengths.length, expectedLengths.length, "Correct number of segments" );
  18906. lengths.forEach( function ( segment, i ) {
  18907. assert.numEqual( segment, expectedLengths[ i ], "segment[" + i + "] correct" );
  18908. } );
  18909. } );
  18910. QUnit.test( "getPointAt", ( assert ) => {
  18911. var expectedPoints = [
  18912. new Vector3( - 10, 0, 2 ),
  18913. new Vector3( - 2.591880240484318, 8.908333501170798, 1.8953420625251136 ),
  18914. new Vector3( 4.866251460832755, 11.22787914038507, 1.150832855206874 ),
  18915. new Vector3( 10, 0, 10 )
  18916. ];
  18917. var points = [
  18918. curve.getPointAt( 0 ),
  18919. curve.getPointAt( 0.3 ),
  18920. curve.getPointAt( 0.5 ),
  18921. curve.getPointAt( 1 )
  18922. ];
  18923. assert.deepEqual( points, expectedPoints, "Correct points" );
  18924. } );
  18925. QUnit.test( "getTangent/getTangentAt", ( assert ) => {
  18926. var expectedTangents = [
  18927. new Vector3( 0.3138715439944244, 0.9411440474105875, 0.12542940601858074 ),
  18928. new Vector3( 0.8351825262580098, 0.54174002562179, - 0.09480449605683638 ),
  18929. new Vector3( 0.9997531780538501, 0, - 0.02221672728433752 ),
  18930. new Vector3( 0.40693407933981185, - 0.7512629496079668, 0.5196235518317053 ),
  18931. new Vector3( - 0.42632467075185815, - 0.6396469221230213, 0.6396085444448543 )
  18932. ];
  18933. var tangents = [
  18934. curve.getTangent( 0 ),
  18935. curve.getTangent( 0.25 ),
  18936. curve.getTangent( 0.5 ),
  18937. curve.getTangent( 0.75 ),
  18938. curve.getTangent( 1 )
  18939. ];
  18940. expectedTangents.forEach( function ( exp, i ) {
  18941. var tangent = tangents[ i ];
  18942. assert.numEqual( tangent.x, exp.x, "getTangent #" + i + ": x correct" );
  18943. assert.numEqual( tangent.y, exp.y, "getTangent #" + i + ": y correct" );
  18944. } );
  18945. //
  18946. expectedTangents = [
  18947. new Vector3( 0.3138715439944244, 0.9411440474105875, 0.12542940601858074 ),
  18948. new Vector3( 0.8016539573770751, 0.5918626760037707, - 0.08396133262002324 ),
  18949. new Vector3( 0.997337559412928, 0.05740742907719314, - 0.044968652092444425 ),
  18950. new Vector3( 0.1389373097746809, - 0.7882209938358005, 0.5995032016837588 ),
  18951. new Vector3( - 0.42632467075185815, - 0.6396469221230213, 0.6396085444448543 )
  18952. ];
  18953. tangents = [
  18954. curve.getTangentAt( 0 ),
  18955. curve.getTangentAt( 0.25 ),
  18956. curve.getTangentAt( 0.5 ),
  18957. curve.getTangentAt( 0.75 ),
  18958. curve.getTangentAt( 1 )
  18959. ];
  18960. expectedTangents.forEach( function ( exp, i ) {
  18961. var tangent = tangents[ i ];
  18962. assert.numEqual( tangent.x, exp.x, "getTangentAt #" + i + ": x correct" );
  18963. assert.numEqual( tangent.y, exp.y, "getTangentAt #" + i + ": y correct" );
  18964. } );
  18965. } );
  18966. QUnit.test( "getUtoTmapping", ( assert ) => {
  18967. var start = curve.getUtoTmapping( 0, 0 );
  18968. var end = curve.getUtoTmapping( 0, curve.getLength() );
  18969. var somewhere = curve.getUtoTmapping( 0.5, 1 );
  18970. var expectedSomewhere = 0.021163245321323316;
  18971. assert.strictEqual( start, 0, "getUtoTmapping( 0, 0 ) is the starting point" );
  18972. assert.strictEqual( end, 1, "getUtoTmapping( 0, length ) is the ending point" );
  18973. assert.numEqual( somewhere, expectedSomewhere, "getUtoTmapping( 0.5, 1 ) is correct" );
  18974. } );
  18975. QUnit.test( "getSpacedPoints", ( assert ) => {
  18976. var expectedPoints = [
  18977. new Vector3( - 10, 0, 2 ),
  18978. new Vector3( - 5.756524515061918, 6.568020242700483, 2.22116711170301 ),
  18979. new Vector3( 1.0003511895116906, 10.49656064587831, 1.4727101010850698 ),
  18980. new Vector3( 8.767656412295171, 10.784286845278622, 1.2873599519775174 ),
  18981. new Vector3( 12.306772513558396, 5.545103788071547, 4.909948454535794 ),
  18982. new Vector3( 10, 0, 10 )
  18983. ];
  18984. var points = curve.getSpacedPoints();
  18985. assert.strictEqual( points.length, expectedPoints.length, "Correct number of points" );
  18986. assert.deepEqual( points, expectedPoints, "Correct points calculated" );
  18987. } );
  18988. QUnit.test( "computeFrenetFrames", ( assert ) => {
  18989. var expected = {
  18990. binormals: [
  18991. new Vector3( - 0.9486358543207215, 0.316370061632252, - 6.938893903907228e-18 ),
  18992. new Vector3( - 0.05491430765311864, 0.9969838307670049, 0.054842137122173326 ),
  18993. new Vector3( 0.5944656510461876, 0.334836503700931, 0.7310917216844742 )
  18994. ],
  18995. normals: [
  18996. new Vector3( 0.03968210891259515, 0.11898683173537697, - 0.9921025471723304 ),
  18997. new Vector3( - 0.047981365124836806, 0.05222670079466692, - 0.9974819097732357 ),
  18998. new Vector3( 0.6818048583242511, - 0.6919077473246573, - 0.23749906180354932 )
  18999. ],
  19000. tangents: [
  19001. new Vector3( 0.3138715439944244, 0.9411440474105875, 0.12542940601858074 ),
  19002. new Vector3( 0.9973375594129282, 0.05740742907719315, - 0.04496865209244443 ),
  19003. new Vector3( - 0.42632467075185815, - 0.6396469221230213, 0.6396085444448543 )
  19004. ]
  19005. };
  19006. var frames = curve.computeFrenetFrames( 2, false );
  19007. Object.keys( expected ).forEach( function ( group, i ) {
  19008. expected[ group ].forEach( function ( vec, j ) {
  19009. assert.numEqual( frames[ group ][ j ].x, vec.x, "Frenet frames [" + i + ", " + j + "].x correct" );
  19010. assert.numEqual( frames[ group ][ j ].y, vec.y, "Frenet frames [" + i + ", " + j + "].y correct" );
  19011. assert.numEqual( frames[ group ][ j ].z, vec.z, "Frenet frames [" + i + ", " + j + "].z correct" );
  19012. } );
  19013. } );
  19014. } );
  19015. } );
  19016. } );
  19017. } );
  19018. /**
  19019. * @author TristanVALCKE / https://github.com/Itee
  19020. */
  19021. /* global QUnit */
  19022. QUnit.module( 'Extras', () => {
  19023. QUnit.module( 'Curves', () => {
  19024. QUnit.module.todo( 'EllipseCurve', ( hooks ) => {
  19025. let curve = undefined;
  19026. hooks.before( function () {
  19027. curve = new EllipseCurve(
  19028. 0, 0, // ax, aY
  19029. 10, 10, // xRadius, yRadius
  19030. 0, 2 * Math.PI, // aStartAngle, aEndAngle
  19031. false, // aClockwise
  19032. 0 // aRotation
  19033. );
  19034. } );
  19035. // INHERITANCE
  19036. QUnit.test( "Extending", ( assert ) => {
  19037. assert.ok( false, "everything's gonna be alright" );
  19038. } );
  19039. // INSTANCING
  19040. QUnit.test( "Instancing", ( assert ) => {
  19041. assert.ok( false, "everything's gonna be alright" );
  19042. } );
  19043. // PUBLIC STUFF
  19044. QUnit.test( "isEllipseCurve", ( assert ) => {
  19045. assert.ok( false, "everything's gonna be alright" );
  19046. } );
  19047. QUnit.test( "getPoint", ( assert ) => {
  19048. assert.ok( false, "everything's gonna be alright" );
  19049. } );
  19050. // OTHERS
  19051. QUnit.test( "Simple curve", ( assert ) => {
  19052. var expectedPoints = [
  19053. new Vector2( 10, 0 ),
  19054. new Vector2( 0, 10 ),
  19055. new Vector2( - 10, 0 ),
  19056. new Vector2( 0, - 10 ),
  19057. new Vector2( 10, 0 )
  19058. ];
  19059. var points = curve.getPoints( expectedPoints.length - 1 );
  19060. assert.strictEqual( points.length, expectedPoints.length, "Correct number of points" );
  19061. points.forEach( function ( point, i ) {
  19062. assert.numEqual( point.x, expectedPoints[ i ].x, "point[" + i + "].x correct" );
  19063. assert.numEqual( point.y, expectedPoints[ i ].y, "point[" + i + "].y correct" );
  19064. } );
  19065. } );
  19066. QUnit.test( "getLength/getLengths", ( assert ) => {
  19067. var length = curve.getLength();
  19068. var expectedLength = 62.829269247282795;
  19069. assert.numEqual( length, expectedLength, "Correct length of curve" );
  19070. var lengths = curve.getLengths( 5 );
  19071. var expectedLengths = [
  19072. 0,
  19073. 11.755705045849462,
  19074. 23.51141009169892,
  19075. 35.26711513754839,
  19076. 47.02282018339785,
  19077. 58.77852522924731
  19078. ];
  19079. assert.strictEqual( lengths.length, expectedLengths.length, "Correct number of segments" );
  19080. lengths.forEach( function ( segment, i ) {
  19081. assert.numEqual( segment, expectedLengths[ i ], "segment[" + i + "] correct" );
  19082. } );
  19083. } );
  19084. QUnit.test( "getPoint/getPointAt", ( assert ) => {
  19085. var testValues = [ 0, 0.3, 0.5, 0.7, 1 ];
  19086. testValues.forEach( function ( val, i ) {
  19087. var expectedX = Math.cos( val * Math.PI * 2 ) * 10;
  19088. var expectedY = Math.sin( val * Math.PI * 2 ) * 10;
  19089. var p = curve.getPoint( val );
  19090. var a = curve.getPointAt( val );
  19091. assert.numEqual( p.x, expectedX, "getPoint(" + val + ").x correct" );
  19092. assert.numEqual( p.y, expectedY, "getPoint(" + val + ").y correct" );
  19093. assert.numEqual( a.x, expectedX, "getPointAt(" + val + ").x correct" );
  19094. assert.numEqual( a.y, expectedY, "getPointAt(" + val + ").y correct" );
  19095. } );
  19096. } );
  19097. QUnit.test( "getTangent", ( assert ) => {
  19098. var expectedTangents = [
  19099. new Vector2( - 0.000314159260186071, 0.9999999506519786 ),
  19100. new Vector2( - 1, 0 ),
  19101. new Vector2( 0, - 1 ),
  19102. new Vector2( 1, 0 ),
  19103. new Vector2( 0.00031415926018600165, 0.9999999506519784 )
  19104. ];
  19105. var tangents = [
  19106. curve.getTangent( 0 ),
  19107. curve.getTangent( 0.25 ),
  19108. curve.getTangent( 0.5 ),
  19109. curve.getTangent( 0.75 ),
  19110. curve.getTangent( 1 )
  19111. ];
  19112. expectedTangents.forEach( function ( exp, i ) {
  19113. var tangent = tangents[ i ];
  19114. assert.numEqual( tangent.x, exp.x, "getTangent #" + i + ": x correct" );
  19115. assert.numEqual( tangent.y, exp.y, "getTangent #" + i + ": y correct" );
  19116. } );
  19117. } );
  19118. QUnit.test( "getUtoTmapping", ( assert ) => {
  19119. var start = curve.getUtoTmapping( 0, 0 );
  19120. var end = curve.getUtoTmapping( 0, curve.getLength() );
  19121. var somewhere = curve.getUtoTmapping( 0.7, 1 );
  19122. var expectedSomewhere = 0.01591614882650014;
  19123. assert.strictEqual( start, 0, "getUtoTmapping( 0, 0 ) is the starting point" );
  19124. assert.strictEqual( end, 1, "getUtoTmapping( 0, length ) is the ending point" );
  19125. assert.numEqual( somewhere, expectedSomewhere, "getUtoTmapping( 0.7, 1 ) is correct" );
  19126. } );
  19127. QUnit.test( "getSpacedPoints", ( assert ) => {
  19128. var expectedPoints = [
  19129. new Vector2( 10, 0 ),
  19130. new Vector2( 3.0901699437494603, 9.51056516295154 ),
  19131. new Vector2( - 8.090169943749492, 5.877852522924707 ),
  19132. new Vector2( - 8.090169943749459, - 5.877852522924751 ),
  19133. new Vector2( 3.0901699437494807, - 9.510565162951533 ),
  19134. new Vector2( 10, - 2.4492935982947065e-15 )
  19135. ];
  19136. var points = curve.getSpacedPoints();
  19137. assert.strictEqual( points.length, expectedPoints.length, "Correct number of points" );
  19138. expectedPoints.forEach( function ( exp, i ) {
  19139. var point = points[ i ];
  19140. assert.numEqual( point.x, exp.x, "Point #" + i + ": x correct" );
  19141. assert.numEqual( point.y, exp.y, "Point #" + i + ": y correct" );
  19142. } );
  19143. } );
  19144. } );
  19145. } );
  19146. } );
  19147. /**
  19148. * @author TristanVALCKE / https://github.com/Itee
  19149. */
  19150. /* global QUnit */
  19151. QUnit.module( 'Extras', () => {
  19152. QUnit.module( 'Curves', () => {
  19153. QUnit.module.todo( 'LineCurve', ( hooks ) => {
  19154. let _points = undefined;
  19155. let _curve = undefined;
  19156. hooks.before( function () {
  19157. _points = [
  19158. new Vector2( 0, 0 ),
  19159. new Vector2( 10, 10 ),
  19160. new Vector2( - 10, 10 ),
  19161. new Vector2( - 8, 5 )
  19162. ];
  19163. _curve = new LineCurve( _points[ 0 ], _points[ 1 ] );
  19164. } );
  19165. // INHERITANCE
  19166. QUnit.test( "Extending", ( assert ) => {
  19167. assert.ok( false, "everything's gonna be alright" );
  19168. } );
  19169. // INSTANCING
  19170. QUnit.test( "Instancing", ( assert ) => {
  19171. assert.ok( false, "everything's gonna be alright" );
  19172. } );
  19173. // PUBLIC STUFF
  19174. QUnit.test( "isLineCurve", ( assert ) => {
  19175. assert.ok( false, "everything's gonna be alright" );
  19176. } );
  19177. QUnit.test( "getPoint", ( assert ) => {
  19178. assert.ok( false, "everything's gonna be alright" );
  19179. } );
  19180. QUnit.test( "getPointAt", ( assert ) => {
  19181. var curve = new LineCurve( _points[ 0 ], _points[ 3 ] );
  19182. var expectedPoints = [
  19183. new Vector2( 0, 0 ),
  19184. new Vector2( - 2.4, 1.5 ),
  19185. new Vector2( - 4, 2.5 ),
  19186. new Vector2( - 8, 5 )
  19187. ];
  19188. var points = [
  19189. curve.getPointAt( 0 ),
  19190. curve.getPointAt( 0.3 ),
  19191. curve.getPointAt( 0.5 ),
  19192. curve.getPointAt( 1 )
  19193. ];
  19194. assert.deepEqual( points, expectedPoints, "Correct points" );
  19195. } );
  19196. QUnit.test( "getTangent", ( assert ) => {
  19197. var curve = _curve;
  19198. var tangent = curve.getTangent( 0 );
  19199. var expectedTangent = Math.sqrt( 0.5 );
  19200. assert.numEqual( tangent.x, expectedTangent, "tangent.x correct" );
  19201. assert.numEqual( tangent.y, expectedTangent, "tangent.y correct" );
  19202. } );
  19203. // OTHERS
  19204. QUnit.test( "Simple curve", ( assert ) => {
  19205. var curve = _curve;
  19206. var expectedPoints = [
  19207. new Vector2( 0, 0 ),
  19208. new Vector2( 2, 2 ),
  19209. new Vector2( 4, 4 ),
  19210. new Vector2( 6, 6 ),
  19211. new Vector2( 8, 8 ),
  19212. new Vector2( 10, 10 )
  19213. ];
  19214. var points = curve.getPoints();
  19215. assert.deepEqual( points, expectedPoints, "Correct points for first curve" );
  19216. //
  19217. curve = new LineCurve( _points[ 1 ], _points[ 2 ] );
  19218. expectedPoints = [
  19219. new Vector2( 10, 10 ),
  19220. new Vector2( 6, 10 ),
  19221. new Vector2( 2, 10 ),
  19222. new Vector2( - 2, 10 ),
  19223. new Vector2( - 6, 10 ),
  19224. new Vector2( - 10, 10 )
  19225. ];
  19226. points = curve.getPoints();
  19227. assert.deepEqual( points, expectedPoints, "Correct points for second curve" );
  19228. } );
  19229. QUnit.test( "getLength/getLengths", ( assert ) => {
  19230. var curve = _curve;
  19231. var length = curve.getLength();
  19232. var expectedLength = Math.sqrt( 200 );
  19233. assert.numEqual( length, expectedLength, "Correct length of curve" );
  19234. var lengths = curve.getLengths( 5 );
  19235. var expectedLengths = [
  19236. 0.0,
  19237. Math.sqrt( 8 ),
  19238. Math.sqrt( 32 ),
  19239. Math.sqrt( 72 ),
  19240. Math.sqrt( 128 ),
  19241. Math.sqrt( 200 )
  19242. ];
  19243. assert.strictEqual( lengths.length, expectedLengths.length, "Correct number of segments" );
  19244. lengths.forEach( function ( segment, i ) {
  19245. assert.numEqual( segment, expectedLengths[ i ], "segment[" + i + "] correct" );
  19246. } );
  19247. } );
  19248. QUnit.test( "getUtoTmapping", ( assert ) => {
  19249. var curve = _curve;
  19250. var start = curve.getUtoTmapping( 0, 0 );
  19251. var end = curve.getUtoTmapping( 0, curve.getLength() );
  19252. var somewhere = curve.getUtoTmapping( 0.3, 0 );
  19253. assert.strictEqual( start, 0, "getUtoTmapping( 0, 0 ) is the starting point" );
  19254. assert.strictEqual( end, 1, "getUtoTmapping( 0, length ) is the ending point" );
  19255. assert.numEqual( somewhere, 0.3, "getUtoTmapping( 0.3, 0 ) is correct" );
  19256. } );
  19257. QUnit.test( "getSpacedPoints", ( assert ) => {
  19258. var curve = _curve;
  19259. var expectedPoints = [
  19260. new Vector2( 0, 0 ),
  19261. new Vector2( 2.5, 2.5 ),
  19262. new Vector2( 5, 5 ),
  19263. new Vector2( 7.5, 7.5 ),
  19264. new Vector2( 10, 10 )
  19265. ];
  19266. var points = curve.getSpacedPoints( 4 );
  19267. assert.strictEqual( points.length, expectedPoints.length, "Correct number of points" );
  19268. assert.deepEqual( points, expectedPoints, "Correct points calculated" );
  19269. } );
  19270. } );
  19271. } );
  19272. } );
  19273. function LineCurve3( v1, v2 ) {
  19274. Curve.call( this );
  19275. this.type = 'LineCurve3';
  19276. this.v1 = v1 || new Vector3();
  19277. this.v2 = v2 || new Vector3();
  19278. }
  19279. LineCurve3.prototype = Object.create( Curve.prototype );
  19280. LineCurve3.prototype.constructor = LineCurve3;
  19281. LineCurve3.prototype.isLineCurve3 = true;
  19282. LineCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  19283. var point = optionalTarget || new Vector3();
  19284. if ( t === 1 ) {
  19285. point.copy( this.v2 );
  19286. } else {
  19287. point.copy( this.v2 ).sub( this.v1 );
  19288. point.multiplyScalar( t ).add( this.v1 );
  19289. }
  19290. return point;
  19291. };
  19292. // Line curve is linear, so we can overwrite default getPointAt
  19293. LineCurve3.prototype.getPointAt = function ( u, optionalTarget ) {
  19294. return this.getPoint( u, optionalTarget );
  19295. };
  19296. LineCurve3.prototype.copy = function ( source ) {
  19297. Curve.prototype.copy.call( this, source );
  19298. this.v1.copy( source.v1 );
  19299. this.v2.copy( source.v2 );
  19300. return this;
  19301. };
  19302. /**
  19303. * @author TristanVALCKE / https://github.com/Itee
  19304. */
  19305. /* global QUnit */
  19306. QUnit.module( 'Extras', () => {
  19307. QUnit.module( 'Curves', () => {
  19308. QUnit.module.todo( 'LineCurve3', ( hooks ) => {
  19309. let _points = undefined;
  19310. let _curve = undefined;
  19311. hooks.before( function () {
  19312. _points = [
  19313. new Vector3( 0, 0, 0 ),
  19314. new Vector3( 10, 10, 10 ),
  19315. new Vector3( - 10, 10, - 10 ),
  19316. new Vector3( - 8, 5, - 7 )
  19317. ];
  19318. _curve = new LineCurve3( _points[ 0 ], _points[ 1 ] );
  19319. } );
  19320. // INHERITANCE
  19321. QUnit.test( "Extending", ( assert ) => {
  19322. assert.ok( false, "everything's gonna be alright" );
  19323. } );
  19324. // INSTANCING
  19325. QUnit.test( "Instancing", ( assert ) => {
  19326. assert.ok( false, "everything's gonna be alright" );
  19327. } );
  19328. // PUBLIC STUFF
  19329. QUnit.test( "isCatmullRomCurve3", ( assert ) => {
  19330. assert.ok( false, "everything's gonna be alright" );
  19331. } );
  19332. QUnit.test( "getPoint", ( assert ) => {
  19333. assert.ok( false, "everything's gonna be alright" );
  19334. } );
  19335. QUnit.test( "getPointAt", ( assert ) => {
  19336. var curve = new LineCurve3( _points[ 0 ], _points[ 3 ] );
  19337. var expectedPoints = [
  19338. new Vector3( 0, 0, 0 ),
  19339. new Vector3( - 2.4, 1.5, - 2.1 ),
  19340. new Vector3( - 4, 2.5, - 3.5 ),
  19341. new Vector3( - 8, 5, - 7 )
  19342. ];
  19343. var points = [
  19344. curve.getPointAt( 0 ),
  19345. curve.getPointAt( 0.3 ),
  19346. curve.getPointAt( 0.5 ),
  19347. curve.getPointAt( 1 )
  19348. ];
  19349. assert.deepEqual( points, expectedPoints, "Correct getPointAt points" );
  19350. } );
  19351. // OTHERS
  19352. QUnit.test( "Simple curve", ( assert ) => {
  19353. var curve = _curve;
  19354. var expectedPoints = [
  19355. new Vector3( 0, 0, 0 ),
  19356. new Vector3( 2, 2, 2 ),
  19357. new Vector3( 4, 4, 4 ),
  19358. new Vector3( 6, 6, 6 ),
  19359. new Vector3( 8, 8, 8 ),
  19360. new Vector3( 10, 10, 10 )
  19361. ];
  19362. var points = curve.getPoints();
  19363. assert.deepEqual( points, expectedPoints, "Correct points for first curve" );
  19364. //
  19365. curve = new LineCurve3( _points[ 1 ], _points[ 2 ] );
  19366. expectedPoints = [
  19367. new Vector3( 10, 10, 10 ),
  19368. new Vector3( 6, 10, 6 ),
  19369. new Vector3( 2, 10, 2 ),
  19370. new Vector3( - 2, 10, - 2 ),
  19371. new Vector3( - 6, 10, - 6 ),
  19372. new Vector3( - 10, 10, - 10 )
  19373. ];
  19374. points = curve.getPoints();
  19375. assert.deepEqual( points, expectedPoints, "Correct points for second curve" );
  19376. } );
  19377. QUnit.test( "getLength/getLengths", ( assert ) => {
  19378. var curve = _curve;
  19379. var length = curve.getLength();
  19380. var expectedLength = Math.sqrt( 300 );
  19381. assert.numEqual( length, expectedLength, "Correct length of curve" );
  19382. var lengths = curve.getLengths( 5 );
  19383. var expectedLengths = [
  19384. 0.0,
  19385. Math.sqrt( 12 ),
  19386. Math.sqrt( 48 ),
  19387. Math.sqrt( 108 ),
  19388. Math.sqrt( 192 ),
  19389. Math.sqrt( 300 )
  19390. ];
  19391. assert.strictEqual( lengths.length, expectedLengths.length, "Correct number of segments" );
  19392. lengths.forEach( function ( segment, i ) {
  19393. assert.numEqual( segment, expectedLengths[ i ], "segment[" + i + "] correct" );
  19394. } );
  19395. } );
  19396. QUnit.test( "getTangent/getTangentAt", ( assert ) => {
  19397. var curve = _curve;
  19398. var tangent = curve.getTangent( 0.5 );
  19399. var expectedTangent = Math.sqrt( 1 / 3 );
  19400. assert.numEqual( tangent.x, expectedTangent, "tangent.x correct" );
  19401. assert.numEqual( tangent.y, expectedTangent, "tangent.y correct" );
  19402. assert.numEqual( tangent.z, expectedTangent, "tangent.z correct" );
  19403. tangent = curve.getTangentAt( 0.5 );
  19404. assert.numEqual( tangent.x, expectedTangent, "tangentAt.x correct" );
  19405. assert.numEqual( tangent.y, expectedTangent, "tangentAt.y correct" );
  19406. assert.numEqual( tangent.z, expectedTangent, "tangentAt.z correct" );
  19407. } );
  19408. QUnit.test( "computeFrenetFrames", ( assert ) => {
  19409. var curve = _curve;
  19410. var expected = {
  19411. binormals: new Vector3( - 0.5 * Math.sqrt( 2 ), 0.5 * Math.sqrt( 2 ), 0 ),
  19412. normals: new Vector3( Math.sqrt( 1 / 6 ), Math.sqrt( 1 / 6 ), - Math.sqrt( 2 / 3 ) ),
  19413. tangents: new Vector3( Math.sqrt( 1 / 3 ), Math.sqrt( 1 / 3 ), Math.sqrt( 1 / 3 ) )
  19414. };
  19415. var frames = curve.computeFrenetFrames( 1, false );
  19416. for ( var val in expected ) {
  19417. assert.numEqual( frames[ val ][ 0 ].x, expected[ val ].x, "Frenet frames " + val + ".x correct" );
  19418. assert.numEqual( frames[ val ][ 0 ].y, expected[ val ].y, "Frenet frames " + val + ".y correct" );
  19419. assert.numEqual( frames[ val ][ 0 ].z, expected[ val ].z, "Frenet frames " + val + ".z correct" );
  19420. }
  19421. } );
  19422. QUnit.test( "getUtoTmapping", ( assert ) => {
  19423. var curve = _curve;
  19424. var start = curve.getUtoTmapping( 0, 0 );
  19425. var end = curve.getUtoTmapping( 0, curve.getLength() );
  19426. var somewhere = curve.getUtoTmapping( 0.7, 0 );
  19427. assert.strictEqual( start, 0, "getUtoTmapping( 0, 0 ) is the starting point" );
  19428. assert.strictEqual( end, 1, "getUtoTmapping( 0, length ) is the ending point" );
  19429. assert.numEqual( somewhere, 0.7, "getUtoTmapping( 0.7, 0 ) is correct" );
  19430. } );
  19431. QUnit.test( "getSpacedPoints", ( assert ) => {
  19432. var curve = _curve;
  19433. var expectedPoints = [
  19434. new Vector3( 0, 0, 0 ),
  19435. new Vector3( 2.5, 2.5, 2.5 ),
  19436. new Vector3( 5, 5, 5 ),
  19437. new Vector3( 7.5, 7.5, 7.5 ),
  19438. new Vector3( 10, 10, 10 )
  19439. ];
  19440. var points = curve.getSpacedPoints( 4 );
  19441. assert.strictEqual( points.length, expectedPoints.length, "Correct number of points" );
  19442. assert.deepEqual( points, expectedPoints, "Correct points calculated" );
  19443. } );
  19444. } );
  19445. } );
  19446. } );
  19447. /**
  19448. * @author TristanVALCKE / https://github.com/Itee
  19449. */
  19450. /* global QUnit */
  19451. QUnit.module( 'Extras', () => {
  19452. QUnit.module( 'Curves', () => {
  19453. QUnit.module.todo( 'QuadraticBezierCurve', ( hooks ) => {
  19454. let _curve = undefined;
  19455. hooks.before( function () {
  19456. _curve = new QuadraticBezierCurve(
  19457. new Vector2( - 10, 0 ),
  19458. new Vector2( 20, 15 ),
  19459. new Vector2( 10, 0 )
  19460. );
  19461. } );
  19462. // INHERITANCE
  19463. QUnit.test( "Extending", ( assert ) => {
  19464. assert.ok( false, "everything's gonna be alright" );
  19465. } );
  19466. // INSTANCING
  19467. QUnit.test( "Instancing", ( assert ) => {
  19468. assert.ok( false, "everything's gonna be alright" );
  19469. } );
  19470. // PUBLIC STUFF
  19471. QUnit.test( "isQuadraticBezierCurve", ( assert ) => {
  19472. assert.ok( false, "everything's gonna be alright" );
  19473. } );
  19474. QUnit.test( "getPoint", ( assert ) => {
  19475. assert.ok( false, "everything's gonna be alright" );
  19476. } );
  19477. // OTHERS
  19478. QUnit.test( "Simple curve", ( assert ) => {
  19479. var curve = _curve;
  19480. var expectedPoints = [
  19481. new Vector2( - 10, 0 ),
  19482. new Vector2( 2.5, 5.625 ),
  19483. new Vector2( 10, 7.5 ),
  19484. new Vector2( 12.5, 5.625 ),
  19485. new Vector2( 10, 0 )
  19486. ];
  19487. var points = curve.getPoints( expectedPoints.length - 1 );
  19488. assert.strictEqual( points.length, expectedPoints.length, "Correct number of points" );
  19489. assert.deepEqual( points, expectedPoints, "Correct points calculated" );
  19490. // symmetry
  19491. var curveRev = new QuadraticBezierCurve(
  19492. curve.v2, curve.v1, curve.v0
  19493. );
  19494. points = curveRev.getPoints( expectedPoints.length - 1 );
  19495. assert.strictEqual( points.length, expectedPoints.length, "Reversed: Correct number of points" );
  19496. assert.deepEqual( points, expectedPoints.reverse(), "Reversed: Correct points curve" );
  19497. } );
  19498. QUnit.test( "getLength/getLengths", ( assert ) => {
  19499. var curve = _curve;
  19500. var length = curve.getLength();
  19501. var expectedLength = 31.269026549416683;
  19502. assert.numEqual( length, expectedLength, "Correct length of curve" );
  19503. var expectedLengths = [
  19504. 0,
  19505. 13.707320124663317,
  19506. 21.43814317269643,
  19507. 24.56314317269643,
  19508. 30.718679298818998
  19509. ];
  19510. var lengths = curve.getLengths( expectedLengths.length - 1 );
  19511. assert.strictEqual( lengths.length, expectedLengths.length, "Correct number of segments" );
  19512. lengths.forEach( function ( segment, i ) {
  19513. assert.numEqual( segment, expectedLengths[ i ], "segment[" + i + "] correct" );
  19514. } );
  19515. } );
  19516. QUnit.test( "getPointAt", ( assert ) => {
  19517. var curve = _curve;
  19518. var expectedPoints = [
  19519. new Vector2( - 10, 0 ),
  19520. new Vector2( - 1.5127849599387615, 3.993582003773624 ),
  19521. new Vector2( 4.310076165722796, 6.269921971403917 ),
  19522. new Vector2( 10, 0 )
  19523. ];
  19524. var points = [
  19525. curve.getPointAt( 0 ),
  19526. curve.getPointAt( 0.3 ),
  19527. curve.getPointAt( 0.5 ),
  19528. curve.getPointAt( 1 )
  19529. ];
  19530. assert.deepEqual( points, expectedPoints, "Correct points" );
  19531. } );
  19532. QUnit.test( "getTangent/getTangentAt", ( assert ) => {
  19533. var curve = _curve;
  19534. var expectedTangents = [
  19535. new Vector2( 0.89443315420562, 0.44720166888975904 ),
  19536. new Vector2( 0.936329177569021, 0.3511234415884543 ),
  19537. new Vector2( 1, 0 ),
  19538. new Vector2( - 5.921189464667277e-13, - 1 ),
  19539. new Vector2( - 0.5546617882904897, - 0.8320758983472577 )
  19540. ];
  19541. var tangents = [
  19542. curve.getTangent( 0 ),
  19543. curve.getTangent( 0.25 ),
  19544. curve.getTangent( 0.5 ),
  19545. curve.getTangent( 0.75 ),
  19546. curve.getTangent( 1 )
  19547. ];
  19548. expectedTangents.forEach( function ( exp, i ) {
  19549. var tangent = tangents[ i ];
  19550. assert.numEqual( tangent.x, exp.x, "getTangent #" + i + ": x correct" );
  19551. assert.numEqual( tangent.y, exp.y, "getTangent #" + i + ": y correct" );
  19552. } );
  19553. //
  19554. expectedTangents = [
  19555. new Vector2( 0.89443315420562, 0.44720166888975904 ),
  19556. new Vector2( 0.9125211423360805, 0.40902954024086674 ),
  19557. new Vector2( 0.9480289098765387, 0.3181842014278863 ),
  19558. new Vector2( 0.7969127189169473, - 0.6040944615111106 ),
  19559. new Vector2( - 0.5546617882904897, - 0.8320758983472577 )
  19560. ];
  19561. tangents = [
  19562. curve.getTangentAt( 0 ),
  19563. curve.getTangentAt( 0.25 ),
  19564. curve.getTangentAt( 0.5 ),
  19565. curve.getTangentAt( 0.75 ),
  19566. curve.getTangentAt( 1 )
  19567. ];
  19568. expectedTangents.forEach( function ( exp, i ) {
  19569. var tangent = tangents[ i ];
  19570. assert.numEqual( tangent.x, exp.x, "getTangentAt #" + i + ": x correct" );
  19571. assert.numEqual( tangent.y, exp.y, "getTangentAt #" + i + ": y correct" );
  19572. } );
  19573. } );
  19574. QUnit.test( "getUtoTmapping", ( assert ) => {
  19575. var curve = _curve;
  19576. var start = curve.getUtoTmapping( 0, 0 );
  19577. var end = curve.getUtoTmapping( 0, curve.getLength() );
  19578. var somewhere = curve.getUtoTmapping( 0.5, 1 );
  19579. var expectedSomewhere = 0.015073978276116116;
  19580. assert.strictEqual( start, 0, "getUtoTmapping( 0, 0 ) is the starting point" );
  19581. assert.strictEqual( end, 1, "getUtoTmapping( 0, length ) is the ending point" );
  19582. assert.numEqual( somewhere, expectedSomewhere, "getUtoTmapping( 0.5, 1 ) is correct" );
  19583. } );
  19584. QUnit.test( "getSpacedPoints", ( assert ) => {
  19585. var curve = _curve;
  19586. var expectedPoints = [
  19587. new Vector2( - 10, 0 ),
  19588. new Vector2( - 4.366603655406173, 2.715408933540383 ),
  19589. new Vector2( 1.3752241477827831, 5.191972084404416 ),
  19590. new Vector2( 7.312990279153634, 7.136310044848586 ),
  19591. new Vector2( 12.499856644824826, 5.653289188715387 ),
  19592. new Vector2( 10, 0 )
  19593. ];
  19594. var points = curve.getSpacedPoints();
  19595. assert.strictEqual( points.length, expectedPoints.length, "Correct number of points" );
  19596. assert.deepEqual( points, expectedPoints, "Correct points calculated" );
  19597. } );
  19598. } );
  19599. } );
  19600. } );
  19601. function QuadraticBezierCurve3( v0, v1, v2 ) {
  19602. Curve.call( this );
  19603. this.type = 'QuadraticBezierCurve3';
  19604. this.v0 = v0 || new Vector3();
  19605. this.v1 = v1 || new Vector3();
  19606. this.v2 = v2 || new Vector3();
  19607. }
  19608. QuadraticBezierCurve3.prototype = Object.create( Curve.prototype );
  19609. QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3;
  19610. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  19611. QuadraticBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  19612. var point = optionalTarget || new Vector3();
  19613. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  19614. point.set(
  19615. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  19616. QuadraticBezier( t, v0.y, v1.y, v2.y ),
  19617. QuadraticBezier( t, v0.z, v1.z, v2.z )
  19618. );
  19619. return point;
  19620. };
  19621. QuadraticBezierCurve3.prototype.copy = function ( source ) {
  19622. Curve.prototype.copy.call( this, source );
  19623. this.v0.copy( source.v0 );
  19624. this.v1.copy( source.v1 );
  19625. this.v2.copy( source.v2 );
  19626. return this;
  19627. };
  19628. /**
  19629. * @author TristanVALCKE / https://github.com/Itee
  19630. */
  19631. /* global QUnit */
  19632. QUnit.module( 'Extras', () => {
  19633. QUnit.module( 'Curves', () => {
  19634. QUnit.module.todo( 'QuadraticBezierCurve3', ( hooks ) => {
  19635. let _curve = undefined;
  19636. hooks.before( function () {
  19637. _curve = new QuadraticBezierCurve3(
  19638. new Vector3( - 10, 0, 2 ),
  19639. new Vector3( 20, 15, - 5 ),
  19640. new Vector3( 10, 0, 10 )
  19641. );
  19642. } );
  19643. // INHERITANCE
  19644. QUnit.test( "Extending", ( assert ) => {
  19645. assert.ok( false, "everything's gonna be alright" );
  19646. } );
  19647. // INSTANCING
  19648. QUnit.test( "Instancing", ( assert ) => {
  19649. assert.ok( false, "everything's gonna be alright" );
  19650. } );
  19651. // PUBLIC STUFF
  19652. QUnit.test( "isQuadraticBezierCurve3", ( assert ) => {
  19653. assert.ok( false, "everything's gonna be alright" );
  19654. } );
  19655. QUnit.test( "getPoint", ( assert ) => {
  19656. assert.ok( false, "everything's gonna be alright" );
  19657. } );
  19658. // OTHERS
  19659. QUnit.test( "Simple curve", ( assert ) => {
  19660. var curve = _curve;
  19661. var expectedPoints = [
  19662. new Vector3( - 10, 0, 2 ),
  19663. new Vector3( 2.5, 5.625, - 0.125 ),
  19664. new Vector3( 10, 7.5, 0.5 ),
  19665. new Vector3( 12.5, 5.625, 3.875 ),
  19666. new Vector3( 10, 0, 10 )
  19667. ];
  19668. var points = curve.getPoints( expectedPoints.length - 1 );
  19669. assert.strictEqual( points.length, expectedPoints.length, "Correct number of points" );
  19670. assert.deepEqual( points, expectedPoints, "Correct points calculated" );
  19671. // symmetry
  19672. var curveRev = new QuadraticBezierCurve3(
  19673. curve.v2, curve.v1, curve.v0
  19674. );
  19675. points = curveRev.getPoints( expectedPoints.length - 1 );
  19676. assert.strictEqual( points.length, expectedPoints.length, "Reversed: Correct number of points" );
  19677. assert.deepEqual( points, expectedPoints.reverse(), "Reversed: Correct points curve" );
  19678. } );
  19679. QUnit.test( "getLength/getLengths", ( assert ) => {
  19680. var curve = _curve;
  19681. var length = curve.getLength();
  19682. var expectedLength = 35.47294274967861;
  19683. assert.numEqual( length, expectedLength, "Correct length of curve" );
  19684. var expectedLengths = [
  19685. 0,
  19686. 13.871057998581074,
  19687. 21.62710402732536,
  19688. 26.226696400568883,
  19689. 34.91037361704809
  19690. ];
  19691. var lengths = curve.getLengths( expectedLengths.length - 1 );
  19692. assert.strictEqual( lengths.length, expectedLengths.length, "Correct number of segments" );
  19693. lengths.forEach( function ( segment, i ) {
  19694. assert.numEqual( segment, expectedLengths[ i ], "segment[" + i + "] correct" );
  19695. } );
  19696. } );
  19697. QUnit.test( "getPointAt", ( assert ) => {
  19698. var curve = _curve;
  19699. var expectedPoints = [
  19700. new Vector3( - 10, 0, 2 ),
  19701. new Vector3( - 0.4981634504454243, 4.427089043881476, 0.19308849757196012 ),
  19702. new Vector3( 6.149415812887238, 6.838853310980195, - 0.20278120208668637 ),
  19703. new Vector3( 10, 0, 10 )
  19704. ];
  19705. var points = [
  19706. curve.getPointAt( 0 ),
  19707. curve.getPointAt( 0.3 ),
  19708. curve.getPointAt( 0.5 ),
  19709. curve.getPointAt( 1 )
  19710. ];
  19711. assert.deepEqual( points, expectedPoints, "Correct points" );
  19712. } );
  19713. QUnit.test( "getTangent/getTangentAt", ( assert ) => {
  19714. var curve = _curve;
  19715. var expectedTangents = [
  19716. new Vector3( 0.8755715084258769, 0.4377711603816079, - 0.2042815331129452 ),
  19717. new Vector3( 0.9340289249885844, 0.3502608468707904, - 0.07005216937416067 ),
  19718. new Vector3( 0.9284766908853163, 0, 0.37139067635396156 ),
  19719. new Vector3( - 3.669031233375946e-13, - 0.6196442885791218, 0.7848827655333463 ),
  19720. new Vector3( - 0.4263618889888853, - 0.6396068005601663, 0.6396238584473043 )
  19721. ];
  19722. var tangents = [
  19723. curve.getTangent( 0 ),
  19724. curve.getTangent( 0.25 ),
  19725. curve.getTangent( 0.5 ),
  19726. curve.getTangent( 0.75 ),
  19727. curve.getTangent( 1 )
  19728. ];
  19729. expectedTangents.forEach( function ( exp, i ) {
  19730. var tangent = tangents[ i ];
  19731. assert.numEqual( tangent.x, exp.x, "getTangent #" + i + ": x correct" );
  19732. assert.numEqual( tangent.y, exp.y, "getTangent #" + i + ": y correct" );
  19733. } );
  19734. //
  19735. expectedTangents = [
  19736. new Vector3( 0.8755715084258769, 0.4377711603816079, - 0.2042815331129452 ),
  19737. new Vector3( 0.9060725703490549, 0.3984742932857448, - 0.14230507668907377 ),
  19738. new Vector3( 0.9621604167456882, 0.2688562845452628, 0.044312872940942424 ),
  19739. new Vector3( 0.016586454041780826, - 0.6163270940470614, 0.7873155674098058 ),
  19740. new Vector3( - 0.4263618889888853, - 0.6396068005601663, 0.6396238584473043 )
  19741. ];
  19742. tangents = [
  19743. curve.getTangentAt( 0 ),
  19744. curve.getTangentAt( 0.25 ),
  19745. curve.getTangentAt( 0.5 ),
  19746. curve.getTangentAt( 0.75 ),
  19747. curve.getTangentAt( 1 )
  19748. ];
  19749. expectedTangents.forEach( function ( exp, i ) {
  19750. var tangent = tangents[ i ];
  19751. assert.numEqual( tangent.x, exp.x, "getTangentAt #" + i + ": x correct" );
  19752. assert.numEqual( tangent.y, exp.y, "getTangentAt #" + i + ": y correct" );
  19753. } );
  19754. } );
  19755. QUnit.test( "getUtoTmapping", ( assert ) => {
  19756. var curve = _curve;
  19757. var start = curve.getUtoTmapping( 0, 0 );
  19758. var end = curve.getUtoTmapping( 0, curve.getLength() );
  19759. var somewhere = curve.getUtoTmapping( 0.5, 1 );
  19760. var expectedSomewhere = 0.014760890927167196;
  19761. assert.strictEqual( start, 0, "getUtoTmapping( 0, 0 ) is the starting point" );
  19762. assert.strictEqual( end, 1, "getUtoTmapping( 0, length ) is the ending point" );
  19763. assert.numEqual( somewhere, expectedSomewhere, "getUtoTmapping( 0.5, 1 ) is correct" );
  19764. } );
  19765. QUnit.test( "getSpacedPoints", ( assert ) => {
  19766. var curve = _curve;
  19767. var expectedPoints = [
  19768. new Vector3( - 10, 0, 2 ),
  19769. new Vector3( - 3.712652983516992, 3.015179001762753, 0.6957120710270492 ),
  19770. new Vector3( 2.7830973773262975, 5.730399338061483, - 0.1452668772806931 ),
  19771. new Vector3( 9.575825284074465, 7.48754187603603, 0.3461104039841496 ),
  19772. new Vector3( 12.345199937734154, 4.575759904730531, 5.142117429101656 ),
  19773. new Vector3( 10, 0, 10 )
  19774. ];
  19775. var points = curve.getSpacedPoints();
  19776. assert.strictEqual( points.length, expectedPoints.length, "Correct number of points" );
  19777. assert.deepEqual( points, expectedPoints, "Correct points calculated" );
  19778. } );
  19779. QUnit.test( "computeFrenetFrames", ( assert ) => {
  19780. var curve = _curve;
  19781. var expected = {
  19782. binormals: [
  19783. new Vector3( - 0.447201668889759, 0.8944331542056199, 0 ),
  19784. new Vector3( - 0.2684231751110917, 0.9631753839815436, - 0.01556209353802903 ),
  19785. new Vector3( 0.3459273556592433, 0.53807011680075, 0.7686447905324219 )
  19786. ],
  19787. normals: [
  19788. new Vector3( - 0.18271617600817133, - 0.09135504253146765, - 0.9789121795283909 ),
  19789. new Vector3( 0.046865035058597876, - 0.003078628350883253, - 0.9988964863970807 ),
  19790. new Vector3( 0.8357929194629689, - 0.5489842348221077, 0.008155102228190641 )
  19791. ],
  19792. tangents: [
  19793. new Vector3( 0.8755715084258767, 0.4377711603816078, - 0.20428153311294514 ),
  19794. new Vector3( 0.9621604167456884, 0.26885628454526284, 0.04431287294094243 ),
  19795. new Vector3( - 0.4263618889888853, - 0.6396068005601663, 0.6396238584473043 )
  19796. ]
  19797. };
  19798. var frames = curve.computeFrenetFrames( 2, false );
  19799. Object.keys( expected ).forEach( function ( group, i ) {
  19800. expected[ group ].forEach( function ( vec, j ) {
  19801. assert.numEqual( frames[ group ][ j ].x, vec.x, "Frenet frames [" + i + ", " + j + "].x correct" );
  19802. assert.numEqual( frames[ group ][ j ].y, vec.y, "Frenet frames [" + i + ", " + j + "].y correct" );
  19803. assert.numEqual( frames[ group ][ j ].z, vec.z, "Frenet frames [" + i + ", " + j + "].z correct" );
  19804. } );
  19805. } );
  19806. } );
  19807. } );
  19808. } );
  19809. } );
  19810. /**
  19811. * @author TristanVALCKE / https://github.com/Itee
  19812. */
  19813. /* global QUnit */
  19814. QUnit.module( 'Extras', () => {
  19815. QUnit.module( 'Curves', () => {
  19816. QUnit.module.todo( 'SplineCurve', ( hooks ) => {
  19817. let _curve = undefined;
  19818. hooks.before( function () {
  19819. _curve = new SplineCurve( [
  19820. new Vector2( - 10, 0 ),
  19821. new Vector2( - 5, 5 ),
  19822. new Vector2( 0, 0 ),
  19823. new Vector2( 5, - 5 ),
  19824. new Vector2( 10, 0 )
  19825. ] );
  19826. } );
  19827. // INHERITANCE
  19828. QUnit.test( "Extending", ( assert ) => {
  19829. assert.ok( false, "everything's gonna be alright" );
  19830. } );
  19831. // INSTANCING
  19832. QUnit.test( "Instancing", ( assert ) => {
  19833. assert.ok( false, "everything's gonna be alright" );
  19834. } );
  19835. // PUBLIC STUFF
  19836. QUnit.test( "isSplineCurve", ( assert ) => {
  19837. assert.ok( false, "everything's gonna be alright" );
  19838. } );
  19839. QUnit.test( "getPoint", ( assert ) => {
  19840. assert.ok( false, "everything's gonna be alright" );
  19841. } );
  19842. // OTHERS
  19843. QUnit.test( "Simple curve", ( assert ) => {
  19844. var curve = _curve;
  19845. var expectedPoints = [
  19846. new Vector2( - 10, 0 ),
  19847. new Vector2( - 6.08, 4.56 ),
  19848. new Vector2( - 2, 2.48 ),
  19849. new Vector2( 2, - 2.48 ),
  19850. new Vector2( 6.08, - 4.56 ),
  19851. new Vector2( 10, 0 )
  19852. ];
  19853. var points = curve.getPoints( 5 );
  19854. assert.strictEqual( points.length, expectedPoints.length, "1st: Correct number of points" );
  19855. points.forEach( function ( point, i ) {
  19856. assert.numEqual( point.x, expectedPoints[ i ].x, "points[" + i + "].x" );
  19857. assert.numEqual( point.y, expectedPoints[ i ].y, "points[" + i + "].y" );
  19858. } );
  19859. //
  19860. points = curve.getPoints( 4 );
  19861. assert.deepEqual( points, curve.points, "2nd: Returned points are identical to control points" );
  19862. } );
  19863. QUnit.test( "getLength/getLengths", ( assert ) => {
  19864. var curve = _curve;
  19865. var length = curve.getLength();
  19866. var expectedLength = 28.876950901868135;
  19867. assert.numEqual( length, expectedLength, "Correct length of curve" );
  19868. var expectedLengths = [
  19869. 0.0,
  19870. Math.sqrt( 50 ),
  19871. Math.sqrt( 200 ),
  19872. Math.sqrt( 450 ),
  19873. Math.sqrt( 800 )
  19874. ];
  19875. var lengths = curve.getLengths( 4 );
  19876. assert.deepEqual( lengths, expectedLengths, "Correct segment lengths" );
  19877. } );
  19878. QUnit.test( "getPointAt", ( assert ) => {
  19879. var curve = _curve;
  19880. assert.ok( curve.getPointAt( 0 ).equals( curve.points[ 0 ] ), "PointAt 0.0 correct" );
  19881. assert.ok( curve.getPointAt( 1 ).equals( curve.points[ 4 ] ), "PointAt 1.0 correct" );
  19882. var pointAt = curve.getPointAt( 0.5 );
  19883. assert.numEqual( pointAt.x, 0.0, "PointAt 0.5 x correct" );
  19884. assert.numEqual( pointAt.y, 0.0, "PointAt 0.5 y correct" );
  19885. } );
  19886. QUnit.test( "getTangent", ( assert ) => {
  19887. var curve = _curve;
  19888. var expectedTangent = [
  19889. new Vector2( 0.7068243340243188, 0.7073891155729485 ), // 0
  19890. new Vector2( 0.7069654305325396, - 0.7072481035902046 ), // 0.5
  19891. new Vector2( 0.7068243340245123, 0.7073891155727552 ) // 1
  19892. ];
  19893. var tangents = [
  19894. curve.getTangent( 0 ),
  19895. curve.getTangent( 0.5 ),
  19896. curve.getTangent( 1 )
  19897. ];
  19898. tangents.forEach( function ( tangent, i ) {
  19899. assert.numEqual( tangent.x, expectedTangent[ i ].x, "tangent[" + i + "].x" );
  19900. assert.numEqual( tangent.y, expectedTangent[ i ].y, "tangent[" + i + "].y" );
  19901. } );
  19902. } );
  19903. QUnit.test( "getUtoTmapping", ( assert ) => {
  19904. var curve = _curve;
  19905. var start = curve.getUtoTmapping( 0, 0 );
  19906. var end = curve.getUtoTmapping( 0, curve.getLength() );
  19907. var middle = curve.getUtoTmapping( 0.5, 0 );
  19908. assert.strictEqual( start, 0, "getUtoTmapping( 0, 0 ) is the starting point" );
  19909. assert.strictEqual( end, 1, "getUtoTmapping( 0, length ) is the ending point" );
  19910. assert.numEqual( middle, 0.5, "getUtoTmapping( 0.5, 0 ) is the middle" );
  19911. } );
  19912. QUnit.test( "getSpacedPoints", ( assert ) => {
  19913. var curve = _curve;
  19914. var expectedPoints = [
  19915. new Vector2( - 10, 0 ),
  19916. new Vector2( - 4.996509634683014, 4.999995128640857 ),
  19917. new Vector2( 0, 0 ),
  19918. new Vector2( 4.996509634683006, - 4.999995128640857 ),
  19919. new Vector2( 10, 0 )
  19920. ];
  19921. var points = curve.getSpacedPoints( 4 );
  19922. assert.strictEqual( points.length, expectedPoints.length, "Correct number of points" );
  19923. points.forEach( function ( point, i ) {
  19924. assert.numEqual( point.x, expectedPoints[ i ].x, "points[" + i + "].x" );
  19925. assert.numEqual( point.y, expectedPoints[ i ].y, "points[" + i + "].y" );
  19926. } );
  19927. } );
  19928. } );
  19929. } );
  19930. } );
  19931. /**
  19932. * @author TristanVALCKE / https://github.com/Itee
  19933. */
  19934. /* global QUnit */
  19935. QUnit.module( 'Extras', () => {
  19936. QUnit.module( 'Objects', () => {
  19937. QUnit.module.todo( 'ImmediateRenderObject', () => {
  19938. // INHERITANCE
  19939. QUnit.test( "Extending", ( assert ) => {
  19940. assert.ok( false, "everything's gonna be alright" );
  19941. } );
  19942. // INSTANCING
  19943. QUnit.test( "Instancing", ( assert ) => {
  19944. assert.ok( false, "everything's gonna be alright" );
  19945. } );
  19946. // PUBLIC STUFF
  19947. QUnit.test( "isImmediateRenderObject", ( assert ) => {
  19948. assert.ok( false, "everything's gonna be alright" );
  19949. } );
  19950. } );
  19951. } );
  19952. } );
  19953. /**
  19954. * @author TristanVALCKE / https://github.com/Itee
  19955. * @author Anonymous
  19956. */
  19957. /* global QUnit */
  19958. QUnit.module( 'Geometries', () => {
  19959. QUnit.module.todo( 'BoxGeometry', ( hooks ) => {
  19960. var geometries = undefined;
  19961. hooks.beforeEach( function () {
  19962. const parameters = {
  19963. width: 10,
  19964. height: 20,
  19965. depth: 30,
  19966. widthSegments: 2,
  19967. heightSegments: 3,
  19968. depthSegments: 4
  19969. };
  19970. geometries = [
  19971. new BoxGeometry(),
  19972. new BoxGeometry( parameters.width, parameters.height, parameters.depth ),
  19973. new BoxGeometry( parameters.width, parameters.height, parameters.depth, parameters.widthSegments, parameters.heightSegments, parameters.depthSegments )
  19974. ];
  19975. } );
  19976. // INHERITANCE
  19977. QUnit.test( "Extending", ( assert ) => {
  19978. assert.ok( false, "everything's gonna be alright" );
  19979. } );
  19980. // INSTANCING
  19981. QUnit.test( "Instancing", ( assert ) => {
  19982. assert.ok( false, "everything's gonna be alright" );
  19983. } );
  19984. // OTHERS
  19985. QUnit.test( 'Standard geometry tests', ( assert ) => {
  19986. runStdGeometryTests( assert, geometries );
  19987. } );
  19988. } );
  19989. QUnit.module.todo( 'BoxBufferGeometry', ( hooks ) => {
  19990. var geometries = undefined;
  19991. hooks.beforeEach( function () {
  19992. const parameters = {
  19993. width: 10,
  19994. height: 20,
  19995. depth: 30,
  19996. widthSegments: 2,
  19997. heightSegments: 3,
  19998. depthSegments: 4
  19999. };
  20000. geometries = [
  20001. new BoxBufferGeometry(),
  20002. new BoxBufferGeometry( parameters.width, parameters.height, parameters.depth ),
  20003. new BoxBufferGeometry( parameters.width, parameters.height, parameters.depth, parameters.widthSegments, parameters.heightSegments, parameters.depthSegments )
  20004. ];
  20005. } );
  20006. // INHERITANCE
  20007. QUnit.test( "Extending", ( assert ) => {
  20008. assert.ok( false, "everything's gonna be alright" );
  20009. } );
  20010. // INSTANCING
  20011. QUnit.test( "Instancing", ( assert ) => {
  20012. assert.ok( false, "everything's gonna be alright" );
  20013. } );
  20014. // OTHERS
  20015. QUnit.test( 'Standard geometry tests', ( assert ) => {
  20016. runStdGeometryTests( assert, geometries );
  20017. } );
  20018. } );
  20019. } );
  20020. /**
  20021. * @author benaadams / https://twitter.com/ben_a_adams
  20022. * @author Mugen87 / https://github.com/Mugen87
  20023. * @author hughes
  20024. */
  20025. function CircleGeometry( radius, segments, thetaStart, thetaLength ) {
  20026. Geometry.call( this );
  20027. this.type = 'CircleGeometry';
  20028. this.parameters = {
  20029. radius: radius,
  20030. segments: segments,
  20031. thetaStart: thetaStart,
  20032. thetaLength: thetaLength
  20033. };
  20034. this.fromBufferGeometry( new CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
  20035. this.mergeVertices();
  20036. }
  20037. CircleGeometry.prototype = Object.create( Geometry.prototype );
  20038. CircleGeometry.prototype.constructor = CircleGeometry;
  20039. // CircleBufferGeometry
  20040. function CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) {
  20041. BufferGeometry.call( this );
  20042. this.type = 'CircleBufferGeometry';
  20043. this.parameters = {
  20044. radius: radius,
  20045. segments: segments,
  20046. thetaStart: thetaStart,
  20047. thetaLength: thetaLength
  20048. };
  20049. radius = radius || 1;
  20050. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  20051. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  20052. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  20053. // buffers
  20054. var indices = [];
  20055. var vertices = [];
  20056. var normals = [];
  20057. var uvs = [];
  20058. // helper variables
  20059. var i, s;
  20060. var vertex = new Vector3();
  20061. var uv = new Vector2();
  20062. // center point
  20063. vertices.push( 0, 0, 0 );
  20064. normals.push( 0, 0, 1 );
  20065. uvs.push( 0.5, 0.5 );
  20066. for ( s = 0, i = 3; s <= segments; s ++, i += 3 ) {
  20067. var segment = thetaStart + s / segments * thetaLength;
  20068. // vertex
  20069. vertex.x = radius * Math.cos( segment );
  20070. vertex.y = radius * Math.sin( segment );
  20071. vertices.push( vertex.x, vertex.y, vertex.z );
  20072. // normal
  20073. normals.push( 0, 0, 1 );
  20074. // uvs
  20075. uv.x = ( vertices[ i ] / radius + 1 ) / 2;
  20076. uv.y = ( vertices[ i + 1 ] / radius + 1 ) / 2;
  20077. uvs.push( uv.x, uv.y );
  20078. }
  20079. // indices
  20080. for ( i = 1; i <= segments; i ++ ) {
  20081. indices.push( i, i + 1, 0 );
  20082. }
  20083. // build geometry
  20084. this.setIndex( indices );
  20085. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  20086. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  20087. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  20088. }
  20089. CircleBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  20090. CircleBufferGeometry.prototype.constructor = CircleBufferGeometry;
  20091. /**
  20092. * @author TristanVALCKE / https://github.com/Itee
  20093. * @author Anonymous
  20094. */
  20095. /* global QUnit */
  20096. QUnit.module( 'Geometries', () => {
  20097. QUnit.module.todo( 'CircleGeometry', ( hooks ) => {
  20098. var geometries = undefined;
  20099. hooks.beforeEach( function () {
  20100. const parameters = {
  20101. radius: 10,
  20102. segments: 20,
  20103. thetaStart: 0.1,
  20104. thetaLength: 0.2
  20105. };
  20106. geometries = [
  20107. new CircleGeometry(),
  20108. new CircleGeometry( parameters.radius ),
  20109. new CircleGeometry( parameters.radius, parameters.segments ),
  20110. new CircleGeometry( parameters.radius, parameters.segments, parameters.thetaStart ),
  20111. new CircleGeometry( parameters.radius, parameters.segments, parameters.thetaStart, parameters.thetaLength ),
  20112. ];
  20113. } );
  20114. // INHERITANCE
  20115. QUnit.test( "Extending", ( assert ) => {
  20116. assert.ok( false, "everything's gonna be alright" );
  20117. } );
  20118. // INSTANCING
  20119. QUnit.test( "Instancing", ( assert ) => {
  20120. assert.ok( false, "everything's gonna be alright" );
  20121. } );
  20122. // OTHERS
  20123. QUnit.test( 'Standard geometry tests', ( assert ) => {
  20124. runStdGeometryTests( assert, geometries );
  20125. } );
  20126. } );
  20127. QUnit.module.todo( 'CircleBufferGeometry', ( hooks ) => {
  20128. var geometries = undefined;
  20129. hooks.beforeEach( function () {
  20130. const parameters = {
  20131. radius: 10,
  20132. segments: 20,
  20133. thetaStart: 0.1,
  20134. thetaLength: 0.2
  20135. };
  20136. geometries = [
  20137. new CircleBufferGeometry(),
  20138. new CircleBufferGeometry( parameters.radius ),
  20139. new CircleBufferGeometry( parameters.radius, parameters.segments ),
  20140. new CircleBufferGeometry( parameters.radius, parameters.segments, parameters.thetaStart ),
  20141. new CircleBufferGeometry( parameters.radius, parameters.segments, parameters.thetaStart, parameters.thetaLength ),
  20142. ];
  20143. } );
  20144. // INHERITANCE
  20145. QUnit.test( "Extending", ( assert ) => {
  20146. assert.ok( false, "everything's gonna be alright" );
  20147. } );
  20148. // INSTANCING
  20149. QUnit.test( "Instancing", ( assert ) => {
  20150. assert.ok( false, "everything's gonna be alright" );
  20151. } );
  20152. // OTHERS
  20153. QUnit.test( 'Standard geometry tests', ( assert ) => {
  20154. runStdGeometryTests( assert, geometries );
  20155. } );
  20156. } );
  20157. } );
  20158. /**
  20159. * @author mrdoob / http://mrdoob.com/
  20160. * @author Mugen87 / https://github.com/Mugen87
  20161. */
  20162. function CylinderGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  20163. Geometry.call( this );
  20164. this.type = 'CylinderGeometry';
  20165. this.parameters = {
  20166. radiusTop: radiusTop,
  20167. radiusBottom: radiusBottom,
  20168. height: height,
  20169. radialSegments: radialSegments,
  20170. heightSegments: heightSegments,
  20171. openEnded: openEnded,
  20172. thetaStart: thetaStart,
  20173. thetaLength: thetaLength
  20174. };
  20175. this.fromBufferGeometry( new CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) );
  20176. this.mergeVertices();
  20177. }
  20178. CylinderGeometry.prototype = Object.create( Geometry.prototype );
  20179. CylinderGeometry.prototype.constructor = CylinderGeometry;
  20180. // CylinderBufferGeometry
  20181. function CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  20182. BufferGeometry.call( this );
  20183. this.type = 'CylinderBufferGeometry';
  20184. this.parameters = {
  20185. radiusTop: radiusTop,
  20186. radiusBottom: radiusBottom,
  20187. height: height,
  20188. radialSegments: radialSegments,
  20189. heightSegments: heightSegments,
  20190. openEnded: openEnded,
  20191. thetaStart: thetaStart,
  20192. thetaLength: thetaLength
  20193. };
  20194. var scope = this;
  20195. radiusTop = radiusTop !== undefined ? radiusTop : 1;
  20196. radiusBottom = radiusBottom !== undefined ? radiusBottom : 1;
  20197. height = height || 1;
  20198. radialSegments = Math.floor( radialSegments ) || 8;
  20199. heightSegments = Math.floor( heightSegments ) || 1;
  20200. openEnded = openEnded !== undefined ? openEnded : false;
  20201. thetaStart = thetaStart !== undefined ? thetaStart : 0.0;
  20202. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  20203. // buffers
  20204. var indices = [];
  20205. var vertices = [];
  20206. var normals = [];
  20207. var uvs = [];
  20208. // helper variables
  20209. var index = 0;
  20210. var indexArray = [];
  20211. var halfHeight = height / 2;
  20212. var groupStart = 0;
  20213. // generate geometry
  20214. generateTorso();
  20215. if ( openEnded === false ) {
  20216. if ( radiusTop > 0 ) generateCap( true );
  20217. if ( radiusBottom > 0 ) generateCap( false );
  20218. }
  20219. // build geometry
  20220. this.setIndex( indices );
  20221. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  20222. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  20223. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  20224. function generateTorso() {
  20225. var x, y;
  20226. var normal = new Vector3();
  20227. var vertex = new Vector3();
  20228. var groupCount = 0;
  20229. // this will be used to calculate the normal
  20230. var slope = ( radiusBottom - radiusTop ) / height;
  20231. // generate vertices, normals and uvs
  20232. for ( y = 0; y <= heightSegments; y ++ ) {
  20233. var indexRow = [];
  20234. var v = y / heightSegments;
  20235. // calculate the radius of the current row
  20236. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  20237. for ( x = 0; x <= radialSegments; x ++ ) {
  20238. var u = x / radialSegments;
  20239. var theta = u * thetaLength + thetaStart;
  20240. var sinTheta = Math.sin( theta );
  20241. var cosTheta = Math.cos( theta );
  20242. // vertex
  20243. vertex.x = radius * sinTheta;
  20244. vertex.y = - v * height + halfHeight;
  20245. vertex.z = radius * cosTheta;
  20246. vertices.push( vertex.x, vertex.y, vertex.z );
  20247. // normal
  20248. normal.set( sinTheta, slope, cosTheta ).normalize();
  20249. normals.push( normal.x, normal.y, normal.z );
  20250. // uv
  20251. uvs.push( u, 1 - v );
  20252. // save index of vertex in respective row
  20253. indexRow.push( index ++ );
  20254. }
  20255. // now save vertices of the row in our index array
  20256. indexArray.push( indexRow );
  20257. }
  20258. // generate indices
  20259. for ( x = 0; x < radialSegments; x ++ ) {
  20260. for ( y = 0; y < heightSegments; y ++ ) {
  20261. // we use the index array to access the correct indices
  20262. var a = indexArray[ y ][ x ];
  20263. var b = indexArray[ y + 1 ][ x ];
  20264. var c = indexArray[ y + 1 ][ x + 1 ];
  20265. var d = indexArray[ y ][ x + 1 ];
  20266. // faces
  20267. indices.push( a, b, d );
  20268. indices.push( b, c, d );
  20269. // update group counter
  20270. groupCount += 6;
  20271. }
  20272. }
  20273. // add a group to the geometry. this will ensure multi material support
  20274. scope.addGroup( groupStart, groupCount, 0 );
  20275. // calculate new start value for groups
  20276. groupStart += groupCount;
  20277. }
  20278. function generateCap( top ) {
  20279. var x, centerIndexStart, centerIndexEnd;
  20280. var uv = new Vector2();
  20281. var vertex = new Vector3();
  20282. var groupCount = 0;
  20283. var radius = ( top === true ) ? radiusTop : radiusBottom;
  20284. var sign = ( top === true ) ? 1 : - 1;
  20285. // save the index of the first center vertex
  20286. centerIndexStart = index;
  20287. // first we generate the center vertex data of the cap.
  20288. // because the geometry needs one set of uvs per face,
  20289. // we must generate a center vertex per face/segment
  20290. for ( x = 1; x <= radialSegments; x ++ ) {
  20291. // vertex
  20292. vertices.push( 0, halfHeight * sign, 0 );
  20293. // normal
  20294. normals.push( 0, sign, 0 );
  20295. // uv
  20296. uvs.push( 0.5, 0.5 );
  20297. // increase index
  20298. index ++;
  20299. }
  20300. // save the index of the last center vertex
  20301. centerIndexEnd = index;
  20302. // now we generate the surrounding vertices, normals and uvs
  20303. for ( x = 0; x <= radialSegments; x ++ ) {
  20304. var u = x / radialSegments;
  20305. var theta = u * thetaLength + thetaStart;
  20306. var cosTheta = Math.cos( theta );
  20307. var sinTheta = Math.sin( theta );
  20308. // vertex
  20309. vertex.x = radius * sinTheta;
  20310. vertex.y = halfHeight * sign;
  20311. vertex.z = radius * cosTheta;
  20312. vertices.push( vertex.x, vertex.y, vertex.z );
  20313. // normal
  20314. normals.push( 0, sign, 0 );
  20315. // uv
  20316. uv.x = ( cosTheta * 0.5 ) + 0.5;
  20317. uv.y = ( sinTheta * 0.5 * sign ) + 0.5;
  20318. uvs.push( uv.x, uv.y );
  20319. // increase index
  20320. index ++;
  20321. }
  20322. // generate indices
  20323. for ( x = 0; x < radialSegments; x ++ ) {
  20324. var c = centerIndexStart + x;
  20325. var i = centerIndexEnd + x;
  20326. if ( top === true ) {
  20327. // face top
  20328. indices.push( i, i + 1, c );
  20329. } else {
  20330. // face bottom
  20331. indices.push( i + 1, i, c );
  20332. }
  20333. groupCount += 3;
  20334. }
  20335. // add a group to the geometry. this will ensure multi material support
  20336. scope.addGroup( groupStart, groupCount, top === true ? 1 : 2 );
  20337. // calculate new start value for groups
  20338. groupStart += groupCount;
  20339. }
  20340. }
  20341. CylinderBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  20342. CylinderBufferGeometry.prototype.constructor = CylinderBufferGeometry;
  20343. /**
  20344. * @author abelnation / http://github.com/abelnation
  20345. */
  20346. function ConeGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  20347. CylinderGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  20348. this.type = 'ConeGeometry';
  20349. this.parameters = {
  20350. radius: radius,
  20351. height: height,
  20352. radialSegments: radialSegments,
  20353. heightSegments: heightSegments,
  20354. openEnded: openEnded,
  20355. thetaStart: thetaStart,
  20356. thetaLength: thetaLength
  20357. };
  20358. }
  20359. ConeGeometry.prototype = Object.create( CylinderGeometry.prototype );
  20360. ConeGeometry.prototype.constructor = ConeGeometry;
  20361. // ConeBufferGeometry
  20362. function ConeBufferGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  20363. CylinderBufferGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  20364. this.type = 'ConeBufferGeometry';
  20365. this.parameters = {
  20366. radius: radius,
  20367. height: height,
  20368. radialSegments: radialSegments,
  20369. heightSegments: heightSegments,
  20370. openEnded: openEnded,
  20371. thetaStart: thetaStart,
  20372. thetaLength: thetaLength
  20373. };
  20374. }
  20375. ConeBufferGeometry.prototype = Object.create( CylinderBufferGeometry.prototype );
  20376. ConeBufferGeometry.prototype.constructor = ConeBufferGeometry;
  20377. /**
  20378. * @author TristanVALCKE / https://github.com/Itee
  20379. */
  20380. /* global QUnit */
  20381. QUnit.module( 'Geometries', () => {
  20382. QUnit.module.todo( 'ConeGeometry', ( hooks ) => {
  20383. var geometries = undefined;
  20384. hooks.beforeEach( function () {
  20385. const parameters = {};
  20386. geometries = [
  20387. new ConeGeometry()
  20388. ];
  20389. } );
  20390. // INHERITANCE
  20391. QUnit.test( "Extending", ( assert ) => {
  20392. assert.ok( false, "everything's gonna be alright" );
  20393. } );
  20394. // INSTANCING
  20395. QUnit.test( "Instancing", ( assert ) => {
  20396. assert.ok( false, "everything's gonna be alright" );
  20397. } );
  20398. // OTHERS
  20399. QUnit.test( 'Standard geometry tests', ( assert ) => {
  20400. runStdGeometryTests( assert, geometries );
  20401. } );
  20402. } );
  20403. QUnit.module.todo( 'ConeBufferGeometry', ( hooks ) => {
  20404. var geometries = undefined;
  20405. hooks.beforeEach( function () {
  20406. const parameters = {};
  20407. geometries = [
  20408. new ConeBufferGeometry()
  20409. ];
  20410. } );
  20411. // INHERITANCE
  20412. QUnit.test( "Extending", ( assert ) => {
  20413. assert.ok( false, "everything's gonna be alright" );
  20414. } );
  20415. // INSTANCING
  20416. QUnit.test( "Instancing", ( assert ) => {
  20417. assert.ok( false, "everything's gonna be alright" );
  20418. } );
  20419. // OTHERS
  20420. QUnit.test( 'Standard geometry tests', ( assert ) => {
  20421. runStdGeometryTests( assert, geometries );
  20422. } );
  20423. } );
  20424. } );
  20425. /**
  20426. * @author TristanVALCKE / https://github.com/Itee
  20427. * @author Anonymous
  20428. */
  20429. /* global QUnit */
  20430. QUnit.module( 'Geometries', () => {
  20431. QUnit.module.todo( 'CylinderGeometry', ( hooks ) => {
  20432. var geometries = undefined;
  20433. hooks.beforeEach( function () {
  20434. const parameters = {
  20435. radiusTop: 10,
  20436. radiusBottom: 20,
  20437. height: 30,
  20438. radialSegments: 20,
  20439. heightSegments: 30,
  20440. openEnded: true,
  20441. thetaStart: 0.1,
  20442. thetaLength: 2.0,
  20443. };
  20444. geometries = [
  20445. new CylinderGeometry(),
  20446. new CylinderGeometry( parameters.radiusTop ),
  20447. new CylinderGeometry( parameters.radiusTop, parameters.radiusBottom ),
  20448. new CylinderGeometry( parameters.radiusTop, parameters.radiusBottom, parameters.height ),
  20449. new CylinderGeometry( parameters.radiusTop, parameters.radiusBottom, parameters.height, parameters.radialSegments ),
  20450. new CylinderGeometry( parameters.radiusTop, parameters.radiusBottom, parameters.height, parameters.radialSegments, parameters.heightSegments ),
  20451. new CylinderGeometry( parameters.radiusTop, parameters.radiusBottom, parameters.height, parameters.radialSegments, parameters.heightSegments, parameters.openEnded ),
  20452. new CylinderGeometry( parameters.radiusTop, parameters.radiusBottom, parameters.height, parameters.radialSegments, parameters.heightSegments, parameters.openEnded, parameters.thetaStart ),
  20453. new CylinderGeometry( parameters.radiusTop, parameters.radiusBottom, parameters.height, parameters.radialSegments, parameters.heightSegments, parameters.openEnded, parameters.thetaStart, parameters.thetaLength ),
  20454. ];
  20455. } );
  20456. // INHERITANCE
  20457. QUnit.test( "Extending", ( assert ) => {
  20458. assert.ok( false, "everything's gonna be alright" );
  20459. } );
  20460. // INSTANCING
  20461. QUnit.test( "Instancing", ( assert ) => {
  20462. assert.ok( false, "everything's gonna be alright" );
  20463. } );
  20464. // OTHERS
  20465. QUnit.test( 'Standard geometry tests', ( assert ) => {
  20466. runStdGeometryTests( assert, geometries );
  20467. } );
  20468. } );
  20469. QUnit.module.todo( 'CylinderBufferGeometry', ( hooks ) => {
  20470. var geometries = undefined;
  20471. hooks.beforeEach( function () {
  20472. const parameters = {
  20473. radiusTop: 10,
  20474. radiusBottom: 20,
  20475. height: 30,
  20476. radialSegments: 20,
  20477. heightSegments: 30,
  20478. openEnded: true,
  20479. thetaStart: 0.1,
  20480. thetaLength: 2.0,
  20481. };
  20482. geometries = [
  20483. new CylinderBufferGeometry(),
  20484. new CylinderBufferGeometry( parameters.radiusTop ),
  20485. new CylinderBufferGeometry( parameters.radiusTop, parameters.radiusBottom ),
  20486. new CylinderBufferGeometry( parameters.radiusTop, parameters.radiusBottom, parameters.height ),
  20487. new CylinderBufferGeometry( parameters.radiusTop, parameters.radiusBottom, parameters.height, parameters.radialSegments ),
  20488. new CylinderBufferGeometry( parameters.radiusTop, parameters.radiusBottom, parameters.height, parameters.radialSegments, parameters.heightSegments ),
  20489. new CylinderBufferGeometry( parameters.radiusTop, parameters.radiusBottom, parameters.height, parameters.radialSegments, parameters.heightSegments, parameters.openEnded ),
  20490. new CylinderBufferGeometry( parameters.radiusTop, parameters.radiusBottom, parameters.height, parameters.radialSegments, parameters.heightSegments, parameters.openEnded, parameters.thetaStart ),
  20491. new CylinderBufferGeometry( parameters.radiusTop, parameters.radiusBottom, parameters.height, parameters.radialSegments, parameters.heightSegments, parameters.openEnded, parameters.thetaStart, parameters.thetaLength ),
  20492. ];
  20493. } );
  20494. // INHERITANCE
  20495. QUnit.test( "Extending", ( assert ) => {
  20496. assert.ok( false, "everything's gonna be alright" );
  20497. } );
  20498. // INSTANCING
  20499. QUnit.test( "Instancing", ( assert ) => {
  20500. assert.ok( false, "everything's gonna be alright" );
  20501. } );
  20502. // OTHERS
  20503. QUnit.test( 'Standard geometry tests', ( assert ) => {
  20504. runStdGeometryTests( assert, geometries );
  20505. } );
  20506. } );
  20507. } );
  20508. /**
  20509. * @author TristanVALCKE / https://github.com/Itee
  20510. * @author Anonymous
  20511. */
  20512. /* global QUnit */
  20513. QUnit.module( 'Geometries', () => {
  20514. QUnit.module.todo( 'CircleGeometry', ( hooks ) => {
  20515. var geometries = undefined;
  20516. hooks.beforeEach( function () {
  20517. const parameters = {
  20518. radius: 10,
  20519. detail: undefined
  20520. };
  20521. geometries = [
  20522. new DodecahedronGeometry(),
  20523. new DodecahedronGeometry( parameters.radius ),
  20524. new DodecahedronGeometry( parameters.radius, parameters.detail ),
  20525. ];
  20526. } );
  20527. // INHERITANCE
  20528. QUnit.test( "Extending", ( assert ) => {
  20529. assert.ok( false, "everything's gonna be alright" );
  20530. } );
  20531. // INSTANCING
  20532. QUnit.test( "Instancing", ( assert ) => {
  20533. assert.ok( false, "everything's gonna be alright" );
  20534. } );
  20535. // OTHERS
  20536. QUnit.test( 'Standard geometry tests', ( assert ) => {
  20537. runStdGeometryTests( assert, geometries );
  20538. } );
  20539. } );
  20540. QUnit.module.todo( 'CircleBufferGeometry', ( hooks ) => {
  20541. var geometries = undefined;
  20542. hooks.beforeEach( function () {
  20543. const parameters = {
  20544. radius: 10,
  20545. detail: undefined
  20546. };
  20547. geometries = [
  20548. new DodecahedronBufferGeometry(),
  20549. new DodecahedronBufferGeometry( parameters.radius ),
  20550. new DodecahedronBufferGeometry( parameters.radius, parameters.detail ),
  20551. ];
  20552. } );
  20553. // INHERITANCE
  20554. QUnit.test( "Extending", ( assert ) => {
  20555. assert.ok( false, "everything's gonna be alright" );
  20556. } );
  20557. // INSTANCING
  20558. QUnit.test( "Instancing", ( assert ) => {
  20559. assert.ok( false, "everything's gonna be alright" );
  20560. } );
  20561. // OTHERS
  20562. QUnit.test( 'Standard geometry tests', ( assert ) => {
  20563. runStdGeometryTests( assert, geometries );
  20564. } );
  20565. } );
  20566. } );
  20567. /**
  20568. * @author WestLangley / http://github.com/WestLangley
  20569. * @author Mugen87 / https://github.com/Mugen87
  20570. */
  20571. function EdgesGeometry( geometry, thresholdAngle ) {
  20572. BufferGeometry.call( this );
  20573. this.type = 'EdgesGeometry';
  20574. this.parameters = {
  20575. thresholdAngle: thresholdAngle
  20576. };
  20577. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  20578. // buffer
  20579. var vertices = [];
  20580. // helper variables
  20581. var thresholdDot = Math.cos( _Math.DEG2RAD * thresholdAngle );
  20582. var edge = [ 0, 0 ], edges = {}, edge1, edge2;
  20583. var key, keys = [ 'a', 'b', 'c' ];
  20584. // prepare source geometry
  20585. var geometry2;
  20586. if ( geometry.isBufferGeometry ) {
  20587. geometry2 = new Geometry();
  20588. geometry2.fromBufferGeometry( geometry );
  20589. } else {
  20590. geometry2 = geometry.clone();
  20591. }
  20592. geometry2.mergeVertices();
  20593. geometry2.computeFaceNormals();
  20594. var sourceVertices = geometry2.vertices;
  20595. var faces = geometry2.faces;
  20596. // now create a data structure where each entry represents an edge with its adjoining faces
  20597. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  20598. var face = faces[ i ];
  20599. for ( var j = 0; j < 3; j ++ ) {
  20600. edge1 = face[ keys[ j ] ];
  20601. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  20602. edge[ 0 ] = Math.min( edge1, edge2 );
  20603. edge[ 1 ] = Math.max( edge1, edge2 );
  20604. key = edge[ 0 ] + ',' + edge[ 1 ];
  20605. if ( edges[ key ] === undefined ) {
  20606. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ], face1: i, face2: undefined };
  20607. } else {
  20608. edges[ key ].face2 = i;
  20609. }
  20610. }
  20611. }
  20612. // generate vertices
  20613. for ( key in edges ) {
  20614. var e = edges[ key ];
  20615. // an edge is only rendered if the angle (in degrees) between the face normals of the adjoining faces exceeds this value. default = 1 degree.
  20616. if ( e.face2 === undefined || faces[ e.face1 ].normal.dot( faces[ e.face2 ].normal ) <= thresholdDot ) {
  20617. var vertex = sourceVertices[ e.index1 ];
  20618. vertices.push( vertex.x, vertex.y, vertex.z );
  20619. vertex = sourceVertices[ e.index2 ];
  20620. vertices.push( vertex.x, vertex.y, vertex.z );
  20621. }
  20622. }
  20623. // build geometry
  20624. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  20625. }
  20626. EdgesGeometry.prototype = Object.create( BufferGeometry.prototype );
  20627. EdgesGeometry.prototype.constructor = EdgesGeometry;
  20628. function Scene() {
  20629. Object3D.call( this );
  20630. this.type = 'Scene';
  20631. this.background = null;
  20632. this.fog = null;
  20633. this.overrideMaterial = null;
  20634. this.autoUpdate = true; // checked by the renderer
  20635. }
  20636. Scene.prototype = Object.assign( Object.create( Object3D.prototype ), {
  20637. constructor: Scene,
  20638. copy: function ( source, recursive ) {
  20639. Object3D.prototype.copy.call( this, source, recursive );
  20640. if ( source.background !== null ) this.background = source.background.clone();
  20641. if ( source.fog !== null ) this.fog = source.fog.clone();
  20642. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  20643. this.autoUpdate = source.autoUpdate;
  20644. this.matrixAutoUpdate = source.matrixAutoUpdate;
  20645. return this;
  20646. },
  20647. toJSON: function ( meta ) {
  20648. var data = Object3D.prototype.toJSON.call( this, meta );
  20649. if ( this.background !== null ) data.object.background = this.background.toJSON( meta );
  20650. if ( this.fog !== null ) data.object.fog = this.fog.toJSON();
  20651. return data;
  20652. }
  20653. } );
  20654. /**
  20655. * @author alteredq / http://alteredqualia.com/
  20656. */
  20657. function DataTexture( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  20658. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  20659. this.image = { data: data, width: width, height: height };
  20660. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  20661. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  20662. this.generateMipmaps = false;
  20663. this.flipY = false;
  20664. this.unpackAlignment = 1;
  20665. }
  20666. DataTexture.prototype = Object.create( Texture.prototype );
  20667. DataTexture.prototype.constructor = DataTexture;
  20668. DataTexture.prototype.isDataTexture = true;
  20669. /**
  20670. * @author mrdoob / http://mrdoob.com/
  20671. */
  20672. function CubeTexture( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  20673. images = images !== undefined ? images : [];
  20674. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  20675. Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  20676. this.flipY = false;
  20677. }
  20678. CubeTexture.prototype = Object.create( Texture.prototype );
  20679. CubeTexture.prototype.constructor = CubeTexture;
  20680. CubeTexture.prototype.isCubeTexture = true;
  20681. Object.defineProperty( CubeTexture.prototype, 'images', {
  20682. get: function () {
  20683. return this.image;
  20684. },
  20685. set: function ( value ) {
  20686. this.image = value;
  20687. }
  20688. } );
  20689. /**
  20690. * @author tschw
  20691. *
  20692. * Uniforms of a program.
  20693. * Those form a tree structure with a special top-level container for the root,
  20694. * which you get by calling 'new WebGLUniforms( gl, program, renderer )'.
  20695. *
  20696. *
  20697. * Properties of inner nodes including the top-level container:
  20698. *
  20699. * .seq - array of nested uniforms
  20700. * .map - nested uniforms by name
  20701. *
  20702. *
  20703. * Methods of all nodes except the top-level container:
  20704. *
  20705. * .setValue( gl, value, [renderer] )
  20706. *
  20707. * uploads a uniform value(s)
  20708. * the 'renderer' parameter is needed for sampler uniforms
  20709. *
  20710. *
  20711. * Static methods of the top-level container (renderer factorizations):
  20712. *
  20713. * .upload( gl, seq, values, renderer )
  20714. *
  20715. * sets uniforms in 'seq' to 'values[id].value'
  20716. *
  20717. * .seqWithValue( seq, values ) : filteredSeq
  20718. *
  20719. * filters 'seq' entries with corresponding entry in values
  20720. *
  20721. *
  20722. * Methods of the top-level container (renderer factorizations):
  20723. *
  20724. * .setValue( gl, name, value )
  20725. *
  20726. * sets uniform with name 'name' to 'value'
  20727. *
  20728. * .set( gl, obj, prop )
  20729. *
  20730. * sets uniform from object and property with same name than uniform
  20731. *
  20732. * .setOptional( gl, obj, prop )
  20733. *
  20734. * like .set for an optional property of the object
  20735. *
  20736. */
  20737. var emptyTexture = new Texture();
  20738. var emptyCubeTexture = new CubeTexture();
  20739. // --- Base for inner nodes (including the root) ---
  20740. function UniformContainer() {
  20741. this.seq = [];
  20742. this.map = {};
  20743. }
  20744. // --- Utilities ---
  20745. // Array Caches (provide typed arrays for temporary by size)
  20746. var arrayCacheF32 = [];
  20747. var arrayCacheI32 = [];
  20748. // Float32Array caches used for uploading Matrix uniforms
  20749. var mat4array = new Float32Array( 16 );
  20750. var mat3array = new Float32Array( 9 );
  20751. // Flattening for arrays of vectors and matrices
  20752. function flatten( array, nBlocks, blockSize ) {
  20753. var firstElem = array[ 0 ];
  20754. if ( firstElem <= 0 || firstElem > 0 ) return array;
  20755. // unoptimized: ! isNaN( firstElem )
  20756. // see http://jacksondunstan.com/articles/983
  20757. var n = nBlocks * blockSize,
  20758. r = arrayCacheF32[ n ];
  20759. if ( r === undefined ) {
  20760. r = new Float32Array( n );
  20761. arrayCacheF32[ n ] = r;
  20762. }
  20763. if ( nBlocks !== 0 ) {
  20764. firstElem.toArray( r, 0 );
  20765. for ( var i = 1, offset = 0; i !== nBlocks; ++ i ) {
  20766. offset += blockSize;
  20767. array[ i ].toArray( r, offset );
  20768. }
  20769. }
  20770. return r;
  20771. }
  20772. // Texture unit allocation
  20773. function allocTexUnits( renderer, n ) {
  20774. var r = arrayCacheI32[ n ];
  20775. if ( r === undefined ) {
  20776. r = new Int32Array( n );
  20777. arrayCacheI32[ n ] = r;
  20778. }
  20779. for ( var i = 0; i !== n; ++ i )
  20780. r[ i ] = renderer.allocTextureUnit();
  20781. return r;
  20782. }
  20783. // --- Setters ---
  20784. // Note: Defining these methods externally, because they come in a bunch
  20785. // and this way their names minify.
  20786. // Single scalar
  20787. function setValue1f( gl, v ) {
  20788. gl.uniform1f( this.addr, v );
  20789. }
  20790. function setValue1i( gl, v ) {
  20791. gl.uniform1i( this.addr, v );
  20792. }
  20793. // Single float vector (from flat array or THREE.VectorN)
  20794. function setValue2fv( gl, v ) {
  20795. if ( v.x === undefined ) {
  20796. gl.uniform2fv( this.addr, v );
  20797. } else {
  20798. gl.uniform2f( this.addr, v.x, v.y );
  20799. }
  20800. }
  20801. function setValue3fv( gl, v ) {
  20802. if ( v.x !== undefined ) {
  20803. gl.uniform3f( this.addr, v.x, v.y, v.z );
  20804. } else if ( v.r !== undefined ) {
  20805. gl.uniform3f( this.addr, v.r, v.g, v.b );
  20806. } else {
  20807. gl.uniform3fv( this.addr, v );
  20808. }
  20809. }
  20810. function setValue4fv( gl, v ) {
  20811. if ( v.x === undefined ) {
  20812. gl.uniform4fv( this.addr, v );
  20813. } else {
  20814. gl.uniform4f( this.addr, v.x, v.y, v.z, v.w );
  20815. }
  20816. }
  20817. // Single matrix (from flat array or MatrixN)
  20818. function setValue2fm( gl, v ) {
  20819. gl.uniformMatrix2fv( this.addr, false, v.elements || v );
  20820. }
  20821. function setValue3fm( gl, v ) {
  20822. if ( v.elements === undefined ) {
  20823. gl.uniformMatrix3fv( this.addr, false, v );
  20824. } else {
  20825. mat3array.set( v.elements );
  20826. gl.uniformMatrix3fv( this.addr, false, mat3array );
  20827. }
  20828. }
  20829. function setValue4fm( gl, v ) {
  20830. if ( v.elements === undefined ) {
  20831. gl.uniformMatrix4fv( this.addr, false, v );
  20832. } else {
  20833. mat4array.set( v.elements );
  20834. gl.uniformMatrix4fv( this.addr, false, mat4array );
  20835. }
  20836. }
  20837. // Single texture (2D / Cube)
  20838. function setValueT1( gl, v, renderer ) {
  20839. var unit = renderer.allocTextureUnit();
  20840. gl.uniform1i( this.addr, unit );
  20841. renderer.setTexture2D( v || emptyTexture, unit );
  20842. }
  20843. function setValueT6( gl, v, renderer ) {
  20844. var unit = renderer.allocTextureUnit();
  20845. gl.uniform1i( this.addr, unit );
  20846. renderer.setTextureCube( v || emptyCubeTexture, unit );
  20847. }
  20848. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  20849. function setValue2iv( gl, v ) {
  20850. gl.uniform2iv( this.addr, v );
  20851. }
  20852. function setValue3iv( gl, v ) {
  20853. gl.uniform3iv( this.addr, v );
  20854. }
  20855. function setValue4iv( gl, v ) {
  20856. gl.uniform4iv( this.addr, v );
  20857. }
  20858. // Helper to pick the right setter for the singular case
  20859. function getSingularSetter( type ) {
  20860. switch ( type ) {
  20861. case 0x1406: return setValue1f; // FLOAT
  20862. case 0x8b50: return setValue2fv; // _VEC2
  20863. case 0x8b51: return setValue3fv; // _VEC3
  20864. case 0x8b52: return setValue4fv; // _VEC4
  20865. case 0x8b5a: return setValue2fm; // _MAT2
  20866. case 0x8b5b: return setValue3fm; // _MAT3
  20867. case 0x8b5c: return setValue4fm; // _MAT4
  20868. case 0x8b5e: case 0x8d66: return setValueT1; // SAMPLER_2D, SAMPLER_EXTERNAL_OES
  20869. case 0x8b60: return setValueT6; // SAMPLER_CUBE
  20870. case 0x1404: case 0x8b56: return setValue1i; // INT, BOOL
  20871. case 0x8b53: case 0x8b57: return setValue2iv; // _VEC2
  20872. case 0x8b54: case 0x8b58: return setValue3iv; // _VEC3
  20873. case 0x8b55: case 0x8b59: return setValue4iv; // _VEC4
  20874. }
  20875. }
  20876. // Array of scalars
  20877. function setValue1fv( gl, v ) {
  20878. gl.uniform1fv( this.addr, v );
  20879. }
  20880. function setValue1iv( gl, v ) {
  20881. gl.uniform1iv( this.addr, v );
  20882. }
  20883. // Array of vectors (flat or from THREE classes)
  20884. function setValueV2a( gl, v ) {
  20885. gl.uniform2fv( this.addr, flatten( v, this.size, 2 ) );
  20886. }
  20887. function setValueV3a( gl, v ) {
  20888. gl.uniform3fv( this.addr, flatten( v, this.size, 3 ) );
  20889. }
  20890. function setValueV4a( gl, v ) {
  20891. gl.uniform4fv( this.addr, flatten( v, this.size, 4 ) );
  20892. }
  20893. // Array of matrices (flat or from THREE clases)
  20894. function setValueM2a( gl, v ) {
  20895. gl.uniformMatrix2fv( this.addr, false, flatten( v, this.size, 4 ) );
  20896. }
  20897. function setValueM3a( gl, v ) {
  20898. gl.uniformMatrix3fv( this.addr, false, flatten( v, this.size, 9 ) );
  20899. }
  20900. function setValueM4a( gl, v ) {
  20901. gl.uniformMatrix4fv( this.addr, false, flatten( v, this.size, 16 ) );
  20902. }
  20903. // Array of textures (2D / Cube)
  20904. function setValueT1a( gl, v, renderer ) {
  20905. var n = v.length,
  20906. units = allocTexUnits( renderer, n );
  20907. gl.uniform1iv( this.addr, units );
  20908. for ( var i = 0; i !== n; ++ i ) {
  20909. renderer.setTexture2D( v[ i ] || emptyTexture, units[ i ] );
  20910. }
  20911. }
  20912. function setValueT6a( gl, v, renderer ) {
  20913. var n = v.length,
  20914. units = allocTexUnits( renderer, n );
  20915. gl.uniform1iv( this.addr, units );
  20916. for ( var i = 0; i !== n; ++ i ) {
  20917. renderer.setTextureCube( v[ i ] || emptyCubeTexture, units[ i ] );
  20918. }
  20919. }
  20920. // Helper to pick the right setter for a pure (bottom-level) array
  20921. function getPureArraySetter( type ) {
  20922. switch ( type ) {
  20923. case 0x1406: return setValue1fv; // FLOAT
  20924. case 0x8b50: return setValueV2a; // _VEC2
  20925. case 0x8b51: return setValueV3a; // _VEC3
  20926. case 0x8b52: return setValueV4a; // _VEC4
  20927. case 0x8b5a: return setValueM2a; // _MAT2
  20928. case 0x8b5b: return setValueM3a; // _MAT3
  20929. case 0x8b5c: return setValueM4a; // _MAT4
  20930. case 0x8b5e: return setValueT1a; // SAMPLER_2D
  20931. case 0x8b60: return setValueT6a; // SAMPLER_CUBE
  20932. case 0x1404: case 0x8b56: return setValue1iv; // INT, BOOL
  20933. case 0x8b53: case 0x8b57: return setValue2iv; // _VEC2
  20934. case 0x8b54: case 0x8b58: return setValue3iv; // _VEC3
  20935. case 0x8b55: case 0x8b59: return setValue4iv; // _VEC4
  20936. }
  20937. }
  20938. // --- Uniform Classes ---
  20939. function SingleUniform( id, activeInfo, addr ) {
  20940. this.id = id;
  20941. this.addr = addr;
  20942. this.setValue = getSingularSetter( activeInfo.type );
  20943. // this.path = activeInfo.name; // DEBUG
  20944. }
  20945. function PureArrayUniform( id, activeInfo, addr ) {
  20946. this.id = id;
  20947. this.addr = addr;
  20948. this.size = activeInfo.size;
  20949. this.setValue = getPureArraySetter( activeInfo.type );
  20950. // this.path = activeInfo.name; // DEBUG
  20951. }
  20952. function StructuredUniform( id ) {
  20953. this.id = id;
  20954. UniformContainer.call( this ); // mix-in
  20955. }
  20956. StructuredUniform.prototype.setValue = function ( gl, value ) {
  20957. // Note: Don't need an extra 'renderer' parameter, since samplers
  20958. // are not allowed in structured uniforms.
  20959. var seq = this.seq;
  20960. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  20961. var u = seq[ i ];
  20962. u.setValue( gl, value[ u.id ] );
  20963. }
  20964. };
  20965. // --- Top-level ---
  20966. // Parser - builds up the property tree from the path strings
  20967. var RePathPart = /([\w\d_]+)(\])?(\[|\.)?/g;
  20968. // extracts
  20969. // - the identifier (member name or array index)
  20970. // - followed by an optional right bracket (found when array index)
  20971. // - followed by an optional left bracket or dot (type of subscript)
  20972. //
  20973. // Note: These portions can be read in a non-overlapping fashion and
  20974. // allow straightforward parsing of the hierarchy that WebGL encodes
  20975. // in the uniform names.
  20976. function addUniform( container, uniformObject ) {
  20977. container.seq.push( uniformObject );
  20978. container.map[ uniformObject.id ] = uniformObject;
  20979. }
  20980. function parseUniform( activeInfo, addr, container ) {
  20981. var path = activeInfo.name,
  20982. pathLength = path.length;
  20983. // reset RegExp object, because of the early exit of a previous run
  20984. RePathPart.lastIndex = 0;
  20985. for ( ; ; ) {
  20986. var match = RePathPart.exec( path ),
  20987. matchEnd = RePathPart.lastIndex,
  20988. id = match[ 1 ],
  20989. idIsIndex = match[ 2 ] === ']',
  20990. subscript = match[ 3 ];
  20991. if ( idIsIndex ) id = id | 0; // convert to integer
  20992. if ( subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength ) {
  20993. // bare name or "pure" bottom-level array "[0]" suffix
  20994. addUniform( container, subscript === undefined ?
  20995. new SingleUniform( id, activeInfo, addr ) :
  20996. new PureArrayUniform( id, activeInfo, addr ) );
  20997. break;
  20998. } else {
  20999. // step into inner node / create it in case it doesn't exist
  21000. var map = container.map, next = map[ id ];
  21001. if ( next === undefined ) {
  21002. next = new StructuredUniform( id );
  21003. addUniform( container, next );
  21004. }
  21005. container = next;
  21006. }
  21007. }
  21008. }
  21009. // Root Container
  21010. function WebGLUniforms( gl, program, renderer ) {
  21011. UniformContainer.call( this );
  21012. this.renderer = renderer;
  21013. var n = gl.getProgramParameter( program, gl.ACTIVE_UNIFORMS );
  21014. for ( var i = 0; i < n; ++ i ) {
  21015. var info = gl.getActiveUniform( program, i ),
  21016. path = info.name,
  21017. addr = gl.getUniformLocation( program, path );
  21018. parseUniform( info, addr, this );
  21019. }
  21020. }
  21021. WebGLUniforms.prototype.setValue = function ( gl, name, value ) {
  21022. var u = this.map[ name ];
  21023. if ( u !== undefined ) u.setValue( gl, value, this.renderer );
  21024. };
  21025. WebGLUniforms.prototype.setOptional = function ( gl, object, name ) {
  21026. var v = object[ name ];
  21027. if ( v !== undefined ) this.setValue( gl, name, v );
  21028. };
  21029. // Static interface
  21030. WebGLUniforms.upload = function ( gl, seq, values, renderer ) {
  21031. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  21032. var u = seq[ i ],
  21033. v = values[ u.id ];
  21034. if ( v.needsUpdate !== false ) {
  21035. // note: always updating when .needsUpdate is undefined
  21036. u.setValue( gl, v.value, renderer );
  21037. }
  21038. }
  21039. };
  21040. WebGLUniforms.seqWithValue = function ( seq, values ) {
  21041. var r = [];
  21042. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  21043. var u = seq[ i ];
  21044. if ( u.id in values ) r.push( u );
  21045. }
  21046. return r;
  21047. };
  21048. var UniformsLib = {
  21049. common: {
  21050. diffuse: { value: new Color( 0xeeeeee ) },
  21051. opacity: { value: 1.0 },
  21052. map: { value: null },
  21053. uvTransform: { value: new Matrix3() },
  21054. alphaMap: { value: null },
  21055. },
  21056. specularmap: {
  21057. specularMap: { value: null },
  21058. },
  21059. envmap: {
  21060. envMap: { value: null },
  21061. flipEnvMap: { value: - 1 },
  21062. reflectivity: { value: 1.0 },
  21063. refractionRatio: { value: 0.98 }
  21064. },
  21065. aomap: {
  21066. aoMap: { value: null },
  21067. aoMapIntensity: { value: 1 }
  21068. },
  21069. lightmap: {
  21070. lightMap: { value: null },
  21071. lightMapIntensity: { value: 1 }
  21072. },
  21073. emissivemap: {
  21074. emissiveMap: { value: null }
  21075. },
  21076. bumpmap: {
  21077. bumpMap: { value: null },
  21078. bumpScale: { value: 1 }
  21079. },
  21080. normalmap: {
  21081. normalMap: { value: null },
  21082. normalScale: { value: new Vector2( 1, 1 ) }
  21083. },
  21084. displacementmap: {
  21085. displacementMap: { value: null },
  21086. displacementScale: { value: 1 },
  21087. displacementBias: { value: 0 }
  21088. },
  21089. roughnessmap: {
  21090. roughnessMap: { value: null }
  21091. },
  21092. metalnessmap: {
  21093. metalnessMap: { value: null }
  21094. },
  21095. gradientmap: {
  21096. gradientMap: { value: null }
  21097. },
  21098. fog: {
  21099. fogDensity: { value: 0.00025 },
  21100. fogNear: { value: 1 },
  21101. fogFar: { value: 2000 },
  21102. fogColor: { value: new Color( 0xffffff ) }
  21103. },
  21104. lights: {
  21105. ambientLightColor: { value: [] },
  21106. directionalLights: { value: [], properties: {
  21107. direction: {},
  21108. color: {},
  21109. shadow: {},
  21110. shadowBias: {},
  21111. shadowRadius: {},
  21112. shadowMapSize: {}
  21113. } },
  21114. directionalShadowMap: { value: [] },
  21115. directionalShadowMatrix: { value: [] },
  21116. spotLights: { value: [], properties: {
  21117. color: {},
  21118. position: {},
  21119. direction: {},
  21120. distance: {},
  21121. coneCos: {},
  21122. penumbraCos: {},
  21123. decay: {},
  21124. shadow: {},
  21125. shadowBias: {},
  21126. shadowRadius: {},
  21127. shadowMapSize: {}
  21128. } },
  21129. spotShadowMap: { value: [] },
  21130. spotShadowMatrix: { value: [] },
  21131. pointLights: { value: [], properties: {
  21132. color: {},
  21133. position: {},
  21134. decay: {},
  21135. distance: {},
  21136. shadow: {},
  21137. shadowBias: {},
  21138. shadowRadius: {},
  21139. shadowMapSize: {},
  21140. shadowCameraNear: {},
  21141. shadowCameraFar: {}
  21142. } },
  21143. pointShadowMap: { value: [] },
  21144. pointShadowMatrix: { value: [] },
  21145. hemisphereLights: { value: [], properties: {
  21146. direction: {},
  21147. skyColor: {},
  21148. groundColor: {}
  21149. } },
  21150. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  21151. rectAreaLights: { value: [], properties: {
  21152. color: {},
  21153. position: {},
  21154. width: {},
  21155. height: {}
  21156. } }
  21157. },
  21158. points: {
  21159. diffuse: { value: new Color( 0xeeeeee ) },
  21160. opacity: { value: 1.0 },
  21161. size: { value: 1.0 },
  21162. scale: { value: 1.0 },
  21163. map: { value: null },
  21164. uvTransform: { value: new Matrix3() }
  21165. }
  21166. };
  21167. var alphamap_fragment = "#ifdef USE_ALPHAMAP\r\n\r\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\r\n\r\n#endif\r\n";
  21168. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\r\n\r\n\tuniform sampler2D alphaMap;\r\n\r\n#endif\r\n";
  21169. var alphatest_fragment = "#ifdef ALPHATEST\r\n\r\n\tif ( diffuseColor.a < ALPHATEST ) discard;\r\n\r\n#endif\r\n";
  21170. var aomap_fragment = "#ifdef USE_AOMAP\r\n\r\n\t// reads channel R, compatible with a combined OcclusionRoughnessMetallic (RGB) texture\r\n\tfloat ambientOcclusion = ( texture2D( aoMap, vUv2 ).r - 1.0 ) * aoMapIntensity + 1.0;\r\n\r\n\treflectedLight.indirectDiffuse *= ambientOcclusion;\r\n\r\n\t#if defined( USE_ENVMAP ) && defined( PHYSICAL )\r\n\r\n\t\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\r\n\r\n\t\treflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.specularRoughness );\r\n\r\n\t#endif\r\n\r\n#endif\r\n";
  21171. var aomap_pars_fragment = "#ifdef USE_AOMAP\r\n\r\n\tuniform sampler2D aoMap;\r\n\tuniform float aoMapIntensity;\r\n\r\n#endif";
  21172. var begin_vertex = "\r\nvec3 transformed = vec3( position );\r\n";
  21173. var beginnormal_vertex = "\r\nvec3 objectNormal = vec3( normal );\r\n";
  21174. var bsdfs = "float punctualLightIntensityToIrradianceFactor( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\r\n\r\n\tif( decayExponent > 0.0 ) {\r\n\r\n#if defined ( PHYSICALLY_CORRECT_LIGHTS )\r\n\r\n\t\t// based upon Frostbite 3 Moving to Physically-based Rendering\r\n\t\t// page 32, equation 26: E[window1]\r\n\t\t// https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf\r\n\t\t// this is intended to be used on spot and point lights who are represented as luminous intensity\r\n\t\t// but who must be converted to luminous irradiance for surface lighting calculation\r\n\t\tfloat distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\r\n\t\tfloat maxDistanceCutoffFactor = pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\r\n\t\treturn distanceFalloff * maxDistanceCutoffFactor;\r\n\r\n#else\r\n\r\n\t\treturn pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );\r\n\r\n#endif\r\n\r\n\t}\r\n\r\n\treturn 1.0;\r\n\r\n}\r\n\r\nvec3 BRDF_Diffuse_Lambert( const in vec3 diffuseColor ) {\r\n\r\n\treturn RECIPROCAL_PI * diffuseColor;\r\n\r\n} // validated\r\n\r\nvec3 F_Schlick( const in vec3 specularColor, const in float dotLH ) {\r\n\r\n\t// Original approximation by Christophe Schlick '94\r\n\t// float fresnel = pow( 1.0 - dotLH, 5.0 );\r\n\r\n\t// Optimized variant (presented by Epic at SIGGRAPH '13)\r\n\t// https://cdn2.unrealengine.com/Resources/files/2013SiggraphPresentationsNotes-26915738.pdf\r\n\tfloat fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );\r\n\r\n\treturn ( 1.0 - specularColor ) * fresnel + specularColor;\r\n\r\n} // validated\r\n\r\n// Microfacet Models for Refraction through Rough Surfaces - equation (34)\r\n// http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html\r\n// alpha is \"roughness squared\" in Disney’s reparameterization\r\nfloat G_GGX_Smith( const in float alpha, const in float dotNL, const in float dotNV ) {\r\n\r\n\t// geometry term (normalized) = G(l)⋅G(v) / 4(n⋅l)(n⋅v)\r\n\t// also see #12151\r\n\r\n\tfloat a2 = pow2( alpha );\r\n\r\n\tfloat gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\r\n\tfloat gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\r\n\r\n\treturn 1.0 / ( gl * gv );\r\n\r\n} // validated\r\n\r\n// Moving Frostbite to Physically Based Rendering 3.0 - page 12, listing 2\r\n// https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf\r\nfloat G_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {\r\n\r\n\tfloat a2 = pow2( alpha );\r\n\r\n\t// dotNL and dotNV are explicitly swapped. This is not a mistake.\r\n\tfloat gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\r\n\tfloat gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\r\n\r\n\treturn 0.5 / max( gv + gl, EPSILON );\r\n\r\n}\r\n\r\n// Microfacet Models for Refraction through Rough Surfaces - equation (33)\r\n// http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html\r\n// alpha is \"roughness squared\" in Disney’s reparameterization\r\nfloat D_GGX( const in float alpha, const in float dotNH ) {\r\n\r\n\tfloat a2 = pow2( alpha );\r\n\r\n\tfloat denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0; // avoid alpha = 0 with dotNH = 1\r\n\r\n\treturn RECIPROCAL_PI * a2 / pow2( denom );\r\n\r\n}\r\n\r\n// GGX Distribution, Schlick Fresnel, GGX-Smith Visibility\r\nvec3 BRDF_Specular_GGX( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {\r\n\r\n\tfloat alpha = pow2( roughness ); // UE4's roughness\r\n\r\n\tvec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\r\n\r\n\tfloat dotNL = saturate( dot( geometry.normal, incidentLight.direction ) );\r\n\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\r\n\tfloat dotNH = saturate( dot( geometry.normal, halfDir ) );\r\n\tfloat dotLH = saturate( dot( incidentLight.direction, halfDir ) );\r\n\r\n\tvec3 F = F_Schlick( specularColor, dotLH );\r\n\r\n\tfloat G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );\r\n\r\n\tfloat D = D_GGX( alpha, dotNH );\r\n\r\n\treturn F * ( G * D );\r\n\r\n} // validated\r\n\r\n// Rect Area Light\r\n\r\n// Area light computation code adapted from:\r\n// Real-Time Polygonal-Light Shading with Linearly Transformed Cosines\r\n// By: Eric Heitz, Jonathan Dupuy, Stephen Hill and David Neubelt\r\n// https://drive.google.com/file/d/0BzvWIdpUpRx_d09ndGVjNVJzZjA/view\r\n// https://eheitzresearch.wordpress.com/415-2/\r\n// http://blog.selfshadow.com/sandbox/ltc.html\r\n\r\nvec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {\r\n\r\n\tconst float LUT_SIZE = 64.0;\r\n\tconst float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;\r\n\tconst float LUT_BIAS = 0.5 / LUT_SIZE;\r\n\r\n\tfloat theta = acos( dot( N, V ) );\r\n\r\n\t// Parameterization of texture:\r\n\t// sqrt(roughness) -> [0,1]\r\n\t// theta -> [0, PI/2]\r\n\tvec2 uv = vec2(\r\n\t\tsqrt( saturate( roughness ) ),\r\n\t\tsaturate( theta / ( 0.5 * PI ) ) );\r\n\r\n\t// Ensure we don't have nonlinearities at the look-up table's edges\r\n\t// see: http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter24.html\r\n\t// \"Shader Analysis\" section\r\n\tuv = uv * LUT_SCALE + LUT_BIAS;\r\n\r\n\treturn uv;\r\n\r\n}\r\n\r\n// Real-Time Area Lighting: a Journey from Research to Production\r\n// By: Stephen Hill & Eric Heitz\r\n// http://advances.realtimerendering.com/s2016/s2016_ltc_rnd.pdf\r\n// An approximation for the form factor of a clipped rectangle.\r\nfloat LTC_ClippedSphereFormFactor( const in vec3 f ) {\r\n\r\n\tfloat l = length( f );\r\n\r\n\treturn max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );\r\n\r\n}\r\n\r\n// Real-Time Polygonal-Light Shading with Linearly Transformed Cosines\r\n// also Real-Time Area Lighting: a Journey from Research to Production\r\n// http://advances.realtimerendering.com/s2016/s2016_ltc_rnd.pdf\r\n// Normalization by 2*PI is incorporated in this function itself.\r\n// theta/sin(theta) is approximated by rational polynomial\r\nvec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {\r\n\r\n\tfloat x = dot( v1, v2 );\r\n\r\n\tfloat y = abs( x );\r\n\tfloat a = 0.86267 + (0.49788 + 0.01436 * y ) * y;\r\n\tfloat b = 3.45068 + (4.18814 + y) * y;\r\n\tfloat v = a / b;\r\n\r\n\tfloat theta_sintheta = (x > 0.0) ? v : 0.5 * inversesqrt( 1.0 - x * x ) - v;\r\n\r\n\treturn cross( v1, v2 ) * theta_sintheta;\r\n\r\n}\r\n\r\nvec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {\r\n\r\n\t// bail if point is on back side of plane of light\r\n\t// assumes ccw winding order of light vertices\r\n\tvec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];\r\n\tvec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];\r\n\tvec3 lightNormal = cross( v1, v2 );\r\n\r\n\tif( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );\r\n\r\n\t// construct orthonormal basis around N\r\n\tvec3 T1, T2;\r\n\tT1 = normalize( V - N * dot( V, N ) );\r\n\tT2 = - cross( N, T1 ); // negated from paper; possibly due to a different assumed handedness of world coordinate system\r\n\r\n\t// compute transform\r\n\tmat3 mat = mInv * transposeMat3( mat3( T1, T2, N ) );\r\n\r\n\t// transform rect\r\n\tvec3 coords[ 4 ];\r\n\tcoords[ 0 ] = mat * ( rectCoords[ 0 ] - P );\r\n\tcoords[ 1 ] = mat * ( rectCoords[ 1 ] - P );\r\n\tcoords[ 2 ] = mat * ( rectCoords[ 2 ] - P );\r\n\tcoords[ 3 ] = mat * ( rectCoords[ 3 ] - P );\r\n\r\n\t// project rect onto sphere\r\n\tcoords[ 0 ] = normalize( coords[ 0 ] );\r\n\tcoords[ 1 ] = normalize( coords[ 1 ] );\r\n\tcoords[ 2 ] = normalize( coords[ 2 ] );\r\n\tcoords[ 3 ] = normalize( coords[ 3 ] );\r\n\r\n\t// calculate vector form factor\r\n\tvec3 vectorFormFactor = vec3( 0.0 );\r\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );\r\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );\r\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );\r\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );\r\n\r\n\t// adjust for horizon clipping\r\n\tvec3 result = vec3( LTC_ClippedSphereFormFactor( vectorFormFactor ) );\r\n\r\n\treturn result;\r\n\r\n}\r\n\r\n// End Rect Area Light\r\n\r\n// ref: https://www.unrealengine.com/blog/physically-based-shading-on-mobile - environmentBRDF for GGX on mobile\r\nvec3 BRDF_Specular_GGX_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {\r\n\r\n\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\r\n\r\n\tconst vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );\r\n\r\n\tconst vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );\r\n\r\n\tvec4 r = roughness * c0 + c1;\r\n\r\n\tfloat a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;\r\n\r\n\tvec2 AB = vec2( -1.04, 1.04 ) * a004 + r.zw;\r\n\r\n\treturn specularColor * AB.x + AB.y;\r\n\r\n} // validated\r\n\r\n\r\nfloat G_BlinnPhong_Implicit( ) {\r\n\r\n\t// geometry term is (n dot l)(n dot v) / 4(n dot l)(n dot v)\r\n\treturn 0.25;\r\n\r\n}\r\n\r\nfloat D_BlinnPhong( const in float shininess, const in float dotNH ) {\r\n\r\n\treturn RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\r\n\r\n}\r\n\r\nvec3 BRDF_Specular_BlinnPhong( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float shininess ) {\r\n\r\n\tvec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\r\n\r\n\t//float dotNL = saturate( dot( geometry.normal, incidentLight.direction ) );\r\n\t//float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\r\n\tfloat dotNH = saturate( dot( geometry.normal, halfDir ) );\r\n\tfloat dotLH = saturate( dot( incidentLight.direction, halfDir ) );\r\n\r\n\tvec3 F = F_Schlick( specularColor, dotLH );\r\n\r\n\tfloat G = G_BlinnPhong_Implicit( );\r\n\r\n\tfloat D = D_BlinnPhong( shininess, dotNH );\r\n\r\n\treturn F * ( G * D );\r\n\r\n} // validated\r\n\r\n// source: http://simonstechblog.blogspot.ca/2011/12/microfacet-brdf.html\r\nfloat GGXRoughnessToBlinnExponent( const in float ggxRoughness ) {\r\n\treturn ( 2.0 / pow2( ggxRoughness + 0.0001 ) - 2.0 );\r\n}\r\n\r\nfloat BlinnExponentToGGXRoughness( const in float blinnExponent ) {\r\n\treturn sqrt( 2.0 / ( blinnExponent + 2.0 ) );\r\n}\r\n";
  21175. var bumpmap_pars_fragment = "#ifdef USE_BUMPMAP\r\n\r\n\tuniform sampler2D bumpMap;\r\n\tuniform float bumpScale;\r\n\r\n\t// Derivative maps - bump mapping unparametrized surfaces by Morten Mikkelsen\r\n\t// http://mmikkelsen3d.blogspot.sk/2011/07/derivative-maps.html\r\n\r\n\t// Evaluate the derivative of the height w.r.t. screen-space using forward differencing (listing 2)\r\n\r\n\tvec2 dHdxy_fwd() {\r\n\r\n\t\tvec2 dSTdx = dFdx( vUv );\r\n\t\tvec2 dSTdy = dFdy( vUv );\r\n\r\n\t\tfloat Hll = bumpScale * texture2D( bumpMap, vUv ).x;\r\n\t\tfloat dBx = bumpScale * texture2D( bumpMap, vUv + dSTdx ).x - Hll;\r\n\t\tfloat dBy = bumpScale * texture2D( bumpMap, vUv + dSTdy ).x - Hll;\r\n\r\n\t\treturn vec2( dBx, dBy );\r\n\r\n\t}\r\n\r\n\tvec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy ) {\r\n\r\n\t\t// Workaround for Adreno 3XX dFd*( vec3 ) bug. See #9988\r\n\r\n\t\tvec3 vSigmaX = vec3( dFdx( surf_pos.x ), dFdx( surf_pos.y ), dFdx( surf_pos.z ) );\r\n\t\tvec3 vSigmaY = vec3( dFdy( surf_pos.x ), dFdy( surf_pos.y ), dFdy( surf_pos.z ) );\r\n\t\tvec3 vN = surf_norm;\t\t// normalized\r\n\r\n\t\tvec3 R1 = cross( vSigmaY, vN );\r\n\t\tvec3 R2 = cross( vN, vSigmaX );\r\n\r\n\t\tfloat fDet = dot( vSigmaX, R1 );\r\n\r\n\t\tvec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\r\n\t\treturn normalize( abs( fDet ) * surf_norm - vGrad );\r\n\r\n\t}\r\n\r\n#endif\r\n";
  21176. var clipping_planes_fragment = "#if NUM_CLIPPING_PLANES > 0\r\n\r\n\tfor ( int i = 0; i < UNION_CLIPPING_PLANES; ++ i ) {\r\n\r\n\t\tvec4 plane = clippingPlanes[ i ];\r\n\t\tif ( dot( vViewPosition, plane.xyz ) > plane.w ) discard;\r\n\r\n\t}\r\n\t\t\r\n\t#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\r\n\r\n\t\tbool clipped = true;\r\n\t\tfor ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; ++ i ) {\r\n\t\t\tvec4 plane = clippingPlanes[ i ];\r\n\t\t\tclipped = ( dot( vViewPosition, plane.xyz ) > plane.w ) && clipped;\r\n\t\t}\r\n\r\n\t\tif ( clipped ) discard;\r\n\t\r\n\t#endif\r\n\r\n#endif\r\n";
  21177. var clipping_planes_pars_fragment = "#if NUM_CLIPPING_PLANES > 0\r\n\r\n\t#if ! defined( PHYSICAL ) && ! defined( PHONG )\r\n\t\tvarying vec3 vViewPosition;\r\n\t#endif\r\n\r\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\r\n\r\n#endif\r\n";
  21178. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG )\r\n\tvarying vec3 vViewPosition;\r\n#endif\r\n";
  21179. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG )\r\n\tvViewPosition = - mvPosition.xyz;\r\n#endif\r\n\r\n";
  21180. var color_fragment = "#ifdef USE_COLOR\r\n\r\n\tdiffuseColor.rgb *= vColor;\r\n\r\n#endif";
  21181. var color_pars_fragment = "#ifdef USE_COLOR\r\n\r\n\tvarying vec3 vColor;\r\n\r\n#endif\r\n";
  21182. var color_pars_vertex = "#ifdef USE_COLOR\r\n\r\n\tvarying vec3 vColor;\r\n\r\n#endif";
  21183. var color_vertex = "#ifdef USE_COLOR\r\n\r\n\tvColor.xyz = color.xyz;\r\n\r\n#endif";
  21184. var common = "#define PI 3.14159265359\r\n#define PI2 6.28318530718\r\n#define PI_HALF 1.5707963267949\r\n#define RECIPROCAL_PI 0.31830988618\r\n#define RECIPROCAL_PI2 0.15915494\r\n#define LOG2 1.442695\r\n#define EPSILON 1e-6\r\n\r\n#define saturate(a) clamp( a, 0.0, 1.0 )\r\n#define whiteCompliment(a) ( 1.0 - saturate( a ) )\r\n\r\nfloat pow2( const in float x ) { return x*x; }\r\nfloat pow3( const in float x ) { return x*x*x; }\r\nfloat pow4( const in float x ) { float x2 = x*x; return x2*x2; }\r\nfloat average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); }\r\n// expects values in the range of [0,1]x[0,1], returns values in the [0,1] range.\r\n// do not collapse into a single function per: http://byteblacksmith.com/improvements-to-the-canonical-one-liner-glsl-rand-for-opengl-es-2-0/\r\nhighp float rand( const in vec2 uv ) {\r\n\tconst highp float a = 12.9898, b = 78.233, c = 43758.5453;\r\n\thighp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\r\n\treturn fract(sin(sn) * c);\r\n}\r\n\r\nstruct IncidentLight {\r\n\tvec3 color;\r\n\tvec3 direction;\r\n\tbool visible;\r\n};\r\n\r\nstruct ReflectedLight {\r\n\tvec3 directDiffuse;\r\n\tvec3 directSpecular;\r\n\tvec3 indirectDiffuse;\r\n\tvec3 indirectSpecular;\r\n};\r\n\r\nstruct GeometricContext {\r\n\tvec3 position;\r\n\tvec3 normal;\r\n\tvec3 viewDir;\r\n};\r\n\r\nvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\r\n\r\n\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\r\n\r\n}\r\n\r\n// http://en.wikibooks.org/wiki/GLSL_Programming/Applying_Matrix_Transformations\r\nvec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {\r\n\r\n\treturn normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );\r\n\r\n}\r\n\r\nvec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\r\n\r\n\tfloat distance = dot( planeNormal, point - pointOnPlane );\r\n\r\n\treturn - distance * planeNormal + point;\r\n\r\n}\r\n\r\nfloat sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\r\n\r\n\treturn sign( dot( point - pointOnPlane, planeNormal ) );\r\n\r\n}\r\n\r\nvec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) {\r\n\r\n\treturn lineDirection * ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) ) + pointOnLine;\r\n\r\n}\r\n\r\nmat3 transposeMat3( const in mat3 m ) {\r\n\r\n\tmat3 tmp;\r\n\r\n\ttmp[ 0 ] = vec3( m[ 0 ].x, m[ 1 ].x, m[ 2 ].x );\r\n\ttmp[ 1 ] = vec3( m[ 0 ].y, m[ 1 ].y, m[ 2 ].y );\r\n\ttmp[ 2 ] = vec3( m[ 0 ].z, m[ 1 ].z, m[ 2 ].z );\r\n\r\n\treturn tmp;\r\n\r\n}\r\n\r\n// https://en.wikipedia.org/wiki/Relative_luminance\r\nfloat linearToRelativeLuminance( const in vec3 color ) {\r\n\r\n\tvec3 weights = vec3( 0.2126, 0.7152, 0.0722 );\r\n\r\n\treturn dot( weights, color.rgb );\r\n\r\n}\r\n";
  21185. var cube_uv_reflection_fragment = "#ifdef ENVMAP_TYPE_CUBE_UV\r\n\r\n#define cubeUV_textureSize (1024.0)\r\n\r\nint getFaceFromDirection(vec3 direction) {\r\n\tvec3 absDirection = abs(direction);\r\n\tint face = -1;\r\n\tif( absDirection.x > absDirection.z ) {\r\n\t\tif(absDirection.x > absDirection.y )\r\n\t\t\tface = direction.x > 0.0 ? 0 : 3;\r\n\t\telse\r\n\t\t\tface = direction.y > 0.0 ? 1 : 4;\r\n\t}\r\n\telse {\r\n\t\tif(absDirection.z > absDirection.y )\r\n\t\t\tface = direction.z > 0.0 ? 2 : 5;\r\n\t\telse\r\n\t\t\tface = direction.y > 0.0 ? 1 : 4;\r\n\t}\r\n\treturn face;\r\n}\r\n#define cubeUV_maxLods1 (log2(cubeUV_textureSize*0.25) - 1.0)\r\n#define cubeUV_rangeClamp (exp2((6.0 - 1.0) * 2.0))\r\n\r\nvec2 MipLevelInfo( vec3 vec, float roughnessLevel, float roughness ) {\r\n\tfloat scale = exp2(cubeUV_maxLods1 - roughnessLevel);\r\n\tfloat dxRoughness = dFdx(roughness);\r\n\tfloat dyRoughness = dFdy(roughness);\r\n\tvec3 dx = dFdx( vec * scale * dxRoughness );\r\n\tvec3 dy = dFdy( vec * scale * dyRoughness );\r\n\tfloat d = max( dot( dx, dx ), dot( dy, dy ) );\r\n\t// Clamp the value to the max mip level counts. hard coded to 6 mips\r\n\td = clamp(d, 1.0, cubeUV_rangeClamp);\r\n\tfloat mipLevel = 0.5 * log2(d);\r\n\treturn vec2(floor(mipLevel), fract(mipLevel));\r\n}\r\n\r\n#define cubeUV_maxLods2 (log2(cubeUV_textureSize*0.25) - 2.0)\r\n#define cubeUV_rcpTextureSize (1.0 / cubeUV_textureSize)\r\n\r\nvec2 getCubeUV(vec3 direction, float roughnessLevel, float mipLevel) {\r\n\tmipLevel = roughnessLevel > cubeUV_maxLods2 - 3.0 ? 0.0 : mipLevel;\r\n\tfloat a = 16.0 * cubeUV_rcpTextureSize;\r\n\r\n\tvec2 exp2_packed = exp2( vec2( roughnessLevel, mipLevel ) );\r\n\tvec2 rcp_exp2_packed = vec2( 1.0 ) / exp2_packed;\r\n\t// float powScale = exp2(roughnessLevel + mipLevel);\r\n\tfloat powScale = exp2_packed.x * exp2_packed.y;\r\n\t// float scale = 1.0 / exp2(roughnessLevel + 2.0 + mipLevel);\r\n\tfloat scale = rcp_exp2_packed.x * rcp_exp2_packed.y * 0.25;\r\n\t// float mipOffset = 0.75*(1.0 - 1.0/exp2(mipLevel))/exp2(roughnessLevel);\r\n\tfloat mipOffset = 0.75*(1.0 - rcp_exp2_packed.y) * rcp_exp2_packed.x;\r\n\r\n\tbool bRes = mipLevel == 0.0;\r\n\tscale = bRes && (scale < a) ? a : scale;\r\n\r\n\tvec3 r;\r\n\tvec2 offset;\r\n\tint face = getFaceFromDirection(direction);\r\n\r\n\tfloat rcpPowScale = 1.0 / powScale;\r\n\r\n\tif( face == 0) {\r\n\t\tr = vec3(direction.x, -direction.z, direction.y);\r\n\t\toffset = vec2(0.0+mipOffset,0.75 * rcpPowScale);\r\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\r\n\t}\r\n\telse if( face == 1) {\r\n\t\tr = vec3(direction.y, direction.x, direction.z);\r\n\t\toffset = vec2(scale+mipOffset, 0.75 * rcpPowScale);\r\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\r\n\t}\r\n\telse if( face == 2) {\r\n\t\tr = vec3(direction.z, direction.x, direction.y);\r\n\t\toffset = vec2(2.0*scale+mipOffset, 0.75 * rcpPowScale);\r\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\r\n\t}\r\n\telse if( face == 3) {\r\n\t\tr = vec3(direction.x, direction.z, direction.y);\r\n\t\toffset = vec2(0.0+mipOffset,0.5 * rcpPowScale);\r\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\r\n\t}\r\n\telse if( face == 4) {\r\n\t\tr = vec3(direction.y, direction.x, -direction.z);\r\n\t\toffset = vec2(scale+mipOffset, 0.5 * rcpPowScale);\r\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\r\n\t}\r\n\telse {\r\n\t\tr = vec3(direction.z, -direction.x, direction.y);\r\n\t\toffset = vec2(2.0*scale+mipOffset, 0.5 * rcpPowScale);\r\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\r\n\t}\r\n\tr = normalize(r);\r\n\tfloat texelOffset = 0.5 * cubeUV_rcpTextureSize;\r\n\tvec2 s = ( r.yz / abs( r.x ) + vec2( 1.0 ) ) * 0.5;\r\n\tvec2 base = offset + vec2( texelOffset );\r\n\treturn base + s * ( scale - 2.0 * texelOffset );\r\n}\r\n\r\n#define cubeUV_maxLods3 (log2(cubeUV_textureSize*0.25) - 3.0)\r\n\r\nvec4 textureCubeUV(vec3 reflectedDirection, float roughness ) {\r\n\tfloat roughnessVal = roughness* cubeUV_maxLods3;\r\n\tfloat r1 = floor(roughnessVal);\r\n\tfloat r2 = r1 + 1.0;\r\n\tfloat t = fract(roughnessVal);\r\n\tvec2 mipInfo = MipLevelInfo(reflectedDirection, r1, roughness);\r\n\tfloat s = mipInfo.y;\r\n\tfloat level0 = mipInfo.x;\r\n\tfloat level1 = level0 + 1.0;\r\n\tlevel1 = level1 > 5.0 ? 5.0 : level1;\r\n\r\n\t// round to nearest mipmap if we are not interpolating.\r\n\tlevel0 += min( floor( s + 0.5 ), 5.0 );\r\n\r\n\t// Tri linear interpolation.\r\n\tvec2 uv_10 = getCubeUV(reflectedDirection, r1, level0);\r\n\tvec4 color10 = envMapTexelToLinear(texture2D(envMap, uv_10));\r\n\r\n\tvec2 uv_20 = getCubeUV(reflectedDirection, r2, level0);\r\n\tvec4 color20 = envMapTexelToLinear(texture2D(envMap, uv_20));\r\n\r\n\tvec4 result = mix(color10, color20, t);\r\n\r\n\treturn vec4(result.rgb, 1.0);\r\n}\r\n\r\n#endif\r\n";
  21186. var defaultnormal_vertex = "vec3 transformedNormal = normalMatrix * objectNormal;\r\n\r\n#ifdef FLIP_SIDED\r\n\r\n\ttransformedNormal = - transformedNormal;\r\n\r\n#endif\r\n";
  21187. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\r\n\r\n\tuniform sampler2D displacementMap;\r\n\tuniform float displacementScale;\r\n\tuniform float displacementBias;\r\n\r\n#endif\r\n";
  21188. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\r\n\r\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, uv ).x * displacementScale + displacementBias );\r\n\r\n#endif\r\n";
  21189. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\r\n\r\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\r\n\r\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\r\n\r\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\r\n\r\n#endif\r\n";
  21190. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\r\n\r\n\tuniform sampler2D emissiveMap;\r\n\r\n#endif\r\n";
  21191. var encodings_fragment = " gl_FragColor = linearToOutputTexel( gl_FragColor );\r\n";
  21192. var encodings_pars_fragment = "// For a discussion of what this is, please read this: http://lousodrome.net/blog/light/2013/05/26/gamma-correct-and-hdr-rendering-in-a-32-bits-buffer/\r\n\r\nvec4 LinearToLinear( in vec4 value ) {\r\n\treturn value;\r\n}\r\n\r\nvec4 GammaToLinear( in vec4 value, in float gammaFactor ) {\r\n\treturn vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );\r\n}\r\nvec4 LinearToGamma( in vec4 value, in float gammaFactor ) {\r\n\treturn vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );\r\n}\r\n\r\nvec4 sRGBToLinear( in vec4 value ) {\r\n\treturn vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );\r\n}\r\nvec4 LinearTosRGB( in vec4 value ) {\r\n\treturn vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.w );\r\n}\r\n\r\nvec4 RGBEToLinear( in vec4 value ) {\r\n\treturn vec4( value.rgb * exp2( value.a * 255.0 - 128.0 ), 1.0 );\r\n}\r\nvec4 LinearToRGBE( in vec4 value ) {\r\n\tfloat maxComponent = max( max( value.r, value.g ), value.b );\r\n\tfloat fExp = clamp( ceil( log2( maxComponent ) ), -128.0, 127.0 );\r\n\treturn vec4( value.rgb / exp2( fExp ), ( fExp + 128.0 ) / 255.0 );\r\n// return vec4( value.brg, ( 3.0 + 128.0 ) / 256.0 );\r\n}\r\n\r\n// reference: http://iwasbeingirony.blogspot.ca/2010/06/difference-between-rgbm-and-rgbd.html\r\nvec4 RGBMToLinear( in vec4 value, in float maxRange ) {\r\n\treturn vec4( value.xyz * value.w * maxRange, 1.0 );\r\n}\r\nvec4 LinearToRGBM( in vec4 value, in float maxRange ) {\r\n\tfloat maxRGB = max( value.x, max( value.g, value.b ) );\r\n\tfloat M = clamp( maxRGB / maxRange, 0.0, 1.0 );\r\n\tM = ceil( M * 255.0 ) / 255.0;\r\n\treturn vec4( value.rgb / ( M * maxRange ), M );\r\n}\r\n\r\n// reference: http://iwasbeingirony.blogspot.ca/2010/06/difference-between-rgbm-and-rgbd.html\r\nvec4 RGBDToLinear( in vec4 value, in float maxRange ) {\r\n\treturn vec4( value.rgb * ( ( maxRange / 255.0 ) / value.a ), 1.0 );\r\n}\r\nvec4 LinearToRGBD( in vec4 value, in float maxRange ) {\r\n\tfloat maxRGB = max( value.x, max( value.g, value.b ) );\r\n\tfloat D = max( maxRange / maxRGB, 1.0 );\r\n\tD = min( floor( D ) / 255.0, 1.0 );\r\n\treturn vec4( value.rgb * ( D * ( 255.0 / maxRange ) ), D );\r\n}\r\n\r\n// LogLuv reference: http://graphicrants.blogspot.ca/2009/04/rgbm-color-encoding.html\r\n\r\n// M matrix, for encoding\r\nconst mat3 cLogLuvM = mat3( 0.2209, 0.3390, 0.4184, 0.1138, 0.6780, 0.7319, 0.0102, 0.1130, 0.2969 );\r\nvec4 LinearToLogLuv( in vec4 value ) {\r\n\tvec3 Xp_Y_XYZp = value.rgb * cLogLuvM;\r\n\tXp_Y_XYZp = max(Xp_Y_XYZp, vec3(1e-6, 1e-6, 1e-6));\r\n\tvec4 vResult;\r\n\tvResult.xy = Xp_Y_XYZp.xy / Xp_Y_XYZp.z;\r\n\tfloat Le = 2.0 * log2(Xp_Y_XYZp.y) + 127.0;\r\n\tvResult.w = fract(Le);\r\n\tvResult.z = (Le - (floor(vResult.w*255.0))/255.0)/255.0;\r\n\treturn vResult;\r\n}\r\n\r\n// Inverse M matrix, for decoding\r\nconst mat3 cLogLuvInverseM = mat3( 6.0014, -2.7008, -1.7996, -1.3320, 3.1029, -5.7721, 0.3008, -1.0882, 5.6268 );\r\nvec4 LogLuvToLinear( in vec4 value ) {\r\n\tfloat Le = value.z * 255.0 + value.w;\r\n\tvec3 Xp_Y_XYZp;\r\n\tXp_Y_XYZp.y = exp2((Le - 127.0) / 2.0);\r\n\tXp_Y_XYZp.z = Xp_Y_XYZp.y / value.y;\r\n\tXp_Y_XYZp.x = value.x * Xp_Y_XYZp.z;\r\n\tvec3 vRGB = Xp_Y_XYZp.rgb * cLogLuvInverseM;\r\n\treturn vec4( max(vRGB, 0.0), 1.0 );\r\n}\r\n";
  21193. var envmap_fragment = "#ifdef USE_ENVMAP\r\n\r\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\r\n\r\n\t\tvec3 cameraToVertex = normalize( vWorldPosition - cameraPosition );\r\n\r\n\t\t// Transforming Normal Vectors with the Inverse Transformation\r\n\t\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\r\n\r\n\t\t#ifdef ENVMAP_MODE_REFLECTION\r\n\r\n\t\t\tvec3 reflectVec = reflect( cameraToVertex, worldNormal );\r\n\r\n\t\t#else\r\n\r\n\t\t\tvec3 reflectVec = refract( cameraToVertex, worldNormal, refractionRatio );\r\n\r\n\t\t#endif\r\n\r\n\t#else\r\n\r\n\t\tvec3 reflectVec = vReflect;\r\n\r\n\t#endif\r\n\r\n\t#ifdef ENVMAP_TYPE_CUBE\r\n\r\n\t\tvec4 envColor = textureCube( envMap, vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\r\n\r\n\t#elif defined( ENVMAP_TYPE_EQUIREC )\r\n\r\n\t\tvec2 sampleUV;\r\n\r\n\t\treflectVec = normalize( reflectVec );\r\n\r\n\t\tsampleUV.y = asin( clamp( reflectVec.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\r\n\r\n\t\tsampleUV.x = atan( reflectVec.z, reflectVec.x ) * RECIPROCAL_PI2 + 0.5;\r\n\r\n\t\tvec4 envColor = texture2D( envMap, sampleUV );\r\n\r\n\t#elif defined( ENVMAP_TYPE_SPHERE )\r\n\r\n\t\treflectVec = normalize( reflectVec );\r\n\r\n\t\tvec3 reflectView = normalize( ( viewMatrix * vec4( reflectVec, 0.0 ) ).xyz + vec3( 0.0, 0.0, 1.0 ) );\r\n\r\n\t\tvec4 envColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5 );\r\n\r\n\t#else\r\n\r\n\t\tvec4 envColor = vec4( 0.0 );\r\n\r\n\t#endif\r\n\r\n\tenvColor = envMapTexelToLinear( envColor );\r\n\r\n\t#ifdef ENVMAP_BLENDING_MULTIPLY\r\n\r\n\t\toutgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );\r\n\r\n\t#elif defined( ENVMAP_BLENDING_MIX )\r\n\r\n\t\toutgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );\r\n\r\n\t#elif defined( ENVMAP_BLENDING_ADD )\r\n\r\n\t\toutgoingLight += envColor.xyz * specularStrength * reflectivity;\r\n\r\n\t#endif\r\n\r\n#endif\r\n";
  21194. var envmap_pars_fragment = "#if defined( USE_ENVMAP ) || defined( PHYSICAL )\r\n\tuniform float reflectivity;\r\n\tuniform float envMapIntensity;\r\n#endif\r\n\r\n#ifdef USE_ENVMAP\r\n\r\n\t#if ! defined( PHYSICAL ) && ( defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) )\r\n\t\tvarying vec3 vWorldPosition;\r\n\t#endif\r\n\r\n\t#ifdef ENVMAP_TYPE_CUBE\r\n\t\tuniform samplerCube envMap;\r\n\t#else\r\n\t\tuniform sampler2D envMap;\r\n\t#endif\r\n\tuniform float flipEnvMap;\r\n\r\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( PHYSICAL )\r\n\t\tuniform float refractionRatio;\r\n\t#else\r\n\t\tvarying vec3 vReflect;\r\n\t#endif\r\n\r\n#endif\r\n";
  21195. var envmap_pars_vertex = "#ifdef USE_ENVMAP\r\n\r\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\r\n\t\tvarying vec3 vWorldPosition;\r\n\r\n\t#else\r\n\r\n\t\tvarying vec3 vReflect;\r\n\t\tuniform float refractionRatio;\r\n\r\n\t#endif\r\n\r\n#endif\r\n";
  21196. var envmap_vertex = "#ifdef USE_ENVMAP\r\n\r\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\r\n\r\n\t\tvWorldPosition = worldPosition.xyz;\r\n\r\n\t#else\r\n\r\n\t\tvec3 cameraToVertex = normalize( worldPosition.xyz - cameraPosition );\r\n\r\n\t\tvec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\r\n\r\n\t\t#ifdef ENVMAP_MODE_REFLECTION\r\n\r\n\t\t\tvReflect = reflect( cameraToVertex, worldNormal );\r\n\r\n\t\t#else\r\n\r\n\t\t\tvReflect = refract( cameraToVertex, worldNormal, refractionRatio );\r\n\r\n\t\t#endif\r\n\r\n\t#endif\r\n\r\n#endif\r\n";
  21197. var fog_vertex = "\r\n#ifdef USE_FOG\r\nfogDepth = -mvPosition.z;\r\n#endif";
  21198. var fog_pars_vertex = "#ifdef USE_FOG\r\n\r\n varying float fogDepth;\r\n\r\n#endif\r\n";
  21199. var fog_fragment = "#ifdef USE_FOG\r\n\r\n\t#ifdef FOG_EXP2\r\n\r\n\t\tfloat fogFactor = whiteCompliment( exp2( - fogDensity * fogDensity * fogDepth * fogDepth * LOG2 ) );\r\n\r\n\t#else\r\n\r\n\t\tfloat fogFactor = smoothstep( fogNear, fogFar, fogDepth );\r\n\r\n\t#endif\r\n\r\n\tgl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );\r\n\r\n#endif\r\n";
  21200. var fog_pars_fragment = "#ifdef USE_FOG\r\n\r\n\tuniform vec3 fogColor;\r\n\tvarying float fogDepth;\r\n\r\n\t#ifdef FOG_EXP2\r\n\r\n\t\tuniform float fogDensity;\r\n\r\n\t#else\r\n\r\n\t\tuniform float fogNear;\r\n\t\tuniform float fogFar;\r\n\r\n\t#endif\r\n\r\n#endif\r\n";
  21201. var gradientmap_pars_fragment = "#ifdef TOON\r\n\r\n\tuniform sampler2D gradientMap;\r\n\r\n\tvec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) {\r\n\r\n\t\t// dotNL will be from -1.0 to 1.0\r\n\t\tfloat dotNL = dot( normal, lightDirection );\r\n\t\tvec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 );\r\n\r\n\t\t#ifdef USE_GRADIENTMAP\r\n\r\n\t\t\treturn texture2D( gradientMap, coord ).rgb;\r\n\r\n\t\t#else\r\n\r\n\t\t\treturn ( coord.x < 0.7 ) ? vec3( 0.7 ) : vec3( 1.0 );\r\n\r\n\t\t#endif\r\n\r\n\r\n\t}\r\n\r\n#endif\r\n";
  21202. var lightmap_fragment = "#ifdef USE_LIGHTMAP\r\n\r\n\treflectedLight.indirectDiffuse += PI * texture2D( lightMap, vUv2 ).xyz * lightMapIntensity; // factor of PI should not be present; included here to prevent breakage\r\n\r\n#endif\r\n";
  21203. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\r\n\r\n\tuniform sampler2D lightMap;\r\n\tuniform float lightMapIntensity;\r\n\r\n#endif";
  21204. var lights_lambert_vertex = "vec3 diffuse = vec3( 1.0 );\r\n\r\nGeometricContext geometry;\r\ngeometry.position = mvPosition.xyz;\r\ngeometry.normal = normalize( transformedNormal );\r\ngeometry.viewDir = normalize( -mvPosition.xyz );\r\n\r\nGeometricContext backGeometry;\r\nbackGeometry.position = geometry.position;\r\nbackGeometry.normal = -geometry.normal;\r\nbackGeometry.viewDir = geometry.viewDir;\r\n\r\nvLightFront = vec3( 0.0 );\r\n\r\n#ifdef DOUBLE_SIDED\r\n\tvLightBack = vec3( 0.0 );\r\n#endif\r\n\r\nIncidentLight directLight;\r\nfloat dotNL;\r\nvec3 directLightColor_Diffuse;\r\n\r\n#if NUM_POINT_LIGHTS > 0\r\n\r\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\r\n\r\n\t\tgetPointDirectLightIrradiance( pointLights[ i ], geometry, directLight );\r\n\r\n\t\tdotNL = dot( geometry.normal, directLight.direction );\r\n\t\tdirectLightColor_Diffuse = PI * directLight.color;\r\n\r\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\r\n\r\n\t\t#ifdef DOUBLE_SIDED\r\n\r\n\t\t\tvLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\r\n\r\n\t\t#endif\r\n\r\n\t}\r\n\r\n#endif\r\n\r\n#if NUM_SPOT_LIGHTS > 0\r\n\r\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\r\n\r\n\t\tgetSpotDirectLightIrradiance( spotLights[ i ], geometry, directLight );\r\n\r\n\t\tdotNL = dot( geometry.normal, directLight.direction );\r\n\t\tdirectLightColor_Diffuse = PI * directLight.color;\r\n\r\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\r\n\r\n\t\t#ifdef DOUBLE_SIDED\r\n\r\n\t\t\tvLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\r\n\r\n\t\t#endif\r\n\t}\r\n\r\n#endif\r\n\r\n\r\n\r\n#if NUM_DIR_LIGHTS > 0\r\n\r\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\r\n\r\n\t\tgetDirectionalDirectLightIrradiance( directionalLights[ i ], geometry, directLight );\r\n\r\n\t\tdotNL = dot( geometry.normal, directLight.direction );\r\n\t\tdirectLightColor_Diffuse = PI * directLight.color;\r\n\r\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\r\n\r\n\t\t#ifdef DOUBLE_SIDED\r\n\r\n\t\t\tvLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\r\n\r\n\t\t#endif\r\n\r\n\t}\r\n\r\n#endif\r\n\r\n#if NUM_HEMI_LIGHTS > 0\r\n\r\n\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\r\n\r\n\t\tvLightFront += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\r\n\r\n\t\t#ifdef DOUBLE_SIDED\r\n\r\n\t\t\tvLightBack += getHemisphereLightIrradiance( hemisphereLights[ i ], backGeometry );\r\n\r\n\t\t#endif\r\n\r\n\t}\r\n\r\n#endif\r\n";
  21205. var lights_pars = "uniform vec3 ambientLightColor;\r\n\r\nvec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {\r\n\r\n\tvec3 irradiance = ambientLightColor;\r\n\r\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\r\n\r\n\t\tirradiance *= PI;\r\n\r\n\t#endif\r\n\r\n\treturn irradiance;\r\n\r\n}\r\n\r\n#if NUM_DIR_LIGHTS > 0\r\n\r\n\tstruct DirectionalLight {\r\n\t\tvec3 direction;\r\n\t\tvec3 color;\r\n\r\n\t\tint shadow;\r\n\t\tfloat shadowBias;\r\n\t\tfloat shadowRadius;\r\n\t\tvec2 shadowMapSize;\r\n\t};\r\n\r\n\tuniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\r\n\r\n\tvoid getDirectionalDirectLightIrradiance( const in DirectionalLight directionalLight, const in GeometricContext geometry, out IncidentLight directLight ) {\r\n\r\n\t\tdirectLight.color = directionalLight.color;\r\n\t\tdirectLight.direction = directionalLight.direction;\r\n\t\tdirectLight.visible = true;\r\n\r\n\t}\r\n\r\n#endif\r\n\r\n\r\n#if NUM_POINT_LIGHTS > 0\r\n\r\n\tstruct PointLight {\r\n\t\tvec3 position;\r\n\t\tvec3 color;\r\n\t\tfloat distance;\r\n\t\tfloat decay;\r\n\r\n\t\tint shadow;\r\n\t\tfloat shadowBias;\r\n\t\tfloat shadowRadius;\r\n\t\tvec2 shadowMapSize;\r\n\t\tfloat shadowCameraNear;\r\n\t\tfloat shadowCameraFar;\r\n\t};\r\n\r\n\tuniform PointLight pointLights[ NUM_POINT_LIGHTS ];\r\n\r\n\t// directLight is an out parameter as having it as a return value caused compiler errors on some devices\r\n\tvoid getPointDirectLightIrradiance( const in PointLight pointLight, const in GeometricContext geometry, out IncidentLight directLight ) {\r\n\r\n\t\tvec3 lVector = pointLight.position - geometry.position;\r\n\t\tdirectLight.direction = normalize( lVector );\r\n\r\n\t\tfloat lightDistance = length( lVector );\r\n\r\n\t\tdirectLight.color = pointLight.color;\r\n\t\tdirectLight.color *= punctualLightIntensityToIrradianceFactor( lightDistance, pointLight.distance, pointLight.decay );\r\n\t\tdirectLight.visible = ( directLight.color != vec3( 0.0 ) );\r\n\r\n\t}\r\n\r\n#endif\r\n\r\n\r\n#if NUM_SPOT_LIGHTS > 0\r\n\r\n\tstruct SpotLight {\r\n\t\tvec3 position;\r\n\t\tvec3 direction;\r\n\t\tvec3 color;\r\n\t\tfloat distance;\r\n\t\tfloat decay;\r\n\t\tfloat coneCos;\r\n\t\tfloat penumbraCos;\r\n\r\n\t\tint shadow;\r\n\t\tfloat shadowBias;\r\n\t\tfloat shadowRadius;\r\n\t\tvec2 shadowMapSize;\r\n\t};\r\n\r\n\tuniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];\r\n\r\n\t// directLight is an out parameter as having it as a return value caused compiler errors on some devices\r\n\tvoid getSpotDirectLightIrradiance( const in SpotLight spotLight, const in GeometricContext geometry, out IncidentLight directLight ) {\r\n\r\n\t\tvec3 lVector = spotLight.position - geometry.position;\r\n\t\tdirectLight.direction = normalize( lVector );\r\n\r\n\t\tfloat lightDistance = length( lVector );\r\n\t\tfloat angleCos = dot( directLight.direction, spotLight.direction );\r\n\r\n\t\tif ( angleCos > spotLight.coneCos ) {\r\n\r\n\t\t\tfloat spotEffect = smoothstep( spotLight.coneCos, spotLight.penumbraCos, angleCos );\r\n\r\n\t\t\tdirectLight.color = spotLight.color;\r\n\t\t\tdirectLight.color *= spotEffect * punctualLightIntensityToIrradianceFactor( lightDistance, spotLight.distance, spotLight.decay );\r\n\t\t\tdirectLight.visible = true;\r\n\r\n\t\t} else {\r\n\r\n\t\t\tdirectLight.color = vec3( 0.0 );\r\n\t\t\tdirectLight.visible = false;\r\n\r\n\t\t}\r\n\t}\r\n\r\n#endif\r\n\r\n\r\n#if NUM_RECT_AREA_LIGHTS > 0\r\n\r\n\tstruct RectAreaLight {\r\n\t\tvec3 color;\r\n\t\tvec3 position;\r\n\t\tvec3 halfWidth;\r\n\t\tvec3 halfHeight;\r\n\t};\r\n\r\n\t// Pre-computed values of LinearTransformedCosine approximation of BRDF\r\n\t// BRDF approximation Texture is 64x64\r\n\tuniform sampler2D ltcMat; // RGBA Float\r\n\tuniform sampler2D ltcMag; // Alpha Float (only has w component)\r\n\r\n\tuniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ];\r\n\r\n#endif\r\n\r\n\r\n#if NUM_HEMI_LIGHTS > 0\r\n\r\n\tstruct HemisphereLight {\r\n\t\tvec3 direction;\r\n\t\tvec3 skyColor;\r\n\t\tvec3 groundColor;\r\n\t};\r\n\r\n\tuniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];\r\n\r\n\tvec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in GeometricContext geometry ) {\r\n\r\n\t\tfloat dotNL = dot( geometry.normal, hemiLight.direction );\r\n\t\tfloat hemiDiffuseWeight = 0.5 * dotNL + 0.5;\r\n\r\n\t\tvec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );\r\n\r\n\t\t#ifndef PHYSICALLY_CORRECT_LIGHTS\r\n\r\n\t\t\tirradiance *= PI;\r\n\r\n\t\t#endif\r\n\r\n\t\treturn irradiance;\r\n\r\n\t}\r\n\r\n#endif\r\n\r\n\r\n#if defined( USE_ENVMAP ) && defined( PHYSICAL )\r\n\r\n\tvec3 getLightProbeIndirectIrradiance( const in GeometricContext geometry, const in int maxMIPLevel ) {\r\n\r\n\t\tvec3 worldNormal = inverseTransformDirection( geometry.normal, viewMatrix );\r\n\r\n\t\t#ifdef ENVMAP_TYPE_CUBE\r\n\r\n\t\t\tvec3 queryVec = vec3( flipEnvMap * worldNormal.x, worldNormal.yz );\r\n\r\n\t\t\t// TODO: replace with properly filtered cubemaps and access the irradiance LOD level, be it the last LOD level\r\n\t\t\t// of a specular cubemap, or just the default level of a specially created irradiance cubemap.\r\n\r\n\t\t\t#ifdef TEXTURE_LOD_EXT\r\n\r\n\t\t\t\tvec4 envMapColor = textureCubeLodEXT( envMap, queryVec, float( maxMIPLevel ) );\r\n\r\n\t\t\t#else\r\n\r\n\t\t\t\t// force the bias high to get the last LOD level as it is the most blurred.\r\n\t\t\t\tvec4 envMapColor = textureCube( envMap, queryVec, float( maxMIPLevel ) );\r\n\r\n\t\t\t#endif\r\n\r\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\r\n\r\n\t\t#elif defined( ENVMAP_TYPE_CUBE_UV )\r\n\r\n\t\t\tvec3 queryVec = vec3( flipEnvMap * worldNormal.x, worldNormal.yz );\r\n\t\t\tvec4 envMapColor = textureCubeUV( queryVec, 1.0 );\r\n\r\n\t\t#else\r\n\r\n\t\t\tvec4 envMapColor = vec4( 0.0 );\r\n\r\n\t\t#endif\r\n\r\n\t\treturn PI * envMapColor.rgb * envMapIntensity;\r\n\r\n\t}\r\n\r\n\t// taken from here: http://casual-effects.blogspot.ca/2011/08/plausible-environment-lighting-in-two.html\r\n\tfloat getSpecularMIPLevel( const in float blinnShininessExponent, const in int maxMIPLevel ) {\r\n\r\n\t\t//float envMapWidth = pow( 2.0, maxMIPLevelScalar );\r\n\t\t//float desiredMIPLevel = log2( envMapWidth * sqrt( 3.0 ) ) - 0.5 * log2( pow2( blinnShininessExponent ) + 1.0 );\r\n\r\n\t\tfloat maxMIPLevelScalar = float( maxMIPLevel );\r\n\t\tfloat desiredMIPLevel = maxMIPLevelScalar + 0.79248 - 0.5 * log2( pow2( blinnShininessExponent ) + 1.0 );\r\n\r\n\t\t// clamp to allowable LOD ranges.\r\n\t\treturn clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );\r\n\r\n\t}\r\n\r\n\tvec3 getLightProbeIndirectRadiance( const in GeometricContext geometry, const in float blinnShininessExponent, const in int maxMIPLevel ) {\r\n\r\n\t\t#ifdef ENVMAP_MODE_REFLECTION\r\n\r\n\t\t\tvec3 reflectVec = reflect( -geometry.viewDir, geometry.normal );\r\n\r\n\t\t#else\r\n\r\n\t\t\tvec3 reflectVec = refract( -geometry.viewDir, geometry.normal, refractionRatio );\r\n\r\n\t\t#endif\r\n\r\n\t\treflectVec = inverseTransformDirection( reflectVec, viewMatrix );\r\n\r\n\t\tfloat specularMIPLevel = getSpecularMIPLevel( blinnShininessExponent, maxMIPLevel );\r\n\r\n\t\t#ifdef ENVMAP_TYPE_CUBE\r\n\r\n\t\t\tvec3 queryReflectVec = vec3( flipEnvMap * reflectVec.x, reflectVec.yz );\r\n\r\n\t\t\t#ifdef TEXTURE_LOD_EXT\r\n\r\n\t\t\t\tvec4 envMapColor = textureCubeLodEXT( envMap, queryReflectVec, specularMIPLevel );\r\n\r\n\t\t\t#else\r\n\r\n\t\t\t\tvec4 envMapColor = textureCube( envMap, queryReflectVec, specularMIPLevel );\r\n\r\n\t\t\t#endif\r\n\r\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\r\n\r\n\t\t#elif defined( ENVMAP_TYPE_CUBE_UV )\r\n\r\n\t\t\tvec3 queryReflectVec = vec3( flipEnvMap * reflectVec.x, reflectVec.yz );\r\n\t\t\tvec4 envMapColor = textureCubeUV(queryReflectVec, BlinnExponentToGGXRoughness(blinnShininessExponent));\r\n\r\n\t\t#elif defined( ENVMAP_TYPE_EQUIREC )\r\n\r\n\t\t\tvec2 sampleUV;\r\n\t\t\tsampleUV.y = asin( clamp( reflectVec.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\r\n\t\t\tsampleUV.x = atan( reflectVec.z, reflectVec.x ) * RECIPROCAL_PI2 + 0.5;\r\n\r\n\t\t\t#ifdef TEXTURE_LOD_EXT\r\n\r\n\t\t\t\tvec4 envMapColor = texture2DLodEXT( envMap, sampleUV, specularMIPLevel );\r\n\r\n\t\t\t#else\r\n\r\n\t\t\t\tvec4 envMapColor = texture2D( envMap, sampleUV, specularMIPLevel );\r\n\r\n\t\t\t#endif\r\n\r\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\r\n\r\n\t\t#elif defined( ENVMAP_TYPE_SPHERE )\r\n\r\n\t\t\tvec3 reflectView = normalize( ( viewMatrix * vec4( reflectVec, 0.0 ) ).xyz + vec3( 0.0,0.0,1.0 ) );\r\n\r\n\t\t\t#ifdef TEXTURE_LOD_EXT\r\n\r\n\t\t\t\tvec4 envMapColor = texture2DLodEXT( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );\r\n\r\n\t\t\t#else\r\n\r\n\t\t\t\tvec4 envMapColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );\r\n\r\n\t\t\t#endif\r\n\r\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\r\n\r\n\t\t#endif\r\n\r\n\t\treturn envMapColor.rgb * envMapIntensity;\r\n\r\n\t}\r\n\r\n#endif\r\n";
  21206. var lights_phong_fragment = "BlinnPhongMaterial material;\r\nmaterial.diffuseColor = diffuseColor.rgb;\r\nmaterial.specularColor = specular;\r\nmaterial.specularShininess = shininess;\r\nmaterial.specularStrength = specularStrength;\r\n";
  21207. var lights_phong_pars_fragment = "varying vec3 vViewPosition;\r\n\r\n#ifndef FLAT_SHADED\r\n\r\n\tvarying vec3 vNormal;\r\n\r\n#endif\r\n\r\n\r\nstruct BlinnPhongMaterial {\r\n\r\n\tvec3\tdiffuseColor;\r\n\tvec3\tspecularColor;\r\n\tfloat\tspecularShininess;\r\n\tfloat\tspecularStrength;\r\n\r\n};\r\n\r\nvoid RE_Direct_BlinnPhong( const in IncidentLight directLight, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\r\n\r\n\t#ifdef TOON\r\n\r\n\t\tvec3 irradiance = getGradientIrradiance( geometry.normal, directLight.direction ) * directLight.color;\r\n\r\n\t#else\r\n\r\n\t\tfloat dotNL = saturate( dot( geometry.normal, directLight.direction ) );\r\n\t\tvec3 irradiance = dotNL * directLight.color;\r\n\r\n\t#endif\r\n\r\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\r\n\r\n\t\tirradiance *= PI; // punctual light\r\n\r\n\t#endif\r\n\r\n\treflectedLight.directDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\r\n\r\n\treflectedLight.directSpecular += irradiance * BRDF_Specular_BlinnPhong( directLight, geometry, material.specularColor, material.specularShininess ) * material.specularStrength;\r\n\r\n}\r\n\r\nvoid RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\r\n\r\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\r\n\r\n}\r\n\r\n#define RE_Direct\t\t\t\tRE_Direct_BlinnPhong\r\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_BlinnPhong\r\n\r\n#define Material_LightProbeLOD( material )\t(0)\r\n";
  21208. var lights_physical_fragment = "PhysicalMaterial material;\r\nmaterial.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );\r\nmaterial.specularRoughness = clamp( roughnessFactor, 0.04, 1.0 );\r\n#ifdef STANDARD\r\n\tmaterial.specularColor = mix( vec3( DEFAULT_SPECULAR_COEFFICIENT ), diffuseColor.rgb, metalnessFactor );\r\n#else\r\n\tmaterial.specularColor = mix( vec3( MAXIMUM_SPECULAR_COEFFICIENT * pow2( reflectivity ) ), diffuseColor.rgb, metalnessFactor );\r\n\tmaterial.clearCoat = saturate( clearCoat ); // Burley clearcoat model\r\n\tmaterial.clearCoatRoughness = clamp( clearCoatRoughness, 0.04, 1.0 );\r\n#endif\r\n";
  21209. var lights_physical_pars_fragment = "struct PhysicalMaterial {\r\n\r\n\tvec3\tdiffuseColor;\r\n\tfloat\tspecularRoughness;\r\n\tvec3\tspecularColor;\r\n\r\n\t#ifndef STANDARD\r\n\t\tfloat clearCoat;\r\n\t\tfloat clearCoatRoughness;\r\n\t#endif\r\n\r\n};\r\n\r\n#define MAXIMUM_SPECULAR_COEFFICIENT 0.16\r\n#define DEFAULT_SPECULAR_COEFFICIENT 0.04\r\n\r\n// Clear coat directional hemishperical reflectance (this approximation should be improved)\r\nfloat clearCoatDHRApprox( const in float roughness, const in float dotNL ) {\r\n\r\n\treturn DEFAULT_SPECULAR_COEFFICIENT + ( 1.0 - DEFAULT_SPECULAR_COEFFICIENT ) * ( pow( 1.0 - dotNL, 5.0 ) * pow( 1.0 - roughness, 2.0 ) );\r\n\r\n}\r\n\r\n#if NUM_RECT_AREA_LIGHTS > 0\r\n\r\n\tvoid RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\r\n\r\n\t\tvec3 normal = geometry.normal;\r\n\t\tvec3 viewDir = geometry.viewDir;\r\n\t\tvec3 position = geometry.position;\r\n\t\tvec3 lightPos = rectAreaLight.position;\r\n\t\tvec3 halfWidth = rectAreaLight.halfWidth;\r\n\t\tvec3 halfHeight = rectAreaLight.halfHeight;\r\n\t\tvec3 lightColor = rectAreaLight.color;\r\n\t\tfloat roughness = material.specularRoughness;\r\n\r\n\t\tvec3 rectCoords[ 4 ];\r\n\t\trectCoords[ 0 ] = lightPos - halfWidth - halfHeight; // counterclockwise\r\n\t\trectCoords[ 1 ] = lightPos + halfWidth - halfHeight;\r\n\t\trectCoords[ 2 ] = lightPos + halfWidth + halfHeight;\r\n\t\trectCoords[ 3 ] = lightPos - halfWidth + halfHeight;\r\n\r\n\t\tvec2 uv = LTC_Uv( normal, viewDir, roughness );\r\n\r\n\t\tfloat norm = texture2D( ltcMag, uv ).a;\r\n\r\n\t\tvec4 t = texture2D( ltcMat, uv );\r\n\r\n\t\tmat3 mInv = mat3(\r\n\t\t\tvec3( 1, 0, t.y ),\r\n\t\t\tvec3( 0, t.z, 0 ),\r\n\t\t\tvec3( t.w, 0, t.x )\r\n\t\t);\r\n\r\n\t\treflectedLight.directSpecular += lightColor * material.specularColor * norm * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords ); // no fresnel\r\n\r\n\t\treflectedLight.directDiffuse += lightColor * material.diffuseColor * LTC_Evaluate( normal, viewDir, position, mat3( 1 ), rectCoords );\r\n\r\n\t}\r\n\r\n#endif\r\n\r\nvoid RE_Direct_Physical( const in IncidentLight directLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\r\n\r\n\tfloat dotNL = saturate( dot( geometry.normal, directLight.direction ) );\r\n\r\n\tvec3 irradiance = dotNL * directLight.color;\r\n\r\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\r\n\r\n\t\tirradiance *= PI; // punctual light\r\n\r\n\t#endif\r\n\r\n\t#ifndef STANDARD\r\n\t\tfloat clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, dotNL );\r\n\t#else\r\n\t\tfloat clearCoatDHR = 0.0;\r\n\t#endif\r\n\r\n\treflectedLight.directSpecular += ( 1.0 - clearCoatDHR ) * irradiance * BRDF_Specular_GGX( directLight, geometry, material.specularColor, material.specularRoughness );\r\n\r\n\treflectedLight.directDiffuse += ( 1.0 - clearCoatDHR ) * irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\r\n\r\n\t#ifndef STANDARD\r\n\r\n\t\treflectedLight.directSpecular += irradiance * material.clearCoat * BRDF_Specular_GGX( directLight, geometry, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );\r\n\r\n\t#endif\r\n\r\n}\r\n\r\nvoid RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\r\n\r\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\r\n\r\n}\r\n\r\nvoid RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 clearCoatRadiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\r\n\r\n\t#ifndef STANDARD\r\n\t\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\r\n\t\tfloat dotNL = dotNV;\r\n\t\tfloat clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, dotNL );\r\n\t#else\r\n\t\tfloat clearCoatDHR = 0.0;\r\n\t#endif\r\n\r\n\treflectedLight.indirectSpecular += ( 1.0 - clearCoatDHR ) * radiance * BRDF_Specular_GGX_Environment( geometry, material.specularColor, material.specularRoughness );\r\n\r\n\t#ifndef STANDARD\r\n\r\n\t\treflectedLight.indirectSpecular += clearCoatRadiance * material.clearCoat * BRDF_Specular_GGX_Environment( geometry, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );\r\n\r\n\t#endif\r\n\r\n}\r\n\r\n#define RE_Direct\t\t\t\tRE_Direct_Physical\r\n#define RE_Direct_RectArea\t\tRE_Direct_RectArea_Physical\r\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Physical\r\n#define RE_IndirectSpecular\t\tRE_IndirectSpecular_Physical\r\n\r\n#define Material_BlinnShininessExponent( material ) GGXRoughnessToBlinnExponent( material.specularRoughness )\r\n#define Material_ClearCoat_BlinnShininessExponent( material ) GGXRoughnessToBlinnExponent( material.clearCoatRoughness )\r\n\r\n// ref: https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf\r\nfloat computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {\r\n\r\n\treturn saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );\r\n\r\n}\r\n";
  21210. var lights_template = "\r\n\r\nGeometricContext geometry;\r\n\r\ngeometry.position = - vViewPosition;\r\ngeometry.normal = normal;\r\ngeometry.viewDir = normalize( vViewPosition );\r\n\r\nIncidentLight directLight;\r\n\r\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\r\n\r\n\tPointLight pointLight;\r\n\r\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\r\n\r\n\t\tpointLight = pointLights[ i ];\r\n\r\n\t\tgetPointDirectLightIrradiance( pointLight, geometry, directLight );\r\n\r\n\t\t#ifdef USE_SHADOWMAP\r\n\t\tdirectLight.color *= all( bvec2( pointLight.shadow, directLight.visible ) ) ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;\r\n\t\t#endif\r\n\r\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\r\n\r\n\t}\r\n\r\n#endif\r\n\r\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\r\n\r\n\tSpotLight spotLight;\r\n\r\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\r\n\r\n\t\tspotLight = spotLights[ i ];\r\n\r\n\t\tgetSpotDirectLightIrradiance( spotLight, geometry, directLight );\r\n\r\n\t\t#ifdef USE_SHADOWMAP\r\n\t\tdirectLight.color *= all( bvec2( spotLight.shadow, directLight.visible ) ) ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\r\n\t\t#endif\r\n\r\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\r\n\r\n\t}\r\n\r\n#endif\r\n\r\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\r\n\r\n\tDirectionalLight directionalLight;\r\n\r\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\r\n\r\n\t\tdirectionalLight = directionalLights[ i ];\r\n\r\n\t\tgetDirectionalDirectLightIrradiance( directionalLight, geometry, directLight );\r\n\r\n\t\t#ifdef USE_SHADOWMAP\r\n\t\tdirectLight.color *= all( bvec2( directionalLight.shadow, directLight.visible ) ) ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\r\n\t\t#endif\r\n\r\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\r\n\r\n\t}\r\n\r\n#endif\r\n\r\n#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\r\n\r\n\tRectAreaLight rectAreaLight;\r\n\r\n\tfor ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {\r\n\r\n\t\trectAreaLight = rectAreaLights[ i ];\r\n\t\tRE_Direct_RectArea( rectAreaLight, geometry, material, reflectedLight );\r\n\r\n\t}\r\n\r\n#endif\r\n\r\n#if defined( RE_IndirectDiffuse )\r\n\r\n\tvec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\r\n\r\n\t#ifdef USE_LIGHTMAP\r\n\r\n\t\tvec3 lightMapIrradiance = texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\r\n\r\n\t\t#ifndef PHYSICALLY_CORRECT_LIGHTS\r\n\r\n\t\t\tlightMapIrradiance *= PI; // factor of PI should not be present; included here to prevent breakage\r\n\r\n\t\t#endif\r\n\r\n\t\tirradiance += lightMapIrradiance;\r\n\r\n\t#endif\r\n\r\n\t#if ( NUM_HEMI_LIGHTS > 0 )\r\n\r\n\t\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\r\n\r\n\t\t\tirradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\r\n\r\n\t\t}\r\n\r\n\t#endif\r\n\r\n\t#if defined( USE_ENVMAP ) && defined( PHYSICAL ) && defined( ENVMAP_TYPE_CUBE_UV )\r\n\r\n\t\t// TODO, replace 8 with the real maxMIPLevel\r\n\t\tirradiance += getLightProbeIndirectIrradiance( geometry, 8 );\r\n\r\n\t#endif\r\n\r\n\tRE_IndirectDiffuse( irradiance, geometry, material, reflectedLight );\r\n\r\n#endif\r\n\r\n#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\r\n\r\n\t// TODO, replace 8 with the real maxMIPLevel\r\n\tvec3 radiance = getLightProbeIndirectRadiance( geometry, Material_BlinnShininessExponent( material ), 8 );\r\n\r\n\t#ifndef STANDARD\r\n\t\tvec3 clearCoatRadiance = getLightProbeIndirectRadiance( geometry, Material_ClearCoat_BlinnShininessExponent( material ), 8 );\r\n\t#else\r\n\t\tvec3 clearCoatRadiance = vec3( 0.0 );\r\n\t#endif\r\n\r\n\tRE_IndirectSpecular( radiance, clearCoatRadiance, geometry, material, reflectedLight );\r\n\r\n#endif\r\n";
  21211. var logdepthbuf_fragment = "#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\r\n\r\n\tgl_FragDepthEXT = log2( vFragDepth ) * logDepthBufFC * 0.5;\r\n\r\n#endif";
  21212. var logdepthbuf_pars_fragment = "#ifdef USE_LOGDEPTHBUF\r\n\r\n\tuniform float logDepthBufFC;\r\n\r\n\t#ifdef USE_LOGDEPTHBUF_EXT\r\n\r\n\t\tvarying float vFragDepth;\r\n\r\n\t#endif\r\n\r\n#endif\r\n";
  21213. var logdepthbuf_pars_vertex = "#ifdef USE_LOGDEPTHBUF\r\n\r\n\t#ifdef USE_LOGDEPTHBUF_EXT\r\n\r\n\t\tvarying float vFragDepth;\r\n\r\n\t#endif\r\n\r\n\tuniform float logDepthBufFC;\r\n\r\n#endif";
  21214. var logdepthbuf_vertex = "#ifdef USE_LOGDEPTHBUF\r\n\r\n\t#ifdef USE_LOGDEPTHBUF_EXT\r\n\r\n\t\tvFragDepth = 1.0 + gl_Position.w;\r\n\r\n\t#else\r\n\r\n\t\tgl_Position.z = log2( max( EPSILON, gl_Position.w + 1.0 ) ) * logDepthBufFC - 1.0;\r\n\r\n\t\tgl_Position.z *= gl_Position.w;\r\n\r\n\t#endif\r\n\r\n#endif\r\n";
  21215. var map_fragment = "#ifdef USE_MAP\r\n\r\n\tvec4 texelColor = texture2D( map, vUv );\r\n\r\n\ttexelColor = mapTexelToLinear( texelColor );\r\n\tdiffuseColor *= texelColor;\r\n\r\n#endif\r\n";
  21216. var map_pars_fragment = "#ifdef USE_MAP\r\n\r\n\tuniform sampler2D map;\r\n\r\n#endif\r\n";
  21217. var map_particle_fragment = "#ifdef USE_MAP\r\n\r\n\tvec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy;\r\n\tvec4 mapTexel = texture2D( map, uv );\r\n\tdiffuseColor *= mapTexelToLinear( mapTexel );\r\n\r\n#endif\r\n";
  21218. var map_particle_pars_fragment = "#ifdef USE_MAP\r\n\r\n\tuniform mat3 uvTransform;\r\n\tuniform sampler2D map;\r\n\r\n#endif\r\n";
  21219. var metalnessmap_fragment = "float metalnessFactor = metalness;\r\n\r\n#ifdef USE_METALNESSMAP\r\n\r\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\r\n\r\n\t// reads channel B, compatible with a combined OcclusionRoughnessMetallic (RGB) texture\r\n\tmetalnessFactor *= texelMetalness.b;\r\n\r\n#endif\r\n";
  21220. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\r\n\r\n\tuniform sampler2D metalnessMap;\r\n\r\n#endif";
  21221. var morphnormal_vertex = "#ifdef USE_MORPHNORMALS\r\n\r\n\tobjectNormal += ( morphNormal0 - normal ) * morphTargetInfluences[ 0 ];\r\n\tobjectNormal += ( morphNormal1 - normal ) * morphTargetInfluences[ 1 ];\r\n\tobjectNormal += ( morphNormal2 - normal ) * morphTargetInfluences[ 2 ];\r\n\tobjectNormal += ( morphNormal3 - normal ) * morphTargetInfluences[ 3 ];\r\n\r\n#endif\r\n";
  21222. var morphtarget_pars_vertex = "#ifdef USE_MORPHTARGETS\r\n\r\n\t#ifndef USE_MORPHNORMALS\r\n\r\n\tuniform float morphTargetInfluences[ 8 ];\r\n\r\n\t#else\r\n\r\n\tuniform float morphTargetInfluences[ 4 ];\r\n\r\n\t#endif\r\n\r\n#endif";
  21223. var morphtarget_vertex = "#ifdef USE_MORPHTARGETS\r\n\r\n\ttransformed += ( morphTarget0 - position ) * morphTargetInfluences[ 0 ];\r\n\ttransformed += ( morphTarget1 - position ) * morphTargetInfluences[ 1 ];\r\n\ttransformed += ( morphTarget2 - position ) * morphTargetInfluences[ 2 ];\r\n\ttransformed += ( morphTarget3 - position ) * morphTargetInfluences[ 3 ];\r\n\r\n\t#ifndef USE_MORPHNORMALS\r\n\r\n\ttransformed += ( morphTarget4 - position ) * morphTargetInfluences[ 4 ];\r\n\ttransformed += ( morphTarget5 - position ) * morphTargetInfluences[ 5 ];\r\n\ttransformed += ( morphTarget6 - position ) * morphTargetInfluences[ 6 ];\r\n\ttransformed += ( morphTarget7 - position ) * morphTargetInfluences[ 7 ];\r\n\r\n\t#endif\r\n\r\n#endif\r\n";
  21224. var normal_fragment = "#ifdef FLAT_SHADED\r\n\r\n\t// Workaround for Adreno/Nexus5 not able able to do dFdx( vViewPosition ) ...\r\n\r\n\tvec3 fdx = vec3( dFdx( vViewPosition.x ), dFdx( vViewPosition.y ), dFdx( vViewPosition.z ) );\r\n\tvec3 fdy = vec3( dFdy( vViewPosition.x ), dFdy( vViewPosition.y ), dFdy( vViewPosition.z ) );\r\n\tvec3 normal = normalize( cross( fdx, fdy ) );\r\n\r\n#else\r\n\r\n\tvec3 normal = normalize( vNormal );\r\n\r\n\t#ifdef DOUBLE_SIDED\r\n\r\n\t\tnormal = normal * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\r\n\r\n\t#endif\r\n\r\n#endif\r\n\r\n#ifdef USE_NORMALMAP\r\n\r\n\tnormal = perturbNormal2Arb( -vViewPosition, normal );\r\n\r\n#elif defined( USE_BUMPMAP )\r\n\r\n\tnormal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );\r\n\r\n#endif\r\n";
  21225. var normalmap_pars_fragment = "#ifdef USE_NORMALMAP\r\n\r\n\tuniform sampler2D normalMap;\r\n\tuniform vec2 normalScale;\r\n\r\n\t// Per-Pixel Tangent Space Normal Mapping\r\n\t// http://hacksoflife.blogspot.ch/2009/11/per-pixel-tangent-space-normal-mapping.html\r\n\r\n\tvec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm ) {\r\n\r\n\t\t// Workaround for Adreno 3XX dFd*( vec3 ) bug. See #9988\r\n\r\n\t\tvec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );\r\n\t\tvec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );\r\n\t\tvec2 st0 = dFdx( vUv.st );\r\n\t\tvec2 st1 = dFdy( vUv.st );\r\n\r\n\t\tvec3 S = normalize( q0 * st1.t - q1 * st0.t );\r\n\t\tvec3 T = normalize( -q0 * st1.s + q1 * st0.s );\r\n\t\tvec3 N = normalize( surf_norm );\r\n\r\n\t\tvec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\r\n\t\tmapN.xy = normalScale * mapN.xy;\r\n\t\tmat3 tsn = mat3( S, T, N );\r\n\t\treturn normalize( tsn * mapN );\r\n\r\n\t}\r\n\r\n#endif\r\n";
  21226. var packing = "vec3 packNormalToRGB( const in vec3 normal ) {\r\n\treturn normalize( normal ) * 0.5 + 0.5;\r\n}\r\n\r\nvec3 unpackRGBToNormal( const in vec3 rgb ) {\r\n\treturn 2.0 * rgb.xyz - 1.0;\r\n}\r\n\r\nconst float PackUpscale = 256. / 255.; // fraction -> 0..1 (including 1)\r\nconst float UnpackDownscale = 255. / 256.; // 0..1 -> fraction (excluding 1)\r\n\r\nconst vec3 PackFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\r\nconst vec4 UnpackFactors = UnpackDownscale / vec4( PackFactors, 1. );\r\n\r\nconst float ShiftRight8 = 1. / 256.;\r\n\r\nvec4 packDepthToRGBA( const in float v ) {\r\n\tvec4 r = vec4( fract( v * PackFactors ), v );\r\n\tr.yzw -= r.xyz * ShiftRight8; // tidy overflow\r\n\treturn r * PackUpscale;\r\n}\r\n\r\nfloat unpackRGBAToDepth( const in vec4 v ) {\r\n\treturn dot( v, UnpackFactors );\r\n}\r\n\r\n// NOTE: viewZ/eyeZ is < 0 when in front of the camera per OpenGL conventions\r\n\r\nfloat viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) {\r\n\treturn ( viewZ + near ) / ( near - far );\r\n}\r\nfloat orthographicDepthToViewZ( const in float linearClipZ, const in float near, const in float far ) {\r\n\treturn linearClipZ * ( near - far ) - near;\r\n}\r\n\r\nfloat viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {\r\n\treturn (( near + viewZ ) * far ) / (( far - near ) * viewZ );\r\n}\r\nfloat perspectiveDepthToViewZ( const in float invClipZ, const in float near, const in float far ) {\r\n\treturn ( near * far ) / ( ( far - near ) * invClipZ - far );\r\n}\r\n";
  21227. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\r\n\r\n\t// Get get normal blending with premultipled, use with CustomBlending, OneFactor, OneMinusSrcAlphaFactor, AddEquation.\r\n\tgl_FragColor.rgb *= gl_FragColor.a;\r\n\r\n#endif\r\n";
  21228. var project_vertex = "vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );\r\n\r\ngl_Position = projectionMatrix * mvPosition;\r\n";
  21229. var dithering_fragment = "#if defined( DITHERING )\r\n\r\n gl_FragColor.rgb = dithering( gl_FragColor.rgb );\r\n\r\n#endif\r\n";
  21230. var dithering_pars_fragment = "#if defined( DITHERING )\r\n\r\n\t// based on https://www.shadertoy.com/view/MslGR8\r\n\tvec3 dithering( vec3 color ) {\r\n\t\t//Calculate grid position\r\n\t\tfloat grid_position = rand( gl_FragCoord.xy );\r\n\r\n\t\t//Shift the individual colors differently, thus making it even harder to see the dithering pattern\r\n\t\tvec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 );\r\n\r\n\t\t//modify shift acording to grid position.\r\n\t\tdither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position );\r\n\r\n\t\t//shift the color by dither_shift\r\n\t\treturn color + dither_shift_RGB;\r\n\t}\r\n\r\n#endif\r\n";
  21231. var roughnessmap_fragment = "float roughnessFactor = roughness;\r\n\r\n#ifdef USE_ROUGHNESSMAP\r\n\r\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\r\n\r\n\t// reads channel G, compatible with a combined OcclusionRoughnessMetallic (RGB) texture\r\n\troughnessFactor *= texelRoughness.g;\r\n\r\n#endif\r\n";
  21232. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\r\n\r\n\tuniform sampler2D roughnessMap;\r\n\r\n#endif";
  21233. var shadowmap_pars_fragment = "#ifdef USE_SHADOWMAP\r\n\r\n\t#if NUM_DIR_LIGHTS > 0\r\n\r\n\t\tuniform sampler2D directionalShadowMap[ NUM_DIR_LIGHTS ];\r\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHTS ];\r\n\r\n\t#endif\r\n\r\n\t#if NUM_SPOT_LIGHTS > 0\r\n\r\n\t\tuniform sampler2D spotShadowMap[ NUM_SPOT_LIGHTS ];\r\n\t\tvarying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHTS ];\r\n\r\n\t#endif\r\n\r\n\t#if NUM_POINT_LIGHTS > 0\r\n\r\n\t\tuniform sampler2D pointShadowMap[ NUM_POINT_LIGHTS ];\r\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHTS ];\r\n\r\n\t#endif\r\n\r\n\r\n\r\n\tfloat texture2DCompare( sampler2D depths, vec2 uv, float compare ) {\r\n\r\n\t\treturn step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) );\r\n\r\n\t}\r\n\r\n\tfloat texture2DShadowLerp( sampler2D depths, vec2 size, vec2 uv, float compare ) {\r\n\r\n\t\tconst vec2 offset = vec2( 0.0, 1.0 );\r\n\r\n\t\tvec2 texelSize = vec2( 1.0 ) / size;\r\n\t\tvec2 centroidUV = floor( uv * size + 0.5 ) / size;\r\n\r\n\t\tfloat lb = texture2DCompare( depths, centroidUV + texelSize * offset.xx, compare );\r\n\t\tfloat lt = texture2DCompare( depths, centroidUV + texelSize * offset.xy, compare );\r\n\t\tfloat rb = texture2DCompare( depths, centroidUV + texelSize * offset.yx, compare );\r\n\t\tfloat rt = texture2DCompare( depths, centroidUV + texelSize * offset.yy, compare );\r\n\r\n\t\tvec2 f = fract( uv * size + 0.5 );\r\n\r\n\t\tfloat a = mix( lb, lt, f.y );\r\n\t\tfloat b = mix( rb, rt, f.y );\r\n\t\tfloat c = mix( a, b, f.x );\r\n\r\n\t\treturn c;\r\n\r\n\t}\r\n\r\n\tfloat getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\r\n\r\n\t\tfloat shadow = 1.0;\r\n\r\n\t\tshadowCoord.xyz /= shadowCoord.w;\r\n\t\tshadowCoord.z += shadowBias;\r\n\r\n\t\t// if ( something && something ) breaks ATI OpenGL shader compiler\r\n\t\t// if ( all( something, something ) ) using this instead\r\n\r\n\t\tbvec4 inFrustumVec = bvec4 ( shadowCoord.x >= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 );\r\n\t\tbool inFrustum = all( inFrustumVec );\r\n\r\n\t\tbvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );\r\n\r\n\t\tbool frustumTest = all( frustumTestVec );\r\n\r\n\t\tif ( frustumTest ) {\r\n\r\n\t\t#if defined( SHADOWMAP_TYPE_PCF )\r\n\r\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\r\n\r\n\t\t\tfloat dx0 = - texelSize.x * shadowRadius;\r\n\t\t\tfloat dy0 = - texelSize.y * shadowRadius;\r\n\t\t\tfloat dx1 = + texelSize.x * shadowRadius;\r\n\t\t\tfloat dy1 = + texelSize.y * shadowRadius;\r\n\r\n\t\t\tshadow = (\r\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\r\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\r\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\r\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\r\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +\r\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\r\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\r\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\r\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\r\n\t\t\t) * ( 1.0 / 9.0 );\r\n\r\n\t\t#elif defined( SHADOWMAP_TYPE_PCF_SOFT )\r\n\r\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\r\n\r\n\t\t\tfloat dx0 = - texelSize.x * shadowRadius;\r\n\t\t\tfloat dy0 = - texelSize.y * shadowRadius;\r\n\t\t\tfloat dx1 = + texelSize.x * shadowRadius;\r\n\t\t\tfloat dy1 = + texelSize.y * shadowRadius;\r\n\r\n\t\t\tshadow = (\r\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\r\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\r\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\r\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\r\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy, shadowCoord.z ) +\r\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\r\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\r\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\r\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\r\n\t\t\t) * ( 1.0 / 9.0 );\r\n\r\n\t\t#else // no percentage-closer filtering:\r\n\r\n\t\t\tshadow = texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z );\r\n\r\n\t\t#endif\r\n\r\n\t\t}\r\n\r\n\t\treturn shadow;\r\n\r\n\t}\r\n\r\n\t// cubeToUV() maps a 3D direction vector suitable for cube texture mapping to a 2D\r\n\t// vector suitable for 2D texture mapping. This code uses the following layout for the\r\n\t// 2D texture:\r\n\t//\r\n\t// xzXZ\r\n\t// y Y\r\n\t//\r\n\t// Y - Positive y direction\r\n\t// y - Negative y direction\r\n\t// X - Positive x direction\r\n\t// x - Negative x direction\r\n\t// Z - Positive z direction\r\n\t// z - Negative z direction\r\n\t//\r\n\t// Source and test bed:\r\n\t// https://gist.github.com/tschw/da10c43c467ce8afd0c4\r\n\r\n\tvec2 cubeToUV( vec3 v, float texelSizeY ) {\r\n\r\n\t\t// Number of texels to avoid at the edge of each square\r\n\r\n\t\tvec3 absV = abs( v );\r\n\r\n\t\t// Intersect unit cube\r\n\r\n\t\tfloat scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );\r\n\t\tabsV *= scaleToCube;\r\n\r\n\t\t// Apply scale to avoid seams\r\n\r\n\t\t// two texels less per square (one texel will do for NEAREST)\r\n\t\tv *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );\r\n\r\n\t\t// Unwrap\r\n\r\n\t\t// space: -1 ... 1 range for each square\r\n\t\t//\r\n\t\t// #X##\t\tdim := ( 4 , 2 )\r\n\t\t// # #\t\tcenter := ( 1 , 1 )\r\n\r\n\t\tvec2 planar = v.xy;\r\n\r\n\t\tfloat almostATexel = 1.5 * texelSizeY;\r\n\t\tfloat almostOne = 1.0 - almostATexel;\r\n\r\n\t\tif ( absV.z >= almostOne ) {\r\n\r\n\t\t\tif ( v.z > 0.0 )\r\n\t\t\t\tplanar.x = 4.0 - v.x;\r\n\r\n\t\t} else if ( absV.x >= almostOne ) {\r\n\r\n\t\t\tfloat signX = sign( v.x );\r\n\t\t\tplanar.x = v.z * signX + 2.0 * signX;\r\n\r\n\t\t} else if ( absV.y >= almostOne ) {\r\n\r\n\t\t\tfloat signY = sign( v.y );\r\n\t\t\tplanar.x = v.x + 2.0 * signY + 2.0;\r\n\t\t\tplanar.y = v.z * signY - 2.0;\r\n\r\n\t\t}\r\n\r\n\t\t// Transform to UV space\r\n\r\n\t\t// scale := 0.5 / dim\r\n\t\t// translate := ( center + 0.5 ) / dim\r\n\t\treturn vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );\r\n\r\n\t}\r\n\r\n\tfloat getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {\r\n\r\n\t\tvec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );\r\n\r\n\t\t// for point lights, the uniform @vShadowCoord is re-purposed to hold\r\n\t\t// the vector from the light to the world-space position of the fragment.\r\n\t\tvec3 lightToPosition = shadowCoord.xyz;\r\n\r\n\t\t// dp = normalized distance from light to fragment position\r\n\t\tfloat dp = ( length( lightToPosition ) - shadowCameraNear ) / ( shadowCameraFar - shadowCameraNear ); // need to clamp?\r\n\t\tdp += shadowBias;\r\n\r\n\t\t// bd3D = base direction 3D\r\n\t\tvec3 bd3D = normalize( lightToPosition );\r\n\r\n\t\t#if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT )\r\n\r\n\t\t\tvec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;\r\n\r\n\t\t\treturn (\r\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +\r\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +\r\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +\r\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +\r\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +\r\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +\r\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +\r\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +\r\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )\r\n\t\t\t) * ( 1.0 / 9.0 );\r\n\r\n\t\t#else // no percentage-closer filtering\r\n\r\n\t\t\treturn texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );\r\n\r\n\t\t#endif\r\n\r\n\t}\r\n\r\n#endif\r\n";
  21234. var shadowmap_pars_vertex = "#ifdef USE_SHADOWMAP\r\n\r\n\t#if NUM_DIR_LIGHTS > 0\r\n\r\n\t\tuniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHTS ];\r\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHTS ];\r\n\r\n\t#endif\r\n\r\n\t#if NUM_SPOT_LIGHTS > 0\r\n\r\n\t\tuniform mat4 spotShadowMatrix[ NUM_SPOT_LIGHTS ];\r\n\t\tvarying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHTS ];\r\n\r\n\t#endif\r\n\r\n\t#if NUM_POINT_LIGHTS > 0\r\n\r\n\t\tuniform mat4 pointShadowMatrix[ NUM_POINT_LIGHTS ];\r\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHTS ];\r\n\r\n\t#endif\r\n\r\n\r\n\r\n#endif\r\n";
  21235. var shadowmap_vertex = "#ifdef USE_SHADOWMAP\r\n\r\n\t#if NUM_DIR_LIGHTS > 0\r\n\r\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\r\n\r\n\t\tvDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * worldPosition;\r\n\r\n\t}\r\n\r\n\t#endif\r\n\r\n\t#if NUM_SPOT_LIGHTS > 0\r\n\r\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\r\n\r\n\t\tvSpotShadowCoord[ i ] = spotShadowMatrix[ i ] * worldPosition;\r\n\r\n\t}\r\n\r\n\t#endif\r\n\r\n\t#if NUM_POINT_LIGHTS > 0\r\n\r\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\r\n\r\n\t\tvPointShadowCoord[ i ] = pointShadowMatrix[ i ] * worldPosition;\r\n\r\n\t}\r\n\r\n\t#endif\r\n\r\n\r\n\r\n#endif\r\n";
  21236. var shadowmask_pars_fragment = "float getShadowMask() {\r\n\r\n\tfloat shadow = 1.0;\r\n\r\n\t#ifdef USE_SHADOWMAP\r\n\r\n\t#if NUM_DIR_LIGHTS > 0\r\n\r\n\tDirectionalLight directionalLight;\r\n\r\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\r\n\r\n\t\tdirectionalLight = directionalLights[ i ];\r\n\t\tshadow *= bool( directionalLight.shadow ) ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\r\n\r\n\t}\r\n\r\n\t#endif\r\n\r\n\t#if NUM_SPOT_LIGHTS > 0\r\n\r\n\tSpotLight spotLight;\r\n\r\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\r\n\r\n\t\tspotLight = spotLights[ i ];\r\n\t\tshadow *= bool( spotLight.shadow ) ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\r\n\r\n\t}\r\n\r\n\t#endif\r\n\r\n\t#if NUM_POINT_LIGHTS > 0\r\n\r\n\tPointLight pointLight;\r\n\r\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\r\n\r\n\t\tpointLight = pointLights[ i ];\r\n\t\tshadow *= bool( pointLight.shadow ) ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;\r\n\r\n\t}\r\n\r\n\t#endif\r\n\r\n\r\n\r\n\t#endif\r\n\r\n\treturn shadow;\r\n\r\n}\r\n";
  21237. var skinbase_vertex = "#ifdef USE_SKINNING\r\n\r\n\tmat4 boneMatX = getBoneMatrix( skinIndex.x );\r\n\tmat4 boneMatY = getBoneMatrix( skinIndex.y );\r\n\tmat4 boneMatZ = getBoneMatrix( skinIndex.z );\r\n\tmat4 boneMatW = getBoneMatrix( skinIndex.w );\r\n\r\n#endif";
  21238. var skinning_pars_vertex = "#ifdef USE_SKINNING\r\n\r\n\tuniform mat4 bindMatrix;\r\n\tuniform mat4 bindMatrixInverse;\r\n\r\n\t#ifdef BONE_TEXTURE\r\n\r\n\t\tuniform sampler2D boneTexture;\r\n\t\tuniform int boneTextureSize;\r\n\r\n\t\tmat4 getBoneMatrix( const in float i ) {\r\n\r\n\t\t\tfloat j = i * 4.0;\r\n\t\t\tfloat x = mod( j, float( boneTextureSize ) );\r\n\t\t\tfloat y = floor( j / float( boneTextureSize ) );\r\n\r\n\t\t\tfloat dx = 1.0 / float( boneTextureSize );\r\n\t\t\tfloat dy = 1.0 / float( boneTextureSize );\r\n\r\n\t\t\ty = dy * ( y + 0.5 );\r\n\r\n\t\t\tvec4 v1 = texture2D( boneTexture, vec2( dx * ( x + 0.5 ), y ) );\r\n\t\t\tvec4 v2 = texture2D( boneTexture, vec2( dx * ( x + 1.5 ), y ) );\r\n\t\t\tvec4 v3 = texture2D( boneTexture, vec2( dx * ( x + 2.5 ), y ) );\r\n\t\t\tvec4 v4 = texture2D( boneTexture, vec2( dx * ( x + 3.5 ), y ) );\r\n\r\n\t\t\tmat4 bone = mat4( v1, v2, v3, v4 );\r\n\r\n\t\t\treturn bone;\r\n\r\n\t\t}\r\n\r\n\t#else\r\n\r\n\t\tuniform mat4 boneMatrices[ MAX_BONES ];\r\n\r\n\t\tmat4 getBoneMatrix( const in float i ) {\r\n\r\n\t\t\tmat4 bone = boneMatrices[ int(i) ];\r\n\t\t\treturn bone;\r\n\r\n\t\t}\r\n\r\n\t#endif\r\n\r\n#endif\r\n";
  21239. var skinning_vertex = "#ifdef USE_SKINNING\r\n\r\n\tvec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );\r\n\r\n\tvec4 skinned = vec4( 0.0 );\r\n\tskinned += boneMatX * skinVertex * skinWeight.x;\r\n\tskinned += boneMatY * skinVertex * skinWeight.y;\r\n\tskinned += boneMatZ * skinVertex * skinWeight.z;\r\n\tskinned += boneMatW * skinVertex * skinWeight.w;\r\n\r\n\ttransformed = ( bindMatrixInverse * skinned ).xyz;\r\n\r\n#endif\r\n";
  21240. var skinnormal_vertex = "#ifdef USE_SKINNING\r\n\r\n\tmat4 skinMatrix = mat4( 0.0 );\r\n\tskinMatrix += skinWeight.x * boneMatX;\r\n\tskinMatrix += skinWeight.y * boneMatY;\r\n\tskinMatrix += skinWeight.z * boneMatZ;\r\n\tskinMatrix += skinWeight.w * boneMatW;\r\n\tskinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;\r\n\r\n\tobjectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;\r\n\r\n#endif\r\n";
  21241. var specularmap_fragment = "float specularStrength;\r\n\r\n#ifdef USE_SPECULARMAP\r\n\r\n\tvec4 texelSpecular = texture2D( specularMap, vUv );\r\n\tspecularStrength = texelSpecular.r;\r\n\r\n#else\r\n\r\n\tspecularStrength = 1.0;\r\n\r\n#endif";
  21242. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\r\n\r\n\tuniform sampler2D specularMap;\r\n\r\n#endif";
  21243. var tonemapping_fragment = "#if defined( TONE_MAPPING )\r\n\r\n gl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\r\n\r\n#endif\r\n";
  21244. var tonemapping_pars_fragment = "#ifndef saturate\r\n\t#define saturate(a) clamp( a, 0.0, 1.0 )\r\n#endif\r\n\r\nuniform float toneMappingExposure;\r\nuniform float toneMappingWhitePoint;\r\n\r\n// exposure only\r\nvec3 LinearToneMapping( vec3 color ) {\r\n\r\n\treturn toneMappingExposure * color;\r\n\r\n}\r\n\r\n// source: https://www.cs.utah.edu/~reinhard/cdrom/\r\nvec3 ReinhardToneMapping( vec3 color ) {\r\n\r\n\tcolor *= toneMappingExposure;\r\n\treturn saturate( color / ( vec3( 1.0 ) + color ) );\r\n\r\n}\r\n\r\n// source: http://filmicgames.com/archives/75\r\n#define Uncharted2Helper( x ) max( ( ( x * ( 0.15 * x + 0.10 * 0.50 ) + 0.20 * 0.02 ) / ( x * ( 0.15 * x + 0.50 ) + 0.20 * 0.30 ) ) - 0.02 / 0.30, vec3( 0.0 ) )\r\nvec3 Uncharted2ToneMapping( vec3 color ) {\r\n\r\n\t// John Hable's filmic operator from Uncharted 2 video game\r\n\tcolor *= toneMappingExposure;\r\n\treturn saturate( Uncharted2Helper( color ) / Uncharted2Helper( vec3( toneMappingWhitePoint ) ) );\r\n\r\n}\r\n\r\n// source: http://filmicgames.com/archives/75\r\nvec3 OptimizedCineonToneMapping( vec3 color ) {\r\n\r\n\t// optimized filmic operator by Jim Hejl and Richard Burgess-Dawson\r\n\tcolor *= toneMappingExposure;\r\n\tcolor = max( vec3( 0.0 ), color - 0.004 );\r\n\treturn pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );\r\n\r\n}\r\n";
  21245. var uv_pars_fragment = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP )\r\n\r\n\tvarying vec2 vUv;\r\n\r\n#endif";
  21246. var uv_pars_vertex = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP )\r\n\r\n\tvarying vec2 vUv;\r\n\tuniform mat3 uvTransform;\r\n\r\n#endif\r\n";
  21247. var uv_vertex = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP )\r\n\r\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\r\n\r\n#endif";
  21248. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\r\n\r\n\tvarying vec2 vUv2;\r\n\r\n#endif";
  21249. var uv2_pars_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\r\n\r\n\tattribute vec2 uv2;\r\n\tvarying vec2 vUv2;\r\n\r\n#endif";
  21250. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\r\n\r\n\tvUv2 = uv2;\r\n\r\n#endif";
  21251. var worldpos_vertex = "#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP )\r\n\r\n\tvec4 worldPosition = modelMatrix * vec4( transformed, 1.0 );\r\n\r\n#endif\r\n";
  21252. var cube_frag = "uniform samplerCube tCube;\r\nuniform float tFlip;\r\nuniform float opacity;\r\n\r\nvarying vec3 vWorldPosition;\r\n\r\nvoid main() {\r\n\r\n\tgl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );\r\n\tgl_FragColor.a *= opacity;\r\n\r\n}\r\n";
  21253. var cube_vert = "varying vec3 vWorldPosition;\r\n\r\n#include <common>\r\n\r\nvoid main() {\r\n\r\n\tvWorldPosition = transformDirection( position, modelMatrix );\r\n\r\n\t#include <begin_vertex>\r\n\t#include <project_vertex>\r\n\r\n\tgl_Position.z = gl_Position.w; // set z to camera.far\r\n\r\n}\r\n";
  21254. var depth_frag = "#if DEPTH_PACKING == 3200\r\n\r\n\tuniform float opacity;\r\n\r\n#endif\r\n\r\n#include <common>\r\n#include <packing>\r\n#include <uv_pars_fragment>\r\n#include <map_pars_fragment>\r\n#include <alphamap_pars_fragment>\r\n#include <logdepthbuf_pars_fragment>\r\n#include <clipping_planes_pars_fragment>\r\n\r\nvoid main() {\r\n\r\n\t#include <clipping_planes_fragment>\r\n\r\n\tvec4 diffuseColor = vec4( 1.0 );\r\n\r\n\t#if DEPTH_PACKING == 3200\r\n\r\n\t\tdiffuseColor.a = opacity;\r\n\r\n\t#endif\r\n\r\n\t#include <map_fragment>\r\n\t#include <alphamap_fragment>\r\n\t#include <alphatest_fragment>\r\n\r\n\t#include <logdepthbuf_fragment>\r\n\r\n\t#if DEPTH_PACKING == 3200\r\n\r\n\t\tgl_FragColor = vec4( vec3( gl_FragCoord.z ), opacity );\r\n\r\n\t#elif DEPTH_PACKING == 3201\r\n\r\n\t\tgl_FragColor = packDepthToRGBA( gl_FragCoord.z );\r\n\r\n\t#endif\r\n\r\n}\r\n";
  21255. var depth_vert = "#include <common>\r\n#include <uv_pars_vertex>\r\n#include <displacementmap_pars_vertex>\r\n#include <morphtarget_pars_vertex>\r\n#include <skinning_pars_vertex>\r\n#include <logdepthbuf_pars_vertex>\r\n#include <clipping_planes_pars_vertex>\r\n\r\nvoid main() {\r\n\r\n\t#include <uv_vertex>\r\n\r\n\t#include <skinbase_vertex>\r\n\r\n\t#ifdef USE_DISPLACEMENTMAP\r\n\r\n\t\t#include <beginnormal_vertex>\r\n\t\t#include <morphnormal_vertex>\r\n\t\t#include <skinnormal_vertex>\r\n\r\n\t#endif\r\n\r\n\t#include <begin_vertex>\r\n\t#include <morphtarget_vertex>\r\n\t#include <skinning_vertex>\r\n\t#include <displacementmap_vertex>\r\n\t#include <project_vertex>\r\n\t#include <logdepthbuf_vertex>\r\n\t#include <clipping_planes_vertex>\r\n\r\n}\r\n";
  21256. var distanceRGBA_frag = "#define DISTANCE\r\n\r\nuniform vec3 referencePosition;\r\nuniform float nearDistance;\r\nuniform float farDistance;\r\nvarying vec3 vWorldPosition;\r\n\r\n#include <common>\r\n#include <packing>\r\n#include <uv_pars_fragment>\r\n#include <map_pars_fragment>\r\n#include <alphamap_pars_fragment>\r\n#include <clipping_planes_pars_fragment>\r\n\r\nvoid main () {\r\n\r\n\t#include <clipping_planes_fragment>\r\n\r\n\tvec4 diffuseColor = vec4( 1.0 );\r\n\r\n\t#include <map_fragment>\r\n\t#include <alphamap_fragment>\r\n\t#include <alphatest_fragment>\r\n\r\n\tfloat dist = length( vWorldPosition - referencePosition );\r\n\tdist = ( dist - nearDistance ) / ( farDistance - nearDistance );\r\n\tdist = saturate( dist ); // clamp to [ 0, 1 ]\r\n\r\n\tgl_FragColor = packDepthToRGBA( dist );\r\n\r\n}\r\n";
  21257. var distanceRGBA_vert = "#define DISTANCE\r\n\r\nvarying vec3 vWorldPosition;\r\n\r\n#include <common>\r\n#include <uv_pars_vertex>\r\n#include <displacementmap_pars_vertex>\r\n#include <morphtarget_pars_vertex>\r\n#include <skinning_pars_vertex>\r\n#include <clipping_planes_pars_vertex>\r\n\r\nvoid main() {\r\n\r\n\t#include <uv_vertex>\r\n\r\n\t#include <skinbase_vertex>\r\n\r\n\t#ifdef USE_DISPLACEMENTMAP\r\n\r\n\t\t#include <beginnormal_vertex>\r\n\t\t#include <morphnormal_vertex>\r\n\t\t#include <skinnormal_vertex>\r\n\r\n\t#endif\r\n\r\n\t#include <begin_vertex>\r\n\t#include <morphtarget_vertex>\r\n\t#include <skinning_vertex>\r\n\t#include <displacementmap_vertex>\r\n\t#include <project_vertex>\r\n\t#include <worldpos_vertex>\r\n\t#include <clipping_planes_vertex>\r\n\r\n\tvWorldPosition = worldPosition.xyz;\r\n\r\n}\r\n";
  21258. var equirect_frag = "uniform sampler2D tEquirect;\r\n\r\nvarying vec3 vWorldPosition;\r\n\r\n#include <common>\r\n\r\nvoid main() {\r\n\r\n\tvec3 direction = normalize( vWorldPosition );\r\n\r\n\tvec2 sampleUV;\r\n\r\n\tsampleUV.y = asin( clamp( direction.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\r\n\r\n\tsampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;\r\n\r\n\tgl_FragColor = texture2D( tEquirect, sampleUV );\r\n\r\n}\r\n";
  21259. var equirect_vert = "varying vec3 vWorldPosition;\r\n\r\n#include <common>\r\n\r\nvoid main() {\r\n\r\n\tvWorldPosition = transformDirection( position, modelMatrix );\r\n\r\n\t#include <begin_vertex>\r\n\t#include <project_vertex>\r\n\r\n}\r\n";
  21260. var linedashed_frag = "uniform vec3 diffuse;\r\nuniform float opacity;\r\n\r\nuniform float dashSize;\r\nuniform float totalSize;\r\n\r\nvarying float vLineDistance;\r\n\r\n#include <common>\r\n#include <color_pars_fragment>\r\n#include <fog_pars_fragment>\r\n#include <logdepthbuf_pars_fragment>\r\n#include <clipping_planes_pars_fragment>\r\n\r\nvoid main() {\r\n\r\n\t#include <clipping_planes_fragment>\r\n\r\n\tif ( mod( vLineDistance, totalSize ) > dashSize ) {\r\n\r\n\t\tdiscard;\r\n\r\n\t}\r\n\r\n\tvec3 outgoingLight = vec3( 0.0 );\r\n\tvec4 diffuseColor = vec4( diffuse, opacity );\r\n\r\n\t#include <logdepthbuf_fragment>\r\n\t#include <color_fragment>\r\n\r\n\toutgoingLight = diffuseColor.rgb; // simple shader\r\n\r\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\r\n\r\n\t#include <premultiplied_alpha_fragment>\r\n\t#include <tonemapping_fragment>\r\n\t#include <encodings_fragment>\r\n\t#include <fog_fragment>\r\n\r\n}\r\n";
  21261. var linedashed_vert = "uniform float scale;\r\nattribute float lineDistance;\r\n\r\nvarying float vLineDistance;\r\n\r\n#include <common>\r\n#include <color_pars_vertex>\r\n#include <fog_pars_vertex>\r\n#include <logdepthbuf_pars_vertex>\r\n#include <clipping_planes_pars_vertex>\r\n\r\nvoid main() {\r\n\r\n\t#include <color_vertex>\r\n\r\n\tvLineDistance = scale * lineDistance;\r\n\r\n\tvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\r\n\tgl_Position = projectionMatrix * mvPosition;\r\n\r\n\t#include <logdepthbuf_vertex>\r\n\t#include <clipping_planes_vertex>\r\n\t#include <fog_vertex>\r\n\r\n}\r\n";
  21262. var meshbasic_frag = "uniform vec3 diffuse;\r\nuniform float opacity;\r\n\r\n#ifndef FLAT_SHADED\r\n\r\n\tvarying vec3 vNormal;\r\n\r\n#endif\r\n\r\n#include <common>\r\n#include <color_pars_fragment>\r\n#include <uv_pars_fragment>\r\n#include <uv2_pars_fragment>\r\n#include <map_pars_fragment>\r\n#include <alphamap_pars_fragment>\r\n#include <aomap_pars_fragment>\r\n#include <lightmap_pars_fragment>\r\n#include <envmap_pars_fragment>\r\n#include <fog_pars_fragment>\r\n#include <specularmap_pars_fragment>\r\n#include <logdepthbuf_pars_fragment>\r\n#include <clipping_planes_pars_fragment>\r\n\r\nvoid main() {\r\n\r\n\t#include <clipping_planes_fragment>\r\n\r\n\tvec4 diffuseColor = vec4( diffuse, opacity );\r\n\r\n\t#include <logdepthbuf_fragment>\r\n\t#include <map_fragment>\r\n\t#include <color_fragment>\r\n\t#include <alphamap_fragment>\r\n\t#include <alphatest_fragment>\r\n\t#include <specularmap_fragment>\r\n\r\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\r\n\r\n\t// accumulation (baked indirect lighting only)\r\n\t#ifdef USE_LIGHTMAP\r\n\r\n\t\treflectedLight.indirectDiffuse += texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\r\n\r\n\t#else\r\n\r\n\t\treflectedLight.indirectDiffuse += vec3( 1.0 );\r\n\r\n\t#endif\r\n\r\n\t// modulation\r\n\t#include <aomap_fragment>\r\n\r\n\treflectedLight.indirectDiffuse *= diffuseColor.rgb;\r\n\r\n\tvec3 outgoingLight = reflectedLight.indirectDiffuse;\r\n\r\n\t#include <envmap_fragment>\r\n\r\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\r\n\r\n\t#include <premultiplied_alpha_fragment>\r\n\t#include <tonemapping_fragment>\r\n\t#include <encodings_fragment>\r\n\t#include <fog_fragment>\r\n\r\n}\r\n";
  21263. var meshbasic_vert = "#include <common>\r\n#include <uv_pars_vertex>\r\n#include <uv2_pars_vertex>\r\n#include <envmap_pars_vertex>\r\n#include <color_pars_vertex>\r\n#include <fog_pars_vertex>\r\n#include <morphtarget_pars_vertex>\r\n#include <skinning_pars_vertex>\r\n#include <logdepthbuf_pars_vertex>\r\n#include <clipping_planes_pars_vertex>\r\n\r\nvoid main() {\r\n\r\n\t#include <uv_vertex>\r\n\t#include <uv2_vertex>\r\n\t#include <color_vertex>\r\n\t#include <skinbase_vertex>\r\n\r\n\t#ifdef USE_ENVMAP\r\n\r\n\t#include <beginnormal_vertex>\r\n\t#include <morphnormal_vertex>\r\n\t#include <skinnormal_vertex>\r\n\t#include <defaultnormal_vertex>\r\n\r\n\t#endif\r\n\r\n\t#include <begin_vertex>\r\n\t#include <morphtarget_vertex>\r\n\t#include <skinning_vertex>\r\n\t#include <project_vertex>\r\n\t#include <logdepthbuf_vertex>\r\n\r\n\t#include <worldpos_vertex>\r\n\t#include <clipping_planes_vertex>\r\n\t#include <envmap_vertex>\r\n\t#include <fog_vertex>\r\n\r\n}\r\n";
  21264. var meshlambert_frag = "uniform vec3 diffuse;\r\nuniform vec3 emissive;\r\nuniform float opacity;\r\n\r\nvarying vec3 vLightFront;\r\n\r\n#ifdef DOUBLE_SIDED\r\n\r\n\tvarying vec3 vLightBack;\r\n\r\n#endif\r\n\r\n#include <common>\r\n#include <packing>\r\n#include <dithering_pars_fragment>\r\n#include <color_pars_fragment>\r\n#include <uv_pars_fragment>\r\n#include <uv2_pars_fragment>\r\n#include <map_pars_fragment>\r\n#include <alphamap_pars_fragment>\r\n#include <aomap_pars_fragment>\r\n#include <lightmap_pars_fragment>\r\n#include <emissivemap_pars_fragment>\r\n#include <envmap_pars_fragment>\r\n#include <bsdfs>\r\n#include <lights_pars>\r\n#include <fog_pars_fragment>\r\n#include <shadowmap_pars_fragment>\r\n#include <shadowmask_pars_fragment>\r\n#include <specularmap_pars_fragment>\r\n#include <logdepthbuf_pars_fragment>\r\n#include <clipping_planes_pars_fragment>\r\n\r\nvoid main() {\r\n\r\n\t#include <clipping_planes_fragment>\r\n\r\n\tvec4 diffuseColor = vec4( diffuse, opacity );\r\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\r\n\tvec3 totalEmissiveRadiance = emissive;\r\n\r\n\t#include <logdepthbuf_fragment>\r\n\t#include <map_fragment>\r\n\t#include <color_fragment>\r\n\t#include <alphamap_fragment>\r\n\t#include <alphatest_fragment>\r\n\t#include <specularmap_fragment>\r\n\t#include <emissivemap_fragment>\r\n\r\n\t// accumulation\r\n\treflectedLight.indirectDiffuse = getAmbientLightIrradiance( ambientLightColor );\r\n\r\n\t#include <lightmap_fragment>\r\n\r\n\treflectedLight.indirectDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb );\r\n\r\n\t#ifdef DOUBLE_SIDED\r\n\r\n\t\treflectedLight.directDiffuse = ( gl_FrontFacing ) ? vLightFront : vLightBack;\r\n\r\n\t#else\r\n\r\n\t\treflectedLight.directDiffuse = vLightFront;\r\n\r\n\t#endif\r\n\r\n\treflectedLight.directDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb ) * getShadowMask();\r\n\r\n\t// modulation\r\n\t#include <aomap_fragment>\r\n\r\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\r\n\r\n\t#include <envmap_fragment>\r\n\r\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\r\n\r\n\t#include <tonemapping_fragment>\r\n\t#include <encodings_fragment>\r\n\t#include <fog_fragment>\r\n\t#include <premultiplied_alpha_fragment>\r\n\t#include <dithering_fragment>\r\n\r\n}\r\n";
  21265. var meshlambert_vert = "#define LAMBERT\r\n\r\nvarying vec3 vLightFront;\r\n\r\n#ifdef DOUBLE_SIDED\r\n\r\n\tvarying vec3 vLightBack;\r\n\r\n#endif\r\n\r\n#include <common>\r\n#include <uv_pars_vertex>\r\n#include <uv2_pars_vertex>\r\n#include <envmap_pars_vertex>\r\n#include <bsdfs>\r\n#include <lights_pars>\r\n#include <color_pars_vertex>\r\n#include <fog_pars_vertex>\r\n#include <morphtarget_pars_vertex>\r\n#include <skinning_pars_vertex>\r\n#include <shadowmap_pars_vertex>\r\n#include <logdepthbuf_pars_vertex>\r\n#include <clipping_planes_pars_vertex>\r\n\r\nvoid main() {\r\n\r\n\t#include <uv_vertex>\r\n\t#include <uv2_vertex>\r\n\t#include <color_vertex>\r\n\r\n\t#include <beginnormal_vertex>\r\n\t#include <morphnormal_vertex>\r\n\t#include <skinbase_vertex>\r\n\t#include <skinnormal_vertex>\r\n\t#include <defaultnormal_vertex>\r\n\r\n\t#include <begin_vertex>\r\n\t#include <morphtarget_vertex>\r\n\t#include <skinning_vertex>\r\n\t#include <project_vertex>\r\n\t#include <logdepthbuf_vertex>\r\n\t#include <clipping_planes_vertex>\r\n\r\n\t#include <worldpos_vertex>\r\n\t#include <envmap_vertex>\r\n\t#include <lights_lambert_vertex>\r\n\t#include <shadowmap_vertex>\r\n\t#include <fog_vertex>\r\n\r\n}\r\n";
  21266. var meshphong_frag = "#define PHONG\r\n\r\nuniform vec3 diffuse;\r\nuniform vec3 emissive;\r\nuniform vec3 specular;\r\nuniform float shininess;\r\nuniform float opacity;\r\n\r\n#include <common>\r\n#include <packing>\r\n#include <dithering_pars_fragment>\r\n#include <color_pars_fragment>\r\n#include <uv_pars_fragment>\r\n#include <uv2_pars_fragment>\r\n#include <map_pars_fragment>\r\n#include <alphamap_pars_fragment>\r\n#include <aomap_pars_fragment>\r\n#include <lightmap_pars_fragment>\r\n#include <emissivemap_pars_fragment>\r\n#include <envmap_pars_fragment>\r\n#include <gradientmap_pars_fragment>\r\n#include <fog_pars_fragment>\r\n#include <bsdfs>\r\n#include <lights_pars>\r\n#include <lights_phong_pars_fragment>\r\n#include <shadowmap_pars_fragment>\r\n#include <bumpmap_pars_fragment>\r\n#include <normalmap_pars_fragment>\r\n#include <specularmap_pars_fragment>\r\n#include <logdepthbuf_pars_fragment>\r\n#include <clipping_planes_pars_fragment>\r\n\r\nvoid main() {\r\n\r\n\t#include <clipping_planes_fragment>\r\n\r\n\tvec4 diffuseColor = vec4( diffuse, opacity );\r\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\r\n\tvec3 totalEmissiveRadiance = emissive;\r\n\r\n\t#include <logdepthbuf_fragment>\r\n\t#include <map_fragment>\r\n\t#include <color_fragment>\r\n\t#include <alphamap_fragment>\r\n\t#include <alphatest_fragment>\r\n\t#include <specularmap_fragment>\r\n\t#include <normal_fragment>\r\n\t#include <emissivemap_fragment>\r\n\r\n\t// accumulation\r\n\t#include <lights_phong_fragment>\r\n\t#include <lights_template>\r\n\r\n\t// modulation\r\n\t#include <aomap_fragment>\r\n\r\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\r\n\r\n\t#include <envmap_fragment>\r\n\r\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\r\n\r\n\t#include <tonemapping_fragment>\r\n\t#include <encodings_fragment>\r\n\t#include <fog_fragment>\r\n\t#include <premultiplied_alpha_fragment>\r\n\t#include <dithering_fragment>\r\n\r\n}\r\n";
  21267. var meshphong_vert = "#define PHONG\r\n\r\nvarying vec3 vViewPosition;\r\n\r\n#ifndef FLAT_SHADED\r\n\r\n\tvarying vec3 vNormal;\r\n\r\n#endif\r\n\r\n#include <common>\r\n#include <uv_pars_vertex>\r\n#include <uv2_pars_vertex>\r\n#include <displacementmap_pars_vertex>\r\n#include <envmap_pars_vertex>\r\n#include <color_pars_vertex>\r\n#include <fog_pars_vertex>\r\n#include <morphtarget_pars_vertex>\r\n#include <skinning_pars_vertex>\r\n#include <shadowmap_pars_vertex>\r\n#include <logdepthbuf_pars_vertex>\r\n#include <clipping_planes_pars_vertex>\r\n\r\nvoid main() {\r\n\r\n\t#include <uv_vertex>\r\n\t#include <uv2_vertex>\r\n\t#include <color_vertex>\r\n\r\n\t#include <beginnormal_vertex>\r\n\t#include <morphnormal_vertex>\r\n\t#include <skinbase_vertex>\r\n\t#include <skinnormal_vertex>\r\n\t#include <defaultnormal_vertex>\r\n\r\n#ifndef FLAT_SHADED // Normal computed with derivatives when FLAT_SHADED\r\n\r\n\tvNormal = normalize( transformedNormal );\r\n\r\n#endif\r\n\r\n\t#include <begin_vertex>\r\n\t#include <morphtarget_vertex>\r\n\t#include <skinning_vertex>\r\n\t#include <displacementmap_vertex>\r\n\t#include <project_vertex>\r\n\t#include <logdepthbuf_vertex>\r\n\t#include <clipping_planes_vertex>\r\n\r\n\tvViewPosition = - mvPosition.xyz;\r\n\r\n\t#include <worldpos_vertex>\r\n\t#include <envmap_vertex>\r\n\t#include <shadowmap_vertex>\r\n\t#include <fog_vertex>\r\n\r\n}\r\n";
  21268. var meshphysical_frag = "#define PHYSICAL\r\n\r\nuniform vec3 diffuse;\r\nuniform vec3 emissive;\r\nuniform float roughness;\r\nuniform float metalness;\r\nuniform float opacity;\r\n\r\n#ifndef STANDARD\r\n\tuniform float clearCoat;\r\n\tuniform float clearCoatRoughness;\r\n#endif\r\n\r\nvarying vec3 vViewPosition;\r\n\r\n#ifndef FLAT_SHADED\r\n\r\n\tvarying vec3 vNormal;\r\n\r\n#endif\r\n\r\n#include <common>\r\n#include <packing>\r\n#include <dithering_pars_fragment>\r\n#include <color_pars_fragment>\r\n#include <uv_pars_fragment>\r\n#include <uv2_pars_fragment>\r\n#include <map_pars_fragment>\r\n#include <alphamap_pars_fragment>\r\n#include <aomap_pars_fragment>\r\n#include <lightmap_pars_fragment>\r\n#include <emissivemap_pars_fragment>\r\n#include <envmap_pars_fragment>\r\n#include <fog_pars_fragment>\r\n#include <bsdfs>\r\n#include <cube_uv_reflection_fragment>\r\n#include <lights_pars>\r\n#include <lights_physical_pars_fragment>\r\n#include <shadowmap_pars_fragment>\r\n#include <bumpmap_pars_fragment>\r\n#include <normalmap_pars_fragment>\r\n#include <roughnessmap_pars_fragment>\r\n#include <metalnessmap_pars_fragment>\r\n#include <logdepthbuf_pars_fragment>\r\n#include <clipping_planes_pars_fragment>\r\n\r\nvoid main() {\r\n\r\n\t#include <clipping_planes_fragment>\r\n\r\n\tvec4 diffuseColor = vec4( diffuse, opacity );\r\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\r\n\tvec3 totalEmissiveRadiance = emissive;\r\n\r\n\t#include <logdepthbuf_fragment>\r\n\t#include <map_fragment>\r\n\t#include <color_fragment>\r\n\t#include <alphamap_fragment>\r\n\t#include <alphatest_fragment>\r\n\t#include <roughnessmap_fragment>\r\n\t#include <metalnessmap_fragment>\r\n\t#include <normal_fragment>\r\n\t#include <emissivemap_fragment>\r\n\r\n\t// accumulation\r\n\t#include <lights_physical_fragment>\r\n\t#include <lights_template>\r\n\r\n\t// modulation\r\n\t#include <aomap_fragment>\r\n\r\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\r\n\r\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\r\n\r\n\t#include <tonemapping_fragment>\r\n\t#include <encodings_fragment>\r\n\t#include <fog_fragment>\r\n\t#include <premultiplied_alpha_fragment>\r\n\t#include <dithering_fragment>\r\n\r\n}\r\n";
  21269. var meshphysical_vert = "#define PHYSICAL\r\n\r\nvarying vec3 vViewPosition;\r\n\r\n#ifndef FLAT_SHADED\r\n\r\n\tvarying vec3 vNormal;\r\n\r\n#endif\r\n\r\n#include <common>\r\n#include <uv_pars_vertex>\r\n#include <uv2_pars_vertex>\r\n#include <displacementmap_pars_vertex>\r\n#include <color_pars_vertex>\r\n#include <fog_pars_vertex>\r\n#include <morphtarget_pars_vertex>\r\n#include <skinning_pars_vertex>\r\n#include <shadowmap_pars_vertex>\r\n#include <logdepthbuf_pars_vertex>\r\n#include <clipping_planes_pars_vertex>\r\n\r\nvoid main() {\r\n\r\n\t#include <uv_vertex>\r\n\t#include <uv2_vertex>\r\n\t#include <color_vertex>\r\n\r\n\t#include <beginnormal_vertex>\r\n\t#include <morphnormal_vertex>\r\n\t#include <skinbase_vertex>\r\n\t#include <skinnormal_vertex>\r\n\t#include <defaultnormal_vertex>\r\n\r\n#ifndef FLAT_SHADED // Normal computed with derivatives when FLAT_SHADED\r\n\r\n\tvNormal = normalize( transformedNormal );\r\n\r\n#endif\r\n\r\n\t#include <begin_vertex>\r\n\t#include <morphtarget_vertex>\r\n\t#include <skinning_vertex>\r\n\t#include <displacementmap_vertex>\r\n\t#include <project_vertex>\r\n\t#include <logdepthbuf_vertex>\r\n\t#include <clipping_planes_vertex>\r\n\r\n\tvViewPosition = - mvPosition.xyz;\r\n\r\n\t#include <worldpos_vertex>\r\n\t#include <shadowmap_vertex>\r\n\t#include <fog_vertex>\r\n\r\n}\r\n";
  21270. var normal_frag = "#define NORMAL\r\n\r\nuniform float opacity;\r\n\r\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP )\r\n\r\n\tvarying vec3 vViewPosition;\r\n\r\n#endif\r\n\r\n#ifndef FLAT_SHADED\r\n\r\n\tvarying vec3 vNormal;\r\n\r\n#endif\r\n\r\n#include <packing>\r\n#include <uv_pars_fragment>\r\n#include <bumpmap_pars_fragment>\r\n#include <normalmap_pars_fragment>\r\n#include <logdepthbuf_pars_fragment>\r\n\r\nvoid main() {\r\n\r\n\t#include <logdepthbuf_fragment>\r\n\t#include <normal_fragment>\r\n\r\n\tgl_FragColor = vec4( packNormalToRGB( normal ), opacity );\r\n\r\n}\r\n";
  21271. var normal_vert = "#define NORMAL\r\n\r\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP )\r\n\r\n\tvarying vec3 vViewPosition;\r\n\r\n#endif\r\n\r\n#ifndef FLAT_SHADED\r\n\r\n\tvarying vec3 vNormal;\r\n\r\n#endif\r\n\r\n#include <uv_pars_vertex>\r\n#include <displacementmap_pars_vertex>\r\n#include <morphtarget_pars_vertex>\r\n#include <skinning_pars_vertex>\r\n#include <logdepthbuf_pars_vertex>\r\n\r\nvoid main() {\r\n\r\n\t#include <uv_vertex>\r\n\r\n\t#include <beginnormal_vertex>\r\n\t#include <morphnormal_vertex>\r\n\t#include <skinbase_vertex>\r\n\t#include <skinnormal_vertex>\r\n\t#include <defaultnormal_vertex>\r\n\r\n#ifndef FLAT_SHADED // Normal computed with derivatives when FLAT_SHADED\r\n\r\n\tvNormal = normalize( transformedNormal );\r\n\r\n#endif\r\n\r\n\t#include <begin_vertex>\r\n\t#include <morphtarget_vertex>\r\n\t#include <skinning_vertex>\r\n\t#include <displacementmap_vertex>\r\n\t#include <project_vertex>\r\n\t#include <logdepthbuf_vertex>\r\n\r\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP )\r\n\r\n\tvViewPosition = - mvPosition.xyz;\r\n\r\n#endif\r\n\r\n}\r\n";
  21272. var points_frag = "uniform vec3 diffuse;\r\nuniform float opacity;\r\n\r\n#include <common>\r\n#include <packing>\r\n#include <color_pars_fragment>\r\n#include <map_particle_pars_fragment>\r\n#include <fog_pars_fragment>\r\n#include <shadowmap_pars_fragment>\r\n#include <logdepthbuf_pars_fragment>\r\n#include <clipping_planes_pars_fragment>\r\n\r\nvoid main() {\r\n\r\n\t#include <clipping_planes_fragment>\r\n\r\n\tvec3 outgoingLight = vec3( 0.0 );\r\n\tvec4 diffuseColor = vec4( diffuse, opacity );\r\n\r\n\t#include <logdepthbuf_fragment>\r\n\t#include <map_particle_fragment>\r\n\t#include <color_fragment>\r\n\t#include <alphatest_fragment>\r\n\r\n\toutgoingLight = diffuseColor.rgb;\r\n\r\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\r\n\r\n\t#include <premultiplied_alpha_fragment>\r\n\t#include <tonemapping_fragment>\r\n\t#include <encodings_fragment>\r\n\t#include <fog_fragment>\r\n\r\n}\r\n";
  21273. var points_vert = "uniform float size;\r\nuniform float scale;\r\n\r\n#include <common>\r\n#include <color_pars_vertex>\r\n#include <fog_pars_vertex>\r\n#include <shadowmap_pars_vertex>\r\n#include <logdepthbuf_pars_vertex>\r\n#include <clipping_planes_pars_vertex>\r\n\r\nvoid main() {\r\n\r\n\t#include <color_vertex>\r\n\t#include <begin_vertex>\r\n\t#include <project_vertex>\r\n\r\n\t#ifdef USE_SIZEATTENUATION\r\n\t\tgl_PointSize = size * ( scale / - mvPosition.z );\r\n\t#else\r\n\t\tgl_PointSize = size;\r\n\t#endif\r\n\r\n\t#include <logdepthbuf_vertex>\r\n\t#include <clipping_planes_vertex>\r\n\t#include <worldpos_vertex>\r\n\t#include <shadowmap_vertex>\r\n\t#include <fog_vertex>\r\n\r\n}\r\n";
  21274. var shadow_frag = "uniform vec3 color;\r\nuniform float opacity;\r\n\r\n#include <common>\r\n#include <packing>\r\n#include <fog_pars_fragment>\r\n#include <bsdfs>\r\n#include <lights_pars>\r\n#include <shadowmap_pars_fragment>\r\n#include <shadowmask_pars_fragment>\r\n\r\nvoid main() {\r\n\r\n\tgl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) );\r\n\r\n\t#include <fog_fragment>\r\n\r\n}\r\n";
  21275. var shadow_vert = "#include <fog_pars_vertex>\r\n#include <shadowmap_pars_vertex>\r\n\r\nvoid main() {\r\n\r\n\t#include <begin_vertex>\r\n\t#include <project_vertex>\r\n\t#include <worldpos_vertex>\r\n\t#include <shadowmap_vertex>\r\n\t#include <fog_vertex>\r\n\r\n}\r\n";
  21276. var ShaderChunk = {
  21277. alphamap_fragment: alphamap_fragment,
  21278. alphamap_pars_fragment: alphamap_pars_fragment,
  21279. alphatest_fragment: alphatest_fragment,
  21280. aomap_fragment: aomap_fragment,
  21281. aomap_pars_fragment: aomap_pars_fragment,
  21282. begin_vertex: begin_vertex,
  21283. beginnormal_vertex: beginnormal_vertex,
  21284. bsdfs: bsdfs,
  21285. bumpmap_pars_fragment: bumpmap_pars_fragment,
  21286. clipping_planes_fragment: clipping_planes_fragment,
  21287. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  21288. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  21289. clipping_planes_vertex: clipping_planes_vertex,
  21290. color_fragment: color_fragment,
  21291. color_pars_fragment: color_pars_fragment,
  21292. color_pars_vertex: color_pars_vertex,
  21293. color_vertex: color_vertex,
  21294. common: common,
  21295. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  21296. defaultnormal_vertex: defaultnormal_vertex,
  21297. displacementmap_pars_vertex: displacementmap_pars_vertex,
  21298. displacementmap_vertex: displacementmap_vertex,
  21299. emissivemap_fragment: emissivemap_fragment,
  21300. emissivemap_pars_fragment: emissivemap_pars_fragment,
  21301. encodings_fragment: encodings_fragment,
  21302. encodings_pars_fragment: encodings_pars_fragment,
  21303. envmap_fragment: envmap_fragment,
  21304. envmap_pars_fragment: envmap_pars_fragment,
  21305. envmap_pars_vertex: envmap_pars_vertex,
  21306. envmap_vertex: envmap_vertex,
  21307. fog_vertex: fog_vertex,
  21308. fog_pars_vertex: fog_pars_vertex,
  21309. fog_fragment: fog_fragment,
  21310. fog_pars_fragment: fog_pars_fragment,
  21311. gradientmap_pars_fragment: gradientmap_pars_fragment,
  21312. lightmap_fragment: lightmap_fragment,
  21313. lightmap_pars_fragment: lightmap_pars_fragment,
  21314. lights_lambert_vertex: lights_lambert_vertex,
  21315. lights_pars: lights_pars,
  21316. lights_phong_fragment: lights_phong_fragment,
  21317. lights_phong_pars_fragment: lights_phong_pars_fragment,
  21318. lights_physical_fragment: lights_physical_fragment,
  21319. lights_physical_pars_fragment: lights_physical_pars_fragment,
  21320. lights_template: lights_template,
  21321. logdepthbuf_fragment: logdepthbuf_fragment,
  21322. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  21323. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  21324. logdepthbuf_vertex: logdepthbuf_vertex,
  21325. map_fragment: map_fragment,
  21326. map_pars_fragment: map_pars_fragment,
  21327. map_particle_fragment: map_particle_fragment,
  21328. map_particle_pars_fragment: map_particle_pars_fragment,
  21329. metalnessmap_fragment: metalnessmap_fragment,
  21330. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  21331. morphnormal_vertex: morphnormal_vertex,
  21332. morphtarget_pars_vertex: morphtarget_pars_vertex,
  21333. morphtarget_vertex: morphtarget_vertex,
  21334. normal_fragment: normal_fragment,
  21335. normalmap_pars_fragment: normalmap_pars_fragment,
  21336. packing: packing,
  21337. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  21338. project_vertex: project_vertex,
  21339. dithering_fragment: dithering_fragment,
  21340. dithering_pars_fragment: dithering_pars_fragment,
  21341. roughnessmap_fragment: roughnessmap_fragment,
  21342. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  21343. shadowmap_pars_fragment: shadowmap_pars_fragment,
  21344. shadowmap_pars_vertex: shadowmap_pars_vertex,
  21345. shadowmap_vertex: shadowmap_vertex,
  21346. shadowmask_pars_fragment: shadowmask_pars_fragment,
  21347. skinbase_vertex: skinbase_vertex,
  21348. skinning_pars_vertex: skinning_pars_vertex,
  21349. skinning_vertex: skinning_vertex,
  21350. skinnormal_vertex: skinnormal_vertex,
  21351. specularmap_fragment: specularmap_fragment,
  21352. specularmap_pars_fragment: specularmap_pars_fragment,
  21353. tonemapping_fragment: tonemapping_fragment,
  21354. tonemapping_pars_fragment: tonemapping_pars_fragment,
  21355. uv_pars_fragment: uv_pars_fragment,
  21356. uv_pars_vertex: uv_pars_vertex,
  21357. uv_vertex: uv_vertex,
  21358. uv2_pars_fragment: uv2_pars_fragment,
  21359. uv2_pars_vertex: uv2_pars_vertex,
  21360. uv2_vertex: uv2_vertex,
  21361. worldpos_vertex: worldpos_vertex,
  21362. cube_frag: cube_frag,
  21363. cube_vert: cube_vert,
  21364. depth_frag: depth_frag,
  21365. depth_vert: depth_vert,
  21366. distanceRGBA_frag: distanceRGBA_frag,
  21367. distanceRGBA_vert: distanceRGBA_vert,
  21368. equirect_frag: equirect_frag,
  21369. equirect_vert: equirect_vert,
  21370. linedashed_frag: linedashed_frag,
  21371. linedashed_vert: linedashed_vert,
  21372. meshbasic_frag: meshbasic_frag,
  21373. meshbasic_vert: meshbasic_vert,
  21374. meshlambert_frag: meshlambert_frag,
  21375. meshlambert_vert: meshlambert_vert,
  21376. meshphong_frag: meshphong_frag,
  21377. meshphong_vert: meshphong_vert,
  21378. meshphysical_frag: meshphysical_frag,
  21379. meshphysical_vert: meshphysical_vert,
  21380. normal_frag: normal_frag,
  21381. normal_vert: normal_vert,
  21382. points_frag: points_frag,
  21383. points_vert: points_vert,
  21384. shadow_frag: shadow_frag,
  21385. shadow_vert: shadow_vert
  21386. };
  21387. var ShaderLib = {
  21388. basic: {
  21389. uniforms: UniformsUtils.merge( [
  21390. UniformsLib.common,
  21391. UniformsLib.specularmap,
  21392. UniformsLib.envmap,
  21393. UniformsLib.aomap,
  21394. UniformsLib.lightmap,
  21395. UniformsLib.fog
  21396. ] ),
  21397. vertexShader: ShaderChunk.meshbasic_vert,
  21398. fragmentShader: ShaderChunk.meshbasic_frag
  21399. },
  21400. lambert: {
  21401. uniforms: UniformsUtils.merge( [
  21402. UniformsLib.common,
  21403. UniformsLib.specularmap,
  21404. UniformsLib.envmap,
  21405. UniformsLib.aomap,
  21406. UniformsLib.lightmap,
  21407. UniformsLib.emissivemap,
  21408. UniformsLib.fog,
  21409. UniformsLib.lights,
  21410. {
  21411. emissive: { value: new Color( 0x000000 ) }
  21412. }
  21413. ] ),
  21414. vertexShader: ShaderChunk.meshlambert_vert,
  21415. fragmentShader: ShaderChunk.meshlambert_frag
  21416. },
  21417. phong: {
  21418. uniforms: UniformsUtils.merge( [
  21419. UniformsLib.common,
  21420. UniformsLib.specularmap,
  21421. UniformsLib.envmap,
  21422. UniformsLib.aomap,
  21423. UniformsLib.lightmap,
  21424. UniformsLib.emissivemap,
  21425. UniformsLib.bumpmap,
  21426. UniformsLib.normalmap,
  21427. UniformsLib.displacementmap,
  21428. UniformsLib.gradientmap,
  21429. UniformsLib.fog,
  21430. UniformsLib.lights,
  21431. {
  21432. emissive: { value: new Color( 0x000000 ) },
  21433. specular: { value: new Color( 0x111111 ) },
  21434. shininess: { value: 30 }
  21435. }
  21436. ] ),
  21437. vertexShader: ShaderChunk.meshphong_vert,
  21438. fragmentShader: ShaderChunk.meshphong_frag
  21439. },
  21440. standard: {
  21441. uniforms: UniformsUtils.merge( [
  21442. UniformsLib.common,
  21443. UniformsLib.envmap,
  21444. UniformsLib.aomap,
  21445. UniformsLib.lightmap,
  21446. UniformsLib.emissivemap,
  21447. UniformsLib.bumpmap,
  21448. UniformsLib.normalmap,
  21449. UniformsLib.displacementmap,
  21450. UniformsLib.roughnessmap,
  21451. UniformsLib.metalnessmap,
  21452. UniformsLib.fog,
  21453. UniformsLib.lights,
  21454. {
  21455. emissive: { value: new Color( 0x000000 ) },
  21456. roughness: { value: 0.5 },
  21457. metalness: { value: 0.5 },
  21458. envMapIntensity: { value: 1 } // temporary
  21459. }
  21460. ] ),
  21461. vertexShader: ShaderChunk.meshphysical_vert,
  21462. fragmentShader: ShaderChunk.meshphysical_frag
  21463. },
  21464. points: {
  21465. uniforms: UniformsUtils.merge( [
  21466. UniformsLib.points,
  21467. UniformsLib.fog
  21468. ] ),
  21469. vertexShader: ShaderChunk.points_vert,
  21470. fragmentShader: ShaderChunk.points_frag
  21471. },
  21472. dashed: {
  21473. uniforms: UniformsUtils.merge( [
  21474. UniformsLib.common,
  21475. UniformsLib.fog,
  21476. {
  21477. scale: { value: 1 },
  21478. dashSize: { value: 1 },
  21479. totalSize: { value: 2 }
  21480. }
  21481. ] ),
  21482. vertexShader: ShaderChunk.linedashed_vert,
  21483. fragmentShader: ShaderChunk.linedashed_frag
  21484. },
  21485. depth: {
  21486. uniforms: UniformsUtils.merge( [
  21487. UniformsLib.common,
  21488. UniformsLib.displacementmap
  21489. ] ),
  21490. vertexShader: ShaderChunk.depth_vert,
  21491. fragmentShader: ShaderChunk.depth_frag
  21492. },
  21493. normal: {
  21494. uniforms: UniformsUtils.merge( [
  21495. UniformsLib.common,
  21496. UniformsLib.bumpmap,
  21497. UniformsLib.normalmap,
  21498. UniformsLib.displacementmap,
  21499. {
  21500. opacity: { value: 1.0 }
  21501. }
  21502. ] ),
  21503. vertexShader: ShaderChunk.normal_vert,
  21504. fragmentShader: ShaderChunk.normal_frag
  21505. },
  21506. /* -------------------------------------------------------------------------
  21507. // Cube map shader
  21508. ------------------------------------------------------------------------- */
  21509. cube: {
  21510. uniforms: {
  21511. tCube: { value: null },
  21512. tFlip: { value: - 1 },
  21513. opacity: { value: 1.0 }
  21514. },
  21515. vertexShader: ShaderChunk.cube_vert,
  21516. fragmentShader: ShaderChunk.cube_frag
  21517. },
  21518. equirect: {
  21519. uniforms: {
  21520. tEquirect: { value: null },
  21521. },
  21522. vertexShader: ShaderChunk.equirect_vert,
  21523. fragmentShader: ShaderChunk.equirect_frag
  21524. },
  21525. distanceRGBA: {
  21526. uniforms: UniformsUtils.merge( [
  21527. UniformsLib.common,
  21528. UniformsLib.displacementmap,
  21529. {
  21530. referencePosition: { value: new Vector3() },
  21531. nearDistance: { value: 1 },
  21532. farDistance: { value: 1000 }
  21533. }
  21534. ] ),
  21535. vertexShader: ShaderChunk.distanceRGBA_vert,
  21536. fragmentShader: ShaderChunk.distanceRGBA_frag
  21537. },
  21538. shadow: {
  21539. uniforms: UniformsUtils.merge( [
  21540. UniformsLib.lights,
  21541. UniformsLib.fog,
  21542. {
  21543. color: { value: new Color( 0x00000 ) },
  21544. opacity: { value: 1.0 }
  21545. },
  21546. ] ),
  21547. vertexShader: ShaderChunk.shadow_vert,
  21548. fragmentShader: ShaderChunk.shadow_frag
  21549. }
  21550. };
  21551. ShaderLib.physical = {
  21552. uniforms: UniformsUtils.merge( [
  21553. ShaderLib.standard.uniforms,
  21554. {
  21555. clearCoat: { value: 0 },
  21556. clearCoatRoughness: { value: 0 }
  21557. }
  21558. ] ),
  21559. vertexShader: ShaderChunk.meshphysical_vert,
  21560. fragmentShader: ShaderChunk.meshphysical_frag
  21561. };
  21562. function Box2( min, max ) {
  21563. this.min = ( min !== undefined ) ? min : new Vector2( + Infinity, + Infinity );
  21564. this.max = ( max !== undefined ) ? max : new Vector2( - Infinity, - Infinity );
  21565. }
  21566. Object.assign( Box2.prototype, {
  21567. set: function ( min, max ) {
  21568. this.min.copy( min );
  21569. this.max.copy( max );
  21570. return this;
  21571. },
  21572. setFromPoints: function ( points ) {
  21573. this.makeEmpty();
  21574. for ( var i = 0, il = points.length; i < il; i ++ ) {
  21575. this.expandByPoint( points[ i ] );
  21576. }
  21577. return this;
  21578. },
  21579. setFromCenterAndSize: function () {
  21580. var v1 = new Vector2();
  21581. return function setFromCenterAndSize( center, size ) {
  21582. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  21583. this.min.copy( center ).sub( halfSize );
  21584. this.max.copy( center ).add( halfSize );
  21585. return this;
  21586. };
  21587. }(),
  21588. clone: function () {
  21589. return new this.constructor().copy( this );
  21590. },
  21591. copy: function ( box ) {
  21592. this.min.copy( box.min );
  21593. this.max.copy( box.max );
  21594. return this;
  21595. },
  21596. makeEmpty: function () {
  21597. this.min.x = this.min.y = + Infinity;
  21598. this.max.x = this.max.y = - Infinity;
  21599. return this;
  21600. },
  21601. isEmpty: function () {
  21602. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  21603. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  21604. },
  21605. getCenter: function ( optionalTarget ) {
  21606. var result = optionalTarget || new Vector2();
  21607. return this.isEmpty() ? result.set( 0, 0 ) : result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  21608. },
  21609. getSize: function ( optionalTarget ) {
  21610. var result = optionalTarget || new Vector2();
  21611. return this.isEmpty() ? result.set( 0, 0 ) : result.subVectors( this.max, this.min );
  21612. },
  21613. expandByPoint: function ( point ) {
  21614. this.min.min( point );
  21615. this.max.max( point );
  21616. return this;
  21617. },
  21618. expandByVector: function ( vector ) {
  21619. this.min.sub( vector );
  21620. this.max.add( vector );
  21621. return this;
  21622. },
  21623. expandByScalar: function ( scalar ) {
  21624. this.min.addScalar( - scalar );
  21625. this.max.addScalar( scalar );
  21626. return this;
  21627. },
  21628. containsPoint: function ( point ) {
  21629. return point.x < this.min.x || point.x > this.max.x ||
  21630. point.y < this.min.y || point.y > this.max.y ? false : true;
  21631. },
  21632. containsBox: function ( box ) {
  21633. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  21634. this.min.y <= box.min.y && box.max.y <= this.max.y;
  21635. },
  21636. getParameter: function ( point, optionalTarget ) {
  21637. // This can potentially have a divide by zero if the box
  21638. // has a size dimension of 0.
  21639. var result = optionalTarget || new Vector2();
  21640. return result.set(
  21641. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  21642. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  21643. );
  21644. },
  21645. intersectsBox: function ( box ) {
  21646. // using 4 splitting planes to rule out intersections
  21647. return box.max.x < this.min.x || box.min.x > this.max.x ||
  21648. box.max.y < this.min.y || box.min.y > this.max.y ? false : true;
  21649. },
  21650. clampPoint: function ( point, optionalTarget ) {
  21651. var result = optionalTarget || new Vector2();
  21652. return result.copy( point ).clamp( this.min, this.max );
  21653. },
  21654. distanceToPoint: function () {
  21655. var v1 = new Vector2();
  21656. return function distanceToPoint( point ) {
  21657. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  21658. return clampedPoint.sub( point ).length();
  21659. };
  21660. }(),
  21661. intersect: function ( box ) {
  21662. this.min.max( box.min );
  21663. this.max.min( box.max );
  21664. return this;
  21665. },
  21666. union: function ( box ) {
  21667. this.min.min( box.min );
  21668. this.max.max( box.max );
  21669. return this;
  21670. },
  21671. translate: function ( offset ) {
  21672. this.min.add( offset );
  21673. this.max.add( offset );
  21674. return this;
  21675. },
  21676. equals: function ( box ) {
  21677. return box.min.equals( this.min ) && box.max.equals( this.max );
  21678. }
  21679. } );
  21680. /**
  21681. * @author mikael emtinger / http://gomo.se/
  21682. * @author alteredq / http://alteredqualia.com/
  21683. */
  21684. function WebGLFlareRenderer( renderer, gl, state, textures, capabilities ) {
  21685. var vertexBuffer, elementBuffer;
  21686. var shader, program, attributes, uniforms;
  21687. var tempTexture, occlusionTexture;
  21688. function init() {
  21689. var vertices = new Float32Array( [
  21690. - 1, - 1, 0, 0,
  21691. 1, - 1, 1, 0,
  21692. 1, 1, 1, 1,
  21693. - 1, 1, 0, 1
  21694. ] );
  21695. var faces = new Uint16Array( [
  21696. 0, 1, 2,
  21697. 0, 2, 3
  21698. ] );
  21699. // buffers
  21700. vertexBuffer = gl.createBuffer();
  21701. elementBuffer = gl.createBuffer();
  21702. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  21703. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  21704. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  21705. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  21706. // textures
  21707. tempTexture = gl.createTexture();
  21708. occlusionTexture = gl.createTexture();
  21709. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  21710. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGB, 16, 16, 0, gl.RGB, gl.UNSIGNED_BYTE, null );
  21711. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  21712. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  21713. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  21714. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  21715. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  21716. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGBA, 16, 16, 0, gl.RGBA, gl.UNSIGNED_BYTE, null );
  21717. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  21718. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  21719. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  21720. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  21721. shader = {
  21722. vertexShader: [
  21723. 'uniform lowp int renderType;',
  21724. 'uniform vec3 screenPosition;',
  21725. 'uniform vec2 scale;',
  21726. 'uniform float rotation;',
  21727. 'uniform sampler2D occlusionMap;',
  21728. 'attribute vec2 position;',
  21729. 'attribute vec2 uv;',
  21730. 'varying vec2 vUV;',
  21731. 'varying float vVisibility;',
  21732. 'void main() {',
  21733. ' vUV = uv;',
  21734. ' vec2 pos = position;',
  21735. ' if ( renderType == 2 ) {',
  21736. ' vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) );',
  21737. ' visibility += texture2D( occlusionMap, vec2( 0.5, 0.1 ) );',
  21738. ' visibility += texture2D( occlusionMap, vec2( 0.9, 0.1 ) );',
  21739. ' visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) );',
  21740. ' visibility += texture2D( occlusionMap, vec2( 0.9, 0.9 ) );',
  21741. ' visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) );',
  21742. ' visibility += texture2D( occlusionMap, vec2( 0.1, 0.9 ) );',
  21743. ' visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) );',
  21744. ' visibility += texture2D( occlusionMap, vec2( 0.5, 0.5 ) );',
  21745. ' vVisibility = visibility.r / 9.0;',
  21746. ' vVisibility *= 1.0 - visibility.g / 9.0;',
  21747. ' vVisibility *= visibility.b / 9.0;',
  21748. ' vVisibility *= 1.0 - visibility.a / 9.0;',
  21749. ' pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;',
  21750. ' pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;',
  21751. ' }',
  21752. ' gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );',
  21753. '}'
  21754. ].join( '\n' ),
  21755. fragmentShader: [
  21756. 'uniform lowp int renderType;',
  21757. 'uniform sampler2D map;',
  21758. 'uniform float opacity;',
  21759. 'uniform vec3 color;',
  21760. 'varying vec2 vUV;',
  21761. 'varying float vVisibility;',
  21762. 'void main() {',
  21763. // pink square
  21764. ' if ( renderType == 0 ) {',
  21765. ' gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );',
  21766. // restore
  21767. ' } else if ( renderType == 1 ) {',
  21768. ' gl_FragColor = texture2D( map, vUV );',
  21769. // flare
  21770. ' } else {',
  21771. ' vec4 texture = texture2D( map, vUV );',
  21772. ' texture.a *= opacity * vVisibility;',
  21773. ' gl_FragColor = texture;',
  21774. ' gl_FragColor.rgb *= color;',
  21775. ' }',
  21776. '}'
  21777. ].join( '\n' )
  21778. };
  21779. program = createProgram( shader );
  21780. attributes = {
  21781. vertex: gl.getAttribLocation( program, 'position' ),
  21782. uv: gl.getAttribLocation( program, 'uv' )
  21783. };
  21784. uniforms = {
  21785. renderType: gl.getUniformLocation( program, 'renderType' ),
  21786. map: gl.getUniformLocation( program, 'map' ),
  21787. occlusionMap: gl.getUniformLocation( program, 'occlusionMap' ),
  21788. opacity: gl.getUniformLocation( program, 'opacity' ),
  21789. color: gl.getUniformLocation( program, 'color' ),
  21790. scale: gl.getUniformLocation( program, 'scale' ),
  21791. rotation: gl.getUniformLocation( program, 'rotation' ),
  21792. screenPosition: gl.getUniformLocation( program, 'screenPosition' )
  21793. };
  21794. }
  21795. /*
  21796. * Render lens flares
  21797. * Method: renders 16x16 0xff00ff-colored points scattered over the light source area,
  21798. * reads these back and calculates occlusion.
  21799. */
  21800. this.render = function ( flares, scene, camera, viewport ) {
  21801. if ( flares.length === 0 ) return;
  21802. var tempPosition = new Vector3();
  21803. var invAspect = viewport.w / viewport.z,
  21804. halfViewportWidth = viewport.z * 0.5,
  21805. halfViewportHeight = viewport.w * 0.5;
  21806. var size = 16 / viewport.w,
  21807. scale = new Vector2( size * invAspect, size );
  21808. var screenPosition = new Vector3( 1, 1, 0 ),
  21809. screenPositionPixels = new Vector2( 1, 1 );
  21810. var validArea = new Box2();
  21811. validArea.min.set( viewport.x, viewport.y );
  21812. validArea.max.set( viewport.x + ( viewport.z - 16 ), viewport.y + ( viewport.w - 16 ) );
  21813. if ( program === undefined ) {
  21814. init();
  21815. }
  21816. state.useProgram( program );
  21817. state.initAttributes();
  21818. state.enableAttribute( attributes.vertex );
  21819. state.enableAttribute( attributes.uv );
  21820. state.disableUnusedAttributes();
  21821. // loop through all lens flares to update their occlusion and positions
  21822. // setup gl and common used attribs/uniforms
  21823. gl.uniform1i( uniforms.occlusionMap, 0 );
  21824. gl.uniform1i( uniforms.map, 1 );
  21825. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  21826. gl.vertexAttribPointer( attributes.vertex, 2, gl.FLOAT, false, 2 * 8, 0 );
  21827. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  21828. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  21829. state.disable( gl.CULL_FACE );
  21830. state.buffers.depth.setMask( false );
  21831. for ( var i = 0, l = flares.length; i < l; i ++ ) {
  21832. size = 16 / viewport.w;
  21833. scale.set( size * invAspect, size );
  21834. // calc object screen position
  21835. var flare = flares[ i ];
  21836. tempPosition.set( flare.matrixWorld.elements[ 12 ], flare.matrixWorld.elements[ 13 ], flare.matrixWorld.elements[ 14 ] );
  21837. tempPosition.applyMatrix4( camera.matrixWorldInverse );
  21838. tempPosition.applyMatrix4( camera.projectionMatrix );
  21839. // setup arrays for gl programs
  21840. screenPosition.copy( tempPosition );
  21841. // horizontal and vertical coordinate of the lower left corner of the pixels to copy
  21842. screenPositionPixels.x = viewport.x + ( screenPosition.x * halfViewportWidth ) + halfViewportWidth - 8;
  21843. screenPositionPixels.y = viewport.y + ( screenPosition.y * halfViewportHeight ) + halfViewportHeight - 8;
  21844. // screen cull
  21845. if ( validArea.containsPoint( screenPositionPixels ) === true ) {
  21846. // save current RGB to temp texture
  21847. state.activeTexture( gl.TEXTURE0 );
  21848. state.bindTexture( gl.TEXTURE_2D, null );
  21849. state.activeTexture( gl.TEXTURE1 );
  21850. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  21851. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGB, screenPositionPixels.x, screenPositionPixels.y, 16, 16, 0 );
  21852. // render pink quad
  21853. gl.uniform1i( uniforms.renderType, 0 );
  21854. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  21855. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  21856. state.disable( gl.BLEND );
  21857. state.enable( gl.DEPTH_TEST );
  21858. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  21859. // copy result to occlusionMap
  21860. state.activeTexture( gl.TEXTURE0 );
  21861. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  21862. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGBA, screenPositionPixels.x, screenPositionPixels.y, 16, 16, 0 );
  21863. // restore graphics
  21864. gl.uniform1i( uniforms.renderType, 1 );
  21865. state.disable( gl.DEPTH_TEST );
  21866. state.activeTexture( gl.TEXTURE1 );
  21867. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  21868. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  21869. // update object positions
  21870. flare.positionScreen.copy( screenPosition );
  21871. if ( flare.customUpdateCallback ) {
  21872. flare.customUpdateCallback( flare );
  21873. } else {
  21874. flare.updateLensFlares();
  21875. }
  21876. // render flares
  21877. gl.uniform1i( uniforms.renderType, 2 );
  21878. state.enable( gl.BLEND );
  21879. for ( var j = 0, jl = flare.lensFlares.length; j < jl; j ++ ) {
  21880. var sprite = flare.lensFlares[ j ];
  21881. if ( sprite.opacity > 0.001 && sprite.scale > 0.001 ) {
  21882. screenPosition.x = sprite.x;
  21883. screenPosition.y = sprite.y;
  21884. screenPosition.z = sprite.z;
  21885. size = sprite.size * sprite.scale / viewport.w;
  21886. scale.x = size * invAspect;
  21887. scale.y = size;
  21888. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  21889. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  21890. gl.uniform1f( uniforms.rotation, sprite.rotation );
  21891. gl.uniform1f( uniforms.opacity, sprite.opacity );
  21892. gl.uniform3f( uniforms.color, sprite.color.r, sprite.color.g, sprite.color.b );
  21893. state.setBlending( sprite.blending, sprite.blendEquation, sprite.blendSrc, sprite.blendDst );
  21894. textures.setTexture2D( sprite.texture, 1 );
  21895. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  21896. }
  21897. }
  21898. }
  21899. }
  21900. // restore gl
  21901. state.enable( gl.CULL_FACE );
  21902. state.enable( gl.DEPTH_TEST );
  21903. state.buffers.depth.setMask( true );
  21904. state.reset();
  21905. };
  21906. function createProgram( shader ) {
  21907. var program = gl.createProgram();
  21908. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  21909. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  21910. var prefix = 'precision ' + capabilities.precision + ' float;\n';
  21911. gl.shaderSource( fragmentShader, prefix + shader.fragmentShader );
  21912. gl.shaderSource( vertexShader, prefix + shader.vertexShader );
  21913. gl.compileShader( fragmentShader );
  21914. gl.compileShader( vertexShader );
  21915. gl.attachShader( program, fragmentShader );
  21916. gl.attachShader( program, vertexShader );
  21917. gl.linkProgram( program );
  21918. return program;
  21919. }
  21920. }
  21921. /**
  21922. * @author mrdoob / http://mrdoob.com/
  21923. */
  21924. function CanvasTexture( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  21925. Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  21926. this.needsUpdate = true;
  21927. }
  21928. CanvasTexture.prototype = Object.create( Texture.prototype );
  21929. CanvasTexture.prototype.constructor = CanvasTexture;
  21930. /**
  21931. * @author mikael emtinger / http://gomo.se/
  21932. * @author alteredq / http://alteredqualia.com/
  21933. */
  21934. function WebGLSpriteRenderer( renderer, gl, state, textures, capabilities ) {
  21935. var vertexBuffer, elementBuffer;
  21936. var program, attributes, uniforms;
  21937. var texture;
  21938. // decompose matrixWorld
  21939. var spritePosition = new Vector3();
  21940. var spriteRotation = new Quaternion();
  21941. var spriteScale = new Vector3();
  21942. function init() {
  21943. var vertices = new Float32Array( [
  21944. - 0.5, - 0.5, 0, 0,
  21945. 0.5, - 0.5, 1, 0,
  21946. 0.5, 0.5, 1, 1,
  21947. - 0.5, 0.5, 0, 1
  21948. ] );
  21949. var faces = new Uint16Array( [
  21950. 0, 1, 2,
  21951. 0, 2, 3
  21952. ] );
  21953. vertexBuffer = gl.createBuffer();
  21954. elementBuffer = gl.createBuffer();
  21955. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  21956. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  21957. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  21958. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  21959. program = createProgram();
  21960. attributes = {
  21961. position: gl.getAttribLocation( program, 'position' ),
  21962. uv: gl.getAttribLocation( program, 'uv' )
  21963. };
  21964. uniforms = {
  21965. uvOffset: gl.getUniformLocation( program, 'uvOffset' ),
  21966. uvScale: gl.getUniformLocation( program, 'uvScale' ),
  21967. rotation: gl.getUniformLocation( program, 'rotation' ),
  21968. scale: gl.getUniformLocation( program, 'scale' ),
  21969. color: gl.getUniformLocation( program, 'color' ),
  21970. map: gl.getUniformLocation( program, 'map' ),
  21971. opacity: gl.getUniformLocation( program, 'opacity' ),
  21972. modelViewMatrix: gl.getUniformLocation( program, 'modelViewMatrix' ),
  21973. projectionMatrix: gl.getUniformLocation( program, 'projectionMatrix' ),
  21974. fogType: gl.getUniformLocation( program, 'fogType' ),
  21975. fogDensity: gl.getUniformLocation( program, 'fogDensity' ),
  21976. fogNear: gl.getUniformLocation( program, 'fogNear' ),
  21977. fogFar: gl.getUniformLocation( program, 'fogFar' ),
  21978. fogColor: gl.getUniformLocation( program, 'fogColor' ),
  21979. fogDepth: gl.getUniformLocation( program, 'fogDepth' ),
  21980. alphaTest: gl.getUniformLocation( program, 'alphaTest' )
  21981. };
  21982. var canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  21983. canvas.width = 8;
  21984. canvas.height = 8;
  21985. var context = canvas.getContext( '2d' );
  21986. context.fillStyle = 'white';
  21987. context.fillRect( 0, 0, 8, 8 );
  21988. texture = new CanvasTexture( canvas );
  21989. }
  21990. this.render = function ( sprites, scene, camera ) {
  21991. if ( sprites.length === 0 ) return;
  21992. // setup gl
  21993. if ( program === undefined ) {
  21994. init();
  21995. }
  21996. state.useProgram( program );
  21997. state.initAttributes();
  21998. state.enableAttribute( attributes.position );
  21999. state.enableAttribute( attributes.uv );
  22000. state.disableUnusedAttributes();
  22001. state.disable( gl.CULL_FACE );
  22002. state.enable( gl.BLEND );
  22003. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  22004. gl.vertexAttribPointer( attributes.position, 2, gl.FLOAT, false, 2 * 8, 0 );
  22005. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  22006. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  22007. gl.uniformMatrix4fv( uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  22008. state.activeTexture( gl.TEXTURE0 );
  22009. gl.uniform1i( uniforms.map, 0 );
  22010. var oldFogType = 0;
  22011. var sceneFogType = 0;
  22012. var fog = scene.fog;
  22013. if ( fog ) {
  22014. gl.uniform3f( uniforms.fogColor, fog.color.r, fog.color.g, fog.color.b );
  22015. if ( fog.isFog ) {
  22016. gl.uniform1f( uniforms.fogNear, fog.near );
  22017. gl.uniform1f( uniforms.fogFar, fog.far );
  22018. gl.uniform1i( uniforms.fogType, 1 );
  22019. oldFogType = 1;
  22020. sceneFogType = 1;
  22021. } else if ( fog.isFogExp2 ) {
  22022. gl.uniform1f( uniforms.fogDensity, fog.density );
  22023. gl.uniform1i( uniforms.fogType, 2 );
  22024. oldFogType = 2;
  22025. sceneFogType = 2;
  22026. }
  22027. } else {
  22028. gl.uniform1i( uniforms.fogType, 0 );
  22029. oldFogType = 0;
  22030. sceneFogType = 0;
  22031. }
  22032. // update positions and sort
  22033. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  22034. var sprite = sprites[ i ];
  22035. sprite.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, sprite.matrixWorld );
  22036. sprite.z = - sprite.modelViewMatrix.elements[ 14 ];
  22037. }
  22038. sprites.sort( painterSortStable );
  22039. // render all sprites
  22040. var scale = [];
  22041. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  22042. var sprite = sprites[ i ];
  22043. var material = sprite.material;
  22044. if ( material.visible === false ) continue;
  22045. sprite.onBeforeRender( renderer, scene, camera, undefined, material, undefined );
  22046. gl.uniform1f( uniforms.alphaTest, material.alphaTest );
  22047. gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, sprite.modelViewMatrix.elements );
  22048. sprite.matrixWorld.decompose( spritePosition, spriteRotation, spriteScale );
  22049. scale[ 0 ] = spriteScale.x;
  22050. scale[ 1 ] = spriteScale.y;
  22051. var fogType = 0;
  22052. if ( scene.fog && material.fog ) {
  22053. fogType = sceneFogType;
  22054. }
  22055. if ( oldFogType !== fogType ) {
  22056. gl.uniform1i( uniforms.fogType, fogType );
  22057. oldFogType = fogType;
  22058. }
  22059. if ( material.map !== null ) {
  22060. gl.uniform2f( uniforms.uvOffset, material.map.offset.x, material.map.offset.y );
  22061. gl.uniform2f( uniforms.uvScale, material.map.repeat.x, material.map.repeat.y );
  22062. } else {
  22063. gl.uniform2f( uniforms.uvOffset, 0, 0 );
  22064. gl.uniform2f( uniforms.uvScale, 1, 1 );
  22065. }
  22066. gl.uniform1f( uniforms.opacity, material.opacity );
  22067. gl.uniform3f( uniforms.color, material.color.r, material.color.g, material.color.b );
  22068. gl.uniform1f( uniforms.rotation, material.rotation );
  22069. gl.uniform2fv( uniforms.scale, scale );
  22070. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha );
  22071. state.buffers.depth.setTest( material.depthTest );
  22072. state.buffers.depth.setMask( material.depthWrite );
  22073. state.buffers.color.setMask( material.colorWrite );
  22074. textures.setTexture2D( material.map || texture, 0 );
  22075. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  22076. sprite.onAfterRender( renderer, scene, camera, undefined, material, undefined );
  22077. }
  22078. // restore gl
  22079. state.enable( gl.CULL_FACE );
  22080. state.reset();
  22081. };
  22082. function createProgram() {
  22083. var program = gl.createProgram();
  22084. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  22085. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  22086. gl.shaderSource( vertexShader, [
  22087. 'precision ' + capabilities.precision + ' float;',
  22088. '#define SHADER_NAME ' + 'SpriteMaterial',
  22089. 'uniform mat4 modelViewMatrix;',
  22090. 'uniform mat4 projectionMatrix;',
  22091. 'uniform float rotation;',
  22092. 'uniform vec2 scale;',
  22093. 'uniform vec2 uvOffset;',
  22094. 'uniform vec2 uvScale;',
  22095. 'attribute vec2 position;',
  22096. 'attribute vec2 uv;',
  22097. 'varying vec2 vUV;',
  22098. 'varying float fogDepth;',
  22099. 'void main() {',
  22100. ' vUV = uvOffset + uv * uvScale;',
  22101. ' vec2 alignedPosition = position * scale;',
  22102. ' vec2 rotatedPosition;',
  22103. ' rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;',
  22104. ' rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;',
  22105. ' vec4 mvPosition;',
  22106. ' mvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );',
  22107. ' mvPosition.xy += rotatedPosition;',
  22108. ' gl_Position = projectionMatrix * mvPosition;',
  22109. ' fogDepth = - mvPosition.z;',
  22110. '}'
  22111. ].join( '\n' ) );
  22112. gl.shaderSource( fragmentShader, [
  22113. 'precision ' + capabilities.precision + ' float;',
  22114. '#define SHADER_NAME ' + 'SpriteMaterial',
  22115. 'uniform vec3 color;',
  22116. 'uniform sampler2D map;',
  22117. 'uniform float opacity;',
  22118. 'uniform int fogType;',
  22119. 'uniform vec3 fogColor;',
  22120. 'uniform float fogDensity;',
  22121. 'uniform float fogNear;',
  22122. 'uniform float fogFar;',
  22123. 'uniform float alphaTest;',
  22124. 'varying vec2 vUV;',
  22125. 'varying float fogDepth;',
  22126. 'void main() {',
  22127. ' vec4 texture = texture2D( map, vUV );',
  22128. ' gl_FragColor = vec4( color * texture.xyz, texture.a * opacity );',
  22129. ' if ( gl_FragColor.a < alphaTest ) discard;',
  22130. ' if ( fogType > 0 ) {',
  22131. ' float fogFactor = 0.0;',
  22132. ' if ( fogType == 1 ) {',
  22133. ' fogFactor = smoothstep( fogNear, fogFar, fogDepth );',
  22134. ' } else {',
  22135. ' const float LOG2 = 1.442695;',
  22136. ' fogFactor = exp2( - fogDensity * fogDensity * fogDepth * fogDepth * LOG2 );',
  22137. ' fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );',
  22138. ' }',
  22139. ' gl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );',
  22140. ' }',
  22141. '}'
  22142. ].join( '\n' ) );
  22143. gl.compileShader( vertexShader );
  22144. gl.compileShader( fragmentShader );
  22145. gl.attachShader( program, vertexShader );
  22146. gl.attachShader( program, fragmentShader );
  22147. gl.linkProgram( program );
  22148. return program;
  22149. }
  22150. function painterSortStable( a, b ) {
  22151. if ( a.renderOrder !== b.renderOrder ) {
  22152. return a.renderOrder - b.renderOrder;
  22153. } else if ( a.z !== b.z ) {
  22154. return b.z - a.z;
  22155. } else {
  22156. return b.id - a.id;
  22157. }
  22158. }
  22159. }
  22160. function Frustum( p0, p1, p2, p3, p4, p5 ) {
  22161. this.planes = [
  22162. ( p0 !== undefined ) ? p0 : new Plane(),
  22163. ( p1 !== undefined ) ? p1 : new Plane(),
  22164. ( p2 !== undefined ) ? p2 : new Plane(),
  22165. ( p3 !== undefined ) ? p3 : new Plane(),
  22166. ( p4 !== undefined ) ? p4 : new Plane(),
  22167. ( p5 !== undefined ) ? p5 : new Plane()
  22168. ];
  22169. }
  22170. Object.assign( Frustum.prototype, {
  22171. set: function ( p0, p1, p2, p3, p4, p5 ) {
  22172. var planes = this.planes;
  22173. planes[ 0 ].copy( p0 );
  22174. planes[ 1 ].copy( p1 );
  22175. planes[ 2 ].copy( p2 );
  22176. planes[ 3 ].copy( p3 );
  22177. planes[ 4 ].copy( p4 );
  22178. planes[ 5 ].copy( p5 );
  22179. return this;
  22180. },
  22181. clone: function () {
  22182. return new this.constructor().copy( this );
  22183. },
  22184. copy: function ( frustum ) {
  22185. var planes = this.planes;
  22186. for ( var i = 0; i < 6; i ++ ) {
  22187. planes[ i ].copy( frustum.planes[ i ] );
  22188. }
  22189. return this;
  22190. },
  22191. setFromMatrix: function ( m ) {
  22192. var planes = this.planes;
  22193. var me = m.elements;
  22194. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  22195. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  22196. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  22197. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  22198. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  22199. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  22200. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  22201. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  22202. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  22203. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  22204. return this;
  22205. },
  22206. intersectsObject: function () {
  22207. var sphere = new Sphere();
  22208. return function intersectsObject( object ) {
  22209. var geometry = object.geometry;
  22210. if ( geometry.boundingSphere === null )
  22211. geometry.computeBoundingSphere();
  22212. sphere.copy( geometry.boundingSphere )
  22213. .applyMatrix4( object.matrixWorld );
  22214. return this.intersectsSphere( sphere );
  22215. };
  22216. }(),
  22217. intersectsSprite: function () {
  22218. var sphere = new Sphere();
  22219. return function intersectsSprite( sprite ) {
  22220. sphere.center.set( 0, 0, 0 );
  22221. sphere.radius = 0.7071067811865476;
  22222. sphere.applyMatrix4( sprite.matrixWorld );
  22223. return this.intersectsSphere( sphere );
  22224. };
  22225. }(),
  22226. intersectsSphere: function ( sphere ) {
  22227. var planes = this.planes;
  22228. var center = sphere.center;
  22229. var negRadius = - sphere.radius;
  22230. for ( var i = 0; i < 6; i ++ ) {
  22231. var distance = planes[ i ].distanceToPoint( center );
  22232. if ( distance < negRadius ) {
  22233. return false;
  22234. }
  22235. }
  22236. return true;
  22237. },
  22238. intersectsBox: function () {
  22239. var p1 = new Vector3(),
  22240. p2 = new Vector3();
  22241. return function intersectsBox( box ) {
  22242. var planes = this.planes;
  22243. for ( var i = 0; i < 6; i ++ ) {
  22244. var plane = planes[ i ];
  22245. p1.x = plane.normal.x > 0 ? box.min.x : box.max.x;
  22246. p2.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  22247. p1.y = plane.normal.y > 0 ? box.min.y : box.max.y;
  22248. p2.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  22249. p1.z = plane.normal.z > 0 ? box.min.z : box.max.z;
  22250. p2.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  22251. var d1 = plane.distanceToPoint( p1 );
  22252. var d2 = plane.distanceToPoint( p2 );
  22253. // if both outside plane, no intersection
  22254. if ( d1 < 0 && d2 < 0 ) {
  22255. return false;
  22256. }
  22257. }
  22258. return true;
  22259. };
  22260. }(),
  22261. containsPoint: function ( point ) {
  22262. var planes = this.planes;
  22263. for ( var i = 0; i < 6; i ++ ) {
  22264. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  22265. return false;
  22266. }
  22267. }
  22268. return true;
  22269. }
  22270. } );
  22271. /**
  22272. * @author alteredq / http://alteredqualia.com/
  22273. * @author mrdoob / http://mrdoob.com/
  22274. */
  22275. function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
  22276. var _frustum = new Frustum(),
  22277. _projScreenMatrix = new Matrix4(),
  22278. _shadowMapSize = new Vector2(),
  22279. _maxShadowMapSize = new Vector2( maxTextureSize, maxTextureSize ),
  22280. _lookTarget = new Vector3(),
  22281. _lightPositionWorld = new Vector3(),
  22282. _MorphingFlag = 1,
  22283. _SkinningFlag = 2,
  22284. _NumberOfMaterialVariants = ( _MorphingFlag | _SkinningFlag ) + 1,
  22285. _depthMaterials = new Array( _NumberOfMaterialVariants ),
  22286. _distanceMaterials = new Array( _NumberOfMaterialVariants ),
  22287. _materialCache = {};
  22288. var cubeDirections = [
  22289. new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ),
  22290. new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 )
  22291. ];
  22292. var cubeUps = [
  22293. new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ),
  22294. new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 )
  22295. ];
  22296. var cube2DViewPorts = [
  22297. new Vector4(), new Vector4(), new Vector4(),
  22298. new Vector4(), new Vector4(), new Vector4()
  22299. ];
  22300. // init
  22301. for ( var i = 0; i !== _NumberOfMaterialVariants; ++ i ) {
  22302. var useMorphing = ( i & _MorphingFlag ) !== 0;
  22303. var useSkinning = ( i & _SkinningFlag ) !== 0;
  22304. var depthMaterial = new MeshDepthMaterial( {
  22305. depthPacking: RGBADepthPacking,
  22306. morphTargets: useMorphing,
  22307. skinning: useSkinning
  22308. } );
  22309. _depthMaterials[ i ] = depthMaterial;
  22310. //
  22311. var distanceMaterial = new MeshDistanceMaterial( {
  22312. morphTargets: useMorphing,
  22313. skinning: useSkinning
  22314. } );
  22315. _distanceMaterials[ i ] = distanceMaterial;
  22316. }
  22317. //
  22318. var scope = this;
  22319. this.enabled = false;
  22320. this.autoUpdate = true;
  22321. this.needsUpdate = false;
  22322. this.type = PCFShadowMap;
  22323. this.renderReverseSided = true;
  22324. this.renderSingleSided = true;
  22325. this.render = function ( lights, scene, camera ) {
  22326. if ( scope.enabled === false ) return;
  22327. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  22328. if ( lights.length === 0 ) return;
  22329. // TODO Clean up (needed in case of contextlost)
  22330. var _gl = _renderer.context;
  22331. var _state = _renderer.state;
  22332. // Set GL state for depth map.
  22333. _state.disable( _gl.BLEND );
  22334. _state.buffers.color.setClear( 1, 1, 1, 1 );
  22335. _state.buffers.depth.setTest( true );
  22336. _state.setScissorTest( false );
  22337. // render depth map
  22338. var faceCount;
  22339. for ( var i = 0, il = lights.length; i < il; i ++ ) {
  22340. var light = lights[ i ];
  22341. var shadow = light.shadow;
  22342. var isPointLight = light && light.isPointLight;
  22343. if ( shadow === undefined ) {
  22344. console.warn( 'THREE.WebGLShadowMap:', light, 'has no shadow.' );
  22345. continue;
  22346. }
  22347. var shadowCamera = shadow.camera;
  22348. _shadowMapSize.copy( shadow.mapSize );
  22349. _shadowMapSize.min( _maxShadowMapSize );
  22350. if ( isPointLight ) {
  22351. var vpWidth = _shadowMapSize.x;
  22352. var vpHeight = _shadowMapSize.y;
  22353. // These viewports map a cube-map onto a 2D texture with the
  22354. // following orientation:
  22355. //
  22356. // xzXZ
  22357. // y Y
  22358. //
  22359. // X - Positive x direction
  22360. // x - Negative x direction
  22361. // Y - Positive y direction
  22362. // y - Negative y direction
  22363. // Z - Positive z direction
  22364. // z - Negative z direction
  22365. // positive X
  22366. cube2DViewPorts[ 0 ].set( vpWidth * 2, vpHeight, vpWidth, vpHeight );
  22367. // negative X
  22368. cube2DViewPorts[ 1 ].set( 0, vpHeight, vpWidth, vpHeight );
  22369. // positive Z
  22370. cube2DViewPorts[ 2 ].set( vpWidth * 3, vpHeight, vpWidth, vpHeight );
  22371. // negative Z
  22372. cube2DViewPorts[ 3 ].set( vpWidth, vpHeight, vpWidth, vpHeight );
  22373. // positive Y
  22374. cube2DViewPorts[ 4 ].set( vpWidth * 3, 0, vpWidth, vpHeight );
  22375. // negative Y
  22376. cube2DViewPorts[ 5 ].set( vpWidth, 0, vpWidth, vpHeight );
  22377. _shadowMapSize.x *= 4.0;
  22378. _shadowMapSize.y *= 2.0;
  22379. }
  22380. if ( shadow.map === null ) {
  22381. var pars = { minFilter: NearestFilter, magFilter: NearestFilter, format: RGBAFormat };
  22382. shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  22383. shadow.map.texture.name = light.name + ".shadowMap";
  22384. shadowCamera.updateProjectionMatrix();
  22385. }
  22386. if ( shadow.isSpotLightShadow ) {
  22387. shadow.update( light );
  22388. }
  22389. var shadowMap = shadow.map;
  22390. var shadowMatrix = shadow.matrix;
  22391. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  22392. shadowCamera.position.copy( _lightPositionWorld );
  22393. if ( isPointLight ) {
  22394. faceCount = 6;
  22395. // for point lights we set the shadow matrix to be a translation-only matrix
  22396. // equal to inverse of the light's position
  22397. shadowMatrix.makeTranslation( - _lightPositionWorld.x, - _lightPositionWorld.y, - _lightPositionWorld.z );
  22398. } else {
  22399. faceCount = 1;
  22400. _lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  22401. shadowCamera.lookAt( _lookTarget );
  22402. shadowCamera.updateMatrixWorld();
  22403. // compute shadow matrix
  22404. shadowMatrix.set(
  22405. 0.5, 0.0, 0.0, 0.5,
  22406. 0.0, 0.5, 0.0, 0.5,
  22407. 0.0, 0.0, 0.5, 0.5,
  22408. 0.0, 0.0, 0.0, 1.0
  22409. );
  22410. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  22411. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  22412. }
  22413. _renderer.setRenderTarget( shadowMap );
  22414. _renderer.clear();
  22415. // render shadow map for each cube face (if omni-directional) or
  22416. // run a single pass if not
  22417. for ( var face = 0; face < faceCount; face ++ ) {
  22418. if ( isPointLight ) {
  22419. _lookTarget.copy( shadowCamera.position );
  22420. _lookTarget.add( cubeDirections[ face ] );
  22421. shadowCamera.up.copy( cubeUps[ face ] );
  22422. shadowCamera.lookAt( _lookTarget );
  22423. shadowCamera.updateMatrixWorld();
  22424. var vpDimensions = cube2DViewPorts[ face ];
  22425. _state.viewport( vpDimensions );
  22426. }
  22427. // update camera matrices and frustum
  22428. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  22429. _frustum.setFromMatrix( _projScreenMatrix );
  22430. // set object matrices & frustum culling
  22431. renderObject( scene, camera, shadowCamera, isPointLight );
  22432. }
  22433. }
  22434. scope.needsUpdate = false;
  22435. };
  22436. function getDepthMaterial( object, material, isPointLight, lightPositionWorld, shadowCameraNear, shadowCameraFar ) {
  22437. var geometry = object.geometry;
  22438. var result = null;
  22439. var materialVariants = _depthMaterials;
  22440. var customMaterial = object.customDepthMaterial;
  22441. if ( isPointLight ) {
  22442. materialVariants = _distanceMaterials;
  22443. customMaterial = object.customDistanceMaterial;
  22444. }
  22445. if ( ! customMaterial ) {
  22446. var useMorphing = false;
  22447. if ( material.morphTargets ) {
  22448. if ( geometry && geometry.isBufferGeometry ) {
  22449. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  22450. } else if ( geometry && geometry.isGeometry ) {
  22451. useMorphing = geometry.morphTargets && geometry.morphTargets.length > 0;
  22452. }
  22453. }
  22454. if ( object.isSkinnedMesh && material.skinning === false ) {
  22455. console.warn( 'THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object );
  22456. }
  22457. var useSkinning = object.isSkinnedMesh && material.skinning;
  22458. var variantIndex = 0;
  22459. if ( useMorphing ) variantIndex |= _MorphingFlag;
  22460. if ( useSkinning ) variantIndex |= _SkinningFlag;
  22461. result = materialVariants[ variantIndex ];
  22462. } else {
  22463. result = customMaterial;
  22464. }
  22465. if ( _renderer.localClippingEnabled &&
  22466. material.clipShadows === true &&
  22467. material.clippingPlanes.length !== 0 ) {
  22468. // in this case we need a unique material instance reflecting the
  22469. // appropriate state
  22470. var keyA = result.uuid, keyB = material.uuid;
  22471. var materialsForVariant = _materialCache[ keyA ];
  22472. if ( materialsForVariant === undefined ) {
  22473. materialsForVariant = {};
  22474. _materialCache[ keyA ] = materialsForVariant;
  22475. }
  22476. var cachedMaterial = materialsForVariant[ keyB ];
  22477. if ( cachedMaterial === undefined ) {
  22478. cachedMaterial = result.clone();
  22479. materialsForVariant[ keyB ] = cachedMaterial;
  22480. }
  22481. result = cachedMaterial;
  22482. }
  22483. result.visible = material.visible;
  22484. result.wireframe = material.wireframe;
  22485. var side = material.side;
  22486. if ( scope.renderSingleSided && side == DoubleSide ) {
  22487. side = FrontSide;
  22488. }
  22489. if ( scope.renderReverseSided ) {
  22490. if ( side === FrontSide ) side = BackSide;
  22491. else if ( side === BackSide ) side = FrontSide;
  22492. }
  22493. result.side = side;
  22494. result.clipShadows = material.clipShadows;
  22495. result.clippingPlanes = material.clippingPlanes;
  22496. result.clipIntersection = material.clipIntersection;
  22497. result.wireframeLinewidth = material.wireframeLinewidth;
  22498. result.linewidth = material.linewidth;
  22499. if ( isPointLight && result.isMeshDistanceMaterial ) {
  22500. result.referencePosition.copy( lightPositionWorld );
  22501. result.nearDistance = shadowCameraNear;
  22502. result.farDistance = shadowCameraFar;
  22503. }
  22504. return result;
  22505. }
  22506. function renderObject( object, camera, shadowCamera, isPointLight ) {
  22507. if ( object.visible === false ) return;
  22508. var visible = object.layers.test( camera.layers );
  22509. if ( visible && ( object.isMesh || object.isLine || object.isPoints ) ) {
  22510. if ( object.castShadow && ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) ) {
  22511. object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  22512. var geometry = _objects.update( object );
  22513. var material = object.material;
  22514. if ( Array.isArray( material ) ) {
  22515. var groups = geometry.groups;
  22516. for ( var k = 0, kl = groups.length; k < kl; k ++ ) {
  22517. var group = groups[ k ];
  22518. var groupMaterial = material[ group.materialIndex ];
  22519. if ( groupMaterial && groupMaterial.visible ) {
  22520. var depthMaterial = getDepthMaterial( object, groupMaterial, isPointLight, _lightPositionWorld, shadowCamera.near, shadowCamera.far );
  22521. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group );
  22522. }
  22523. }
  22524. } else if ( material.visible ) {
  22525. var depthMaterial = getDepthMaterial( object, material, isPointLight, _lightPositionWorld, shadowCamera.near, shadowCamera.far );
  22526. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null );
  22527. }
  22528. }
  22529. }
  22530. var children = object.children;
  22531. for ( var i = 0, l = children.length; i < l; i ++ ) {
  22532. renderObject( children[ i ], camera, shadowCamera, isPointLight );
  22533. }
  22534. }
  22535. }
  22536. /**
  22537. * @author mrdoob / http://mrdoob.com/
  22538. */
  22539. function WebGLAttributes( gl ) {
  22540. var buffers = {};
  22541. function createBuffer( attribute, bufferType ) {
  22542. var array = attribute.array;
  22543. var usage = attribute.dynamic ? gl.DYNAMIC_DRAW : gl.STATIC_DRAW;
  22544. var buffer = gl.createBuffer();
  22545. gl.bindBuffer( bufferType, buffer );
  22546. gl.bufferData( bufferType, array, usage );
  22547. attribute.onUploadCallback();
  22548. var type = gl.FLOAT;
  22549. if ( array instanceof Float32Array ) {
  22550. type = gl.FLOAT;
  22551. } else if ( array instanceof Float64Array ) {
  22552. console.warn( 'THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.' );
  22553. } else if ( array instanceof Uint16Array ) {
  22554. type = gl.UNSIGNED_SHORT;
  22555. } else if ( array instanceof Int16Array ) {
  22556. type = gl.SHORT;
  22557. } else if ( array instanceof Uint32Array ) {
  22558. type = gl.UNSIGNED_INT;
  22559. } else if ( array instanceof Int32Array ) {
  22560. type = gl.INT;
  22561. } else if ( array instanceof Int8Array ) {
  22562. type = gl.BYTE;
  22563. } else if ( array instanceof Uint8Array ) {
  22564. type = gl.UNSIGNED_BYTE;
  22565. }
  22566. return {
  22567. buffer: buffer,
  22568. type: type,
  22569. bytesPerElement: array.BYTES_PER_ELEMENT,
  22570. version: attribute.version
  22571. };
  22572. }
  22573. function updateBuffer( buffer, attribute, bufferType ) {
  22574. var array = attribute.array;
  22575. var updateRange = attribute.updateRange;
  22576. gl.bindBuffer( bufferType, buffer );
  22577. if ( attribute.dynamic === false ) {
  22578. gl.bufferData( bufferType, array, gl.STATIC_DRAW );
  22579. } else if ( updateRange.count === - 1 ) {
  22580. // Not using update ranges
  22581. gl.bufferSubData( bufferType, 0, array );
  22582. } else if ( updateRange.count === 0 ) {
  22583. console.error( 'THREE.WebGLObjects.updateBuffer: dynamic THREE.BufferAttribute marked as needsUpdate but updateRange.count is 0, ensure you are using set methods or updating manually.' );
  22584. } else {
  22585. gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
  22586. array.subarray( updateRange.offset, updateRange.offset + updateRange.count ) );
  22587. updateRange.count = - 1; // reset range
  22588. }
  22589. }
  22590. //
  22591. function get( attribute ) {
  22592. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  22593. return buffers[ attribute.uuid ];
  22594. }
  22595. function remove( attribute ) {
  22596. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  22597. var data = buffers[ attribute.uuid ];
  22598. if ( data ) {
  22599. gl.deleteBuffer( data.buffer );
  22600. delete buffers[ attribute.uuid ];
  22601. }
  22602. }
  22603. function update( attribute, bufferType ) {
  22604. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  22605. var data = buffers[ attribute.uuid ];
  22606. if ( data === undefined ) {
  22607. buffers[ attribute.uuid ] = createBuffer( attribute, bufferType );
  22608. } else if ( data.version < attribute.version ) {
  22609. updateBuffer( data.buffer, attribute, bufferType );
  22610. data.version = attribute.version;
  22611. }
  22612. }
  22613. return {
  22614. get: get,
  22615. remove: remove,
  22616. update: update
  22617. };
  22618. }
  22619. /**
  22620. * @author mrdoob / http://mrdoob.com/
  22621. * @author Mugen87 / https://github.com/Mugen87
  22622. */
  22623. function PlaneGeometry( width, height, widthSegments, heightSegments ) {
  22624. Geometry.call( this );
  22625. this.type = 'PlaneGeometry';
  22626. this.parameters = {
  22627. width: width,
  22628. height: height,
  22629. widthSegments: widthSegments,
  22630. heightSegments: heightSegments
  22631. };
  22632. this.fromBufferGeometry( new PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  22633. this.mergeVertices();
  22634. }
  22635. PlaneGeometry.prototype = Object.create( Geometry.prototype );
  22636. PlaneGeometry.prototype.constructor = PlaneGeometry;
  22637. // PlaneBufferGeometry
  22638. function PlaneBufferGeometry( width, height, widthSegments, heightSegments ) {
  22639. BufferGeometry.call( this );
  22640. this.type = 'PlaneBufferGeometry';
  22641. this.parameters = {
  22642. width: width,
  22643. height: height,
  22644. widthSegments: widthSegments,
  22645. heightSegments: heightSegments
  22646. };
  22647. width = width || 1;
  22648. height = height || 1;
  22649. var width_half = width / 2;
  22650. var height_half = height / 2;
  22651. var gridX = Math.floor( widthSegments ) || 1;
  22652. var gridY = Math.floor( heightSegments ) || 1;
  22653. var gridX1 = gridX + 1;
  22654. var gridY1 = gridY + 1;
  22655. var segment_width = width / gridX;
  22656. var segment_height = height / gridY;
  22657. var ix, iy;
  22658. // buffers
  22659. var indices = [];
  22660. var vertices = [];
  22661. var normals = [];
  22662. var uvs = [];
  22663. // generate vertices, normals and uvs
  22664. for ( iy = 0; iy < gridY1; iy ++ ) {
  22665. var y = iy * segment_height - height_half;
  22666. for ( ix = 0; ix < gridX1; ix ++ ) {
  22667. var x = ix * segment_width - width_half;
  22668. vertices.push( x, - y, 0 );
  22669. normals.push( 0, 0, 1 );
  22670. uvs.push( ix / gridX );
  22671. uvs.push( 1 - ( iy / gridY ) );
  22672. }
  22673. }
  22674. // indices
  22675. for ( iy = 0; iy < gridY; iy ++ ) {
  22676. for ( ix = 0; ix < gridX; ix ++ ) {
  22677. var a = ix + gridX1 * iy;
  22678. var b = ix + gridX1 * ( iy + 1 );
  22679. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  22680. var d = ( ix + 1 ) + gridX1 * iy;
  22681. // faces
  22682. indices.push( a, b, d );
  22683. indices.push( b, c, d );
  22684. }
  22685. }
  22686. // build geometry
  22687. this.setIndex( indices );
  22688. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  22689. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  22690. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  22691. }
  22692. PlaneBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  22693. PlaneBufferGeometry.prototype.constructor = PlaneBufferGeometry;
  22694. /**
  22695. * @author mrdoob / http://mrdoob.com/
  22696. */
  22697. function WebGLBackground( renderer, state, geometries, premultipliedAlpha ) {
  22698. var clearColor = new Color( 0x000000 );
  22699. var clearAlpha = 0;
  22700. var planeCamera, planeMesh;
  22701. var boxMesh;
  22702. function render( renderList, scene, camera, forceClear ) {
  22703. var background = scene.background;
  22704. if ( background === null ) {
  22705. setClear( clearColor, clearAlpha );
  22706. } else if ( background && background.isColor ) {
  22707. setClear( background, 1 );
  22708. forceClear = true;
  22709. }
  22710. if ( renderer.autoClear || forceClear ) {
  22711. renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil );
  22712. }
  22713. if ( background && background.isCubeTexture ) {
  22714. if ( boxMesh === undefined ) {
  22715. boxMesh = new Mesh(
  22716. new BoxBufferGeometry( 1, 1, 1 ),
  22717. new ShaderMaterial( {
  22718. uniforms: ShaderLib.cube.uniforms,
  22719. vertexShader: ShaderLib.cube.vertexShader,
  22720. fragmentShader: ShaderLib.cube.fragmentShader,
  22721. side: BackSide,
  22722. depthTest: true,
  22723. depthWrite: false,
  22724. fog: false
  22725. } )
  22726. );
  22727. boxMesh.geometry.removeAttribute( 'normal' );
  22728. boxMesh.geometry.removeAttribute( 'uv' );
  22729. boxMesh.onBeforeRender = function ( renderer, scene, camera ) {
  22730. this.matrixWorld.copyPosition( camera.matrixWorld );
  22731. };
  22732. geometries.update( boxMesh.geometry );
  22733. }
  22734. boxMesh.material.uniforms.tCube.value = background;
  22735. renderList.push( boxMesh, boxMesh.geometry, boxMesh.material, 0, null );
  22736. } else if ( background && background.isTexture ) {
  22737. if ( planeCamera === undefined ) {
  22738. planeCamera = new OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
  22739. planeMesh = new Mesh(
  22740. new PlaneBufferGeometry( 2, 2 ),
  22741. new MeshBasicMaterial( { depthTest: false, depthWrite: false, fog: false } )
  22742. );
  22743. geometries.update( planeMesh.geometry );
  22744. }
  22745. planeMesh.material.map = background;
  22746. // TODO Push this to renderList
  22747. renderer.renderBufferDirect( planeCamera, null, planeMesh.geometry, planeMesh.material, planeMesh, null );
  22748. }
  22749. }
  22750. function setClear( color, alpha ) {
  22751. state.buffers.color.setClear( color.r, color.g, color.b, alpha, premultipliedAlpha );
  22752. }
  22753. return {
  22754. getClearColor: function () {
  22755. return clearColor;
  22756. },
  22757. setClearColor: function ( color, alpha ) {
  22758. clearColor.set( color );
  22759. clearAlpha = alpha !== undefined ? alpha : 1;
  22760. setClear( clearColor, clearAlpha );
  22761. },
  22762. getClearAlpha: function () {
  22763. return clearAlpha;
  22764. },
  22765. setClearAlpha: function ( alpha ) {
  22766. clearAlpha = alpha;
  22767. setClear( clearColor, clearAlpha );
  22768. },
  22769. render: render
  22770. };
  22771. }
  22772. /**
  22773. * @author mrdoob / http://mrdoob.com/
  22774. */
  22775. function painterSortStable( a, b ) {
  22776. if ( a.renderOrder !== b.renderOrder ) {
  22777. return a.renderOrder - b.renderOrder;
  22778. } else if ( a.program && b.program && a.program !== b.program ) {
  22779. return a.program.id - b.program.id;
  22780. } else if ( a.material.id !== b.material.id ) {
  22781. return a.material.id - b.material.id;
  22782. } else if ( a.z !== b.z ) {
  22783. return a.z - b.z;
  22784. } else {
  22785. return a.id - b.id;
  22786. }
  22787. }
  22788. function reversePainterSortStable( a, b ) {
  22789. if ( a.renderOrder !== b.renderOrder ) {
  22790. return a.renderOrder - b.renderOrder;
  22791. } if ( a.z !== b.z ) {
  22792. return b.z - a.z;
  22793. } else {
  22794. return a.id - b.id;
  22795. }
  22796. }
  22797. function WebGLRenderList() {
  22798. var renderItems = [];
  22799. var renderItemsIndex = 0;
  22800. var opaque = [];
  22801. var transparent = [];
  22802. function init() {
  22803. renderItemsIndex = 0;
  22804. opaque.length = 0;
  22805. transparent.length = 0;
  22806. }
  22807. function push( object, geometry, material, z, group ) {
  22808. var renderItem = renderItems[ renderItemsIndex ];
  22809. if ( renderItem === undefined ) {
  22810. renderItem = {
  22811. id: object.id,
  22812. object: object,
  22813. geometry: geometry,
  22814. material: material,
  22815. program: material.program,
  22816. renderOrder: object.renderOrder,
  22817. z: z,
  22818. group: group
  22819. };
  22820. renderItems[ renderItemsIndex ] = renderItem;
  22821. } else {
  22822. renderItem.id = object.id;
  22823. renderItem.object = object;
  22824. renderItem.geometry = geometry;
  22825. renderItem.material = material;
  22826. renderItem.program = material.program;
  22827. renderItem.renderOrder = object.renderOrder;
  22828. renderItem.z = z;
  22829. renderItem.group = group;
  22830. }
  22831. ( material.transparent === true ? transparent : opaque ).push( renderItem );
  22832. renderItemsIndex ++;
  22833. }
  22834. function sort() {
  22835. if ( opaque.length > 1 ) opaque.sort( painterSortStable );
  22836. if ( transparent.length > 1 ) transparent.sort( reversePainterSortStable );
  22837. }
  22838. return {
  22839. opaque: opaque,
  22840. transparent: transparent,
  22841. init: init,
  22842. push: push,
  22843. sort: sort
  22844. };
  22845. }
  22846. function WebGLRenderLists() {
  22847. var lists = {};
  22848. function get( scene, camera ) {
  22849. var hash = scene.id + ',' + camera.id;
  22850. var list = lists[ hash ];
  22851. if ( list === undefined ) {
  22852. // console.log( 'THREE.WebGLRenderLists:', hash );
  22853. list = new WebGLRenderList();
  22854. lists[ hash ] = list;
  22855. }
  22856. return list;
  22857. }
  22858. function dispose() {
  22859. lists = {};
  22860. }
  22861. return {
  22862. get: get,
  22863. dispose: dispose
  22864. };
  22865. }
  22866. /**
  22867. * @author mrdoob / http://mrdoob.com/
  22868. */
  22869. function absNumericalSort( a, b ) {
  22870. return Math.abs( b[ 1 ] ) - Math.abs( a[ 1 ] );
  22871. }
  22872. function WebGLMorphtargets( gl ) {
  22873. var influencesList = {};
  22874. var morphInfluences = new Float32Array( 8 );
  22875. function update( object, geometry, material, program ) {
  22876. var objectInfluences = object.morphTargetInfluences;
  22877. var length = objectInfluences.length;
  22878. var influences = influencesList[ geometry.id ];
  22879. if ( influences === undefined ) {
  22880. // initialise list
  22881. influences = [];
  22882. for ( var i = 0; i < length; i ++ ) {
  22883. influences[ i ] = [ i, 0 ];
  22884. }
  22885. influencesList[ geometry.id ] = influences;
  22886. }
  22887. var morphTargets = material.morphTargets && geometry.morphAttributes.position;
  22888. var morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  22889. // Remove current morphAttributes
  22890. for ( var i = 0; i < length; i ++ ) {
  22891. var influence = influences[ i ];
  22892. if ( influence[ 1 ] !== 0 ) {
  22893. if ( morphTargets ) geometry.removeAttribute( 'morphTarget' + i );
  22894. if ( morphNormals ) geometry.removeAttribute( 'morphNormal' + i );
  22895. }
  22896. }
  22897. // Collect influences
  22898. for ( var i = 0; i < length; i ++ ) {
  22899. var influence = influences[ i ];
  22900. influence[ 0 ] = i;
  22901. influence[ 1 ] = objectInfluences[ i ];
  22902. }
  22903. influences.sort( absNumericalSort );
  22904. // Add morphAttributes
  22905. for ( var i = 0; i < 8; i ++ ) {
  22906. var influence = influences[ i ];
  22907. if ( influence ) {
  22908. var index = influence[ 0 ];
  22909. var value = influence[ 1 ];
  22910. if ( value ) {
  22911. if ( morphTargets ) geometry.addAttribute( 'morphTarget' + i, morphTargets[ index ] );
  22912. if ( morphNormals ) geometry.addAttribute( 'morphNormal' + i, morphNormals[ index ] );
  22913. morphInfluences[ i ] = value;
  22914. continue;
  22915. }
  22916. }
  22917. morphInfluences[ i ] = 0;
  22918. }
  22919. program.getUniforms().setValue( gl, 'morphTargetInfluences', morphInfluences );
  22920. }
  22921. return {
  22922. update: update
  22923. };
  22924. }
  22925. /**
  22926. * @author mrdoob / http://mrdoob.com/
  22927. */
  22928. function WebGLIndexedBufferRenderer( gl, extensions, infoRender ) {
  22929. var mode;
  22930. function setMode( value ) {
  22931. mode = value;
  22932. }
  22933. var type, bytesPerElement;
  22934. function setIndex( value ) {
  22935. type = value.type;
  22936. bytesPerElement = value.bytesPerElement;
  22937. }
  22938. function render( start, count ) {
  22939. gl.drawElements( mode, count, type, start * bytesPerElement );
  22940. infoRender.calls ++;
  22941. infoRender.vertices += count;
  22942. if ( mode === gl.TRIANGLES ) infoRender.faces += count / 3;
  22943. else if ( mode === gl.POINTS ) infoRender.points += count;
  22944. }
  22945. function renderInstances( geometry, start, count ) {
  22946. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  22947. if ( extension === null ) {
  22948. console.error( 'THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  22949. return;
  22950. }
  22951. extension.drawElementsInstancedANGLE( mode, count, type, start * bytesPerElement, geometry.maxInstancedCount );
  22952. infoRender.calls ++;
  22953. infoRender.vertices += count * geometry.maxInstancedCount;
  22954. if ( mode === gl.TRIANGLES ) infoRender.faces += geometry.maxInstancedCount * count / 3;
  22955. else if ( mode === gl.POINTS ) infoRender.points += geometry.maxInstancedCount * count;
  22956. }
  22957. //
  22958. this.setMode = setMode;
  22959. this.setIndex = setIndex;
  22960. this.render = render;
  22961. this.renderInstances = renderInstances;
  22962. }
  22963. /**
  22964. * @author mrdoob / http://mrdoob.com/
  22965. */
  22966. function WebGLBufferRenderer( gl, extensions, infoRender ) {
  22967. var mode;
  22968. function setMode( value ) {
  22969. mode = value;
  22970. }
  22971. function render( start, count ) {
  22972. gl.drawArrays( mode, start, count );
  22973. infoRender.calls ++;
  22974. infoRender.vertices += count;
  22975. if ( mode === gl.TRIANGLES ) infoRender.faces += count / 3;
  22976. else if ( mode === gl.POINTS ) infoRender.points += count;
  22977. }
  22978. function renderInstances( geometry, start, count ) {
  22979. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  22980. if ( extension === null ) {
  22981. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  22982. return;
  22983. }
  22984. var position = geometry.attributes.position;
  22985. if ( position.isInterleavedBufferAttribute ) {
  22986. count = position.data.count;
  22987. extension.drawArraysInstancedANGLE( mode, 0, count, geometry.maxInstancedCount );
  22988. } else {
  22989. extension.drawArraysInstancedANGLE( mode, start, count, geometry.maxInstancedCount );
  22990. }
  22991. infoRender.calls ++;
  22992. infoRender.vertices += count * geometry.maxInstancedCount;
  22993. if ( mode === gl.TRIANGLES ) infoRender.faces += geometry.maxInstancedCount * count / 3;
  22994. else if ( mode === gl.POINTS ) infoRender.points += geometry.maxInstancedCount * count;
  22995. }
  22996. //
  22997. this.setMode = setMode;
  22998. this.render = render;
  22999. this.renderInstances = renderInstances;
  23000. }
  23001. /**
  23002. * @author mrdoob / http://mrdoob.com/
  23003. */
  23004. function WebGLGeometries( gl, attributes, infoMemory ) {
  23005. var geometries = {};
  23006. var wireframeAttributes = {};
  23007. function onGeometryDispose( event ) {
  23008. var geometry = event.target;
  23009. var buffergeometry = geometries[ geometry.id ];
  23010. if ( buffergeometry.index !== null ) {
  23011. attributes.remove( buffergeometry.index );
  23012. }
  23013. for ( var name in buffergeometry.attributes ) {
  23014. attributes.remove( buffergeometry.attributes[ name ] );
  23015. }
  23016. geometry.removeEventListener( 'dispose', onGeometryDispose );
  23017. delete geometries[ geometry.id ];
  23018. // TODO Remove duplicate code
  23019. var attribute = wireframeAttributes[ geometry.id ];
  23020. if ( attribute ) {
  23021. attributes.remove( attribute );
  23022. delete wireframeAttributes[ geometry.id ];
  23023. }
  23024. attribute = wireframeAttributes[ buffergeometry.id ];
  23025. if ( attribute ) {
  23026. attributes.remove( attribute );
  23027. delete wireframeAttributes[ buffergeometry.id ];
  23028. }
  23029. //
  23030. infoMemory.geometries --;
  23031. }
  23032. function get( object, geometry ) {
  23033. var buffergeometry = geometries[ geometry.id ];
  23034. if ( buffergeometry ) return buffergeometry;
  23035. geometry.addEventListener( 'dispose', onGeometryDispose );
  23036. if ( geometry.isBufferGeometry ) {
  23037. buffergeometry = geometry;
  23038. } else if ( geometry.isGeometry ) {
  23039. if ( geometry._bufferGeometry === undefined ) {
  23040. geometry._bufferGeometry = new BufferGeometry().setFromObject( object );
  23041. }
  23042. buffergeometry = geometry._bufferGeometry;
  23043. }
  23044. geometries[ geometry.id ] = buffergeometry;
  23045. infoMemory.geometries ++;
  23046. return buffergeometry;
  23047. }
  23048. function update( geometry ) {
  23049. var index = geometry.index;
  23050. var geometryAttributes = geometry.attributes;
  23051. if ( index !== null ) {
  23052. attributes.update( index, gl.ELEMENT_ARRAY_BUFFER );
  23053. }
  23054. for ( var name in geometryAttributes ) {
  23055. attributes.update( geometryAttributes[ name ], gl.ARRAY_BUFFER );
  23056. }
  23057. // morph targets
  23058. var morphAttributes = geometry.morphAttributes;
  23059. for ( var name in morphAttributes ) {
  23060. var array = morphAttributes[ name ];
  23061. for ( var i = 0, l = array.length; i < l; i ++ ) {
  23062. attributes.update( array[ i ], gl.ARRAY_BUFFER );
  23063. }
  23064. }
  23065. }
  23066. function getWireframeAttribute( geometry ) {
  23067. var attribute = wireframeAttributes[ geometry.id ];
  23068. if ( attribute ) return attribute;
  23069. var indices = [];
  23070. var geometryIndex = geometry.index;
  23071. var geometryAttributes = geometry.attributes;
  23072. // console.time( 'wireframe' );
  23073. if ( geometryIndex !== null ) {
  23074. var array = geometryIndex.array;
  23075. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  23076. var a = array[ i + 0 ];
  23077. var b = array[ i + 1 ];
  23078. var c = array[ i + 2 ];
  23079. indices.push( a, b, b, c, c, a );
  23080. }
  23081. } else {
  23082. var array = geometryAttributes.position.array;
  23083. for ( var i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  23084. var a = i + 0;
  23085. var b = i + 1;
  23086. var c = i + 2;
  23087. indices.push( a, b, b, c, c, a );
  23088. }
  23089. }
  23090. // console.timeEnd( 'wireframe' );
  23091. attribute = new ( arrayMax( indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 );
  23092. attributes.update( attribute, gl.ELEMENT_ARRAY_BUFFER );
  23093. wireframeAttributes[ geometry.id ] = attribute;
  23094. return attribute;
  23095. }
  23096. return {
  23097. get: get,
  23098. update: update,
  23099. getWireframeAttribute: getWireframeAttribute
  23100. };
  23101. }
  23102. /**
  23103. * @author mrdoob / http://mrdoob.com/
  23104. */
  23105. function UniformsCache() {
  23106. var lights = {};
  23107. return {
  23108. get: function ( light ) {
  23109. if ( lights[ light.id ] !== undefined ) {
  23110. return lights[ light.id ];
  23111. }
  23112. var uniforms;
  23113. switch ( light.type ) {
  23114. case 'DirectionalLight':
  23115. uniforms = {
  23116. direction: new Vector3(),
  23117. color: new Color(),
  23118. shadow: false,
  23119. shadowBias: 0,
  23120. shadowRadius: 1,
  23121. shadowMapSize: new Vector2()
  23122. };
  23123. break;
  23124. case 'SpotLight':
  23125. uniforms = {
  23126. position: new Vector3(),
  23127. direction: new Vector3(),
  23128. color: new Color(),
  23129. distance: 0,
  23130. coneCos: 0,
  23131. penumbraCos: 0,
  23132. decay: 0,
  23133. shadow: false,
  23134. shadowBias: 0,
  23135. shadowRadius: 1,
  23136. shadowMapSize: new Vector2()
  23137. };
  23138. break;
  23139. case 'PointLight':
  23140. uniforms = {
  23141. position: new Vector3(),
  23142. color: new Color(),
  23143. distance: 0,
  23144. decay: 0,
  23145. shadow: false,
  23146. shadowBias: 0,
  23147. shadowRadius: 1,
  23148. shadowMapSize: new Vector2(),
  23149. shadowCameraNear: 1,
  23150. shadowCameraFar: 1000
  23151. };
  23152. break;
  23153. case 'HemisphereLight':
  23154. uniforms = {
  23155. direction: new Vector3(),
  23156. skyColor: new Color(),
  23157. groundColor: new Color()
  23158. };
  23159. break;
  23160. case 'RectAreaLight':
  23161. uniforms = {
  23162. color: new Color(),
  23163. position: new Vector3(),
  23164. halfWidth: new Vector3(),
  23165. halfHeight: new Vector3()
  23166. // TODO (abelnation): set RectAreaLight shadow uniforms
  23167. };
  23168. break;
  23169. }
  23170. lights[ light.id ] = uniforms;
  23171. return uniforms;
  23172. }
  23173. };
  23174. }
  23175. function WebGLLights() {
  23176. var cache = new UniformsCache();
  23177. var state = {
  23178. hash: '',
  23179. ambient: [ 0, 0, 0 ],
  23180. directional: [],
  23181. directionalShadowMap: [],
  23182. directionalShadowMatrix: [],
  23183. spot: [],
  23184. spotShadowMap: [],
  23185. spotShadowMatrix: [],
  23186. rectArea: [],
  23187. point: [],
  23188. pointShadowMap: [],
  23189. pointShadowMatrix: [],
  23190. hemi: []
  23191. };
  23192. var vector3 = new Vector3();
  23193. var matrix4 = new Matrix4();
  23194. var matrix42 = new Matrix4();
  23195. function setup( lights, shadows, camera ) {
  23196. var r = 0, g = 0, b = 0;
  23197. var directionalLength = 0;
  23198. var pointLength = 0;
  23199. var spotLength = 0;
  23200. var rectAreaLength = 0;
  23201. var hemiLength = 0;
  23202. var viewMatrix = camera.matrixWorldInverse;
  23203. for ( var i = 0, l = lights.length; i < l; i ++ ) {
  23204. var light = lights[ i ];
  23205. var color = light.color;
  23206. var intensity = light.intensity;
  23207. var distance = light.distance;
  23208. var shadowMap = ( light.shadow && light.shadow.map ) ? light.shadow.map.texture : null;
  23209. if ( light.isAmbientLight ) {
  23210. r += color.r * intensity;
  23211. g += color.g * intensity;
  23212. b += color.b * intensity;
  23213. } else if ( light.isDirectionalLight ) {
  23214. var uniforms = cache.get( light );
  23215. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  23216. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  23217. vector3.setFromMatrixPosition( light.target.matrixWorld );
  23218. uniforms.direction.sub( vector3 );
  23219. uniforms.direction.transformDirection( viewMatrix );
  23220. uniforms.shadow = light.castShadow;
  23221. if ( light.castShadow ) {
  23222. var shadow = light.shadow;
  23223. uniforms.shadowBias = shadow.bias;
  23224. uniforms.shadowRadius = shadow.radius;
  23225. uniforms.shadowMapSize = shadow.mapSize;
  23226. }
  23227. state.directionalShadowMap[ directionalLength ] = shadowMap;
  23228. state.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix;
  23229. state.directional[ directionalLength ] = uniforms;
  23230. directionalLength ++;
  23231. } else if ( light.isSpotLight ) {
  23232. var uniforms = cache.get( light );
  23233. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  23234. uniforms.position.applyMatrix4( viewMatrix );
  23235. uniforms.color.copy( color ).multiplyScalar( intensity );
  23236. uniforms.distance = distance;
  23237. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  23238. vector3.setFromMatrixPosition( light.target.matrixWorld );
  23239. uniforms.direction.sub( vector3 );
  23240. uniforms.direction.transformDirection( viewMatrix );
  23241. uniforms.coneCos = Math.cos( light.angle );
  23242. uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) );
  23243. uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
  23244. uniforms.shadow = light.castShadow;
  23245. if ( light.castShadow ) {
  23246. var shadow = light.shadow;
  23247. uniforms.shadowBias = shadow.bias;
  23248. uniforms.shadowRadius = shadow.radius;
  23249. uniforms.shadowMapSize = shadow.mapSize;
  23250. }
  23251. state.spotShadowMap[ spotLength ] = shadowMap;
  23252. state.spotShadowMatrix[ spotLength ] = light.shadow.matrix;
  23253. state.spot[ spotLength ] = uniforms;
  23254. spotLength ++;
  23255. } else if ( light.isRectAreaLight ) {
  23256. var uniforms = cache.get( light );
  23257. // (a) intensity controls irradiance of entire light
  23258. uniforms.color
  23259. .copy( color )
  23260. .multiplyScalar( intensity / ( light.width * light.height ) );
  23261. // (b) intensity controls the radiance per light area
  23262. // uniforms.color.copy( color ).multiplyScalar( intensity );
  23263. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  23264. uniforms.position.applyMatrix4( viewMatrix );
  23265. // extract local rotation of light to derive width/height half vectors
  23266. matrix42.identity();
  23267. matrix4.copy( light.matrixWorld );
  23268. matrix4.premultiply( viewMatrix );
  23269. matrix42.extractRotation( matrix4 );
  23270. uniforms.halfWidth.set( light.width * 0.5, 0.0, 0.0 );
  23271. uniforms.halfHeight.set( 0.0, light.height * 0.5, 0.0 );
  23272. uniforms.halfWidth.applyMatrix4( matrix42 );
  23273. uniforms.halfHeight.applyMatrix4( matrix42 );
  23274. // TODO (abelnation): RectAreaLight distance?
  23275. // uniforms.distance = distance;
  23276. state.rectArea[ rectAreaLength ] = uniforms;
  23277. rectAreaLength ++;
  23278. } else if ( light.isPointLight ) {
  23279. var uniforms = cache.get( light );
  23280. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  23281. uniforms.position.applyMatrix4( viewMatrix );
  23282. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  23283. uniforms.distance = light.distance;
  23284. uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
  23285. uniforms.shadow = light.castShadow;
  23286. if ( light.castShadow ) {
  23287. var shadow = light.shadow;
  23288. uniforms.shadowBias = shadow.bias;
  23289. uniforms.shadowRadius = shadow.radius;
  23290. uniforms.shadowMapSize = shadow.mapSize;
  23291. uniforms.shadowCameraNear = shadow.camera.near;
  23292. uniforms.shadowCameraFar = shadow.camera.far;
  23293. }
  23294. state.pointShadowMap[ pointLength ] = shadowMap;
  23295. state.pointShadowMatrix[ pointLength ] = light.shadow.matrix;
  23296. state.point[ pointLength ] = uniforms;
  23297. pointLength ++;
  23298. } else if ( light.isHemisphereLight ) {
  23299. var uniforms = cache.get( light );
  23300. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  23301. uniforms.direction.transformDirection( viewMatrix );
  23302. uniforms.direction.normalize();
  23303. uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
  23304. uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
  23305. state.hemi[ hemiLength ] = uniforms;
  23306. hemiLength ++;
  23307. }
  23308. }
  23309. state.ambient[ 0 ] = r;
  23310. state.ambient[ 1 ] = g;
  23311. state.ambient[ 2 ] = b;
  23312. state.directional.length = directionalLength;
  23313. state.spot.length = spotLength;
  23314. state.rectArea.length = rectAreaLength;
  23315. state.point.length = pointLength;
  23316. state.hemi.length = hemiLength;
  23317. // TODO (sam-g-steel) why aren't we using join
  23318. state.hash = directionalLength + ',' + pointLength + ',' + spotLength + ',' + rectAreaLength + ',' + hemiLength + ',' + shadows.length;
  23319. }
  23320. return {
  23321. setup: setup,
  23322. state: state
  23323. };
  23324. }
  23325. /**
  23326. * @author mrdoob / http://mrdoob.com/
  23327. */
  23328. function WebGLObjects( geometries, infoRender ) {
  23329. var updateList = {};
  23330. function update( object ) {
  23331. var frame = infoRender.frame;
  23332. var geometry = object.geometry;
  23333. var buffergeometry = geometries.get( object, geometry );
  23334. // Update once per frame
  23335. if ( updateList[ buffergeometry.id ] !== frame ) {
  23336. if ( geometry.isGeometry ) {
  23337. buffergeometry.updateFromObject( object );
  23338. }
  23339. geometries.update( buffergeometry );
  23340. updateList[ buffergeometry.id ] = frame;
  23341. }
  23342. return buffergeometry;
  23343. }
  23344. function clear() {
  23345. updateList = {};
  23346. }
  23347. return {
  23348. update: update,
  23349. clear: clear
  23350. };
  23351. }
  23352. /**
  23353. * @author mrdoob / http://mrdoob.com/
  23354. */
  23355. function addLineNumbers( string ) {
  23356. var lines = string.split( '\n' );
  23357. for ( var i = 0; i < lines.length; i ++ ) {
  23358. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  23359. }
  23360. return lines.join( '\n' );
  23361. }
  23362. function WebGLShader( gl, type, string ) {
  23363. var shader = gl.createShader( type );
  23364. gl.shaderSource( shader, string );
  23365. gl.compileShader( shader );
  23366. if ( gl.getShaderParameter( shader, gl.COMPILE_STATUS ) === false ) {
  23367. console.error( 'THREE.WebGLShader: Shader couldn\'t compile.' );
  23368. }
  23369. if ( gl.getShaderInfoLog( shader ) !== '' ) {
  23370. console.warn( 'THREE.WebGLShader: gl.getShaderInfoLog()', type === gl.VERTEX_SHADER ? 'vertex' : 'fragment', gl.getShaderInfoLog( shader ), addLineNumbers( string ) );
  23371. }
  23372. // --enable-privileged-webgl-extension
  23373. // console.log( type, gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  23374. return shader;
  23375. }
  23376. /**
  23377. * @author mrdoob / http://mrdoob.com/
  23378. */
  23379. var programIdCount = 0;
  23380. function getEncodingComponents( encoding ) {
  23381. switch ( encoding ) {
  23382. case LinearEncoding:
  23383. return [ 'Linear', '( value )' ];
  23384. case sRGBEncoding:
  23385. return [ 'sRGB', '( value )' ];
  23386. case RGBEEncoding:
  23387. return [ 'RGBE', '( value )' ];
  23388. case RGBM7Encoding:
  23389. return [ 'RGBM', '( value, 7.0 )' ];
  23390. case RGBM16Encoding:
  23391. return [ 'RGBM', '( value, 16.0 )' ];
  23392. case RGBDEncoding:
  23393. return [ 'RGBD', '( value, 256.0 )' ];
  23394. case GammaEncoding:
  23395. return [ 'Gamma', '( value, float( GAMMA_FACTOR ) )' ];
  23396. default:
  23397. throw new Error( 'unsupported encoding: ' + encoding );
  23398. }
  23399. }
  23400. function getTexelDecodingFunction( functionName, encoding ) {
  23401. var components = getEncodingComponents( encoding );
  23402. return "vec4 " + functionName + "( vec4 value ) { return " + components[ 0 ] + "ToLinear" + components[ 1 ] + "; }";
  23403. }
  23404. function getTexelEncodingFunction( functionName, encoding ) {
  23405. var components = getEncodingComponents( encoding );
  23406. return "vec4 " + functionName + "( vec4 value ) { return LinearTo" + components[ 0 ] + components[ 1 ] + "; }";
  23407. }
  23408. function getToneMappingFunction( functionName, toneMapping ) {
  23409. var toneMappingName;
  23410. switch ( toneMapping ) {
  23411. case LinearToneMapping:
  23412. toneMappingName = "Linear";
  23413. break;
  23414. case ReinhardToneMapping:
  23415. toneMappingName = "Reinhard";
  23416. break;
  23417. case Uncharted2ToneMapping:
  23418. toneMappingName = "Uncharted2";
  23419. break;
  23420. case CineonToneMapping:
  23421. toneMappingName = "OptimizedCineon";
  23422. break;
  23423. default:
  23424. throw new Error( 'unsupported toneMapping: ' + toneMapping );
  23425. }
  23426. return "vec3 " + functionName + "( vec3 color ) { return " + toneMappingName + "ToneMapping( color ); }";
  23427. }
  23428. function generateExtensions( extensions, parameters, rendererExtensions ) {
  23429. extensions = extensions || {};
  23430. var chunks = [
  23431. ( extensions.derivatives || parameters.envMapCubeUV || parameters.bumpMap || parameters.normalMap || parameters.flatShading ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  23432. ( extensions.fragDepth || parameters.logarithmicDepthBuffer ) && rendererExtensions.get( 'EXT_frag_depth' ) ? '#extension GL_EXT_frag_depth : enable' : '',
  23433. ( extensions.drawBuffers ) && rendererExtensions.get( 'WEBGL_draw_buffers' ) ? '#extension GL_EXT_draw_buffers : require' : '',
  23434. ( extensions.shaderTextureLOD || parameters.envMap ) && rendererExtensions.get( 'EXT_shader_texture_lod' ) ? '#extension GL_EXT_shader_texture_lod : enable' : ''
  23435. ];
  23436. return chunks.filter( filterEmptyLine ).join( '\n' );
  23437. }
  23438. function generateDefines( defines ) {
  23439. var chunks = [];
  23440. for ( var name in defines ) {
  23441. var value = defines[ name ];
  23442. if ( value === false ) continue;
  23443. chunks.push( '#define ' + name + ' ' + value );
  23444. }
  23445. return chunks.join( '\n' );
  23446. }
  23447. function fetchAttributeLocations( gl, program ) {
  23448. var attributes = {};
  23449. var n = gl.getProgramParameter( program, gl.ACTIVE_ATTRIBUTES );
  23450. for ( var i = 0; i < n; i ++ ) {
  23451. var info = gl.getActiveAttrib( program, i );
  23452. var name = info.name;
  23453. // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  23454. attributes[ name ] = gl.getAttribLocation( program, name );
  23455. }
  23456. return attributes;
  23457. }
  23458. function filterEmptyLine( string ) {
  23459. return string !== '';
  23460. }
  23461. function replaceLightNums( string, parameters ) {
  23462. return string
  23463. .replace( /NUM_DIR_LIGHTS/g, parameters.numDirLights )
  23464. .replace( /NUM_SPOT_LIGHTS/g, parameters.numSpotLights )
  23465. .replace( /NUM_RECT_AREA_LIGHTS/g, parameters.numRectAreaLights )
  23466. .replace( /NUM_POINT_LIGHTS/g, parameters.numPointLights )
  23467. .replace( /NUM_HEMI_LIGHTS/g, parameters.numHemiLights );
  23468. }
  23469. function parseIncludes( string ) {
  23470. var pattern = /^[ \t]*#include +<([\w\d.]+)>/gm;
  23471. function replace( match, include ) {
  23472. var replace = ShaderChunk[ include ];
  23473. if ( replace === undefined ) {
  23474. throw new Error( 'Can not resolve #include <' + include + '>' );
  23475. }
  23476. return parseIncludes( replace );
  23477. }
  23478. return string.replace( pattern, replace );
  23479. }
  23480. function unrollLoops( string ) {
  23481. var pattern = /for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  23482. function replace( match, start, end, snippet ) {
  23483. var unroll = '';
  23484. for ( var i = parseInt( start ); i < parseInt( end ); i ++ ) {
  23485. unroll += snippet.replace( /\[ i \]/g, '[ ' + i + ' ]' );
  23486. }
  23487. return unroll;
  23488. }
  23489. return string.replace( pattern, replace );
  23490. }
  23491. function WebGLProgram( renderer, extensions, code, material, shader, parameters ) {
  23492. var gl = renderer.context;
  23493. var defines = material.defines;
  23494. var vertexShader = shader.vertexShader;
  23495. var fragmentShader = shader.fragmentShader;
  23496. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  23497. if ( parameters.shadowMapType === PCFShadowMap ) {
  23498. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  23499. } else if ( parameters.shadowMapType === PCFSoftShadowMap ) {
  23500. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  23501. }
  23502. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  23503. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  23504. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  23505. if ( parameters.envMap ) {
  23506. switch ( material.envMap.mapping ) {
  23507. case CubeReflectionMapping:
  23508. case CubeRefractionMapping:
  23509. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  23510. break;
  23511. case CubeUVReflectionMapping:
  23512. case CubeUVRefractionMapping:
  23513. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  23514. break;
  23515. case EquirectangularReflectionMapping:
  23516. case EquirectangularRefractionMapping:
  23517. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  23518. break;
  23519. case SphericalReflectionMapping:
  23520. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  23521. break;
  23522. }
  23523. switch ( material.envMap.mapping ) {
  23524. case CubeRefractionMapping:
  23525. case EquirectangularRefractionMapping:
  23526. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  23527. break;
  23528. }
  23529. switch ( material.combine ) {
  23530. case MultiplyOperation:
  23531. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  23532. break;
  23533. case MixOperation:
  23534. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  23535. break;
  23536. case AddOperation:
  23537. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  23538. break;
  23539. }
  23540. }
  23541. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  23542. // console.log( 'building new program ' );
  23543. //
  23544. var customExtensions = generateExtensions( material.extensions, parameters, extensions );
  23545. var customDefines = generateDefines( defines );
  23546. //
  23547. var program = gl.createProgram();
  23548. var prefixVertex, prefixFragment;
  23549. if ( material.isRawShaderMaterial ) {
  23550. prefixVertex = [
  23551. customDefines
  23552. ].filter( filterEmptyLine ).join( '\n' );
  23553. if ( prefixVertex.length > 0 ) {
  23554. prefixVertex += '\n';
  23555. }
  23556. prefixFragment = [
  23557. customExtensions,
  23558. customDefines
  23559. ].filter( filterEmptyLine ).join( '\n' );
  23560. if ( prefixFragment.length > 0 ) {
  23561. prefixFragment += '\n';
  23562. }
  23563. } else {
  23564. prefixVertex = [
  23565. 'precision ' + parameters.precision + ' float;',
  23566. 'precision ' + parameters.precision + ' int;',
  23567. '#define SHADER_NAME ' + shader.name,
  23568. customDefines,
  23569. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  23570. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  23571. '#define MAX_BONES ' + parameters.maxBones,
  23572. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  23573. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  23574. parameters.map ? '#define USE_MAP' : '',
  23575. parameters.envMap ? '#define USE_ENVMAP' : '',
  23576. parameters.envMap ? '#define ' + envMapModeDefine : '',
  23577. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  23578. parameters.aoMap ? '#define USE_AOMAP' : '',
  23579. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  23580. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  23581. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  23582. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  23583. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  23584. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  23585. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  23586. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  23587. parameters.vertexColors ? '#define USE_COLOR' : '',
  23588. parameters.flatShading ? '#define FLAT_SHADED' : '',
  23589. parameters.skinning ? '#define USE_SKINNING' : '',
  23590. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  23591. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  23592. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  23593. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  23594. parameters.flipSided ? '#define FLIP_SIDED' : '',
  23595. '#define NUM_CLIPPING_PLANES ' + parameters.numClippingPlanes,
  23596. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  23597. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  23598. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  23599. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  23600. parameters.logarithmicDepthBuffer && extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  23601. 'uniform mat4 modelMatrix;',
  23602. 'uniform mat4 modelViewMatrix;',
  23603. 'uniform mat4 projectionMatrix;',
  23604. 'uniform mat4 viewMatrix;',
  23605. 'uniform mat3 normalMatrix;',
  23606. 'uniform vec3 cameraPosition;',
  23607. 'attribute vec3 position;',
  23608. 'attribute vec3 normal;',
  23609. 'attribute vec2 uv;',
  23610. '#ifdef USE_COLOR',
  23611. ' attribute vec3 color;',
  23612. '#endif',
  23613. '#ifdef USE_MORPHTARGETS',
  23614. ' attribute vec3 morphTarget0;',
  23615. ' attribute vec3 morphTarget1;',
  23616. ' attribute vec3 morphTarget2;',
  23617. ' attribute vec3 morphTarget3;',
  23618. ' #ifdef USE_MORPHNORMALS',
  23619. ' attribute vec3 morphNormal0;',
  23620. ' attribute vec3 morphNormal1;',
  23621. ' attribute vec3 morphNormal2;',
  23622. ' attribute vec3 morphNormal3;',
  23623. ' #else',
  23624. ' attribute vec3 morphTarget4;',
  23625. ' attribute vec3 morphTarget5;',
  23626. ' attribute vec3 morphTarget6;',
  23627. ' attribute vec3 morphTarget7;',
  23628. ' #endif',
  23629. '#endif',
  23630. '#ifdef USE_SKINNING',
  23631. ' attribute vec4 skinIndex;',
  23632. ' attribute vec4 skinWeight;',
  23633. '#endif',
  23634. '\n'
  23635. ].filter( filterEmptyLine ).join( '\n' );
  23636. prefixFragment = [
  23637. customExtensions,
  23638. 'precision ' + parameters.precision + ' float;',
  23639. 'precision ' + parameters.precision + ' int;',
  23640. '#define SHADER_NAME ' + shader.name,
  23641. customDefines,
  23642. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest : '',
  23643. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  23644. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  23645. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  23646. parameters.map ? '#define USE_MAP' : '',
  23647. parameters.envMap ? '#define USE_ENVMAP' : '',
  23648. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  23649. parameters.envMap ? '#define ' + envMapModeDefine : '',
  23650. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  23651. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  23652. parameters.aoMap ? '#define USE_AOMAP' : '',
  23653. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  23654. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  23655. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  23656. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  23657. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  23658. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  23659. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  23660. parameters.vertexColors ? '#define USE_COLOR' : '',
  23661. parameters.gradientMap ? '#define USE_GRADIENTMAP' : '',
  23662. parameters.flatShading ? '#define FLAT_SHADED' : '',
  23663. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  23664. parameters.flipSided ? '#define FLIP_SIDED' : '',
  23665. '#define NUM_CLIPPING_PLANES ' + parameters.numClippingPlanes,
  23666. '#define UNION_CLIPPING_PLANES ' + ( parameters.numClippingPlanes - parameters.numClipIntersection ),
  23667. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  23668. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  23669. parameters.premultipliedAlpha ? "#define PREMULTIPLIED_ALPHA" : '',
  23670. parameters.physicallyCorrectLights ? "#define PHYSICALLY_CORRECT_LIGHTS" : '',
  23671. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  23672. parameters.logarithmicDepthBuffer && extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  23673. parameters.envMap && extensions.get( 'EXT_shader_texture_lod' ) ? '#define TEXTURE_LOD_EXT' : '',
  23674. 'uniform mat4 viewMatrix;',
  23675. 'uniform vec3 cameraPosition;',
  23676. ( parameters.toneMapping !== NoToneMapping ) ? "#define TONE_MAPPING" : '',
  23677. ( parameters.toneMapping !== NoToneMapping ) ? ShaderChunk[ 'tonemapping_pars_fragment' ] : '', // this code is required here because it is used by the toneMapping() function defined below
  23678. ( parameters.toneMapping !== NoToneMapping ) ? getToneMappingFunction( "toneMapping", parameters.toneMapping ) : '',
  23679. parameters.dithering ? '#define DITHERING' : '',
  23680. ( parameters.outputEncoding || parameters.mapEncoding || parameters.envMapEncoding || parameters.emissiveMapEncoding ) ? ShaderChunk[ 'encodings_pars_fragment' ] : '', // this code is required here because it is used by the various encoding/decoding function defined below
  23681. parameters.mapEncoding ? getTexelDecodingFunction( 'mapTexelToLinear', parameters.mapEncoding ) : '',
  23682. parameters.envMapEncoding ? getTexelDecodingFunction( 'envMapTexelToLinear', parameters.envMapEncoding ) : '',
  23683. parameters.emissiveMapEncoding ? getTexelDecodingFunction( 'emissiveMapTexelToLinear', parameters.emissiveMapEncoding ) : '',
  23684. parameters.outputEncoding ? getTexelEncodingFunction( "linearToOutputTexel", parameters.outputEncoding ) : '',
  23685. parameters.depthPacking ? "#define DEPTH_PACKING " + material.depthPacking : '',
  23686. '\n'
  23687. ].filter( filterEmptyLine ).join( '\n' );
  23688. }
  23689. vertexShader = parseIncludes( vertexShader );
  23690. vertexShader = replaceLightNums( vertexShader, parameters );
  23691. fragmentShader = parseIncludes( fragmentShader );
  23692. fragmentShader = replaceLightNums( fragmentShader, parameters );
  23693. if ( ! material.isShaderMaterial ) {
  23694. vertexShader = unrollLoops( vertexShader );
  23695. fragmentShader = unrollLoops( fragmentShader );
  23696. }
  23697. var vertexGlsl = prefixVertex + vertexShader;
  23698. var fragmentGlsl = prefixFragment + fragmentShader;
  23699. // console.log( '*VERTEX*', vertexGlsl );
  23700. // console.log( '*FRAGMENT*', fragmentGlsl );
  23701. var glVertexShader = WebGLShader( gl, gl.VERTEX_SHADER, vertexGlsl );
  23702. var glFragmentShader = WebGLShader( gl, gl.FRAGMENT_SHADER, fragmentGlsl );
  23703. gl.attachShader( program, glVertexShader );
  23704. gl.attachShader( program, glFragmentShader );
  23705. // Force a particular attribute to index 0.
  23706. if ( material.index0AttributeName !== undefined ) {
  23707. gl.bindAttribLocation( program, 0, material.index0AttributeName );
  23708. } else if ( parameters.morphTargets === true ) {
  23709. // programs with morphTargets displace position out of attribute 0
  23710. gl.bindAttribLocation( program, 0, 'position' );
  23711. }
  23712. gl.linkProgram( program );
  23713. var programLog = gl.getProgramInfoLog( program );
  23714. var vertexLog = gl.getShaderInfoLog( glVertexShader );
  23715. var fragmentLog = gl.getShaderInfoLog( glFragmentShader );
  23716. var runnable = true;
  23717. var haveDiagnostics = true;
  23718. // console.log( '**VERTEX**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glVertexShader ) );
  23719. // console.log( '**FRAGMENT**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glFragmentShader ) );
  23720. if ( gl.getProgramParameter( program, gl.LINK_STATUS ) === false ) {
  23721. runnable = false;
  23722. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), 'gl.VALIDATE_STATUS', gl.getProgramParameter( program, gl.VALIDATE_STATUS ), 'gl.getProgramInfoLog', programLog, vertexLog, fragmentLog );
  23723. } else if ( programLog !== '' ) {
  23724. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  23725. } else if ( vertexLog === '' || fragmentLog === '' ) {
  23726. haveDiagnostics = false;
  23727. }
  23728. if ( haveDiagnostics ) {
  23729. this.diagnostics = {
  23730. runnable: runnable,
  23731. material: material,
  23732. programLog: programLog,
  23733. vertexShader: {
  23734. log: vertexLog,
  23735. prefix: prefixVertex
  23736. },
  23737. fragmentShader: {
  23738. log: fragmentLog,
  23739. prefix: prefixFragment
  23740. }
  23741. };
  23742. }
  23743. // clean up
  23744. gl.deleteShader( glVertexShader );
  23745. gl.deleteShader( glFragmentShader );
  23746. // set up caching for uniform locations
  23747. var cachedUniforms;
  23748. this.getUniforms = function () {
  23749. if ( cachedUniforms === undefined ) {
  23750. cachedUniforms = new WebGLUniforms( gl, program, renderer );
  23751. }
  23752. return cachedUniforms;
  23753. };
  23754. // set up caching for attribute locations
  23755. var cachedAttributes;
  23756. this.getAttributes = function () {
  23757. if ( cachedAttributes === undefined ) {
  23758. cachedAttributes = fetchAttributeLocations( gl, program );
  23759. }
  23760. return cachedAttributes;
  23761. };
  23762. // free resource
  23763. this.destroy = function () {
  23764. gl.deleteProgram( program );
  23765. this.program = undefined;
  23766. };
  23767. // DEPRECATED
  23768. Object.defineProperties( this, {
  23769. uniforms: {
  23770. get: function () {
  23771. console.warn( 'THREE.WebGLProgram: .uniforms is now .getUniforms().' );
  23772. return this.getUniforms();
  23773. }
  23774. },
  23775. attributes: {
  23776. get: function () {
  23777. console.warn( 'THREE.WebGLProgram: .attributes is now .getAttributes().' );
  23778. return this.getAttributes();
  23779. }
  23780. }
  23781. } );
  23782. //
  23783. this.id = programIdCount ++;
  23784. this.code = code;
  23785. this.usedTimes = 1;
  23786. this.program = program;
  23787. this.vertexShader = glVertexShader;
  23788. this.fragmentShader = glFragmentShader;
  23789. return this;
  23790. }
  23791. /**
  23792. * @author mrdoob / http://mrdoob.com/
  23793. */
  23794. function WebGLPrograms( renderer, extensions, capabilities ) {
  23795. var programs = [];
  23796. var shaderIDs = {
  23797. MeshDepthMaterial: 'depth',
  23798. MeshDistanceMaterial: 'distanceRGBA',
  23799. MeshNormalMaterial: 'normal',
  23800. MeshBasicMaterial: 'basic',
  23801. MeshLambertMaterial: 'lambert',
  23802. MeshPhongMaterial: 'phong',
  23803. MeshToonMaterial: 'phong',
  23804. MeshStandardMaterial: 'physical',
  23805. MeshPhysicalMaterial: 'physical',
  23806. LineBasicMaterial: 'basic',
  23807. LineDashedMaterial: 'dashed',
  23808. PointsMaterial: 'points',
  23809. ShadowMaterial: 'shadow'
  23810. };
  23811. var parameterNames = [
  23812. "precision", "supportsVertexTextures", "map", "mapEncoding", "envMap", "envMapMode", "envMapEncoding",
  23813. "lightMap", "aoMap", "emissiveMap", "emissiveMapEncoding", "bumpMap", "normalMap", "displacementMap", "specularMap",
  23814. "roughnessMap", "metalnessMap", "gradientMap",
  23815. "alphaMap", "combine", "vertexColors", "fog", "useFog", "fogExp",
  23816. "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
  23817. "maxBones", "useVertexTexture", "morphTargets", "morphNormals",
  23818. "maxMorphTargets", "maxMorphNormals", "premultipliedAlpha",
  23819. "numDirLights", "numPointLights", "numSpotLights", "numHemiLights", "numRectAreaLights",
  23820. "shadowMapEnabled", "shadowMapType", "toneMapping", 'physicallyCorrectLights',
  23821. "alphaTest", "doubleSided", "flipSided", "numClippingPlanes", "numClipIntersection", "depthPacking", "dithering"
  23822. ];
  23823. function allocateBones( object ) {
  23824. var skeleton = object.skeleton;
  23825. var bones = skeleton.bones;
  23826. if ( capabilities.floatVertexTextures ) {
  23827. return 1024;
  23828. } else {
  23829. // default for when object is not specified
  23830. // ( for example when prebuilding shader to be used with multiple objects )
  23831. //
  23832. // - leave some extra space for other uniforms
  23833. // - limit here is ANGLE's 254 max uniform vectors
  23834. // (up to 54 should be safe)
  23835. var nVertexUniforms = capabilities.maxVertexUniforms;
  23836. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  23837. var maxBones = Math.min( nVertexMatrices, bones.length );
  23838. if ( maxBones < bones.length ) {
  23839. console.warn( 'THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.' );
  23840. return 0;
  23841. }
  23842. return maxBones;
  23843. }
  23844. }
  23845. function getTextureEncodingFromMap( map, gammaOverrideLinear ) {
  23846. var encoding;
  23847. if ( ! map ) {
  23848. encoding = LinearEncoding;
  23849. } else if ( map.isTexture ) {
  23850. encoding = map.encoding;
  23851. } else if ( map.isWebGLRenderTarget ) {
  23852. console.warn( "THREE.WebGLPrograms.getTextureEncodingFromMap: don't use render targets as textures. Use their .texture property instead." );
  23853. encoding = map.texture.encoding;
  23854. }
  23855. // add backwards compatibility for WebGLRenderer.gammaInput/gammaOutput parameter, should probably be removed at some point.
  23856. if ( encoding === LinearEncoding && gammaOverrideLinear ) {
  23857. encoding = GammaEncoding;
  23858. }
  23859. return encoding;
  23860. }
  23861. this.getParameters = function ( material, lights, shadows, fog, nClipPlanes, nClipIntersection, object ) {
  23862. var shaderID = shaderIDs[ material.type ];
  23863. // heuristics to create shader parameters according to lights in the scene
  23864. // (not to blow over maxLights budget)
  23865. var maxBones = object.isSkinnedMesh ? allocateBones( object ) : 0;
  23866. var precision = capabilities.precision;
  23867. if ( material.precision !== null ) {
  23868. precision = capabilities.getMaxPrecision( material.precision );
  23869. if ( precision !== material.precision ) {
  23870. console.warn( 'THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.' );
  23871. }
  23872. }
  23873. var currentRenderTarget = renderer.getRenderTarget();
  23874. var parameters = {
  23875. shaderID: shaderID,
  23876. precision: precision,
  23877. supportsVertexTextures: capabilities.vertexTextures,
  23878. outputEncoding: getTextureEncodingFromMap( ( ! currentRenderTarget ) ? null : currentRenderTarget.texture, renderer.gammaOutput ),
  23879. map: !! material.map,
  23880. mapEncoding: getTextureEncodingFromMap( material.map, renderer.gammaInput ),
  23881. envMap: !! material.envMap,
  23882. envMapMode: material.envMap && material.envMap.mapping,
  23883. envMapEncoding: getTextureEncodingFromMap( material.envMap, renderer.gammaInput ),
  23884. envMapCubeUV: ( !! material.envMap ) && ( ( material.envMap.mapping === CubeUVReflectionMapping ) || ( material.envMap.mapping === CubeUVRefractionMapping ) ),
  23885. lightMap: !! material.lightMap,
  23886. aoMap: !! material.aoMap,
  23887. emissiveMap: !! material.emissiveMap,
  23888. emissiveMapEncoding: getTextureEncodingFromMap( material.emissiveMap, renderer.gammaInput ),
  23889. bumpMap: !! material.bumpMap,
  23890. normalMap: !! material.normalMap,
  23891. displacementMap: !! material.displacementMap,
  23892. roughnessMap: !! material.roughnessMap,
  23893. metalnessMap: !! material.metalnessMap,
  23894. specularMap: !! material.specularMap,
  23895. alphaMap: !! material.alphaMap,
  23896. gradientMap: !! material.gradientMap,
  23897. combine: material.combine,
  23898. vertexColors: material.vertexColors,
  23899. fog: !! fog,
  23900. useFog: material.fog,
  23901. fogExp: ( fog && fog.isFogExp2 ),
  23902. flatShading: material.flatShading,
  23903. sizeAttenuation: material.sizeAttenuation,
  23904. logarithmicDepthBuffer: capabilities.logarithmicDepthBuffer,
  23905. skinning: material.skinning && maxBones > 0,
  23906. maxBones: maxBones,
  23907. useVertexTexture: capabilities.floatVertexTextures,
  23908. morphTargets: material.morphTargets,
  23909. morphNormals: material.morphNormals,
  23910. maxMorphTargets: renderer.maxMorphTargets,
  23911. maxMorphNormals: renderer.maxMorphNormals,
  23912. numDirLights: lights.directional.length,
  23913. numPointLights: lights.point.length,
  23914. numSpotLights: lights.spot.length,
  23915. numRectAreaLights: lights.rectArea.length,
  23916. numHemiLights: lights.hemi.length,
  23917. numClippingPlanes: nClipPlanes,
  23918. numClipIntersection: nClipIntersection,
  23919. dithering: material.dithering,
  23920. shadowMapEnabled: renderer.shadowMap.enabled && object.receiveShadow && shadows.length > 0,
  23921. shadowMapType: renderer.shadowMap.type,
  23922. toneMapping: renderer.toneMapping,
  23923. physicallyCorrectLights: renderer.physicallyCorrectLights,
  23924. premultipliedAlpha: material.premultipliedAlpha,
  23925. alphaTest: material.alphaTest,
  23926. doubleSided: material.side === DoubleSide,
  23927. flipSided: material.side === BackSide,
  23928. depthPacking: ( material.depthPacking !== undefined ) ? material.depthPacking : false
  23929. };
  23930. return parameters;
  23931. };
  23932. this.getProgramCode = function ( material, parameters ) {
  23933. var array = [];
  23934. if ( parameters.shaderID ) {
  23935. array.push( parameters.shaderID );
  23936. } else {
  23937. array.push( material.fragmentShader );
  23938. array.push( material.vertexShader );
  23939. }
  23940. if ( material.defines !== undefined ) {
  23941. for ( var name in material.defines ) {
  23942. array.push( name );
  23943. array.push( material.defines[ name ] );
  23944. }
  23945. }
  23946. for ( var i = 0; i < parameterNames.length; i ++ ) {
  23947. array.push( parameters[ parameterNames[ i ] ] );
  23948. }
  23949. array.push( material.onBeforeCompile.toString() );
  23950. array.push( renderer.gammaOutput );
  23951. return array.join();
  23952. };
  23953. this.acquireProgram = function ( material, shader, parameters, code ) {
  23954. var program;
  23955. // Check if code has been already compiled
  23956. for ( var p = 0, pl = programs.length; p < pl; p ++ ) {
  23957. var programInfo = programs[ p ];
  23958. if ( programInfo.code === code ) {
  23959. program = programInfo;
  23960. ++ program.usedTimes;
  23961. break;
  23962. }
  23963. }
  23964. if ( program === undefined ) {
  23965. program = new WebGLProgram( renderer, extensions, code, material, shader, parameters );
  23966. programs.push( program );
  23967. }
  23968. return program;
  23969. };
  23970. this.releaseProgram = function ( program ) {
  23971. if ( -- program.usedTimes === 0 ) {
  23972. // Remove from unordered set
  23973. var i = programs.indexOf( program );
  23974. programs[ i ] = programs[ programs.length - 1 ];
  23975. programs.pop();
  23976. // Free WebGL resources
  23977. program.destroy();
  23978. }
  23979. };
  23980. // Exposed for resource monitoring & error feedback via renderer.info:
  23981. this.programs = programs;
  23982. }
  23983. /**
  23984. * @author mrdoob / http://mrdoob.com/
  23985. */
  23986. function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, infoMemory ) {
  23987. var _isWebGL2 = ( typeof WebGL2RenderingContext !== 'undefined' && _gl instanceof window.WebGL2RenderingContext );
  23988. //
  23989. function clampToMaxSize( image, maxSize ) {
  23990. if ( image.width > maxSize || image.height > maxSize ) {
  23991. // Warning: Scaling through the canvas will only work with images that use
  23992. // premultiplied alpha.
  23993. var scale = maxSize / Math.max( image.width, image.height );
  23994. var canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  23995. canvas.width = Math.floor( image.width * scale );
  23996. canvas.height = Math.floor( image.height * scale );
  23997. var context = canvas.getContext( '2d' );
  23998. context.drawImage( image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height );
  23999. console.warn( 'THREE.WebGLRenderer: image is too big (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  24000. return canvas;
  24001. }
  24002. return image;
  24003. }
  24004. function isPowerOfTwo( image ) {
  24005. return _Math.isPowerOfTwo( image.width ) && _Math.isPowerOfTwo( image.height );
  24006. }
  24007. function makePowerOfTwo( image ) {
  24008. if ( image instanceof HTMLImageElement || image instanceof HTMLCanvasElement || image instanceof ImageBitmap ) {
  24009. var canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  24010. canvas.width = _Math.floorPowerOfTwo( image.width );
  24011. canvas.height = _Math.floorPowerOfTwo( image.height );
  24012. var context = canvas.getContext( '2d' );
  24013. context.drawImage( image, 0, 0, canvas.width, canvas.height );
  24014. console.warn( 'THREE.WebGLRenderer: image is not power of two (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  24015. return canvas;
  24016. }
  24017. return image;
  24018. }
  24019. function textureNeedsPowerOfTwo( texture ) {
  24020. return ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) ||
  24021. ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter );
  24022. }
  24023. function textureNeedsGenerateMipmaps( texture, isPowerOfTwo ) {
  24024. return texture.generateMipmaps && isPowerOfTwo &&
  24025. texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  24026. }
  24027. // Fallback filters for non-power-of-2 textures
  24028. function filterFallback( f ) {
  24029. if ( f === NearestFilter || f === NearestMipMapNearestFilter || f === NearestMipMapLinearFilter ) {
  24030. return _gl.NEAREST;
  24031. }
  24032. return _gl.LINEAR;
  24033. }
  24034. //
  24035. function onTextureDispose( event ) {
  24036. var texture = event.target;
  24037. texture.removeEventListener( 'dispose', onTextureDispose );
  24038. deallocateTexture( texture );
  24039. infoMemory.textures --;
  24040. }
  24041. function onRenderTargetDispose( event ) {
  24042. var renderTarget = event.target;
  24043. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  24044. deallocateRenderTarget( renderTarget );
  24045. infoMemory.textures --;
  24046. }
  24047. //
  24048. function deallocateTexture( texture ) {
  24049. var textureProperties = properties.get( texture );
  24050. if ( texture.image && textureProperties.__image__webglTextureCube ) {
  24051. // cube texture
  24052. _gl.deleteTexture( textureProperties.__image__webglTextureCube );
  24053. } else {
  24054. // 2D texture
  24055. if ( textureProperties.__webglInit === undefined ) return;
  24056. _gl.deleteTexture( textureProperties.__webglTexture );
  24057. }
  24058. // remove all webgl properties
  24059. properties.remove( texture );
  24060. }
  24061. function deallocateRenderTarget( renderTarget ) {
  24062. var renderTargetProperties = properties.get( renderTarget );
  24063. var textureProperties = properties.get( renderTarget.texture );
  24064. if ( ! renderTarget ) return;
  24065. if ( textureProperties.__webglTexture !== undefined ) {
  24066. _gl.deleteTexture( textureProperties.__webglTexture );
  24067. }
  24068. if ( renderTarget.depthTexture ) {
  24069. renderTarget.depthTexture.dispose();
  24070. }
  24071. if ( renderTarget.isWebGLRenderTargetCube ) {
  24072. for ( var i = 0; i < 6; i ++ ) {
  24073. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  24074. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] );
  24075. }
  24076. } else {
  24077. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  24078. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer );
  24079. }
  24080. properties.remove( renderTarget.texture );
  24081. properties.remove( renderTarget );
  24082. }
  24083. //
  24084. function setTexture2D( texture, slot ) {
  24085. var textureProperties = properties.get( texture );
  24086. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  24087. var image = texture.image;
  24088. if ( image === undefined ) {
  24089. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined', texture );
  24090. } else if ( image.complete === false ) {
  24091. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete', texture );
  24092. } else {
  24093. uploadTexture( textureProperties, texture, slot );
  24094. return;
  24095. }
  24096. }
  24097. state.activeTexture( _gl.TEXTURE0 + slot );
  24098. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  24099. }
  24100. function setTextureCube( texture, slot ) {
  24101. var textureProperties = properties.get( texture );
  24102. if ( texture.image.length === 6 ) {
  24103. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  24104. if ( ! textureProperties.__image__webglTextureCube ) {
  24105. texture.addEventListener( 'dispose', onTextureDispose );
  24106. textureProperties.__image__webglTextureCube = _gl.createTexture();
  24107. infoMemory.textures ++;
  24108. }
  24109. state.activeTexture( _gl.TEXTURE0 + slot );
  24110. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  24111. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  24112. var isCompressed = ( texture && texture.isCompressedTexture );
  24113. var isDataTexture = ( texture.image[ 0 ] && texture.image[ 0 ].isDataTexture );
  24114. var cubeImage = [];
  24115. for ( var i = 0; i < 6; i ++ ) {
  24116. if ( ! isCompressed && ! isDataTexture ) {
  24117. cubeImage[ i ] = clampToMaxSize( texture.image[ i ], capabilities.maxCubemapSize );
  24118. } else {
  24119. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  24120. }
  24121. }
  24122. var image = cubeImage[ 0 ],
  24123. isPowerOfTwoImage = isPowerOfTwo( image ),
  24124. glFormat = utils.convert( texture.format ),
  24125. glType = utils.convert( texture.type );
  24126. setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, isPowerOfTwoImage );
  24127. for ( var i = 0; i < 6; i ++ ) {
  24128. if ( ! isCompressed ) {
  24129. if ( isDataTexture ) {
  24130. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  24131. } else {
  24132. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, glFormat, glType, cubeImage[ i ] );
  24133. }
  24134. } else {
  24135. var mipmap, mipmaps = cubeImage[ i ].mipmaps;
  24136. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  24137. mipmap = mipmaps[ j ];
  24138. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  24139. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  24140. state.compressedTexImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  24141. } else {
  24142. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()' );
  24143. }
  24144. } else {
  24145. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  24146. }
  24147. }
  24148. }
  24149. }
  24150. if ( textureNeedsGenerateMipmaps( texture, isPowerOfTwoImage ) ) {
  24151. _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  24152. }
  24153. textureProperties.__version = texture.version;
  24154. if ( texture.onUpdate ) texture.onUpdate( texture );
  24155. } else {
  24156. state.activeTexture( _gl.TEXTURE0 + slot );
  24157. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  24158. }
  24159. }
  24160. }
  24161. function setTextureCubeDynamic( texture, slot ) {
  24162. state.activeTexture( _gl.TEXTURE0 + slot );
  24163. state.bindTexture( _gl.TEXTURE_CUBE_MAP, properties.get( texture ).__webglTexture );
  24164. }
  24165. function setTextureParameters( textureType, texture, isPowerOfTwoImage ) {
  24166. var extension;
  24167. if ( isPowerOfTwoImage ) {
  24168. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, utils.convert( texture.wrapS ) );
  24169. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, utils.convert( texture.wrapT ) );
  24170. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, utils.convert( texture.magFilter ) );
  24171. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, utils.convert( texture.minFilter ) );
  24172. } else {
  24173. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
  24174. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
  24175. if ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) {
  24176. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.', texture );
  24177. }
  24178. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, filterFallback( texture.magFilter ) );
  24179. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, filterFallback( texture.minFilter ) );
  24180. if ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter ) {
  24181. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.', texture );
  24182. }
  24183. }
  24184. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  24185. if ( extension ) {
  24186. if ( texture.type === FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
  24187. if ( texture.type === HalfFloatType && extensions.get( 'OES_texture_half_float_linear' ) === null ) return;
  24188. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  24189. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, capabilities.getMaxAnisotropy() ) );
  24190. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  24191. }
  24192. }
  24193. }
  24194. function uploadTexture( textureProperties, texture, slot ) {
  24195. if ( textureProperties.__webglInit === undefined ) {
  24196. textureProperties.__webglInit = true;
  24197. texture.addEventListener( 'dispose', onTextureDispose );
  24198. textureProperties.__webglTexture = _gl.createTexture();
  24199. infoMemory.textures ++;
  24200. }
  24201. state.activeTexture( _gl.TEXTURE0 + slot );
  24202. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  24203. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  24204. _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
  24205. _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
  24206. var image = clampToMaxSize( texture.image, capabilities.maxTextureSize );
  24207. if ( textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( image ) === false ) {
  24208. image = makePowerOfTwo( image );
  24209. }
  24210. var isPowerOfTwoImage = isPowerOfTwo( image ),
  24211. glFormat = utils.convert( texture.format ),
  24212. glType = utils.convert( texture.type );
  24213. setTextureParameters( _gl.TEXTURE_2D, texture, isPowerOfTwoImage );
  24214. var mipmap, mipmaps = texture.mipmaps;
  24215. if ( texture.isDepthTexture ) {
  24216. // populate depth texture with dummy data
  24217. var internalFormat = _gl.DEPTH_COMPONENT;
  24218. if ( texture.type === FloatType ) {
  24219. if ( ! _isWebGL2 ) throw new Error( 'Float Depth Texture only supported in WebGL2.0' );
  24220. internalFormat = _gl.DEPTH_COMPONENT32F;
  24221. } else if ( _isWebGL2 ) {
  24222. // WebGL 2.0 requires signed internalformat for glTexImage2D
  24223. internalFormat = _gl.DEPTH_COMPONENT16;
  24224. }
  24225. if ( texture.format === DepthFormat && internalFormat === _gl.DEPTH_COMPONENT ) {
  24226. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  24227. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  24228. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  24229. if ( texture.type !== UnsignedShortType && texture.type !== UnsignedIntType ) {
  24230. console.warn( 'THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.' );
  24231. texture.type = UnsignedShortType;
  24232. glType = utils.convert( texture.type );
  24233. }
  24234. }
  24235. // Depth stencil textures need the DEPTH_STENCIL internal format
  24236. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  24237. if ( texture.format === DepthStencilFormat ) {
  24238. internalFormat = _gl.DEPTH_STENCIL;
  24239. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  24240. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  24241. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  24242. if ( texture.type !== UnsignedInt248Type ) {
  24243. console.warn( 'THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.' );
  24244. texture.type = UnsignedInt248Type;
  24245. glType = utils.convert( texture.type );
  24246. }
  24247. }
  24248. state.texImage2D( _gl.TEXTURE_2D, 0, internalFormat, image.width, image.height, 0, glFormat, glType, null );
  24249. } else if ( texture.isDataTexture ) {
  24250. // use manually created mipmaps if available
  24251. // if there are no manual mipmaps
  24252. // set 0 level mipmap and then use GL to generate other mipmap levels
  24253. if ( mipmaps.length > 0 && isPowerOfTwoImage ) {
  24254. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  24255. mipmap = mipmaps[ i ];
  24256. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  24257. }
  24258. texture.generateMipmaps = false;
  24259. } else {
  24260. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, image.width, image.height, 0, glFormat, glType, image.data );
  24261. }
  24262. } else if ( texture.isCompressedTexture ) {
  24263. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  24264. mipmap = mipmaps[ i ];
  24265. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  24266. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  24267. state.compressedTexImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  24268. } else {
  24269. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()' );
  24270. }
  24271. } else {
  24272. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  24273. }
  24274. }
  24275. } else {
  24276. // regular Texture (image, video, canvas)
  24277. // use manually created mipmaps if available
  24278. // if there are no manual mipmaps
  24279. // set 0 level mipmap and then use GL to generate other mipmap levels
  24280. if ( mipmaps.length > 0 && isPowerOfTwoImage ) {
  24281. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  24282. mipmap = mipmaps[ i ];
  24283. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, glFormat, glType, mipmap );
  24284. }
  24285. texture.generateMipmaps = false;
  24286. } else {
  24287. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, glFormat, glType, image );
  24288. }
  24289. }
  24290. if ( textureNeedsGenerateMipmaps( texture, isPowerOfTwoImage ) ) _gl.generateMipmap( _gl.TEXTURE_2D );
  24291. textureProperties.__version = texture.version;
  24292. if ( texture.onUpdate ) texture.onUpdate( texture );
  24293. }
  24294. // Render targets
  24295. // Setup storage for target texture and bind it to correct framebuffer
  24296. function setupFrameBufferTexture( framebuffer, renderTarget, attachment, textureTarget ) {
  24297. var glFormat = utils.convert( renderTarget.texture.format );
  24298. var glType = utils.convert( renderTarget.texture.type );
  24299. state.texImage2D( textureTarget, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  24300. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  24301. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
  24302. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  24303. }
  24304. // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  24305. function setupRenderBufferStorage( renderbuffer, renderTarget ) {
  24306. _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer );
  24307. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  24308. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_COMPONENT16, renderTarget.width, renderTarget.height );
  24309. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  24310. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  24311. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_STENCIL, renderTarget.width, renderTarget.height );
  24312. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  24313. } else {
  24314. // FIXME: We don't support !depth !stencil
  24315. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.RGBA4, renderTarget.width, renderTarget.height );
  24316. }
  24317. _gl.bindRenderbuffer( _gl.RENDERBUFFER, null );
  24318. }
  24319. // Setup resources for a Depth Texture for a FBO (needs an extension)
  24320. function setupDepthTexture( framebuffer, renderTarget ) {
  24321. var isCube = ( renderTarget && renderTarget.isWebGLRenderTargetCube );
  24322. if ( isCube ) throw new Error( 'Depth Texture with cube render targets is not supported' );
  24323. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  24324. if ( ! ( renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture ) ) {
  24325. throw new Error( 'renderTarget.depthTexture must be an instance of THREE.DepthTexture' );
  24326. }
  24327. // upload an empty depth texture with framebuffer size
  24328. if ( ! properties.get( renderTarget.depthTexture ).__webglTexture ||
  24329. renderTarget.depthTexture.image.width !== renderTarget.width ||
  24330. renderTarget.depthTexture.image.height !== renderTarget.height ) {
  24331. renderTarget.depthTexture.image.width = renderTarget.width;
  24332. renderTarget.depthTexture.image.height = renderTarget.height;
  24333. renderTarget.depthTexture.needsUpdate = true;
  24334. }
  24335. setTexture2D( renderTarget.depthTexture, 0 );
  24336. var webglDepthTexture = properties.get( renderTarget.depthTexture ).__webglTexture;
  24337. if ( renderTarget.depthTexture.format === DepthFormat ) {
  24338. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0 );
  24339. } else if ( renderTarget.depthTexture.format === DepthStencilFormat ) {
  24340. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0 );
  24341. } else {
  24342. throw new Error( 'Unknown depthTexture format' );
  24343. }
  24344. }
  24345. // Setup GL resources for a non-texture depth buffer
  24346. function setupDepthRenderbuffer( renderTarget ) {
  24347. var renderTargetProperties = properties.get( renderTarget );
  24348. var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
  24349. if ( renderTarget.depthTexture ) {
  24350. if ( isCube ) throw new Error( 'target.depthTexture not supported in Cube render targets' );
  24351. setupDepthTexture( renderTargetProperties.__webglFramebuffer, renderTarget );
  24352. } else {
  24353. if ( isCube ) {
  24354. renderTargetProperties.__webglDepthbuffer = [];
  24355. for ( var i = 0; i < 6; i ++ ) {
  24356. _gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer[ i ] );
  24357. renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer();
  24358. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget );
  24359. }
  24360. } else {
  24361. _gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer );
  24362. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  24363. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget );
  24364. }
  24365. }
  24366. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  24367. }
  24368. // Set up GL resources for the render target
  24369. function setupRenderTarget( renderTarget ) {
  24370. var renderTargetProperties = properties.get( renderTarget );
  24371. var textureProperties = properties.get( renderTarget.texture );
  24372. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  24373. textureProperties.__webglTexture = _gl.createTexture();
  24374. infoMemory.textures ++;
  24375. var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
  24376. var isTargetPowerOfTwo = isPowerOfTwo( renderTarget );
  24377. // Setup framebuffer
  24378. if ( isCube ) {
  24379. renderTargetProperties.__webglFramebuffer = [];
  24380. for ( var i = 0; i < 6; i ++ ) {
  24381. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  24382. }
  24383. } else {
  24384. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  24385. }
  24386. // Setup color buffer
  24387. if ( isCube ) {
  24388. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture );
  24389. setTextureParameters( _gl.TEXTURE_CUBE_MAP, renderTarget.texture, isTargetPowerOfTwo );
  24390. for ( var i = 0; i < 6; i ++ ) {
  24391. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i );
  24392. }
  24393. if ( textureNeedsGenerateMipmaps( renderTarget.texture, isTargetPowerOfTwo ) ) _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  24394. state.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  24395. } else {
  24396. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  24397. setTextureParameters( _gl.TEXTURE_2D, renderTarget.texture, isTargetPowerOfTwo );
  24398. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D );
  24399. if ( textureNeedsGenerateMipmaps( renderTarget.texture, isTargetPowerOfTwo ) ) _gl.generateMipmap( _gl.TEXTURE_2D );
  24400. state.bindTexture( _gl.TEXTURE_2D, null );
  24401. }
  24402. // Setup depth and stencil buffers
  24403. if ( renderTarget.depthBuffer ) {
  24404. setupDepthRenderbuffer( renderTarget );
  24405. }
  24406. }
  24407. function updateRenderTargetMipmap( renderTarget ) {
  24408. var texture = renderTarget.texture;
  24409. var isTargetPowerOfTwo = isPowerOfTwo( renderTarget );
  24410. if ( textureNeedsGenerateMipmaps( texture, isTargetPowerOfTwo ) ) {
  24411. var target = renderTarget.isWebGLRenderTargetCube ? _gl.TEXTURE_CUBE_MAP : _gl.TEXTURE_2D;
  24412. var webglTexture = properties.get( texture ).__webglTexture;
  24413. state.bindTexture( target, webglTexture );
  24414. _gl.generateMipmap( target );
  24415. state.bindTexture( target, null );
  24416. }
  24417. }
  24418. this.setTexture2D = setTexture2D;
  24419. this.setTextureCube = setTextureCube;
  24420. this.setTextureCubeDynamic = setTextureCubeDynamic;
  24421. this.setupRenderTarget = setupRenderTarget;
  24422. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  24423. }
  24424. /**
  24425. * @author fordacious / fordacious.github.io
  24426. */
  24427. function WebGLProperties() {
  24428. var properties = {};
  24429. function get( object ) {
  24430. var uuid = object.uuid;
  24431. var map = properties[ uuid ];
  24432. if ( map === undefined ) {
  24433. map = {};
  24434. properties[ uuid ] = map;
  24435. }
  24436. return map;
  24437. }
  24438. function remove( object ) {
  24439. delete properties[ object.uuid ];
  24440. }
  24441. function clear() {
  24442. properties = {};
  24443. }
  24444. return {
  24445. get: get,
  24446. remove: remove,
  24447. clear: clear
  24448. };
  24449. }
  24450. /**
  24451. * @author mrdoob / http://mrdoob.com/
  24452. */
  24453. function WebGLState( gl, extensions, utils ) {
  24454. function ColorBuffer() {
  24455. var locked = false;
  24456. var color = new Vector4();
  24457. var currentColorMask = null;
  24458. var currentColorClear = new Vector4( 0, 0, 0, 0 );
  24459. return {
  24460. setMask: function ( colorMask ) {
  24461. if ( currentColorMask !== colorMask && ! locked ) {
  24462. gl.colorMask( colorMask, colorMask, colorMask, colorMask );
  24463. currentColorMask = colorMask;
  24464. }
  24465. },
  24466. setLocked: function ( lock ) {
  24467. locked = lock;
  24468. },
  24469. setClear: function ( r, g, b, a, premultipliedAlpha ) {
  24470. if ( premultipliedAlpha === true ) {
  24471. r *= a; g *= a; b *= a;
  24472. }
  24473. color.set( r, g, b, a );
  24474. if ( currentColorClear.equals( color ) === false ) {
  24475. gl.clearColor( r, g, b, a );
  24476. currentColorClear.copy( color );
  24477. }
  24478. },
  24479. reset: function () {
  24480. locked = false;
  24481. currentColorMask = null;
  24482. currentColorClear.set( - 1, 0, 0, 0 ); // set to invalid state
  24483. }
  24484. };
  24485. }
  24486. function DepthBuffer() {
  24487. var locked = false;
  24488. var currentDepthMask = null;
  24489. var currentDepthFunc = null;
  24490. var currentDepthClear = null;
  24491. return {
  24492. setTest: function ( depthTest ) {
  24493. if ( depthTest ) {
  24494. enable( gl.DEPTH_TEST );
  24495. } else {
  24496. disable( gl.DEPTH_TEST );
  24497. }
  24498. },
  24499. setMask: function ( depthMask ) {
  24500. if ( currentDepthMask !== depthMask && ! locked ) {
  24501. gl.depthMask( depthMask );
  24502. currentDepthMask = depthMask;
  24503. }
  24504. },
  24505. setFunc: function ( depthFunc ) {
  24506. if ( currentDepthFunc !== depthFunc ) {
  24507. if ( depthFunc ) {
  24508. switch ( depthFunc ) {
  24509. case NeverDepth:
  24510. gl.depthFunc( gl.NEVER );
  24511. break;
  24512. case AlwaysDepth:
  24513. gl.depthFunc( gl.ALWAYS );
  24514. break;
  24515. case LessDepth:
  24516. gl.depthFunc( gl.LESS );
  24517. break;
  24518. case LessEqualDepth:
  24519. gl.depthFunc( gl.LEQUAL );
  24520. break;
  24521. case EqualDepth:
  24522. gl.depthFunc( gl.EQUAL );
  24523. break;
  24524. case GreaterEqualDepth:
  24525. gl.depthFunc( gl.GEQUAL );
  24526. break;
  24527. case GreaterDepth:
  24528. gl.depthFunc( gl.GREATER );
  24529. break;
  24530. case NotEqualDepth:
  24531. gl.depthFunc( gl.NOTEQUAL );
  24532. break;
  24533. default:
  24534. gl.depthFunc( gl.LEQUAL );
  24535. }
  24536. } else {
  24537. gl.depthFunc( gl.LEQUAL );
  24538. }
  24539. currentDepthFunc = depthFunc;
  24540. }
  24541. },
  24542. setLocked: function ( lock ) {
  24543. locked = lock;
  24544. },
  24545. setClear: function ( depth ) {
  24546. if ( currentDepthClear !== depth ) {
  24547. gl.clearDepth( depth );
  24548. currentDepthClear = depth;
  24549. }
  24550. },
  24551. reset: function () {
  24552. locked = false;
  24553. currentDepthMask = null;
  24554. currentDepthFunc = null;
  24555. currentDepthClear = null;
  24556. }
  24557. };
  24558. }
  24559. function StencilBuffer() {
  24560. var locked = false;
  24561. var currentStencilMask = null;
  24562. var currentStencilFunc = null;
  24563. var currentStencilRef = null;
  24564. var currentStencilFuncMask = null;
  24565. var currentStencilFail = null;
  24566. var currentStencilZFail = null;
  24567. var currentStencilZPass = null;
  24568. var currentStencilClear = null;
  24569. return {
  24570. setTest: function ( stencilTest ) {
  24571. if ( stencilTest ) {
  24572. enable( gl.STENCIL_TEST );
  24573. } else {
  24574. disable( gl.STENCIL_TEST );
  24575. }
  24576. },
  24577. setMask: function ( stencilMask ) {
  24578. if ( currentStencilMask !== stencilMask && ! locked ) {
  24579. gl.stencilMask( stencilMask );
  24580. currentStencilMask = stencilMask;
  24581. }
  24582. },
  24583. setFunc: function ( stencilFunc, stencilRef, stencilMask ) {
  24584. if ( currentStencilFunc !== stencilFunc ||
  24585. currentStencilRef !== stencilRef ||
  24586. currentStencilFuncMask !== stencilMask ) {
  24587. gl.stencilFunc( stencilFunc, stencilRef, stencilMask );
  24588. currentStencilFunc = stencilFunc;
  24589. currentStencilRef = stencilRef;
  24590. currentStencilFuncMask = stencilMask;
  24591. }
  24592. },
  24593. setOp: function ( stencilFail, stencilZFail, stencilZPass ) {
  24594. if ( currentStencilFail !== stencilFail ||
  24595. currentStencilZFail !== stencilZFail ||
  24596. currentStencilZPass !== stencilZPass ) {
  24597. gl.stencilOp( stencilFail, stencilZFail, stencilZPass );
  24598. currentStencilFail = stencilFail;
  24599. currentStencilZFail = stencilZFail;
  24600. currentStencilZPass = stencilZPass;
  24601. }
  24602. },
  24603. setLocked: function ( lock ) {
  24604. locked = lock;
  24605. },
  24606. setClear: function ( stencil ) {
  24607. if ( currentStencilClear !== stencil ) {
  24608. gl.clearStencil( stencil );
  24609. currentStencilClear = stencil;
  24610. }
  24611. },
  24612. reset: function () {
  24613. locked = false;
  24614. currentStencilMask = null;
  24615. currentStencilFunc = null;
  24616. currentStencilRef = null;
  24617. currentStencilFuncMask = null;
  24618. currentStencilFail = null;
  24619. currentStencilZFail = null;
  24620. currentStencilZPass = null;
  24621. currentStencilClear = null;
  24622. }
  24623. };
  24624. }
  24625. //
  24626. var colorBuffer = new ColorBuffer();
  24627. var depthBuffer = new DepthBuffer();
  24628. var stencilBuffer = new StencilBuffer();
  24629. var maxVertexAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
  24630. var newAttributes = new Uint8Array( maxVertexAttributes );
  24631. var enabledAttributes = new Uint8Array( maxVertexAttributes );
  24632. var attributeDivisors = new Uint8Array( maxVertexAttributes );
  24633. var capabilities = {};
  24634. var compressedTextureFormats = null;
  24635. var currentProgram = null;
  24636. var currentBlending = null;
  24637. var currentBlendEquation = null;
  24638. var currentBlendSrc = null;
  24639. var currentBlendDst = null;
  24640. var currentBlendEquationAlpha = null;
  24641. var currentBlendSrcAlpha = null;
  24642. var currentBlendDstAlpha = null;
  24643. var currentPremultipledAlpha = false;
  24644. var currentFlipSided = null;
  24645. var currentCullFace = null;
  24646. var currentLineWidth = null;
  24647. var currentPolygonOffsetFactor = null;
  24648. var currentPolygonOffsetUnits = null;
  24649. var maxTextures = gl.getParameter( gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS );
  24650. var version = parseFloat( /^WebGL\ ([0-9])/.exec( gl.getParameter( gl.VERSION ) )[ 1 ] );
  24651. var lineWidthAvailable = parseFloat( version ) >= 1.0;
  24652. var currentTextureSlot = null;
  24653. var currentBoundTextures = {};
  24654. var currentScissor = new Vector4();
  24655. var currentViewport = new Vector4();
  24656. function createTexture( type, target, count ) {
  24657. var data = new Uint8Array( 4 ); // 4 is required to match default unpack alignment of 4.
  24658. var texture = gl.createTexture();
  24659. gl.bindTexture( type, texture );
  24660. gl.texParameteri( type, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  24661. gl.texParameteri( type, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  24662. for ( var i = 0; i < count; i ++ ) {
  24663. gl.texImage2D( target + i, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, data );
  24664. }
  24665. return texture;
  24666. }
  24667. var emptyTextures = {};
  24668. emptyTextures[ gl.TEXTURE_2D ] = createTexture( gl.TEXTURE_2D, gl.TEXTURE_2D, 1 );
  24669. emptyTextures[ gl.TEXTURE_CUBE_MAP ] = createTexture( gl.TEXTURE_CUBE_MAP, gl.TEXTURE_CUBE_MAP_POSITIVE_X, 6 );
  24670. // init
  24671. colorBuffer.setClear( 0, 0, 0, 1 );
  24672. depthBuffer.setClear( 1 );
  24673. stencilBuffer.setClear( 0 );
  24674. enable( gl.DEPTH_TEST );
  24675. depthBuffer.setFunc( LessEqualDepth );
  24676. setFlipSided( false );
  24677. setCullFace( CullFaceBack );
  24678. enable( gl.CULL_FACE );
  24679. enable( gl.BLEND );
  24680. setBlending( NormalBlending );
  24681. //
  24682. function initAttributes() {
  24683. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  24684. newAttributes[ i ] = 0;
  24685. }
  24686. }
  24687. function enableAttribute( attribute ) {
  24688. newAttributes[ attribute ] = 1;
  24689. if ( enabledAttributes[ attribute ] === 0 ) {
  24690. gl.enableVertexAttribArray( attribute );
  24691. enabledAttributes[ attribute ] = 1;
  24692. }
  24693. if ( attributeDivisors[ attribute ] !== 0 ) {
  24694. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  24695. extension.vertexAttribDivisorANGLE( attribute, 0 );
  24696. attributeDivisors[ attribute ] = 0;
  24697. }
  24698. }
  24699. function enableAttributeAndDivisor( attribute, meshPerAttribute ) {
  24700. newAttributes[ attribute ] = 1;
  24701. if ( enabledAttributes[ attribute ] === 0 ) {
  24702. gl.enableVertexAttribArray( attribute );
  24703. enabledAttributes[ attribute ] = 1;
  24704. }
  24705. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  24706. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  24707. extension.vertexAttribDivisorANGLE( attribute, meshPerAttribute );
  24708. attributeDivisors[ attribute ] = meshPerAttribute;
  24709. }
  24710. }
  24711. function disableUnusedAttributes() {
  24712. for ( var i = 0, l = enabledAttributes.length; i !== l; ++ i ) {
  24713. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  24714. gl.disableVertexAttribArray( i );
  24715. enabledAttributes[ i ] = 0;
  24716. }
  24717. }
  24718. }
  24719. function enable( id ) {
  24720. if ( capabilities[ id ] !== true ) {
  24721. gl.enable( id );
  24722. capabilities[ id ] = true;
  24723. }
  24724. }
  24725. function disable( id ) {
  24726. if ( capabilities[ id ] !== false ) {
  24727. gl.disable( id );
  24728. capabilities[ id ] = false;
  24729. }
  24730. }
  24731. function getCompressedTextureFormats() {
  24732. if ( compressedTextureFormats === null ) {
  24733. compressedTextureFormats = [];
  24734. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) ||
  24735. extensions.get( 'WEBGL_compressed_texture_s3tc' ) ||
  24736. extensions.get( 'WEBGL_compressed_texture_etc1' ) ) {
  24737. var formats = gl.getParameter( gl.COMPRESSED_TEXTURE_FORMATS );
  24738. for ( var i = 0; i < formats.length; i ++ ) {
  24739. compressedTextureFormats.push( formats[ i ] );
  24740. }
  24741. }
  24742. }
  24743. return compressedTextureFormats;
  24744. }
  24745. function useProgram( program ) {
  24746. if ( currentProgram !== program ) {
  24747. gl.useProgram( program );
  24748. currentProgram = program;
  24749. return true;
  24750. }
  24751. return false;
  24752. }
  24753. function setBlending( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
  24754. if ( blending !== NoBlending ) {
  24755. enable( gl.BLEND );
  24756. } else {
  24757. disable( gl.BLEND );
  24758. }
  24759. if ( blending !== CustomBlending ) {
  24760. if ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) {
  24761. switch ( blending ) {
  24762. case AdditiveBlending:
  24763. if ( premultipliedAlpha ) {
  24764. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  24765. gl.blendFuncSeparate( gl.ONE, gl.ONE, gl.ONE, gl.ONE );
  24766. } else {
  24767. gl.blendEquation( gl.FUNC_ADD );
  24768. gl.blendFunc( gl.SRC_ALPHA, gl.ONE );
  24769. }
  24770. break;
  24771. case SubtractiveBlending:
  24772. if ( premultipliedAlpha ) {
  24773. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  24774. gl.blendFuncSeparate( gl.ZERO, gl.ZERO, gl.ONE_MINUS_SRC_COLOR, gl.ONE_MINUS_SRC_ALPHA );
  24775. } else {
  24776. gl.blendEquation( gl.FUNC_ADD );
  24777. gl.blendFunc( gl.ZERO, gl.ONE_MINUS_SRC_COLOR );
  24778. }
  24779. break;
  24780. case MultiplyBlending:
  24781. if ( premultipliedAlpha ) {
  24782. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  24783. gl.blendFuncSeparate( gl.ZERO, gl.SRC_COLOR, gl.ZERO, gl.SRC_ALPHA );
  24784. } else {
  24785. gl.blendEquation( gl.FUNC_ADD );
  24786. gl.blendFunc( gl.ZERO, gl.SRC_COLOR );
  24787. }
  24788. break;
  24789. default:
  24790. if ( premultipliedAlpha ) {
  24791. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  24792. gl.blendFuncSeparate( gl.ONE, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  24793. } else {
  24794. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  24795. gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  24796. }
  24797. }
  24798. }
  24799. currentBlendEquation = null;
  24800. currentBlendSrc = null;
  24801. currentBlendDst = null;
  24802. currentBlendEquationAlpha = null;
  24803. currentBlendSrcAlpha = null;
  24804. currentBlendDstAlpha = null;
  24805. } else {
  24806. blendEquationAlpha = blendEquationAlpha || blendEquation;
  24807. blendSrcAlpha = blendSrcAlpha || blendSrc;
  24808. blendDstAlpha = blendDstAlpha || blendDst;
  24809. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  24810. gl.blendEquationSeparate( utils.convert( blendEquation ), utils.convert( blendEquationAlpha ) );
  24811. currentBlendEquation = blendEquation;
  24812. currentBlendEquationAlpha = blendEquationAlpha;
  24813. }
  24814. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  24815. gl.blendFuncSeparate( utils.convert( blendSrc ), utils.convert( blendDst ), utils.convert( blendSrcAlpha ), utils.convert( blendDstAlpha ) );
  24816. currentBlendSrc = blendSrc;
  24817. currentBlendDst = blendDst;
  24818. currentBlendSrcAlpha = blendSrcAlpha;
  24819. currentBlendDstAlpha = blendDstAlpha;
  24820. }
  24821. }
  24822. currentBlending = blending;
  24823. currentPremultipledAlpha = premultipliedAlpha;
  24824. }
  24825. function setMaterial( material ) {
  24826. material.side === DoubleSide
  24827. ? disable( gl.CULL_FACE )
  24828. : enable( gl.CULL_FACE );
  24829. setFlipSided( material.side === BackSide );
  24830. material.transparent === true
  24831. ? setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha )
  24832. : setBlending( NoBlending );
  24833. depthBuffer.setFunc( material.depthFunc );
  24834. depthBuffer.setTest( material.depthTest );
  24835. depthBuffer.setMask( material.depthWrite );
  24836. colorBuffer.setMask( material.colorWrite );
  24837. setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  24838. }
  24839. //
  24840. function setFlipSided( flipSided ) {
  24841. if ( currentFlipSided !== flipSided ) {
  24842. if ( flipSided ) {
  24843. gl.frontFace( gl.CW );
  24844. } else {
  24845. gl.frontFace( gl.CCW );
  24846. }
  24847. currentFlipSided = flipSided;
  24848. }
  24849. }
  24850. function setCullFace( cullFace ) {
  24851. if ( cullFace !== CullFaceNone ) {
  24852. enable( gl.CULL_FACE );
  24853. if ( cullFace !== currentCullFace ) {
  24854. if ( cullFace === CullFaceBack ) {
  24855. gl.cullFace( gl.BACK );
  24856. } else if ( cullFace === CullFaceFront ) {
  24857. gl.cullFace( gl.FRONT );
  24858. } else {
  24859. gl.cullFace( gl.FRONT_AND_BACK );
  24860. }
  24861. }
  24862. } else {
  24863. disable( gl.CULL_FACE );
  24864. }
  24865. currentCullFace = cullFace;
  24866. }
  24867. function setLineWidth( width ) {
  24868. if ( width !== currentLineWidth ) {
  24869. if ( lineWidthAvailable ) gl.lineWidth( width );
  24870. currentLineWidth = width;
  24871. }
  24872. }
  24873. function setPolygonOffset( polygonOffset, factor, units ) {
  24874. if ( polygonOffset ) {
  24875. enable( gl.POLYGON_OFFSET_FILL );
  24876. if ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) {
  24877. gl.polygonOffset( factor, units );
  24878. currentPolygonOffsetFactor = factor;
  24879. currentPolygonOffsetUnits = units;
  24880. }
  24881. } else {
  24882. disable( gl.POLYGON_OFFSET_FILL );
  24883. }
  24884. }
  24885. function setScissorTest( scissorTest ) {
  24886. if ( scissorTest ) {
  24887. enable( gl.SCISSOR_TEST );
  24888. } else {
  24889. disable( gl.SCISSOR_TEST );
  24890. }
  24891. }
  24892. // texture
  24893. function activeTexture( webglSlot ) {
  24894. if ( webglSlot === undefined ) webglSlot = gl.TEXTURE0 + maxTextures - 1;
  24895. if ( currentTextureSlot !== webglSlot ) {
  24896. gl.activeTexture( webglSlot );
  24897. currentTextureSlot = webglSlot;
  24898. }
  24899. }
  24900. function bindTexture( webglType, webglTexture ) {
  24901. if ( currentTextureSlot === null ) {
  24902. activeTexture();
  24903. }
  24904. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  24905. if ( boundTexture === undefined ) {
  24906. boundTexture = { type: undefined, texture: undefined };
  24907. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  24908. }
  24909. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  24910. gl.bindTexture( webglType, webglTexture || emptyTextures[ webglType ] );
  24911. boundTexture.type = webglType;
  24912. boundTexture.texture = webglTexture;
  24913. }
  24914. }
  24915. function compressedTexImage2D() {
  24916. try {
  24917. gl.compressedTexImage2D.apply( gl, arguments );
  24918. } catch ( error ) {
  24919. console.error( 'THREE.WebGLState:', error );
  24920. }
  24921. }
  24922. function texImage2D() {
  24923. try {
  24924. gl.texImage2D.apply( gl, arguments );
  24925. } catch ( error ) {
  24926. console.error( 'THREE.WebGLState:', error );
  24927. }
  24928. }
  24929. //
  24930. function scissor( scissor ) {
  24931. if ( currentScissor.equals( scissor ) === false ) {
  24932. gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );
  24933. currentScissor.copy( scissor );
  24934. }
  24935. }
  24936. function viewport( viewport ) {
  24937. if ( currentViewport.equals( viewport ) === false ) {
  24938. gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );
  24939. currentViewport.copy( viewport );
  24940. }
  24941. }
  24942. //
  24943. function reset() {
  24944. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  24945. if ( enabledAttributes[ i ] === 1 ) {
  24946. gl.disableVertexAttribArray( i );
  24947. enabledAttributes[ i ] = 0;
  24948. }
  24949. }
  24950. capabilities = {};
  24951. compressedTextureFormats = null;
  24952. currentTextureSlot = null;
  24953. currentBoundTextures = {};
  24954. currentProgram = null;
  24955. currentBlending = null;
  24956. currentFlipSided = null;
  24957. currentCullFace = null;
  24958. colorBuffer.reset();
  24959. depthBuffer.reset();
  24960. stencilBuffer.reset();
  24961. }
  24962. return {
  24963. buffers: {
  24964. color: colorBuffer,
  24965. depth: depthBuffer,
  24966. stencil: stencilBuffer
  24967. },
  24968. initAttributes: initAttributes,
  24969. enableAttribute: enableAttribute,
  24970. enableAttributeAndDivisor: enableAttributeAndDivisor,
  24971. disableUnusedAttributes: disableUnusedAttributes,
  24972. enable: enable,
  24973. disable: disable,
  24974. getCompressedTextureFormats: getCompressedTextureFormats,
  24975. useProgram: useProgram,
  24976. setBlending: setBlending,
  24977. setMaterial: setMaterial,
  24978. setFlipSided: setFlipSided,
  24979. setCullFace: setCullFace,
  24980. setLineWidth: setLineWidth,
  24981. setPolygonOffset: setPolygonOffset,
  24982. setScissorTest: setScissorTest,
  24983. activeTexture: activeTexture,
  24984. bindTexture: bindTexture,
  24985. compressedTexImage2D: compressedTexImage2D,
  24986. texImage2D: texImage2D,
  24987. scissor: scissor,
  24988. viewport: viewport,
  24989. reset: reset
  24990. };
  24991. }
  24992. /**
  24993. * @author mrdoob / http://mrdoob.com/
  24994. */
  24995. function WebGLCapabilities( gl, extensions, parameters ) {
  24996. var maxAnisotropy;
  24997. function getMaxAnisotropy() {
  24998. if ( maxAnisotropy !== undefined ) return maxAnisotropy;
  24999. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  25000. if ( extension !== null ) {
  25001. maxAnisotropy = gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  25002. } else {
  25003. maxAnisotropy = 0;
  25004. }
  25005. return maxAnisotropy;
  25006. }
  25007. function getMaxPrecision( precision ) {
  25008. if ( precision === 'highp' ) {
  25009. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.HIGH_FLOAT ).precision > 0 &&
  25010. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.HIGH_FLOAT ).precision > 0 ) {
  25011. return 'highp';
  25012. }
  25013. precision = 'mediump';
  25014. }
  25015. if ( precision === 'mediump' ) {
  25016. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.MEDIUM_FLOAT ).precision > 0 &&
  25017. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT ).precision > 0 ) {
  25018. return 'mediump';
  25019. }
  25020. }
  25021. return 'lowp';
  25022. }
  25023. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  25024. var maxPrecision = getMaxPrecision( precision );
  25025. if ( maxPrecision !== precision ) {
  25026. console.warn( 'THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.' );
  25027. precision = maxPrecision;
  25028. }
  25029. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  25030. var maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  25031. var maxVertexTextures = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );
  25032. var maxTextureSize = gl.getParameter( gl.MAX_TEXTURE_SIZE );
  25033. var maxCubemapSize = gl.getParameter( gl.MAX_CUBE_MAP_TEXTURE_SIZE );
  25034. var maxAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
  25035. var maxVertexUniforms = gl.getParameter( gl.MAX_VERTEX_UNIFORM_VECTORS );
  25036. var maxVaryings = gl.getParameter( gl.MAX_VARYING_VECTORS );
  25037. var maxFragmentUniforms = gl.getParameter( gl.MAX_FRAGMENT_UNIFORM_VECTORS );
  25038. var vertexTextures = maxVertexTextures > 0;
  25039. var floatFragmentTextures = !! extensions.get( 'OES_texture_float' );
  25040. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  25041. return {
  25042. getMaxAnisotropy: getMaxAnisotropy,
  25043. getMaxPrecision: getMaxPrecision,
  25044. precision: precision,
  25045. logarithmicDepthBuffer: logarithmicDepthBuffer,
  25046. maxTextures: maxTextures,
  25047. maxVertexTextures: maxVertexTextures,
  25048. maxTextureSize: maxTextureSize,
  25049. maxCubemapSize: maxCubemapSize,
  25050. maxAttributes: maxAttributes,
  25051. maxVertexUniforms: maxVertexUniforms,
  25052. maxVaryings: maxVaryings,
  25053. maxFragmentUniforms: maxFragmentUniforms,
  25054. vertexTextures: vertexTextures,
  25055. floatFragmentTextures: floatFragmentTextures,
  25056. floatVertexTextures: floatVertexTextures
  25057. };
  25058. }
  25059. /**
  25060. * @author mrdoob / http://mrdoob.com/
  25061. */
  25062. function WebVRManager( renderer ) {
  25063. var scope = this;
  25064. var device = null;
  25065. var frameData = null;
  25066. if ( typeof window !== 'undefined' && 'VRFrameData' in window ) {
  25067. frameData = new window.VRFrameData();
  25068. }
  25069. var matrixWorldInverse = new Matrix4();
  25070. var standingMatrix = new Matrix4();
  25071. var standingMatrixInverse = new Matrix4();
  25072. var cameraL = new PerspectiveCamera();
  25073. cameraL.bounds = new Vector4( 0.0, 0.0, 0.5, 1.0 );
  25074. cameraL.layers.enable( 1 );
  25075. var cameraR = new PerspectiveCamera();
  25076. cameraR.bounds = new Vector4( 0.5, 0.0, 0.5, 1.0 );
  25077. cameraR.layers.enable( 2 );
  25078. var cameraVR = new ArrayCamera( [ cameraL, cameraR ] );
  25079. cameraVR.layers.enable( 1 );
  25080. cameraVR.layers.enable( 2 );
  25081. //
  25082. var currentSize, currentPixelRatio;
  25083. function onVRDisplayPresentChange() {
  25084. if ( device !== null && device.isPresenting ) {
  25085. var eyeParameters = device.getEyeParameters( 'left' );
  25086. var renderWidth = eyeParameters.renderWidth;
  25087. var renderHeight = eyeParameters.renderHeight;
  25088. currentPixelRatio = renderer.getPixelRatio();
  25089. currentSize = renderer.getSize();
  25090. renderer.setDrawingBufferSize( renderWidth * 2, renderHeight, 1 );
  25091. } else if ( scope.enabled ) {
  25092. renderer.setDrawingBufferSize( currentSize.width, currentSize.height, currentPixelRatio );
  25093. }
  25094. }
  25095. if ( typeof window !== 'undefined' ) {
  25096. window.addEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange, false );
  25097. }
  25098. //
  25099. this.enabled = false;
  25100. this.standing = false;
  25101. this.getDevice = function () {
  25102. return device;
  25103. };
  25104. this.setDevice = function ( value ) {
  25105. if ( value !== undefined ) device = value;
  25106. };
  25107. this.getCamera = function ( camera ) {
  25108. if ( device === null ) return camera;
  25109. device.depthNear = camera.near;
  25110. device.depthFar = camera.far;
  25111. device.getFrameData( frameData );
  25112. //
  25113. var pose = frameData.pose;
  25114. if ( pose.position !== null ) {
  25115. camera.position.fromArray( pose.position );
  25116. } else {
  25117. camera.position.set( 0, 0, 0 );
  25118. }
  25119. if ( pose.orientation !== null ) {
  25120. camera.quaternion.fromArray( pose.orientation );
  25121. }
  25122. camera.updateMatrixWorld();
  25123. var stageParameters = device.stageParameters;
  25124. if ( this.standing && stageParameters ) {
  25125. standingMatrix.fromArray( stageParameters.sittingToStandingTransform );
  25126. standingMatrixInverse.getInverse( standingMatrix );
  25127. camera.matrixWorld.multiply( standingMatrix );
  25128. camera.matrixWorldInverse.multiply( standingMatrixInverse );
  25129. }
  25130. if ( device.isPresenting === false ) return camera;
  25131. //
  25132. cameraL.near = camera.near;
  25133. cameraR.near = camera.near;
  25134. cameraL.far = camera.far;
  25135. cameraR.far = camera.far;
  25136. cameraVR.matrixWorld.copy( camera.matrixWorld );
  25137. cameraVR.matrixWorldInverse.copy( camera.matrixWorldInverse );
  25138. cameraL.matrixWorldInverse.fromArray( frameData.leftViewMatrix );
  25139. cameraR.matrixWorldInverse.fromArray( frameData.rightViewMatrix );
  25140. if ( this.standing && stageParameters ) {
  25141. cameraL.matrixWorldInverse.multiply( standingMatrixInverse );
  25142. cameraR.matrixWorldInverse.multiply( standingMatrixInverse );
  25143. }
  25144. var parent = camera.parent;
  25145. if ( parent !== null ) {
  25146. matrixWorldInverse.getInverse( parent.matrixWorld );
  25147. cameraL.matrixWorldInverse.multiply( matrixWorldInverse );
  25148. cameraR.matrixWorldInverse.multiply( matrixWorldInverse );
  25149. }
  25150. // envMap and Mirror needs camera.matrixWorld
  25151. cameraL.matrixWorld.getInverse( cameraL.matrixWorldInverse );
  25152. cameraR.matrixWorld.getInverse( cameraR.matrixWorldInverse );
  25153. cameraL.projectionMatrix.fromArray( frameData.leftProjectionMatrix );
  25154. cameraR.projectionMatrix.fromArray( frameData.rightProjectionMatrix );
  25155. // HACK @mrdoob
  25156. // https://github.com/w3c/webvr/issues/203
  25157. cameraVR.projectionMatrix.copy( cameraL.projectionMatrix );
  25158. //
  25159. var layers = device.getLayers();
  25160. if ( layers.length ) {
  25161. var layer = layers[ 0 ];
  25162. if ( layer.leftBounds !== null && layer.leftBounds.length === 4 ) {
  25163. cameraL.bounds.fromArray( layer.leftBounds );
  25164. }
  25165. if ( layer.rightBounds !== null && layer.rightBounds.length === 4 ) {
  25166. cameraR.bounds.fromArray( layer.rightBounds );
  25167. }
  25168. }
  25169. return cameraVR;
  25170. };
  25171. this.getStandingMatrix = function () {
  25172. return standingMatrix;
  25173. };
  25174. this.submitFrame = function () {
  25175. if ( device && device.isPresenting ) device.submitFrame();
  25176. };
  25177. this.dispose = function () {
  25178. window.removeEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange );
  25179. };
  25180. }
  25181. /**
  25182. * @author mrdoob / http://mrdoob.com/
  25183. */
  25184. function WebGLExtensions( gl ) {
  25185. var extensions = {};
  25186. return {
  25187. get: function ( name ) {
  25188. if ( extensions[ name ] !== undefined ) {
  25189. return extensions[ name ];
  25190. }
  25191. var extension;
  25192. switch ( name ) {
  25193. case 'WEBGL_depth_texture':
  25194. extension = gl.getExtension( 'WEBGL_depth_texture' ) || gl.getExtension( 'MOZ_WEBGL_depth_texture' ) || gl.getExtension( 'WEBKIT_WEBGL_depth_texture' );
  25195. break;
  25196. case 'EXT_texture_filter_anisotropic':
  25197. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  25198. break;
  25199. case 'WEBGL_compressed_texture_s3tc':
  25200. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  25201. break;
  25202. case 'WEBGL_compressed_texture_pvrtc':
  25203. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  25204. break;
  25205. case 'WEBGL_compressed_texture_etc1':
  25206. extension = gl.getExtension( 'WEBGL_compressed_texture_etc1' );
  25207. break;
  25208. default:
  25209. extension = gl.getExtension( name );
  25210. }
  25211. if ( extension === null ) {
  25212. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  25213. }
  25214. extensions[ name ] = extension;
  25215. return extension;
  25216. }
  25217. };
  25218. }
  25219. /**
  25220. * @author tschw
  25221. */
  25222. function WebGLClipping() {
  25223. var scope = this,
  25224. globalState = null,
  25225. numGlobalPlanes = 0,
  25226. localClippingEnabled = false,
  25227. renderingShadows = false,
  25228. plane = new Plane(),
  25229. viewNormalMatrix = new Matrix3(),
  25230. uniform = { value: null, needsUpdate: false };
  25231. this.uniform = uniform;
  25232. this.numPlanes = 0;
  25233. this.numIntersection = 0;
  25234. this.init = function ( planes, enableLocalClipping, camera ) {
  25235. var enabled =
  25236. planes.length !== 0 ||
  25237. enableLocalClipping ||
  25238. // enable state of previous frame - the clipping code has to
  25239. // run another frame in order to reset the state:
  25240. numGlobalPlanes !== 0 ||
  25241. localClippingEnabled;
  25242. localClippingEnabled = enableLocalClipping;
  25243. globalState = projectPlanes( planes, camera, 0 );
  25244. numGlobalPlanes = planes.length;
  25245. return enabled;
  25246. };
  25247. this.beginShadows = function () {
  25248. renderingShadows = true;
  25249. projectPlanes( null );
  25250. };
  25251. this.endShadows = function () {
  25252. renderingShadows = false;
  25253. resetGlobalState();
  25254. };
  25255. this.setState = function ( planes, clipIntersection, clipShadows, camera, cache, fromCache ) {
  25256. if ( ! localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && ! clipShadows ) {
  25257. // there's no local clipping
  25258. if ( renderingShadows ) {
  25259. // there's no global clipping
  25260. projectPlanes( null );
  25261. } else {
  25262. resetGlobalState();
  25263. }
  25264. } else {
  25265. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  25266. lGlobal = nGlobal * 4,
  25267. dstArray = cache.clippingState || null;
  25268. uniform.value = dstArray; // ensure unique state
  25269. dstArray = projectPlanes( planes, camera, lGlobal, fromCache );
  25270. for ( var i = 0; i !== lGlobal; ++ i ) {
  25271. dstArray[ i ] = globalState[ i ];
  25272. }
  25273. cache.clippingState = dstArray;
  25274. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  25275. this.numPlanes += nGlobal;
  25276. }
  25277. };
  25278. function resetGlobalState() {
  25279. if ( uniform.value !== globalState ) {
  25280. uniform.value = globalState;
  25281. uniform.needsUpdate = numGlobalPlanes > 0;
  25282. }
  25283. scope.numPlanes = numGlobalPlanes;
  25284. scope.numIntersection = 0;
  25285. }
  25286. function projectPlanes( planes, camera, dstOffset, skipTransform ) {
  25287. var nPlanes = planes !== null ? planes.length : 0,
  25288. dstArray = null;
  25289. if ( nPlanes !== 0 ) {
  25290. dstArray = uniform.value;
  25291. if ( skipTransform !== true || dstArray === null ) {
  25292. var flatSize = dstOffset + nPlanes * 4,
  25293. viewMatrix = camera.matrixWorldInverse;
  25294. viewNormalMatrix.getNormalMatrix( viewMatrix );
  25295. if ( dstArray === null || dstArray.length < flatSize ) {
  25296. dstArray = new Float32Array( flatSize );
  25297. }
  25298. for ( var i = 0, i4 = dstOffset; i !== nPlanes; ++ i, i4 += 4 ) {
  25299. plane.copy( planes[ i ] ).applyMatrix4( viewMatrix, viewNormalMatrix );
  25300. plane.normal.toArray( dstArray, i4 );
  25301. dstArray[ i4 + 3 ] = plane.constant;
  25302. }
  25303. }
  25304. uniform.value = dstArray;
  25305. uniform.needsUpdate = true;
  25306. }
  25307. scope.numPlanes = nPlanes;
  25308. return dstArray;
  25309. }
  25310. }
  25311. /**
  25312. * @author thespite / http://www.twitter.com/thespite
  25313. */
  25314. function WebGLUtils( gl, extensions ) {
  25315. function convert( p ) {
  25316. var extension;
  25317. if ( p === RepeatWrapping ) return gl.REPEAT;
  25318. if ( p === ClampToEdgeWrapping ) return gl.CLAMP_TO_EDGE;
  25319. if ( p === MirroredRepeatWrapping ) return gl.MIRRORED_REPEAT;
  25320. if ( p === NearestFilter ) return gl.NEAREST;
  25321. if ( p === NearestMipMapNearestFilter ) return gl.NEAREST_MIPMAP_NEAREST;
  25322. if ( p === NearestMipMapLinearFilter ) return gl.NEAREST_MIPMAP_LINEAR;
  25323. if ( p === LinearFilter ) return gl.LINEAR;
  25324. if ( p === LinearMipMapNearestFilter ) return gl.LINEAR_MIPMAP_NEAREST;
  25325. if ( p === LinearMipMapLinearFilter ) return gl.LINEAR_MIPMAP_LINEAR;
  25326. if ( p === UnsignedByteType ) return gl.UNSIGNED_BYTE;
  25327. if ( p === UnsignedShort4444Type ) return gl.UNSIGNED_SHORT_4_4_4_4;
  25328. if ( p === UnsignedShort5551Type ) return gl.UNSIGNED_SHORT_5_5_5_1;
  25329. if ( p === UnsignedShort565Type ) return gl.UNSIGNED_SHORT_5_6_5;
  25330. if ( p === ByteType ) return gl.BYTE;
  25331. if ( p === ShortType ) return gl.SHORT;
  25332. if ( p === UnsignedShortType ) return gl.UNSIGNED_SHORT;
  25333. if ( p === IntType ) return gl.INT;
  25334. if ( p === UnsignedIntType ) return gl.UNSIGNED_INT;
  25335. if ( p === FloatType ) return gl.FLOAT;
  25336. if ( p === HalfFloatType ) {
  25337. extension = extensions.get( 'OES_texture_half_float' );
  25338. if ( extension !== null ) return extension.HALF_FLOAT_OES;
  25339. }
  25340. if ( p === AlphaFormat ) return gl.ALPHA;
  25341. if ( p === RGBFormat ) return gl.RGB;
  25342. if ( p === RGBAFormat ) return gl.RGBA;
  25343. if ( p === LuminanceFormat ) return gl.LUMINANCE;
  25344. if ( p === LuminanceAlphaFormat ) return gl.LUMINANCE_ALPHA;
  25345. if ( p === DepthFormat ) return gl.DEPTH_COMPONENT;
  25346. if ( p === DepthStencilFormat ) return gl.DEPTH_STENCIL;
  25347. if ( p === AddEquation ) return gl.FUNC_ADD;
  25348. if ( p === SubtractEquation ) return gl.FUNC_SUBTRACT;
  25349. if ( p === ReverseSubtractEquation ) return gl.FUNC_REVERSE_SUBTRACT;
  25350. if ( p === ZeroFactor ) return gl.ZERO;
  25351. if ( p === OneFactor ) return gl.ONE;
  25352. if ( p === SrcColorFactor ) return gl.SRC_COLOR;
  25353. if ( p === OneMinusSrcColorFactor ) return gl.ONE_MINUS_SRC_COLOR;
  25354. if ( p === SrcAlphaFactor ) return gl.SRC_ALPHA;
  25355. if ( p === OneMinusSrcAlphaFactor ) return gl.ONE_MINUS_SRC_ALPHA;
  25356. if ( p === DstAlphaFactor ) return gl.DST_ALPHA;
  25357. if ( p === OneMinusDstAlphaFactor ) return gl.ONE_MINUS_DST_ALPHA;
  25358. if ( p === DstColorFactor ) return gl.DST_COLOR;
  25359. if ( p === OneMinusDstColorFactor ) return gl.ONE_MINUS_DST_COLOR;
  25360. if ( p === SrcAlphaSaturateFactor ) return gl.SRC_ALPHA_SATURATE;
  25361. if ( p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format ||
  25362. p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format ) {
  25363. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  25364. if ( extension !== null ) {
  25365. if ( p === RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  25366. if ( p === RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  25367. if ( p === RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  25368. if ( p === RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  25369. }
  25370. }
  25371. if ( p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format ||
  25372. p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format ) {
  25373. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  25374. if ( extension !== null ) {
  25375. if ( p === RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  25376. if ( p === RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  25377. if ( p === RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  25378. if ( p === RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  25379. }
  25380. }
  25381. if ( p === RGB_ETC1_Format ) {
  25382. extension = extensions.get( 'WEBGL_compressed_texture_etc1' );
  25383. if ( extension !== null ) return extension.COMPRESSED_RGB_ETC1_WEBGL;
  25384. }
  25385. if ( p === MinEquation || p === MaxEquation ) {
  25386. extension = extensions.get( 'EXT_blend_minmax' );
  25387. if ( extension !== null ) {
  25388. if ( p === MinEquation ) return extension.MIN_EXT;
  25389. if ( p === MaxEquation ) return extension.MAX_EXT;
  25390. }
  25391. }
  25392. if ( p === UnsignedInt248Type ) {
  25393. extension = extensions.get( 'WEBGL_depth_texture' );
  25394. if ( extension !== null ) return extension.UNSIGNED_INT_24_8_WEBGL;
  25395. }
  25396. return 0;
  25397. }
  25398. return { convert: convert };
  25399. }
  25400. function WebGLRenderer( parameters ) {
  25401. console.log( 'THREE.WebGLRenderer', REVISION );
  25402. parameters = parameters || {};
  25403. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' ),
  25404. _context = parameters.context !== undefined ? parameters.context : null,
  25405. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  25406. _depth = parameters.depth !== undefined ? parameters.depth : true,
  25407. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  25408. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  25409. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  25410. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false;
  25411. var lightsArray = [];
  25412. var shadowsArray = [];
  25413. var currentRenderList = null;
  25414. var spritesArray = [];
  25415. var flaresArray = [];
  25416. // public properties
  25417. this.domElement = _canvas;
  25418. this.context = null;
  25419. // clearing
  25420. this.autoClear = true;
  25421. this.autoClearColor = true;
  25422. this.autoClearDepth = true;
  25423. this.autoClearStencil = true;
  25424. // scene graph
  25425. this.sortObjects = true;
  25426. // user-defined clipping
  25427. this.clippingPlanes = [];
  25428. this.localClippingEnabled = false;
  25429. // physically based shading
  25430. this.gammaFactor = 2.0; // for backwards compatibility
  25431. this.gammaInput = false;
  25432. this.gammaOutput = false;
  25433. // physical lights
  25434. this.physicallyCorrectLights = false;
  25435. // tone mapping
  25436. this.toneMapping = LinearToneMapping;
  25437. this.toneMappingExposure = 1.0;
  25438. this.toneMappingWhitePoint = 1.0;
  25439. // morphs
  25440. this.maxMorphTargets = 8;
  25441. this.maxMorphNormals = 4;
  25442. // internal properties
  25443. var _this = this,
  25444. _isContextLost = false,
  25445. // internal state cache
  25446. _currentRenderTarget = null,
  25447. _currentFramebuffer = null,
  25448. _currentMaterialId = - 1,
  25449. _currentGeometryProgram = '',
  25450. _currentCamera = null,
  25451. _currentArrayCamera = null,
  25452. _currentViewport = new Vector4(),
  25453. _currentScissor = new Vector4(),
  25454. _currentScissorTest = null,
  25455. //
  25456. _usedTextureUnits = 0,
  25457. //
  25458. _width = _canvas.width,
  25459. _height = _canvas.height,
  25460. _pixelRatio = 1,
  25461. _viewport = new Vector4( 0, 0, _width, _height ),
  25462. _scissor = new Vector4( 0, 0, _width, _height ),
  25463. _scissorTest = false,
  25464. // frustum
  25465. _frustum = new Frustum(),
  25466. // clipping
  25467. _clipping = new WebGLClipping(),
  25468. _clippingEnabled = false,
  25469. _localClippingEnabled = false,
  25470. // camera matrices cache
  25471. _projScreenMatrix = new Matrix4(),
  25472. _vector3 = new Vector3(),
  25473. // info
  25474. _infoMemory = {
  25475. geometries: 0,
  25476. textures: 0
  25477. },
  25478. _infoRender = {
  25479. frame: 0,
  25480. calls: 0,
  25481. vertices: 0,
  25482. faces: 0,
  25483. points: 0
  25484. };
  25485. this.info = {
  25486. render: _infoRender,
  25487. memory: _infoMemory,
  25488. programs: null
  25489. };
  25490. function getTargetPixelRatio() {
  25491. return _currentRenderTarget === null ? _pixelRatio : 1;
  25492. }
  25493. // initialize
  25494. var _gl;
  25495. try {
  25496. var contextAttributes = {
  25497. alpha: _alpha,
  25498. depth: _depth,
  25499. stencil: _stencil,
  25500. antialias: _antialias,
  25501. premultipliedAlpha: _premultipliedAlpha,
  25502. preserveDrawingBuffer: _preserveDrawingBuffer
  25503. };
  25504. _gl = _context || _canvas.getContext( 'webgl', contextAttributes ) || _canvas.getContext( 'experimental-webgl', contextAttributes );
  25505. if ( _gl === null ) {
  25506. if ( _canvas.getContext( 'webgl' ) !== null ) {
  25507. throw 'Error creating WebGL context with your selected attributes.';
  25508. } else {
  25509. throw 'Error creating WebGL context.';
  25510. }
  25511. }
  25512. // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  25513. if ( _gl.getShaderPrecisionFormat === undefined ) {
  25514. _gl.getShaderPrecisionFormat = function () {
  25515. return { 'rangeMin': 1, 'rangeMax': 1, 'precision': 1 };
  25516. };
  25517. }
  25518. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  25519. _canvas.addEventListener( 'webglcontextrestored', onContextRestore, false );
  25520. } catch ( error ) {
  25521. console.error( 'THREE.WebGLRenderer: ' + error );
  25522. }
  25523. var extensions, capabilities, state;
  25524. var properties, textures, attributes, geometries, objects, lights;
  25525. var programCache, renderLists;
  25526. var background, morphtargets, bufferRenderer, indexedBufferRenderer;
  25527. var flareRenderer, spriteRenderer;
  25528. var utils;
  25529. function initGLContext() {
  25530. extensions = new WebGLExtensions( _gl );
  25531. extensions.get( 'WEBGL_depth_texture' );
  25532. extensions.get( 'OES_texture_float' );
  25533. extensions.get( 'OES_texture_float_linear' );
  25534. extensions.get( 'OES_texture_half_float' );
  25535. extensions.get( 'OES_texture_half_float_linear' );
  25536. extensions.get( 'OES_standard_derivatives' );
  25537. extensions.get( 'OES_element_index_uint' );
  25538. extensions.get( 'ANGLE_instanced_arrays' );
  25539. utils = new WebGLUtils( _gl, extensions );
  25540. capabilities = new WebGLCapabilities( _gl, extensions, parameters );
  25541. state = new WebGLState( _gl, extensions, utils );
  25542. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
  25543. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
  25544. properties = new WebGLProperties();
  25545. textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, _infoMemory );
  25546. attributes = new WebGLAttributes( _gl );
  25547. geometries = new WebGLGeometries( _gl, attributes, _infoMemory );
  25548. objects = new WebGLObjects( geometries, _infoRender );
  25549. morphtargets = new WebGLMorphtargets( _gl );
  25550. programCache = new WebGLPrograms( _this, extensions, capabilities );
  25551. lights = new WebGLLights();
  25552. renderLists = new WebGLRenderLists();
  25553. background = new WebGLBackground( _this, state, geometries, _premultipliedAlpha );
  25554. bufferRenderer = new WebGLBufferRenderer( _gl, extensions, _infoRender );
  25555. indexedBufferRenderer = new WebGLIndexedBufferRenderer( _gl, extensions, _infoRender );
  25556. flareRenderer = new WebGLFlareRenderer( _this, _gl, state, textures, capabilities );
  25557. spriteRenderer = new WebGLSpriteRenderer( _this, _gl, state, textures, capabilities );
  25558. _this.info.programs = programCache.programs;
  25559. _this.context = _gl;
  25560. _this.capabilities = capabilities;
  25561. _this.extensions = extensions;
  25562. _this.properties = properties;
  25563. _this.renderLists = renderLists;
  25564. _this.state = state;
  25565. }
  25566. initGLContext();
  25567. // vr
  25568. var vr = new WebVRManager( _this );
  25569. this.vr = vr;
  25570. // shadow map
  25571. var shadowMap = new WebGLShadowMap( _this, objects, capabilities.maxTextureSize );
  25572. this.shadowMap = shadowMap;
  25573. // API
  25574. this.getContext = function () {
  25575. return _gl;
  25576. };
  25577. this.getContextAttributes = function () {
  25578. return _gl.getContextAttributes();
  25579. };
  25580. this.forceContextLoss = function () {
  25581. var extension = extensions.get( 'WEBGL_lose_context' );
  25582. if ( extension ) extension.loseContext();
  25583. };
  25584. this.forceContextRestore = function () {
  25585. var extension = extensions.get( 'WEBGL_lose_context' );
  25586. if ( extension ) extension.restoreContext();
  25587. };
  25588. this.getPixelRatio = function () {
  25589. return _pixelRatio;
  25590. };
  25591. this.setPixelRatio = function ( value ) {
  25592. if ( value === undefined ) return;
  25593. _pixelRatio = value;
  25594. this.setSize( _width, _height, false );
  25595. };
  25596. this.getSize = function () {
  25597. return {
  25598. width: _width,
  25599. height: _height
  25600. };
  25601. };
  25602. this.setSize = function ( width, height, updateStyle ) {
  25603. var device = vr.getDevice();
  25604. if ( device && device.isPresenting ) {
  25605. console.warn( 'THREE.WebGLRenderer: Can\'t change size while VR device is presenting.' );
  25606. return;
  25607. }
  25608. _width = width;
  25609. _height = height;
  25610. _canvas.width = width * _pixelRatio;
  25611. _canvas.height = height * _pixelRatio;
  25612. if ( updateStyle !== false ) {
  25613. _canvas.style.width = width + 'px';
  25614. _canvas.style.height = height + 'px';
  25615. }
  25616. this.setViewport( 0, 0, width, height );
  25617. };
  25618. this.getDrawingBufferSize = function () {
  25619. return {
  25620. width: _width * _pixelRatio,
  25621. height: _height * _pixelRatio
  25622. };
  25623. };
  25624. this.setDrawingBufferSize = function ( width, height, pixelRatio ) {
  25625. _width = width;
  25626. _height = height;
  25627. _pixelRatio = pixelRatio;
  25628. _canvas.width = width * pixelRatio;
  25629. _canvas.height = height * pixelRatio;
  25630. this.setViewport( 0, 0, width, height );
  25631. };
  25632. this.setViewport = function ( x, y, width, height ) {
  25633. _viewport.set( x, _height - y - height, width, height );
  25634. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
  25635. };
  25636. this.setScissor = function ( x, y, width, height ) {
  25637. _scissor.set( x, _height - y - height, width, height );
  25638. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
  25639. };
  25640. this.setScissorTest = function ( boolean ) {
  25641. state.setScissorTest( _scissorTest = boolean );
  25642. };
  25643. // Clearing
  25644. this.getClearColor = function () {
  25645. return background.getClearColor();
  25646. };
  25647. this.setClearColor = function () {
  25648. background.setClearColor.apply( background, arguments );
  25649. };
  25650. this.getClearAlpha = function () {
  25651. return background.getClearAlpha();
  25652. };
  25653. this.setClearAlpha = function () {
  25654. background.setClearAlpha.apply( background, arguments );
  25655. };
  25656. this.clear = function ( color, depth, stencil ) {
  25657. var bits = 0;
  25658. if ( color === undefined || color ) bits |= _gl.COLOR_BUFFER_BIT;
  25659. if ( depth === undefined || depth ) bits |= _gl.DEPTH_BUFFER_BIT;
  25660. if ( stencil === undefined || stencil ) bits |= _gl.STENCIL_BUFFER_BIT;
  25661. _gl.clear( bits );
  25662. };
  25663. this.clearColor = function () {
  25664. this.clear( true, false, false );
  25665. };
  25666. this.clearDepth = function () {
  25667. this.clear( false, true, false );
  25668. };
  25669. this.clearStencil = function () {
  25670. this.clear( false, false, true );
  25671. };
  25672. this.clearTarget = function ( renderTarget, color, depth, stencil ) {
  25673. this.setRenderTarget( renderTarget );
  25674. this.clear( color, depth, stencil );
  25675. };
  25676. //
  25677. this.dispose = function () {
  25678. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  25679. _canvas.removeEventListener( 'webglcontextrestored', onContextRestore, false );
  25680. renderLists.dispose();
  25681. vr.dispose();
  25682. };
  25683. // Events
  25684. function onContextLost( event ) {
  25685. event.preventDefault();
  25686. console.log( 'THREE.WebGLRenderer: Context Lost.' );
  25687. _isContextLost = true;
  25688. }
  25689. function onContextRestore( /* event */ ) {
  25690. console.log( 'THREE.WebGLRenderer: Context Restored.' );
  25691. _isContextLost = false;
  25692. initGLContext();
  25693. }
  25694. function onMaterialDispose( event ) {
  25695. var material = event.target;
  25696. material.removeEventListener( 'dispose', onMaterialDispose );
  25697. deallocateMaterial( material );
  25698. }
  25699. // Buffer deallocation
  25700. function deallocateMaterial( material ) {
  25701. releaseMaterialProgramReference( material );
  25702. properties.remove( material );
  25703. }
  25704. function releaseMaterialProgramReference( material ) {
  25705. var programInfo = properties.get( material ).program;
  25706. material.program = undefined;
  25707. if ( programInfo !== undefined ) {
  25708. programCache.releaseProgram( programInfo );
  25709. }
  25710. }
  25711. // Buffer rendering
  25712. function renderObjectImmediate( object, program, material ) {
  25713. object.render( function ( object ) {
  25714. _this.renderBufferImmediate( object, program, material );
  25715. } );
  25716. }
  25717. this.renderBufferImmediate = function ( object, program, material ) {
  25718. state.initAttributes();
  25719. var buffers = properties.get( object );
  25720. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  25721. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  25722. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  25723. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  25724. var programAttributes = program.getAttributes();
  25725. if ( object.hasPositions ) {
  25726. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.position );
  25727. _gl.bufferData( _gl.ARRAY_BUFFER, object.positionArray, _gl.DYNAMIC_DRAW );
  25728. state.enableAttribute( programAttributes.position );
  25729. _gl.vertexAttribPointer( programAttributes.position, 3, _gl.FLOAT, false, 0, 0 );
  25730. }
  25731. if ( object.hasNormals ) {
  25732. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.normal );
  25733. if ( ! material.isMeshPhongMaterial &&
  25734. ! material.isMeshStandardMaterial &&
  25735. ! material.isMeshNormalMaterial &&
  25736. material.flatShading === true ) {
  25737. for ( var i = 0, l = object.count * 3; i < l; i += 9 ) {
  25738. var array = object.normalArray;
  25739. var nx = ( array[ i + 0 ] + array[ i + 3 ] + array[ i + 6 ] ) / 3;
  25740. var ny = ( array[ i + 1 ] + array[ i + 4 ] + array[ i + 7 ] ) / 3;
  25741. var nz = ( array[ i + 2 ] + array[ i + 5 ] + array[ i + 8 ] ) / 3;
  25742. array[ i + 0 ] = nx;
  25743. array[ i + 1 ] = ny;
  25744. array[ i + 2 ] = nz;
  25745. array[ i + 3 ] = nx;
  25746. array[ i + 4 ] = ny;
  25747. array[ i + 5 ] = nz;
  25748. array[ i + 6 ] = nx;
  25749. array[ i + 7 ] = ny;
  25750. array[ i + 8 ] = nz;
  25751. }
  25752. }
  25753. _gl.bufferData( _gl.ARRAY_BUFFER, object.normalArray, _gl.DYNAMIC_DRAW );
  25754. state.enableAttribute( programAttributes.normal );
  25755. _gl.vertexAttribPointer( programAttributes.normal, 3, _gl.FLOAT, false, 0, 0 );
  25756. }
  25757. if ( object.hasUvs && material.map ) {
  25758. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.uv );
  25759. _gl.bufferData( _gl.ARRAY_BUFFER, object.uvArray, _gl.DYNAMIC_DRAW );
  25760. state.enableAttribute( programAttributes.uv );
  25761. _gl.vertexAttribPointer( programAttributes.uv, 2, _gl.FLOAT, false, 0, 0 );
  25762. }
  25763. if ( object.hasColors && material.vertexColors !== NoColors ) {
  25764. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.color );
  25765. _gl.bufferData( _gl.ARRAY_BUFFER, object.colorArray, _gl.DYNAMIC_DRAW );
  25766. state.enableAttribute( programAttributes.color );
  25767. _gl.vertexAttribPointer( programAttributes.color, 3, _gl.FLOAT, false, 0, 0 );
  25768. }
  25769. state.disableUnusedAttributes();
  25770. _gl.drawArrays( _gl.TRIANGLES, 0, object.count );
  25771. object.count = 0;
  25772. };
  25773. this.renderBufferDirect = function ( camera, fog, geometry, material, object, group ) {
  25774. state.setMaterial( material );
  25775. var program = setProgram( camera, fog, material, object );
  25776. var geometryProgram = geometry.id + '_' + program.id + '_' + ( material.wireframe === true );
  25777. var updateBuffers = false;
  25778. if ( geometryProgram !== _currentGeometryProgram ) {
  25779. _currentGeometryProgram = geometryProgram;
  25780. updateBuffers = true;
  25781. }
  25782. if ( object.morphTargetInfluences ) {
  25783. morphtargets.update( object, geometry, material, program );
  25784. updateBuffers = true;
  25785. }
  25786. //
  25787. var index = geometry.index;
  25788. var position = geometry.attributes.position;
  25789. var rangeFactor = 1;
  25790. if ( material.wireframe === true ) {
  25791. index = geometries.getWireframeAttribute( geometry );
  25792. rangeFactor = 2;
  25793. }
  25794. var attribute;
  25795. var renderer = bufferRenderer;
  25796. if ( index !== null ) {
  25797. attribute = attributes.get( index );
  25798. renderer = indexedBufferRenderer;
  25799. renderer.setIndex( attribute );
  25800. }
  25801. if ( updateBuffers ) {
  25802. setupVertexAttributes( material, program, geometry );
  25803. if ( index !== null ) {
  25804. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, attribute.buffer );
  25805. }
  25806. }
  25807. //
  25808. var dataCount = 0;
  25809. if ( index !== null ) {
  25810. dataCount = index.count;
  25811. } else if ( position !== undefined ) {
  25812. dataCount = position.count;
  25813. }
  25814. var rangeStart = geometry.drawRange.start * rangeFactor;
  25815. var rangeCount = geometry.drawRange.count * rangeFactor;
  25816. var groupStart = group !== null ? group.start * rangeFactor : 0;
  25817. var groupCount = group !== null ? group.count * rangeFactor : Infinity;
  25818. var drawStart = Math.max( rangeStart, groupStart );
  25819. var drawEnd = Math.min( dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
  25820. var drawCount = Math.max( 0, drawEnd - drawStart + 1 );
  25821. if ( drawCount === 0 ) return;
  25822. //
  25823. if ( object.isMesh ) {
  25824. if ( material.wireframe === true ) {
  25825. state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() );
  25826. renderer.setMode( _gl.LINES );
  25827. } else {
  25828. switch ( object.drawMode ) {
  25829. case TrianglesDrawMode:
  25830. renderer.setMode( _gl.TRIANGLES );
  25831. break;
  25832. case TriangleStripDrawMode:
  25833. renderer.setMode( _gl.TRIANGLE_STRIP );
  25834. break;
  25835. case TriangleFanDrawMode:
  25836. renderer.setMode( _gl.TRIANGLE_FAN );
  25837. break;
  25838. }
  25839. }
  25840. } else if ( object.isLine ) {
  25841. var lineWidth = material.linewidth;
  25842. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  25843. state.setLineWidth( lineWidth * getTargetPixelRatio() );
  25844. if ( object.isLineSegments ) {
  25845. renderer.setMode( _gl.LINES );
  25846. } else if ( object.isLineLoop ) {
  25847. renderer.setMode( _gl.LINE_LOOP );
  25848. } else {
  25849. renderer.setMode( _gl.LINE_STRIP );
  25850. }
  25851. } else if ( object.isPoints ) {
  25852. renderer.setMode( _gl.POINTS );
  25853. }
  25854. if ( geometry && geometry.isInstancedBufferGeometry ) {
  25855. if ( geometry.maxInstancedCount > 0 ) {
  25856. renderer.renderInstances( geometry, drawStart, drawCount );
  25857. }
  25858. } else {
  25859. renderer.render( drawStart, drawCount );
  25860. }
  25861. };
  25862. function setupVertexAttributes( material, program, geometry, startIndex ) {
  25863. if ( geometry && geometry.isInstancedBufferGeometry ) {
  25864. if ( extensions.get( 'ANGLE_instanced_arrays' ) === null ) {
  25865. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  25866. return;
  25867. }
  25868. }
  25869. if ( startIndex === undefined ) startIndex = 0;
  25870. state.initAttributes();
  25871. var geometryAttributes = geometry.attributes;
  25872. var programAttributes = program.getAttributes();
  25873. var materialDefaultAttributeValues = material.defaultAttributeValues;
  25874. for ( var name in programAttributes ) {
  25875. var programAttribute = programAttributes[ name ];
  25876. if ( programAttribute >= 0 ) {
  25877. var geometryAttribute = geometryAttributes[ name ];
  25878. if ( geometryAttribute !== undefined ) {
  25879. var normalized = geometryAttribute.normalized;
  25880. var size = geometryAttribute.itemSize;
  25881. var attribute = attributes.get( geometryAttribute );
  25882. // TODO Attribute may not be available on context restore
  25883. if ( attribute === undefined ) continue;
  25884. var buffer = attribute.buffer;
  25885. var type = attribute.type;
  25886. var bytesPerElement = attribute.bytesPerElement;
  25887. if ( geometryAttribute.isInterleavedBufferAttribute ) {
  25888. var data = geometryAttribute.data;
  25889. var stride = data.stride;
  25890. var offset = geometryAttribute.offset;
  25891. if ( data && data.isInstancedInterleavedBuffer ) {
  25892. state.enableAttributeAndDivisor( programAttribute, data.meshPerAttribute );
  25893. if ( geometry.maxInstancedCount === undefined ) {
  25894. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  25895. }
  25896. } else {
  25897. state.enableAttribute( programAttribute );
  25898. }
  25899. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  25900. _gl.vertexAttribPointer( programAttribute, size, type, normalized, stride * bytesPerElement, ( startIndex * stride + offset ) * bytesPerElement );
  25901. } else {
  25902. if ( geometryAttribute.isInstancedBufferAttribute ) {
  25903. state.enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute );
  25904. if ( geometry.maxInstancedCount === undefined ) {
  25905. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  25906. }
  25907. } else {
  25908. state.enableAttribute( programAttribute );
  25909. }
  25910. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  25911. _gl.vertexAttribPointer( programAttribute, size, type, normalized, 0, startIndex * size * bytesPerElement );
  25912. }
  25913. } else if ( materialDefaultAttributeValues !== undefined ) {
  25914. var value = materialDefaultAttributeValues[ name ];
  25915. if ( value !== undefined ) {
  25916. switch ( value.length ) {
  25917. case 2:
  25918. _gl.vertexAttrib2fv( programAttribute, value );
  25919. break;
  25920. case 3:
  25921. _gl.vertexAttrib3fv( programAttribute, value );
  25922. break;
  25923. case 4:
  25924. _gl.vertexAttrib4fv( programAttribute, value );
  25925. break;
  25926. default:
  25927. _gl.vertexAttrib1fv( programAttribute, value );
  25928. }
  25929. }
  25930. }
  25931. }
  25932. }
  25933. state.disableUnusedAttributes();
  25934. }
  25935. // Compile
  25936. this.compile = function ( scene, camera ) {
  25937. lightsArray.length = 0;
  25938. shadowsArray.length = 0;
  25939. scene.traverse( function ( object ) {
  25940. if ( object.isLight ) {
  25941. lightsArray.push( object );
  25942. if ( object.castShadow ) {
  25943. shadowsArray.push( object );
  25944. }
  25945. }
  25946. } );
  25947. lights.setup( lightsArray, shadowsArray, camera );
  25948. scene.traverse( function ( object ) {
  25949. if ( object.material ) {
  25950. if ( Array.isArray( object.material ) ) {
  25951. for ( var i = 0; i < object.material.length; i ++ ) {
  25952. initMaterial( object.material[ i ], scene.fog, object );
  25953. }
  25954. } else {
  25955. initMaterial( object.material, scene.fog, object );
  25956. }
  25957. }
  25958. } );
  25959. };
  25960. // Animation Loop
  25961. var isAnimating = false;
  25962. var onAnimationFrame = null;
  25963. function start() {
  25964. if ( isAnimating ) return;
  25965. var device = vr.getDevice();
  25966. if ( device && device.isPresenting ) {
  25967. device.requestAnimationFrame( loop );
  25968. } else {
  25969. window.requestAnimationFrame( loop );
  25970. }
  25971. isAnimating = true;
  25972. }
  25973. function loop( time ) {
  25974. if ( onAnimationFrame !== null ) onAnimationFrame( time );
  25975. var device = vr.getDevice();
  25976. if ( device && device.isPresenting ) {
  25977. device.requestAnimationFrame( loop );
  25978. } else {
  25979. window.requestAnimationFrame( loop );
  25980. }
  25981. }
  25982. this.animate = function ( callback ) {
  25983. onAnimationFrame = callback;
  25984. start();
  25985. };
  25986. // Rendering
  25987. this.render = function ( scene, camera, renderTarget, forceClear ) {
  25988. if ( ! ( camera && camera.isCamera ) ) {
  25989. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  25990. return;
  25991. }
  25992. if ( _isContextLost ) return;
  25993. // reset caching for this frame
  25994. _currentGeometryProgram = '';
  25995. _currentMaterialId = - 1;
  25996. _currentCamera = null;
  25997. // update scene graph
  25998. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  25999. // update camera matrices and frustum
  26000. if ( camera.parent === null ) camera.updateMatrixWorld();
  26001. if ( vr.enabled ) {
  26002. camera = vr.getCamera( camera );
  26003. }
  26004. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  26005. _frustum.setFromMatrix( _projScreenMatrix );
  26006. lightsArray.length = 0;
  26007. shadowsArray.length = 0;
  26008. spritesArray.length = 0;
  26009. flaresArray.length = 0;
  26010. _localClippingEnabled = this.localClippingEnabled;
  26011. _clippingEnabled = _clipping.init( this.clippingPlanes, _localClippingEnabled, camera );
  26012. currentRenderList = renderLists.get( scene, camera );
  26013. currentRenderList.init();
  26014. projectObject( scene, camera, _this.sortObjects );
  26015. if ( _this.sortObjects === true ) {
  26016. currentRenderList.sort();
  26017. }
  26018. //
  26019. if ( _clippingEnabled ) _clipping.beginShadows();
  26020. shadowMap.render( shadowsArray, scene, camera );
  26021. lights.setup( lightsArray, shadowsArray, camera );
  26022. if ( _clippingEnabled ) _clipping.endShadows();
  26023. //
  26024. _infoRender.frame ++;
  26025. _infoRender.calls = 0;
  26026. _infoRender.vertices = 0;
  26027. _infoRender.faces = 0;
  26028. _infoRender.points = 0;
  26029. if ( renderTarget === undefined ) {
  26030. renderTarget = null;
  26031. }
  26032. this.setRenderTarget( renderTarget );
  26033. //
  26034. background.render( currentRenderList, scene, camera, forceClear );
  26035. // render scene
  26036. var opaqueObjects = currentRenderList.opaque;
  26037. var transparentObjects = currentRenderList.transparent;
  26038. if ( scene.overrideMaterial ) {
  26039. var overrideMaterial = scene.overrideMaterial;
  26040. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera, overrideMaterial );
  26041. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera, overrideMaterial );
  26042. } else {
  26043. // opaque pass (front-to-back order)
  26044. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera );
  26045. // transparent pass (back-to-front order)
  26046. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera );
  26047. }
  26048. // custom renderers
  26049. spriteRenderer.render( spritesArray, scene, camera );
  26050. flareRenderer.render( flaresArray, scene, camera, _currentViewport );
  26051. // Generate mipmap if we're using any kind of mipmap filtering
  26052. if ( renderTarget ) {
  26053. textures.updateRenderTargetMipmap( renderTarget );
  26054. }
  26055. // Ensure depth buffer writing is enabled so it can be cleared on next render
  26056. state.buffers.depth.setTest( true );
  26057. state.buffers.depth.setMask( true );
  26058. state.buffers.color.setMask( true );
  26059. state.setPolygonOffset( false );
  26060. if ( vr.enabled ) {
  26061. vr.submitFrame();
  26062. }
  26063. // _gl.finish();
  26064. };
  26065. /*
  26066. // TODO Duplicated code (Frustum)
  26067. var _sphere = new Sphere();
  26068. function isObjectViewable( object ) {
  26069. var geometry = object.geometry;
  26070. if ( geometry.boundingSphere === null )
  26071. geometry.computeBoundingSphere();
  26072. _sphere.copy( geometry.boundingSphere ).
  26073. applyMatrix4( object.matrixWorld );
  26074. return isSphereViewable( _sphere );
  26075. }
  26076. function isSpriteViewable( sprite ) {
  26077. _sphere.center.set( 0, 0, 0 );
  26078. _sphere.radius = 0.7071067811865476;
  26079. _sphere.applyMatrix4( sprite.matrixWorld );
  26080. return isSphereViewable( _sphere );
  26081. }
  26082. function isSphereViewable( sphere ) {
  26083. if ( ! _frustum.intersectsSphere( sphere ) ) return false;
  26084. var numPlanes = _clipping.numPlanes;
  26085. if ( numPlanes === 0 ) return true;
  26086. var planes = _this.clippingPlanes,
  26087. center = sphere.center,
  26088. negRad = - sphere.radius,
  26089. i = 0;
  26090. do {
  26091. // out when deeper than radius in the negative halfspace
  26092. if ( planes[ i ].distanceToPoint( center ) < negRad ) return false;
  26093. } while ( ++ i !== numPlanes );
  26094. return true;
  26095. }
  26096. */
  26097. function projectObject( object, camera, sortObjects ) {
  26098. if ( object.visible === false ) return;
  26099. var visible = object.layers.test( camera.layers );
  26100. if ( visible ) {
  26101. if ( object.isLight ) {
  26102. lightsArray.push( object );
  26103. if ( object.castShadow ) {
  26104. shadowsArray.push( object );
  26105. }
  26106. } else if ( object.isSprite ) {
  26107. if ( ! object.frustumCulled || _frustum.intersectsSprite( object ) ) {
  26108. spritesArray.push( object );
  26109. }
  26110. } else if ( object.isLensFlare ) {
  26111. flaresArray.push( object );
  26112. } else if ( object.isImmediateRenderObject ) {
  26113. if ( sortObjects ) {
  26114. _vector3.setFromMatrixPosition( object.matrixWorld )
  26115. .applyMatrix4( _projScreenMatrix );
  26116. }
  26117. currentRenderList.push( object, null, object.material, _vector3.z, null );
  26118. } else if ( object.isMesh || object.isLine || object.isPoints ) {
  26119. if ( object.isSkinnedMesh ) {
  26120. object.skeleton.update();
  26121. }
  26122. if ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) {
  26123. if ( sortObjects ) {
  26124. _vector3.setFromMatrixPosition( object.matrixWorld )
  26125. .applyMatrix4( _projScreenMatrix );
  26126. }
  26127. var geometry = objects.update( object );
  26128. var material = object.material;
  26129. if ( Array.isArray( material ) ) {
  26130. var groups = geometry.groups;
  26131. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  26132. var group = groups[ i ];
  26133. var groupMaterial = material[ group.materialIndex ];
  26134. if ( groupMaterial && groupMaterial.visible ) {
  26135. currentRenderList.push( object, geometry, groupMaterial, _vector3.z, group );
  26136. }
  26137. }
  26138. } else if ( material.visible ) {
  26139. currentRenderList.push( object, geometry, material, _vector3.z, null );
  26140. }
  26141. }
  26142. }
  26143. }
  26144. var children = object.children;
  26145. for ( var i = 0, l = children.length; i < l; i ++ ) {
  26146. projectObject( children[ i ], camera, sortObjects );
  26147. }
  26148. }
  26149. function renderObjects( renderList, scene, camera, overrideMaterial ) {
  26150. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  26151. var renderItem = renderList[ i ];
  26152. var object = renderItem.object;
  26153. var geometry = renderItem.geometry;
  26154. var material = overrideMaterial === undefined ? renderItem.material : overrideMaterial;
  26155. var group = renderItem.group;
  26156. if ( camera.isArrayCamera ) {
  26157. _currentArrayCamera = camera;
  26158. var cameras = camera.cameras;
  26159. for ( var j = 0, jl = cameras.length; j < jl; j ++ ) {
  26160. var camera2 = cameras[ j ];
  26161. if ( object.layers.test( camera2.layers ) ) {
  26162. var bounds = camera2.bounds;
  26163. var x = bounds.x * _width;
  26164. var y = bounds.y * _height;
  26165. var width = bounds.z * _width;
  26166. var height = bounds.w * _height;
  26167. state.viewport( _currentViewport.set( x, y, width, height ).multiplyScalar( _pixelRatio ) );
  26168. renderObject( object, scene, camera2, geometry, material, group );
  26169. }
  26170. }
  26171. } else {
  26172. _currentArrayCamera = null;
  26173. renderObject( object, scene, camera, geometry, material, group );
  26174. }
  26175. }
  26176. }
  26177. function renderObject( object, scene, camera, geometry, material, group ) {
  26178. object.onBeforeRender( _this, scene, camera, geometry, material, group );
  26179. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  26180. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  26181. if ( object.isImmediateRenderObject ) {
  26182. state.setMaterial( material );
  26183. var program = setProgram( camera, scene.fog, material, object );
  26184. _currentGeometryProgram = '';
  26185. renderObjectImmediate( object, program, material );
  26186. } else {
  26187. _this.renderBufferDirect( camera, scene.fog, geometry, material, object, group );
  26188. }
  26189. object.onAfterRender( _this, scene, camera, geometry, material, group );
  26190. }
  26191. function initMaterial( material, fog, object ) {
  26192. var materialProperties = properties.get( material );
  26193. var parameters = programCache.getParameters(
  26194. material, lights.state, shadowsArray, fog, _clipping.numPlanes, _clipping.numIntersection, object );
  26195. var code = programCache.getProgramCode( material, parameters );
  26196. var program = materialProperties.program;
  26197. var programChange = true;
  26198. if ( program === undefined ) {
  26199. // new material
  26200. material.addEventListener( 'dispose', onMaterialDispose );
  26201. } else if ( program.code !== code ) {
  26202. // changed glsl or parameters
  26203. releaseMaterialProgramReference( material );
  26204. } else if ( parameters.shaderID !== undefined ) {
  26205. // same glsl and uniform list
  26206. return;
  26207. } else {
  26208. // only rebuild uniform list
  26209. programChange = false;
  26210. }
  26211. if ( programChange ) {
  26212. if ( parameters.shaderID ) {
  26213. var shader = ShaderLib[ parameters.shaderID ];
  26214. materialProperties.shader = {
  26215. name: material.type,
  26216. uniforms: UniformsUtils.clone( shader.uniforms ),
  26217. vertexShader: shader.vertexShader,
  26218. fragmentShader: shader.fragmentShader
  26219. };
  26220. } else {
  26221. materialProperties.shader = {
  26222. name: material.type,
  26223. uniforms: material.uniforms,
  26224. vertexShader: material.vertexShader,
  26225. fragmentShader: material.fragmentShader
  26226. };
  26227. }
  26228. material.onBeforeCompile( materialProperties.shader );
  26229. program = programCache.acquireProgram( material, materialProperties.shader, parameters, code );
  26230. materialProperties.program = program;
  26231. material.program = program;
  26232. }
  26233. var programAttributes = program.getAttributes();
  26234. if ( material.morphTargets ) {
  26235. material.numSupportedMorphTargets = 0;
  26236. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  26237. if ( programAttributes[ 'morphTarget' + i ] >= 0 ) {
  26238. material.numSupportedMorphTargets ++;
  26239. }
  26240. }
  26241. }
  26242. if ( material.morphNormals ) {
  26243. material.numSupportedMorphNormals = 0;
  26244. for ( var i = 0; i < _this.maxMorphNormals; i ++ ) {
  26245. if ( programAttributes[ 'morphNormal' + i ] >= 0 ) {
  26246. material.numSupportedMorphNormals ++;
  26247. }
  26248. }
  26249. }
  26250. var uniforms = materialProperties.shader.uniforms;
  26251. if ( ! material.isShaderMaterial &&
  26252. ! material.isRawShaderMaterial ||
  26253. material.clipping === true ) {
  26254. materialProperties.numClippingPlanes = _clipping.numPlanes;
  26255. materialProperties.numIntersection = _clipping.numIntersection;
  26256. uniforms.clippingPlanes = _clipping.uniform;
  26257. }
  26258. materialProperties.fog = fog;
  26259. // store the light setup it was created for
  26260. materialProperties.lightsHash = lights.state.hash;
  26261. if ( material.lights ) {
  26262. // wire up the material to this renderer's lighting state
  26263. uniforms.ambientLightColor.value = lights.state.ambient;
  26264. uniforms.directionalLights.value = lights.state.directional;
  26265. uniforms.spotLights.value = lights.state.spot;
  26266. uniforms.rectAreaLights.value = lights.state.rectArea;
  26267. uniforms.pointLights.value = lights.state.point;
  26268. uniforms.hemisphereLights.value = lights.state.hemi;
  26269. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  26270. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  26271. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  26272. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  26273. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  26274. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix;
  26275. // TODO (abelnation): add area lights shadow info to uniforms
  26276. }
  26277. var progUniforms = materialProperties.program.getUniforms(),
  26278. uniformsList =
  26279. WebGLUniforms.seqWithValue( progUniforms.seq, uniforms );
  26280. materialProperties.uniformsList = uniformsList;
  26281. }
  26282. function setProgram( camera, fog, material, object ) {
  26283. _usedTextureUnits = 0;
  26284. var materialProperties = properties.get( material );
  26285. if ( _clippingEnabled ) {
  26286. if ( _localClippingEnabled || camera !== _currentCamera ) {
  26287. var useCache =
  26288. camera === _currentCamera &&
  26289. material.id === _currentMaterialId;
  26290. // we might want to call this function with some ClippingGroup
  26291. // object instead of the material, once it becomes feasible
  26292. // (#8465, #8379)
  26293. _clipping.setState(
  26294. material.clippingPlanes, material.clipIntersection, material.clipShadows,
  26295. camera, materialProperties, useCache );
  26296. }
  26297. }
  26298. if ( material.needsUpdate === false ) {
  26299. if ( materialProperties.program === undefined ) {
  26300. material.needsUpdate = true;
  26301. } else if ( material.fog && materialProperties.fog !== fog ) {
  26302. material.needsUpdate = true;
  26303. } else if ( material.lights && materialProperties.lightsHash !== lights.state.hash ) {
  26304. material.needsUpdate = true;
  26305. } else if ( materialProperties.numClippingPlanes !== undefined &&
  26306. ( materialProperties.numClippingPlanes !== _clipping.numPlanes ||
  26307. materialProperties.numIntersection !== _clipping.numIntersection ) ) {
  26308. material.needsUpdate = true;
  26309. }
  26310. }
  26311. if ( material.needsUpdate ) {
  26312. initMaterial( material, fog, object );
  26313. material.needsUpdate = false;
  26314. }
  26315. var refreshProgram = false;
  26316. var refreshMaterial = false;
  26317. var refreshLights = false;
  26318. var program = materialProperties.program,
  26319. p_uniforms = program.getUniforms(),
  26320. m_uniforms = materialProperties.shader.uniforms;
  26321. if ( state.useProgram( program.program ) ) {
  26322. refreshProgram = true;
  26323. refreshMaterial = true;
  26324. refreshLights = true;
  26325. }
  26326. if ( material.id !== _currentMaterialId ) {
  26327. _currentMaterialId = material.id;
  26328. refreshMaterial = true;
  26329. }
  26330. if ( refreshProgram || camera !== _currentCamera ) {
  26331. p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
  26332. if ( capabilities.logarithmicDepthBuffer ) {
  26333. p_uniforms.setValue( _gl, 'logDepthBufFC',
  26334. 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  26335. }
  26336. // Avoid unneeded uniform updates per ArrayCamera's sub-camera
  26337. if ( _currentCamera !== ( _currentArrayCamera || camera ) ) {
  26338. _currentCamera = ( _currentArrayCamera || camera );
  26339. // lighting uniforms depend on the camera so enforce an update
  26340. // now, in case this material supports lights - or later, when
  26341. // the next material that does gets activated:
  26342. refreshMaterial = true; // set to true on material change
  26343. refreshLights = true; // remains set until update done
  26344. }
  26345. // load material specific uniforms
  26346. // (shader material also gets them for the sake of genericity)
  26347. if ( material.isShaderMaterial ||
  26348. material.isMeshPhongMaterial ||
  26349. material.isMeshStandardMaterial ||
  26350. material.envMap ) {
  26351. var uCamPos = p_uniforms.map.cameraPosition;
  26352. if ( uCamPos !== undefined ) {
  26353. uCamPos.setValue( _gl,
  26354. _vector3.setFromMatrixPosition( camera.matrixWorld ) );
  26355. }
  26356. }
  26357. if ( material.isMeshPhongMaterial ||
  26358. material.isMeshLambertMaterial ||
  26359. material.isMeshBasicMaterial ||
  26360. material.isMeshStandardMaterial ||
  26361. material.isShaderMaterial ||
  26362. material.skinning ) {
  26363. p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
  26364. }
  26365. }
  26366. // skinning uniforms must be set even if material didn't change
  26367. // auto-setting of texture unit for bone texture must go before other textures
  26368. // not sure why, but otherwise weird things happen
  26369. if ( material.skinning ) {
  26370. p_uniforms.setOptional( _gl, object, 'bindMatrix' );
  26371. p_uniforms.setOptional( _gl, object, 'bindMatrixInverse' );
  26372. var skeleton = object.skeleton;
  26373. if ( skeleton ) {
  26374. var bones = skeleton.bones;
  26375. if ( capabilities.floatVertexTextures ) {
  26376. if ( skeleton.boneTexture === undefined ) {
  26377. // layout (1 matrix = 4 pixels)
  26378. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  26379. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  26380. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  26381. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  26382. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  26383. var size = Math.sqrt( bones.length * 4 ); // 4 pixels needed for 1 matrix
  26384. size = _Math.ceilPowerOfTwo( size );
  26385. size = Math.max( size, 4 );
  26386. var boneMatrices = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel
  26387. boneMatrices.set( skeleton.boneMatrices ); // copy current values
  26388. var boneTexture = new DataTexture( boneMatrices, size, size, RGBAFormat, FloatType );
  26389. skeleton.boneMatrices = boneMatrices;
  26390. skeleton.boneTexture = boneTexture;
  26391. skeleton.boneTextureSize = size;
  26392. }
  26393. p_uniforms.setValue( _gl, 'boneTexture', skeleton.boneTexture );
  26394. p_uniforms.setValue( _gl, 'boneTextureSize', skeleton.boneTextureSize );
  26395. } else {
  26396. p_uniforms.setOptional( _gl, skeleton, 'boneMatrices' );
  26397. }
  26398. }
  26399. }
  26400. if ( refreshMaterial ) {
  26401. p_uniforms.setValue( _gl, 'toneMappingExposure', _this.toneMappingExposure );
  26402. p_uniforms.setValue( _gl, 'toneMappingWhitePoint', _this.toneMappingWhitePoint );
  26403. if ( material.lights ) {
  26404. // the current material requires lighting info
  26405. // note: all lighting uniforms are always set correctly
  26406. // they simply reference the renderer's state for their
  26407. // values
  26408. //
  26409. // use the current material's .needsUpdate flags to set
  26410. // the GL state when required
  26411. markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
  26412. }
  26413. // refresh uniforms common to several materials
  26414. if ( fog && material.fog ) {
  26415. refreshUniformsFog( m_uniforms, fog );
  26416. }
  26417. if ( material.isMeshBasicMaterial ) {
  26418. refreshUniformsCommon( m_uniforms, material );
  26419. } else if ( material.isMeshLambertMaterial ) {
  26420. refreshUniformsCommon( m_uniforms, material );
  26421. refreshUniformsLambert( m_uniforms, material );
  26422. } else if ( material.isMeshPhongMaterial ) {
  26423. refreshUniformsCommon( m_uniforms, material );
  26424. if ( material.isMeshToonMaterial ) {
  26425. refreshUniformsToon( m_uniforms, material );
  26426. } else {
  26427. refreshUniformsPhong( m_uniforms, material );
  26428. }
  26429. } else if ( material.isMeshStandardMaterial ) {
  26430. refreshUniformsCommon( m_uniforms, material );
  26431. if ( material.isMeshPhysicalMaterial ) {
  26432. refreshUniformsPhysical( m_uniforms, material );
  26433. } else {
  26434. refreshUniformsStandard( m_uniforms, material );
  26435. }
  26436. } else if ( material.isMeshDepthMaterial ) {
  26437. refreshUniformsCommon( m_uniforms, material );
  26438. refreshUniformsDepth( m_uniforms, material );
  26439. } else if ( material.isMeshDistanceMaterial ) {
  26440. refreshUniformsCommon( m_uniforms, material );
  26441. refreshUniformsDistance( m_uniforms, material );
  26442. } else if ( material.isMeshNormalMaterial ) {
  26443. refreshUniformsCommon( m_uniforms, material );
  26444. refreshUniformsNormal( m_uniforms, material );
  26445. } else if ( material.isLineBasicMaterial ) {
  26446. refreshUniformsLine( m_uniforms, material );
  26447. if ( material.isLineDashedMaterial ) {
  26448. refreshUniformsDash( m_uniforms, material );
  26449. }
  26450. } else if ( material.isPointsMaterial ) {
  26451. refreshUniformsPoints( m_uniforms, material );
  26452. } else if ( material.isShadowMaterial ) {
  26453. m_uniforms.color.value = material.color;
  26454. m_uniforms.opacity.value = material.opacity;
  26455. }
  26456. // RectAreaLight Texture
  26457. // TODO (mrdoob): Find a nicer implementation
  26458. if ( m_uniforms.ltcMat !== undefined ) m_uniforms.ltcMat.value = UniformsLib.LTC_MAT_TEXTURE;
  26459. if ( m_uniforms.ltcMag !== undefined ) m_uniforms.ltcMag.value = UniformsLib.LTC_MAG_TEXTURE;
  26460. WebGLUniforms.upload(
  26461. _gl, materialProperties.uniformsList, m_uniforms, _this );
  26462. }
  26463. // common matrices
  26464. p_uniforms.setValue( _gl, 'modelViewMatrix', object.modelViewMatrix );
  26465. p_uniforms.setValue( _gl, 'normalMatrix', object.normalMatrix );
  26466. p_uniforms.setValue( _gl, 'modelMatrix', object.matrixWorld );
  26467. return program;
  26468. }
  26469. // Uniforms (refresh uniforms objects)
  26470. function refreshUniformsCommon( uniforms, material ) {
  26471. uniforms.opacity.value = material.opacity;
  26472. if ( material.color ) {
  26473. uniforms.diffuse.value = material.color;
  26474. }
  26475. if ( material.emissive ) {
  26476. uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity );
  26477. }
  26478. if ( material.map ) {
  26479. uniforms.map.value = material.map;
  26480. }
  26481. if ( material.alphaMap ) {
  26482. uniforms.alphaMap.value = material.alphaMap;
  26483. }
  26484. if ( material.specularMap ) {
  26485. uniforms.specularMap.value = material.specularMap;
  26486. }
  26487. if ( material.envMap ) {
  26488. uniforms.envMap.value = material.envMap;
  26489. // don't flip CubeTexture envMaps, flip everything else:
  26490. // WebGLRenderTargetCube will be flipped for backwards compatibility
  26491. // WebGLRenderTargetCube.texture will be flipped because it's a Texture and NOT a CubeTexture
  26492. // this check must be handled differently, or removed entirely, if WebGLRenderTargetCube uses a CubeTexture in the future
  26493. uniforms.flipEnvMap.value = ( ! ( material.envMap && material.envMap.isCubeTexture ) ) ? 1 : - 1;
  26494. uniforms.reflectivity.value = material.reflectivity;
  26495. uniforms.refractionRatio.value = material.refractionRatio;
  26496. }
  26497. if ( material.lightMap ) {
  26498. uniforms.lightMap.value = material.lightMap;
  26499. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  26500. }
  26501. if ( material.aoMap ) {
  26502. uniforms.aoMap.value = material.aoMap;
  26503. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  26504. }
  26505. // uv repeat and offset setting priorities
  26506. // 1. color map
  26507. // 2. specular map
  26508. // 3. normal map
  26509. // 4. bump map
  26510. // 5. alpha map
  26511. // 6. emissive map
  26512. var uvScaleMap;
  26513. if ( material.map ) {
  26514. uvScaleMap = material.map;
  26515. } else if ( material.specularMap ) {
  26516. uvScaleMap = material.specularMap;
  26517. } else if ( material.displacementMap ) {
  26518. uvScaleMap = material.displacementMap;
  26519. } else if ( material.normalMap ) {
  26520. uvScaleMap = material.normalMap;
  26521. } else if ( material.bumpMap ) {
  26522. uvScaleMap = material.bumpMap;
  26523. } else if ( material.roughnessMap ) {
  26524. uvScaleMap = material.roughnessMap;
  26525. } else if ( material.metalnessMap ) {
  26526. uvScaleMap = material.metalnessMap;
  26527. } else if ( material.alphaMap ) {
  26528. uvScaleMap = material.alphaMap;
  26529. } else if ( material.emissiveMap ) {
  26530. uvScaleMap = material.emissiveMap;
  26531. }
  26532. if ( uvScaleMap !== undefined ) {
  26533. // backwards compatibility
  26534. if ( uvScaleMap.isWebGLRenderTarget ) {
  26535. uvScaleMap = uvScaleMap.texture;
  26536. }
  26537. if ( uvScaleMap.matrixAutoUpdate === true ) {
  26538. var offset = uvScaleMap.offset;
  26539. var repeat = uvScaleMap.repeat;
  26540. var rotation = uvScaleMap.rotation;
  26541. var center = uvScaleMap.center;
  26542. uvScaleMap.matrix.setUvTransform( offset.x, offset.y, repeat.x, repeat.y, rotation, center.x, center.y );
  26543. }
  26544. uniforms.uvTransform.value.copy( uvScaleMap.matrix );
  26545. }
  26546. }
  26547. function refreshUniformsLine( uniforms, material ) {
  26548. uniforms.diffuse.value = material.color;
  26549. uniforms.opacity.value = material.opacity;
  26550. }
  26551. function refreshUniformsDash( uniforms, material ) {
  26552. uniforms.dashSize.value = material.dashSize;
  26553. uniforms.totalSize.value = material.dashSize + material.gapSize;
  26554. uniforms.scale.value = material.scale;
  26555. }
  26556. function refreshUniformsPoints( uniforms, material ) {
  26557. uniforms.diffuse.value = material.color;
  26558. uniforms.opacity.value = material.opacity;
  26559. uniforms.size.value = material.size * _pixelRatio;
  26560. uniforms.scale.value = _height * 0.5;
  26561. uniforms.map.value = material.map;
  26562. if ( material.map !== null ) {
  26563. if ( material.map.matrixAutoUpdate === true ) {
  26564. var offset = material.map.offset;
  26565. var repeat = material.map.repeat;
  26566. var rotation = material.map.rotation;
  26567. var center = material.map.center;
  26568. material.map.matrix.setUvTransform( offset.x, offset.y, repeat.x, repeat.y, rotation, center.x, center.y );
  26569. }
  26570. uniforms.uvTransform.value.copy( material.map.matrix );
  26571. }
  26572. }
  26573. function refreshUniformsFog( uniforms, fog ) {
  26574. uniforms.fogColor.value = fog.color;
  26575. if ( fog.isFog ) {
  26576. uniforms.fogNear.value = fog.near;
  26577. uniforms.fogFar.value = fog.far;
  26578. } else if ( fog.isFogExp2 ) {
  26579. uniforms.fogDensity.value = fog.density;
  26580. }
  26581. }
  26582. function refreshUniformsLambert( uniforms, material ) {
  26583. if ( material.emissiveMap ) {
  26584. uniforms.emissiveMap.value = material.emissiveMap;
  26585. }
  26586. }
  26587. function refreshUniformsPhong( uniforms, material ) {
  26588. uniforms.specular.value = material.specular;
  26589. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  26590. if ( material.emissiveMap ) {
  26591. uniforms.emissiveMap.value = material.emissiveMap;
  26592. }
  26593. if ( material.bumpMap ) {
  26594. uniforms.bumpMap.value = material.bumpMap;
  26595. uniforms.bumpScale.value = material.bumpScale;
  26596. }
  26597. if ( material.normalMap ) {
  26598. uniforms.normalMap.value = material.normalMap;
  26599. uniforms.normalScale.value.copy( material.normalScale );
  26600. }
  26601. if ( material.displacementMap ) {
  26602. uniforms.displacementMap.value = material.displacementMap;
  26603. uniforms.displacementScale.value = material.displacementScale;
  26604. uniforms.displacementBias.value = material.displacementBias;
  26605. }
  26606. }
  26607. function refreshUniformsToon( uniforms, material ) {
  26608. refreshUniformsPhong( uniforms, material );
  26609. if ( material.gradientMap ) {
  26610. uniforms.gradientMap.value = material.gradientMap;
  26611. }
  26612. }
  26613. function refreshUniformsStandard( uniforms, material ) {
  26614. uniforms.roughness.value = material.roughness;
  26615. uniforms.metalness.value = material.metalness;
  26616. if ( material.roughnessMap ) {
  26617. uniforms.roughnessMap.value = material.roughnessMap;
  26618. }
  26619. if ( material.metalnessMap ) {
  26620. uniforms.metalnessMap.value = material.metalnessMap;
  26621. }
  26622. if ( material.emissiveMap ) {
  26623. uniforms.emissiveMap.value = material.emissiveMap;
  26624. }
  26625. if ( material.bumpMap ) {
  26626. uniforms.bumpMap.value = material.bumpMap;
  26627. uniforms.bumpScale.value = material.bumpScale;
  26628. }
  26629. if ( material.normalMap ) {
  26630. uniforms.normalMap.value = material.normalMap;
  26631. uniforms.normalScale.value.copy( material.normalScale );
  26632. }
  26633. if ( material.displacementMap ) {
  26634. uniforms.displacementMap.value = material.displacementMap;
  26635. uniforms.displacementScale.value = material.displacementScale;
  26636. uniforms.displacementBias.value = material.displacementBias;
  26637. }
  26638. if ( material.envMap ) {
  26639. //uniforms.envMap.value = material.envMap; // part of uniforms common
  26640. uniforms.envMapIntensity.value = material.envMapIntensity;
  26641. }
  26642. }
  26643. function refreshUniformsPhysical( uniforms, material ) {
  26644. uniforms.clearCoat.value = material.clearCoat;
  26645. uniforms.clearCoatRoughness.value = material.clearCoatRoughness;
  26646. refreshUniformsStandard( uniforms, material );
  26647. }
  26648. function refreshUniformsDepth( uniforms, material ) {
  26649. if ( material.displacementMap ) {
  26650. uniforms.displacementMap.value = material.displacementMap;
  26651. uniforms.displacementScale.value = material.displacementScale;
  26652. uniforms.displacementBias.value = material.displacementBias;
  26653. }
  26654. }
  26655. function refreshUniformsDistance( uniforms, material ) {
  26656. if ( material.displacementMap ) {
  26657. uniforms.displacementMap.value = material.displacementMap;
  26658. uniforms.displacementScale.value = material.displacementScale;
  26659. uniforms.displacementBias.value = material.displacementBias;
  26660. }
  26661. uniforms.referencePosition.value.copy( material.referencePosition );
  26662. uniforms.nearDistance.value = material.nearDistance;
  26663. uniforms.farDistance.value = material.farDistance;
  26664. }
  26665. function refreshUniformsNormal( uniforms, material ) {
  26666. if ( material.bumpMap ) {
  26667. uniforms.bumpMap.value = material.bumpMap;
  26668. uniforms.bumpScale.value = material.bumpScale;
  26669. }
  26670. if ( material.normalMap ) {
  26671. uniforms.normalMap.value = material.normalMap;
  26672. uniforms.normalScale.value.copy( material.normalScale );
  26673. }
  26674. if ( material.displacementMap ) {
  26675. uniforms.displacementMap.value = material.displacementMap;
  26676. uniforms.displacementScale.value = material.displacementScale;
  26677. uniforms.displacementBias.value = material.displacementBias;
  26678. }
  26679. }
  26680. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  26681. function markUniformsLightsNeedsUpdate( uniforms, value ) {
  26682. uniforms.ambientLightColor.needsUpdate = value;
  26683. uniforms.directionalLights.needsUpdate = value;
  26684. uniforms.pointLights.needsUpdate = value;
  26685. uniforms.spotLights.needsUpdate = value;
  26686. uniforms.rectAreaLights.needsUpdate = value;
  26687. uniforms.hemisphereLights.needsUpdate = value;
  26688. }
  26689. // GL state setting
  26690. this.setFaceCulling = function ( cullFace, frontFaceDirection ) {
  26691. state.setCullFace( cullFace );
  26692. state.setFlipSided( frontFaceDirection === FrontFaceDirectionCW );
  26693. };
  26694. // Textures
  26695. function allocTextureUnit() {
  26696. var textureUnit = _usedTextureUnits;
  26697. if ( textureUnit >= capabilities.maxTextures ) {
  26698. console.warn( 'THREE.WebGLRenderer: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + capabilities.maxTextures );
  26699. }
  26700. _usedTextureUnits += 1;
  26701. return textureUnit;
  26702. }
  26703. this.allocTextureUnit = allocTextureUnit;
  26704. // this.setTexture2D = setTexture2D;
  26705. this.setTexture2D = ( function () {
  26706. var warned = false;
  26707. // backwards compatibility: peel texture.texture
  26708. return function setTexture2D( texture, slot ) {
  26709. if ( texture && texture.isWebGLRenderTarget ) {
  26710. if ( ! warned ) {
  26711. console.warn( "THREE.WebGLRenderer.setTexture2D: don't use render targets as textures. Use their .texture property instead." );
  26712. warned = true;
  26713. }
  26714. texture = texture.texture;
  26715. }
  26716. textures.setTexture2D( texture, slot );
  26717. };
  26718. }() );
  26719. this.setTexture = ( function () {
  26720. var warned = false;
  26721. return function setTexture( texture, slot ) {
  26722. if ( ! warned ) {
  26723. console.warn( "THREE.WebGLRenderer: .setTexture is deprecated, use setTexture2D instead." );
  26724. warned = true;
  26725. }
  26726. textures.setTexture2D( texture, slot );
  26727. };
  26728. }() );
  26729. this.setTextureCube = ( function () {
  26730. var warned = false;
  26731. return function setTextureCube( texture, slot ) {
  26732. // backwards compatibility: peel texture.texture
  26733. if ( texture && texture.isWebGLRenderTargetCube ) {
  26734. if ( ! warned ) {
  26735. console.warn( "THREE.WebGLRenderer.setTextureCube: don't use cube render targets as textures. Use their .texture property instead." );
  26736. warned = true;
  26737. }
  26738. texture = texture.texture;
  26739. }
  26740. // currently relying on the fact that WebGLRenderTargetCube.texture is a Texture and NOT a CubeTexture
  26741. // TODO: unify these code paths
  26742. if ( ( texture && texture.isCubeTexture ) ||
  26743. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  26744. // CompressedTexture can have Array in image :/
  26745. // this function alone should take care of cube textures
  26746. textures.setTextureCube( texture, slot );
  26747. } else {
  26748. // assumed: texture property of THREE.WebGLRenderTargetCube
  26749. textures.setTextureCubeDynamic( texture, slot );
  26750. }
  26751. };
  26752. }() );
  26753. this.getRenderTarget = function () {
  26754. return _currentRenderTarget;
  26755. };
  26756. this.setRenderTarget = function ( renderTarget ) {
  26757. _currentRenderTarget = renderTarget;
  26758. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  26759. textures.setupRenderTarget( renderTarget );
  26760. }
  26761. var framebuffer = null;
  26762. var isCube = false;
  26763. if ( renderTarget ) {
  26764. var __webglFramebuffer = properties.get( renderTarget ).__webglFramebuffer;
  26765. if ( renderTarget.isWebGLRenderTargetCube ) {
  26766. framebuffer = __webglFramebuffer[ renderTarget.activeCubeFace ];
  26767. isCube = true;
  26768. } else {
  26769. framebuffer = __webglFramebuffer;
  26770. }
  26771. _currentViewport.copy( renderTarget.viewport );
  26772. _currentScissor.copy( renderTarget.scissor );
  26773. _currentScissorTest = renderTarget.scissorTest;
  26774. } else {
  26775. _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio );
  26776. _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio );
  26777. _currentScissorTest = _scissorTest;
  26778. }
  26779. if ( _currentFramebuffer !== framebuffer ) {
  26780. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  26781. _currentFramebuffer = framebuffer;
  26782. }
  26783. state.viewport( _currentViewport );
  26784. state.scissor( _currentScissor );
  26785. state.setScissorTest( _currentScissorTest );
  26786. if ( isCube ) {
  26787. var textureProperties = properties.get( renderTarget.texture );
  26788. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + renderTarget.activeCubeFace, textureProperties.__webglTexture, renderTarget.activeMipMapLevel );
  26789. }
  26790. };
  26791. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer ) {
  26792. if ( ! ( renderTarget && renderTarget.isWebGLRenderTarget ) ) {
  26793. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  26794. return;
  26795. }
  26796. var framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  26797. if ( framebuffer ) {
  26798. var restore = false;
  26799. if ( framebuffer !== _currentFramebuffer ) {
  26800. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  26801. restore = true;
  26802. }
  26803. try {
  26804. var texture = renderTarget.texture;
  26805. var textureFormat = texture.format;
  26806. var textureType = texture.type;
  26807. if ( textureFormat !== RGBAFormat && utils.convert( textureFormat ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) {
  26808. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  26809. return;
  26810. }
  26811. if ( textureType !== UnsignedByteType && utils.convert( textureType ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_TYPE ) && // IE11, Edge and Chrome Mac < 52 (#9513)
  26812. ! ( textureType === FloatType && ( extensions.get( 'OES_texture_float' ) || extensions.get( 'WEBGL_color_buffer_float' ) ) ) && // Chrome Mac >= 52 and Firefox
  26813. ! ( textureType === HalfFloatType && extensions.get( 'EXT_color_buffer_half_float' ) ) ) {
  26814. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  26815. return;
  26816. }
  26817. if ( _gl.checkFramebufferStatus( _gl.FRAMEBUFFER ) === _gl.FRAMEBUFFER_COMPLETE ) {
  26818. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  26819. if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
  26820. _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), buffer );
  26821. }
  26822. } else {
  26823. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  26824. }
  26825. } finally {
  26826. if ( restore ) {
  26827. _gl.bindFramebuffer( _gl.FRAMEBUFFER, _currentFramebuffer );
  26828. }
  26829. }
  26830. }
  26831. };
  26832. }
  26833. /**
  26834. * @author TristanVALCKE / https://github.com/Itee
  26835. * @author Anonymous
  26836. */
  26837. /* global QUnit */
  26838. function testEdges( vertList, idxList, numAfter, assert ) {
  26839. var geoms = createGeometries( vertList, idxList );
  26840. for ( var i = 0; i < geoms.length; i ++ ) {
  26841. var geom = geoms[ i ];
  26842. var numBefore = idxList.length;
  26843. assert.equal( countEdges( geom ), numBefore, "Edges before!" );
  26844. var egeom = new EdgesGeometry( geom );
  26845. assert.equal( countEdges( egeom ), numAfter, "Edges after!" );
  26846. output( geom, egeom );
  26847. }
  26848. }
  26849. function createGeometries( vertList, idxList ) {
  26850. var geomIB = createIndexedBufferGeometry( vertList, idxList );
  26851. var geom = new Geometry().fromBufferGeometry( geomIB );
  26852. var geomB = new BufferGeometry().fromGeometry( geom );
  26853. var geomDC = addDrawCalls( geomIB.clone() );
  26854. return [ geom, geomB, geomIB, geomDC ];
  26855. }
  26856. function createIndexedBufferGeometry( vertList, idxList ) {
  26857. var geom = new BufferGeometry();
  26858. var indexTable = [];
  26859. var numTris = idxList.length / 3;
  26860. var numVerts = 0;
  26861. var indices = new Uint32Array( numTris * 3 );
  26862. var vertices = new Float32Array( vertList.length * 3 );
  26863. for ( var i = 0; i < numTris; i ++ ) {
  26864. for ( var j = 0; j < 3; j ++ ) {
  26865. var idx = idxList[ 3 * i + j ];
  26866. if ( indexTable[ idx ] === undefined ) {
  26867. var v = vertList[ idx ];
  26868. vertices[ 3 * numVerts ] = v.x;
  26869. vertices[ 3 * numVerts + 1 ] = v.y;
  26870. vertices[ 3 * numVerts + 2 ] = v.z;
  26871. indexTable[ idx ] = numVerts;
  26872. numVerts ++;
  26873. }
  26874. indices[ 3 * i + j ] = indexTable[ idx ];
  26875. }
  26876. }
  26877. vertices = vertices.subarray( 0, 3 * numVerts );
  26878. geom.setIndex( new BufferAttribute( indices, 1 ) );
  26879. geom.addAttribute( 'position', new BufferAttribute( vertices, 3 ) );
  26880. geom.computeFaceNormals();
  26881. return geom;
  26882. }
  26883. function addDrawCalls( geometry ) {
  26884. var numTris = geometry.index.count / 3;
  26885. for ( var i = 0; i < numTris; i ++ ) {
  26886. var start = i * 3;
  26887. var count = 3;
  26888. geometry.addGroup( start, count );
  26889. }
  26890. return geometry;
  26891. }
  26892. function countEdges( geom ) {
  26893. if ( geom instanceof EdgesGeometry ) {
  26894. return geom.getAttribute( 'position' ).count / 2;
  26895. }
  26896. if ( geom.faces !== undefined ) {
  26897. return geom.faces.length * 3;
  26898. }
  26899. var indices = geom.index;
  26900. if ( indices ) {
  26901. return indices.count;
  26902. }
  26903. return geom.getAttribute( 'position' ).count;
  26904. }
  26905. //
  26906. // DEBUGGING
  26907. //
  26908. var DEBUG = false;
  26909. var renderer;
  26910. var camera;
  26911. var scene = new Scene();
  26912. var xoffset = 0;
  26913. function output( geom, egeom ) {
  26914. if ( DEBUG !== true ) return;
  26915. if ( ! renderer ) initDebug();
  26916. var mesh = new Mesh( geom, undefined );
  26917. var edges = new LineSegments( egeom, new LineBasicMaterial( { color: 'black' } ) );
  26918. mesh.position.setX( xoffset );
  26919. edges.position.setX( xoffset ++ );
  26920. scene.add( mesh );
  26921. scene.add( edges );
  26922. if ( scene.children.length % 8 === 0 ) {
  26923. xoffset += 2;
  26924. }
  26925. }
  26926. function initDebug() {
  26927. renderer = new WebGLRenderer( {
  26928. antialias: true
  26929. } );
  26930. var width = 600;
  26931. var height = 480;
  26932. renderer.setSize( width, height );
  26933. renderer.setClearColor( 0xCCCCCC );
  26934. camera = new PerspectiveCamera( 45, width / height, 1, 100 );
  26935. camera.position.x = 30;
  26936. camera.position.z = 40;
  26937. camera.lookAt( new Vector3( 30, 0, 0 ) );
  26938. document.body.appendChild( renderer.domElement );
  26939. var controls = new THREE.OrbitControls( camera, renderer.domElement ); // TODO: please do somethings for that -_-'
  26940. controls.target = new Vector3( 30, 0, 0 );
  26941. animate();
  26942. function animate() {
  26943. requestAnimationFrame( animate );
  26944. controls.update();
  26945. renderer.render( scene, camera );
  26946. }
  26947. }
  26948. QUnit.module( 'Geometries', () => {
  26949. QUnit.module.todo( 'EdgesGeometry', () => {
  26950. var vertList = [
  26951. new Vector3( 0, 0, 0 ),
  26952. new Vector3( 1, 0, 0 ),
  26953. new Vector3( 1, 1, 0 ),
  26954. new Vector3( 0, 1, 0 ),
  26955. new Vector3( 1, 1, 1 ),
  26956. ];
  26957. // INHERITANCE
  26958. QUnit.test( "Extending", ( assert ) => {
  26959. assert.ok( false, "everything's gonna be alright" );
  26960. } );
  26961. // INSTANCING
  26962. QUnit.test( "Instancing", ( assert ) => {
  26963. assert.ok( false, "everything's gonna be alright" );
  26964. } );
  26965. // OTHERS
  26966. QUnit.test( "singularity", ( assert ) => {
  26967. testEdges( vertList, [ 1, 1, 1 ], 0, assert );
  26968. } );
  26969. QUnit.test( "needle", ( assert ) => {
  26970. testEdges( vertList, [ 0, 0, 1 ], 0, assert );
  26971. } );
  26972. QUnit.test( "single triangle", ( assert ) => {
  26973. testEdges( vertList, [ 0, 1, 2 ], 3, assert );
  26974. } );
  26975. QUnit.test( "two isolated triangles", ( assert ) => {
  26976. var vertList = [
  26977. new Vector3( 0, 0, 0 ),
  26978. new Vector3( 1, 0, 0 ),
  26979. new Vector3( 1, 1, 0 ),
  26980. new Vector3( 0, 0, 1 ),
  26981. new Vector3( 1, 0, 1 ),
  26982. new Vector3( 1, 1, 1 ),
  26983. ];
  26984. testEdges( vertList, [ 0, 1, 2, 3, 4, 5 ], 6, assert );
  26985. } );
  26986. QUnit.test( "two flat triangles", ( assert ) => {
  26987. testEdges( vertList, [ 0, 1, 2, 0, 2, 3 ], 4, assert );
  26988. } );
  26989. QUnit.test( "two flat triangles, inverted", ( assert ) => {
  26990. testEdges( vertList, [ 0, 1, 2, 0, 3, 2 ], 5, assert );
  26991. } );
  26992. QUnit.test( "two non-coplanar triangles", ( assert ) => {
  26993. testEdges( vertList, [ 0, 1, 2, 0, 4, 2 ], 5, assert );
  26994. } );
  26995. QUnit.test( "three triangles, coplanar first", ( assert ) => {
  26996. testEdges( vertList, [ 0, 1, 2, 0, 2, 3, 0, 4, 2 ], 7, assert );
  26997. } );
  26998. QUnit.test( "three triangles, coplanar last", ( assert ) => {
  26999. testEdges( vertList, [ 0, 1, 2, 0, 4, 2, 0, 2, 3 ], 6, assert ); // Should be 7
  27000. } );
  27001. QUnit.test( "tetrahedron", ( assert ) => {
  27002. testEdges( vertList, [ 0, 1, 2, 0, 1, 4, 0, 4, 2, 1, 2, 4 ], 6, assert );
  27003. } );
  27004. } );
  27005. } );
  27006. /**
  27007. * @author zz85 / http://www.lab4games.net/zz85/blog
  27008. *
  27009. * Creates extruded geometry from a path shape.
  27010. *
  27011. * parameters = {
  27012. *
  27013. * curveSegments: <int>, // number of points on the curves
  27014. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  27015. * amount: <int>, // Depth to extrude the shape
  27016. *
  27017. * bevelEnabled: <bool>, // turn on bevel
  27018. * bevelThickness: <float>, // how deep into the original shape bevel goes
  27019. * bevelSize: <float>, // how far from shape outline is bevel
  27020. * bevelSegments: <int>, // number of bevel layers
  27021. *
  27022. * extrudePath: <THREE.Curve> // curve to extrude shape along
  27023. * frames: <Object> // containing arrays of tangents, normals, binormals
  27024. *
  27025. * UVGenerator: <Object> // object that provides UV generator functions
  27026. *
  27027. * }
  27028. */
  27029. function ExtrudeGeometry( shapes, options ) {
  27030. Geometry.call( this );
  27031. this.type = 'ExtrudeGeometry';
  27032. this.parameters = {
  27033. shapes: shapes,
  27034. options: options
  27035. };
  27036. this.fromBufferGeometry( new ExtrudeBufferGeometry( shapes, options ) );
  27037. this.mergeVertices();
  27038. }
  27039. ExtrudeGeometry.prototype = Object.create( Geometry.prototype );
  27040. ExtrudeGeometry.prototype.constructor = ExtrudeGeometry;
  27041. // ExtrudeBufferGeometry
  27042. function ExtrudeBufferGeometry( shapes, options ) {
  27043. if ( typeof ( shapes ) === "undefined" ) {
  27044. return;
  27045. }
  27046. BufferGeometry.call( this );
  27047. this.type = 'ExtrudeBufferGeometry';
  27048. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  27049. this.addShapeList( shapes, options );
  27050. this.computeVertexNormals();
  27051. // can't really use automatic vertex normals
  27052. // as then front and back sides get smoothed too
  27053. // should do separate smoothing just for sides
  27054. //this.computeVertexNormals();
  27055. //console.log( "took", ( Date.now() - startTime ) );
  27056. }
  27057. ExtrudeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  27058. ExtrudeBufferGeometry.prototype.constructor = ExtrudeBufferGeometry;
  27059. ExtrudeBufferGeometry.prototype.getArrays = function () {
  27060. var positionAttribute = this.getAttribute( "position" );
  27061. var verticesArray = positionAttribute ? Array.prototype.slice.call( positionAttribute.array ) : [];
  27062. var uvAttribute = this.getAttribute( "uv" );
  27063. var uvArray = uvAttribute ? Array.prototype.slice.call( uvAttribute.array ) : [];
  27064. var IndexAttribute = this.index;
  27065. var indicesArray = IndexAttribute ? Array.prototype.slice.call( IndexAttribute.array ) : [];
  27066. return {
  27067. position: verticesArray,
  27068. uv: uvArray,
  27069. index: indicesArray
  27070. };
  27071. };
  27072. ExtrudeBufferGeometry.prototype.addShapeList = function ( shapes, options ) {
  27073. var sl = shapes.length;
  27074. options.arrays = this.getArrays();
  27075. for ( var s = 0; s < sl; s ++ ) {
  27076. var shape = shapes[ s ];
  27077. this.addShape( shape, options );
  27078. }
  27079. this.setIndex( options.arrays.index );
  27080. this.addAttribute( 'position', new Float32BufferAttribute( options.arrays.position, 3 ) );
  27081. this.addAttribute( 'uv', new Float32BufferAttribute( options.arrays.uv, 2 ) );
  27082. };
  27083. ExtrudeBufferGeometry.prototype.addShape = function ( shape, options ) {
  27084. var arrays = options.arrays ? options.arrays : this.getArrays();
  27085. var verticesArray = arrays.position;
  27086. var indicesArray = arrays.index;
  27087. var uvArray = arrays.uv;
  27088. var placeholder = [];
  27089. var amount = options.amount !== undefined ? options.amount : 100;
  27090. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6; // 10
  27091. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2; // 8
  27092. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  27093. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true; // false
  27094. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  27095. var steps = options.steps !== undefined ? options.steps : 1;
  27096. var extrudePath = options.extrudePath;
  27097. var extrudePts, extrudeByPath = false;
  27098. // Use default WorldUVGenerator if no UV generators are specified.
  27099. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : ExtrudeGeometry.WorldUVGenerator;
  27100. var splineTube, binormal, normal, position2;
  27101. if ( extrudePath ) {
  27102. extrudePts = extrudePath.getSpacedPoints( steps );
  27103. extrudeByPath = true;
  27104. bevelEnabled = false; // bevels not supported for path extrusion
  27105. // SETUP TNB variables
  27106. // TODO1 - have a .isClosed in spline?
  27107. splineTube = options.frames !== undefined ? options.frames : extrudePath.computeFrenetFrames( steps, false );
  27108. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  27109. binormal = new Vector3();
  27110. normal = new Vector3();
  27111. position2 = new Vector3();
  27112. }
  27113. // Safeguards if bevels are not enabled
  27114. if ( ! bevelEnabled ) {
  27115. bevelSegments = 0;
  27116. bevelThickness = 0;
  27117. bevelSize = 0;
  27118. }
  27119. // Variables initialization
  27120. var ahole, h, hl; // looping of holes
  27121. var scope = this;
  27122. var shapePoints = shape.extractPoints( curveSegments );
  27123. var vertices = shapePoints.shape;
  27124. var holes = shapePoints.holes;
  27125. var reverse = ! ShapeUtils.isClockWise( vertices );
  27126. if ( reverse ) {
  27127. vertices = vertices.reverse();
  27128. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  27129. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  27130. ahole = holes[ h ];
  27131. if ( ShapeUtils.isClockWise( ahole ) ) {
  27132. holes[ h ] = ahole.reverse();
  27133. }
  27134. }
  27135. }
  27136. var faces = ShapeUtils.triangulateShape( vertices, holes );
  27137. /* Vertices */
  27138. var contour = vertices; // vertices has all points but contour has only points of circumference
  27139. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  27140. ahole = holes[ h ];
  27141. vertices = vertices.concat( ahole );
  27142. }
  27143. function scalePt2( pt, vec, size ) {
  27144. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  27145. return vec.clone().multiplyScalar( size ).add( pt );
  27146. }
  27147. var b, bs, t, z,
  27148. vert, vlen = vertices.length,
  27149. face, flen = faces.length;
  27150. // Find directions for point movement
  27151. function getBevelVec( inPt, inPrev, inNext ) {
  27152. // computes for inPt the corresponding point inPt' on a new contour
  27153. // shifted by 1 unit (length of normalized vector) to the left
  27154. // if we walk along contour clockwise, this new contour is outside the old one
  27155. //
  27156. // inPt' is the intersection of the two lines parallel to the two
  27157. // adjacent edges of inPt at a distance of 1 unit on the left side.
  27158. var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  27159. // good reading for geometry algorithms (here: line-line intersection)
  27160. // http://geomalgorithms.com/a05-_intersect-1.html
  27161. var v_prev_x = inPt.x - inPrev.x,
  27162. v_prev_y = inPt.y - inPrev.y;
  27163. var v_next_x = inNext.x - inPt.x,
  27164. v_next_y = inNext.y - inPt.y;
  27165. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  27166. // check for collinear edges
  27167. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  27168. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  27169. // not collinear
  27170. // length of vectors for normalizing
  27171. var v_prev_len = Math.sqrt( v_prev_lensq );
  27172. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  27173. // shift adjacent points by unit vectors to the left
  27174. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  27175. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  27176. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  27177. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  27178. // scaling factor for v_prev to intersection point
  27179. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  27180. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  27181. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  27182. // vector from inPt to intersection point
  27183. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  27184. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  27185. // Don't normalize!, otherwise sharp corners become ugly
  27186. // but prevent crazy spikes
  27187. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  27188. if ( v_trans_lensq <= 2 ) {
  27189. return new Vector2( v_trans_x, v_trans_y );
  27190. } else {
  27191. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  27192. }
  27193. } else {
  27194. // handle special case of collinear edges
  27195. var direction_eq = false; // assumes: opposite
  27196. if ( v_prev_x > Number.EPSILON ) {
  27197. if ( v_next_x > Number.EPSILON ) {
  27198. direction_eq = true;
  27199. }
  27200. } else {
  27201. if ( v_prev_x < - Number.EPSILON ) {
  27202. if ( v_next_x < - Number.EPSILON ) {
  27203. direction_eq = true;
  27204. }
  27205. } else {
  27206. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  27207. direction_eq = true;
  27208. }
  27209. }
  27210. }
  27211. if ( direction_eq ) {
  27212. // console.log("Warning: lines are a straight sequence");
  27213. v_trans_x = - v_prev_y;
  27214. v_trans_y = v_prev_x;
  27215. shrink_by = Math.sqrt( v_prev_lensq );
  27216. } else {
  27217. // console.log("Warning: lines are a straight spike");
  27218. v_trans_x = v_prev_x;
  27219. v_trans_y = v_prev_y;
  27220. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  27221. }
  27222. }
  27223. return new Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  27224. }
  27225. var contourMovements = [];
  27226. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  27227. if ( j === il ) j = 0;
  27228. if ( k === il ) k = 0;
  27229. // (j)---(i)---(k)
  27230. // console.log('i,j,k', i, j , k)
  27231. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  27232. }
  27233. var holesMovements = [],
  27234. oneHoleMovements, verticesMovements = contourMovements.concat();
  27235. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  27236. ahole = holes[ h ];
  27237. oneHoleMovements = [];
  27238. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  27239. if ( j === il ) j = 0;
  27240. if ( k === il ) k = 0;
  27241. // (j)---(i)---(k)
  27242. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  27243. }
  27244. holesMovements.push( oneHoleMovements );
  27245. verticesMovements = verticesMovements.concat( oneHoleMovements );
  27246. }
  27247. // Loop bevelSegments, 1 for the front, 1 for the back
  27248. for ( b = 0; b < bevelSegments; b ++ ) {
  27249. //for ( b = bevelSegments; b > 0; b -- ) {
  27250. t = b / bevelSegments;
  27251. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  27252. bs = bevelSize * Math.sin( t * Math.PI / 2 );
  27253. // contract shape
  27254. for ( i = 0, il = contour.length; i < il; i ++ ) {
  27255. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  27256. v( vert.x, vert.y, - z );
  27257. }
  27258. // expand holes
  27259. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  27260. ahole = holes[ h ];
  27261. oneHoleMovements = holesMovements[ h ];
  27262. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  27263. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  27264. v( vert.x, vert.y, - z );
  27265. }
  27266. }
  27267. }
  27268. bs = bevelSize;
  27269. // Back facing vertices
  27270. for ( i = 0; i < vlen; i ++ ) {
  27271. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  27272. if ( ! extrudeByPath ) {
  27273. v( vert.x, vert.y, 0 );
  27274. } else {
  27275. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  27276. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  27277. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  27278. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  27279. v( position2.x, position2.y, position2.z );
  27280. }
  27281. }
  27282. // Add stepped vertices...
  27283. // Including front facing vertices
  27284. var s;
  27285. for ( s = 1; s <= steps; s ++ ) {
  27286. for ( i = 0; i < vlen; i ++ ) {
  27287. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  27288. if ( ! extrudeByPath ) {
  27289. v( vert.x, vert.y, amount / steps * s );
  27290. } else {
  27291. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  27292. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  27293. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  27294. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  27295. v( position2.x, position2.y, position2.z );
  27296. }
  27297. }
  27298. }
  27299. // Add bevel segments planes
  27300. //for ( b = 1; b <= bevelSegments; b ++ ) {
  27301. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  27302. t = b / bevelSegments;
  27303. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  27304. bs = bevelSize * Math.sin( t * Math.PI / 2 );
  27305. // contract shape
  27306. for ( i = 0, il = contour.length; i < il; i ++ ) {
  27307. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  27308. v( vert.x, vert.y, amount + z );
  27309. }
  27310. // expand holes
  27311. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  27312. ahole = holes[ h ];
  27313. oneHoleMovements = holesMovements[ h ];
  27314. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  27315. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  27316. if ( ! extrudeByPath ) {
  27317. v( vert.x, vert.y, amount + z );
  27318. } else {
  27319. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  27320. }
  27321. }
  27322. }
  27323. }
  27324. /* Faces */
  27325. // Top and bottom faces
  27326. buildLidFaces();
  27327. // Sides faces
  27328. buildSideFaces();
  27329. ///// Internal functions
  27330. function buildLidFaces() {
  27331. var start = verticesArray.length / 3;
  27332. if ( bevelEnabled ) {
  27333. var layer = 0; // steps + 1
  27334. var offset = vlen * layer;
  27335. // Bottom faces
  27336. for ( i = 0; i < flen; i ++ ) {
  27337. face = faces[ i ];
  27338. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  27339. }
  27340. layer = steps + bevelSegments * 2;
  27341. offset = vlen * layer;
  27342. // Top faces
  27343. for ( i = 0; i < flen; i ++ ) {
  27344. face = faces[ i ];
  27345. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  27346. }
  27347. } else {
  27348. // Bottom faces
  27349. for ( i = 0; i < flen; i ++ ) {
  27350. face = faces[ i ];
  27351. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  27352. }
  27353. // Top faces
  27354. for ( i = 0; i < flen; i ++ ) {
  27355. face = faces[ i ];
  27356. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  27357. }
  27358. }
  27359. scope.addGroup( start, verticesArray.length / 3 - start, options.material !== undefined ? options.material : 0 );
  27360. }
  27361. // Create faces for the z-sides of the shape
  27362. function buildSideFaces() {
  27363. var start = verticesArray.length / 3;
  27364. var layeroffset = 0;
  27365. sidewalls( contour, layeroffset );
  27366. layeroffset += contour.length;
  27367. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  27368. ahole = holes[ h ];
  27369. sidewalls( ahole, layeroffset );
  27370. //, true
  27371. layeroffset += ahole.length;
  27372. }
  27373. scope.addGroup( start, verticesArray.length / 3 - start, options.extrudeMaterial !== undefined ? options.extrudeMaterial : 1 );
  27374. }
  27375. function sidewalls( contour, layeroffset ) {
  27376. var j, k;
  27377. i = contour.length;
  27378. while ( -- i >= 0 ) {
  27379. j = i;
  27380. k = i - 1;
  27381. if ( k < 0 ) k = contour.length - 1;
  27382. //console.log('b', i,j, i-1, k,vertices.length);
  27383. var s = 0,
  27384. sl = steps + bevelSegments * 2;
  27385. for ( s = 0; s < sl; s ++ ) {
  27386. var slen1 = vlen * s;
  27387. var slen2 = vlen * ( s + 1 );
  27388. var a = layeroffset + j + slen1,
  27389. b = layeroffset + k + slen1,
  27390. c = layeroffset + k + slen2,
  27391. d = layeroffset + j + slen2;
  27392. f4( a, b, c, d );
  27393. }
  27394. }
  27395. }
  27396. function v( x, y, z ) {
  27397. placeholder.push( x );
  27398. placeholder.push( y );
  27399. placeholder.push( z );
  27400. }
  27401. function f3( a, b, c ) {
  27402. addVertex( a );
  27403. addVertex( b );
  27404. addVertex( c );
  27405. var nextIndex = verticesArray.length / 3;
  27406. var uvs = uvgen.generateTopUV( scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  27407. addUV( uvs[ 0 ] );
  27408. addUV( uvs[ 1 ] );
  27409. addUV( uvs[ 2 ] );
  27410. }
  27411. function f4( a, b, c, d ) {
  27412. addVertex( a );
  27413. addVertex( b );
  27414. addVertex( d );
  27415. addVertex( b );
  27416. addVertex( c );
  27417. addVertex( d );
  27418. var nextIndex = verticesArray.length / 3;
  27419. var uvs = uvgen.generateSideWallUV( scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  27420. addUV( uvs[ 0 ] );
  27421. addUV( uvs[ 1 ] );
  27422. addUV( uvs[ 3 ] );
  27423. addUV( uvs[ 1 ] );
  27424. addUV( uvs[ 2 ] );
  27425. addUV( uvs[ 3 ] );
  27426. }
  27427. function addVertex( index ) {
  27428. indicesArray.push( verticesArray.length / 3 );
  27429. verticesArray.push( placeholder[ index * 3 + 0 ] );
  27430. verticesArray.push( placeholder[ index * 3 + 1 ] );
  27431. verticesArray.push( placeholder[ index * 3 + 2 ] );
  27432. }
  27433. function addUV( vector2 ) {
  27434. uvArray.push( vector2.x );
  27435. uvArray.push( vector2.y );
  27436. }
  27437. if ( ! options.arrays ) {
  27438. this.setIndex( indicesArray );
  27439. this.addAttribute( 'position', new Float32BufferAttribute( verticesArray, 3 ) );
  27440. this.addAttribute( 'uv', new Float32BufferAttribute( options.arrays.uv, 2 ) );
  27441. }
  27442. };
  27443. ExtrudeGeometry.WorldUVGenerator = {
  27444. generateTopUV: function ( geometry, vertices, indexA, indexB, indexC ) {
  27445. var a_x = vertices[ indexA * 3 ];
  27446. var a_y = vertices[ indexA * 3 + 1 ];
  27447. var b_x = vertices[ indexB * 3 ];
  27448. var b_y = vertices[ indexB * 3 + 1 ];
  27449. var c_x = vertices[ indexC * 3 ];
  27450. var c_y = vertices[ indexC * 3 + 1 ];
  27451. return [
  27452. new Vector2( a_x, a_y ),
  27453. new Vector2( b_x, b_y ),
  27454. new Vector2( c_x, c_y )
  27455. ];
  27456. },
  27457. generateSideWallUV: function ( geometry, vertices, indexA, indexB, indexC, indexD ) {
  27458. var a_x = vertices[ indexA * 3 ];
  27459. var a_y = vertices[ indexA * 3 + 1 ];
  27460. var a_z = vertices[ indexA * 3 + 2 ];
  27461. var b_x = vertices[ indexB * 3 ];
  27462. var b_y = vertices[ indexB * 3 + 1 ];
  27463. var b_z = vertices[ indexB * 3 + 2 ];
  27464. var c_x = vertices[ indexC * 3 ];
  27465. var c_y = vertices[ indexC * 3 + 1 ];
  27466. var c_z = vertices[ indexC * 3 + 2 ];
  27467. var d_x = vertices[ indexD * 3 ];
  27468. var d_y = vertices[ indexD * 3 + 1 ];
  27469. var d_z = vertices[ indexD * 3 + 2 ];
  27470. if ( Math.abs( a_y - b_y ) < 0.01 ) {
  27471. return [
  27472. new Vector2( a_x, 1 - a_z ),
  27473. new Vector2( b_x, 1 - b_z ),
  27474. new Vector2( c_x, 1 - c_z ),
  27475. new Vector2( d_x, 1 - d_z )
  27476. ];
  27477. } else {
  27478. return [
  27479. new Vector2( a_y, 1 - a_z ),
  27480. new Vector2( b_y, 1 - b_z ),
  27481. new Vector2( c_y, 1 - c_z ),
  27482. new Vector2( d_y, 1 - d_z )
  27483. ];
  27484. }
  27485. }
  27486. };
  27487. /**
  27488. * @author TristanVALCKE / https://github.com/Itee
  27489. */
  27490. /* global QUnit */
  27491. QUnit.module( 'Geometries', () => {
  27492. QUnit.module.todo( 'ExtrudeGeometry', () => {
  27493. // INHERITANCE
  27494. QUnit.test( "Extending", ( assert ) => {
  27495. assert.ok( false, "everything's gonna be alright" );
  27496. } );
  27497. // INSTANCING
  27498. QUnit.test( "Instancing", ( assert ) => {
  27499. assert.ok( false, "everything's gonna be alright" );
  27500. } );
  27501. } );
  27502. QUnit.module.todo( 'ExtrudeBufferGeometry', () => {
  27503. // INHERITANCE
  27504. QUnit.test( "Extending", ( assert ) => {
  27505. assert.ok( false, "everything's gonna be alright" );
  27506. } );
  27507. // INSTANCING
  27508. QUnit.test( "Instancing", ( assert ) => {
  27509. assert.ok( false, "everything's gonna be alright" );
  27510. } );
  27511. // STATIC STUFF
  27512. QUnit.test( "WorldUVGenerator.generateTopUV", ( assert ) => {
  27513. assert.ok( false, "everything's gonna be alright" );
  27514. } );
  27515. QUnit.test( "WorldUVGenerator.generateSideWallUV", ( assert ) => {
  27516. assert.ok( false, "everything's gonna be alright" );
  27517. } );
  27518. // OTHERS
  27519. QUnit.test( "getArrays", ( assert ) => {
  27520. assert.ok( false, "everything's gonna be alright" );
  27521. } );
  27522. QUnit.test( "addShapeList", ( assert ) => {
  27523. assert.ok( false, "everything's gonna be alright" );
  27524. } );
  27525. QUnit.test( "addShape", ( assert ) => {
  27526. assert.ok( false, "everything's gonna be alright" );
  27527. } );
  27528. } );
  27529. } );
  27530. /**
  27531. * @author timothypratley / https://github.com/timothypratley
  27532. * @author Mugen87 / https://github.com/Mugen87
  27533. */
  27534. function IcosahedronGeometry( radius, detail ) {
  27535. Geometry.call( this );
  27536. this.type = 'IcosahedronGeometry';
  27537. this.parameters = {
  27538. radius: radius,
  27539. detail: detail
  27540. };
  27541. this.fromBufferGeometry( new IcosahedronBufferGeometry( radius, detail ) );
  27542. this.mergeVertices();
  27543. }
  27544. IcosahedronGeometry.prototype = Object.create( Geometry.prototype );
  27545. IcosahedronGeometry.prototype.constructor = IcosahedronGeometry;
  27546. // IcosahedronBufferGeometry
  27547. function IcosahedronBufferGeometry( radius, detail ) {
  27548. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  27549. var vertices = [
  27550. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  27551. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  27552. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  27553. ];
  27554. var indices = [
  27555. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  27556. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  27557. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  27558. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  27559. ];
  27560. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  27561. this.type = 'IcosahedronBufferGeometry';
  27562. this.parameters = {
  27563. radius: radius,
  27564. detail: detail
  27565. };
  27566. }
  27567. IcosahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  27568. IcosahedronBufferGeometry.prototype.constructor = IcosahedronBufferGeometry;
  27569. /**
  27570. * @author TristanVALCKE / https://github.com/Itee
  27571. * @author Anonymous
  27572. */
  27573. /* global QUnit */
  27574. QUnit.module( 'Geometries', () => {
  27575. QUnit.module.todo( 'IcosahedronGeometry', ( hooks ) => {
  27576. var geometries = undefined;
  27577. hooks.beforeEach( function () {
  27578. const parameters = {
  27579. radius: 10,
  27580. detail: undefined
  27581. };
  27582. geometries = [
  27583. new IcosahedronGeometry(),
  27584. new IcosahedronGeometry( parameters.radius ),
  27585. new IcosahedronGeometry( parameters.radius, parameters.detail ),
  27586. ];
  27587. } );
  27588. // INHERITANCE
  27589. QUnit.test( "Extending", ( assert ) => {
  27590. assert.ok( false, "everything's gonna be alright" );
  27591. } );
  27592. // INSTANCING
  27593. QUnit.test( "Instancing", ( assert ) => {
  27594. assert.ok( false, "everything's gonna be alright" );
  27595. } );
  27596. // OTHERS
  27597. QUnit.test( 'Standard geometry tests', ( assert ) => {
  27598. runStdGeometryTests( assert, geometries );
  27599. } );
  27600. } );
  27601. QUnit.module.todo( 'IcosahedronBufferGeometry', ( hooks ) => {
  27602. var geometries = undefined;
  27603. hooks.beforeEach( function () {
  27604. const parameters = {
  27605. radius: 10,
  27606. detail: undefined
  27607. };
  27608. geometries = [
  27609. new IcosahedronBufferGeometry(),
  27610. new IcosahedronBufferGeometry( parameters.radius ),
  27611. new IcosahedronBufferGeometry( parameters.radius, parameters.detail ),
  27612. ];
  27613. } );
  27614. // INHERITANCE
  27615. QUnit.test( "Extending", ( assert ) => {
  27616. assert.ok( false, "everything's gonna be alright" );
  27617. } );
  27618. // INSTANCING
  27619. QUnit.test( "Instancing", ( assert ) => {
  27620. assert.ok( false, "everything's gonna be alright" );
  27621. } );
  27622. // OTHERS
  27623. QUnit.test( 'Standard geometry tests', ( assert ) => {
  27624. runStdGeometryTests( assert, geometries );
  27625. } );
  27626. } );
  27627. } );
  27628. /**
  27629. * @author astrodud / http://astrodud.isgreat.org/
  27630. * @author zz85 / https://github.com/zz85
  27631. * @author bhouston / http://clara.io
  27632. * @author Mugen87 / https://github.com/Mugen87
  27633. */
  27634. function LatheGeometry( points, segments, phiStart, phiLength ) {
  27635. Geometry.call( this );
  27636. this.type = 'LatheGeometry';
  27637. this.parameters = {
  27638. points: points,
  27639. segments: segments,
  27640. phiStart: phiStart,
  27641. phiLength: phiLength
  27642. };
  27643. this.fromBufferGeometry( new LatheBufferGeometry( points, segments, phiStart, phiLength ) );
  27644. this.mergeVertices();
  27645. }
  27646. LatheGeometry.prototype = Object.create( Geometry.prototype );
  27647. LatheGeometry.prototype.constructor = LatheGeometry;
  27648. // LatheBufferGeometry
  27649. function LatheBufferGeometry( points, segments, phiStart, phiLength ) {
  27650. BufferGeometry.call( this );
  27651. this.type = 'LatheBufferGeometry';
  27652. this.parameters = {
  27653. points: points,
  27654. segments: segments,
  27655. phiStart: phiStart,
  27656. phiLength: phiLength
  27657. };
  27658. segments = Math.floor( segments ) || 12;
  27659. phiStart = phiStart || 0;
  27660. phiLength = phiLength || Math.PI * 2;
  27661. // clamp phiLength so it's in range of [ 0, 2PI ]
  27662. phiLength = _Math.clamp( phiLength, 0, Math.PI * 2 );
  27663. // buffers
  27664. var indices = [];
  27665. var vertices = [];
  27666. var uvs = [];
  27667. // helper variables
  27668. var base;
  27669. var inverseSegments = 1.0 / segments;
  27670. var vertex = new Vector3();
  27671. var uv = new Vector2();
  27672. var i, j;
  27673. // generate vertices and uvs
  27674. for ( i = 0; i <= segments; i ++ ) {
  27675. var phi = phiStart + i * inverseSegments * phiLength;
  27676. var sin = Math.sin( phi );
  27677. var cos = Math.cos( phi );
  27678. for ( j = 0; j <= ( points.length - 1 ); j ++ ) {
  27679. // vertex
  27680. vertex.x = points[ j ].x * sin;
  27681. vertex.y = points[ j ].y;
  27682. vertex.z = points[ j ].x * cos;
  27683. vertices.push( vertex.x, vertex.y, vertex.z );
  27684. // uv
  27685. uv.x = i / segments;
  27686. uv.y = j / ( points.length - 1 );
  27687. uvs.push( uv.x, uv.y );
  27688. }
  27689. }
  27690. // indices
  27691. for ( i = 0; i < segments; i ++ ) {
  27692. for ( j = 0; j < ( points.length - 1 ); j ++ ) {
  27693. base = j + i * points.length;
  27694. var a = base;
  27695. var b = base + points.length;
  27696. var c = base + points.length + 1;
  27697. var d = base + 1;
  27698. // faces
  27699. indices.push( a, b, d );
  27700. indices.push( b, c, d );
  27701. }
  27702. }
  27703. // build geometry
  27704. this.setIndex( indices );
  27705. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27706. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  27707. // generate normals
  27708. this.computeVertexNormals();
  27709. // if the geometry is closed, we need to average the normals along the seam.
  27710. // because the corresponding vertices are identical (but still have different UVs).
  27711. if ( phiLength === Math.PI * 2 ) {
  27712. var normals = this.attributes.normal.array;
  27713. var n1 = new Vector3();
  27714. var n2 = new Vector3();
  27715. var n = new Vector3();
  27716. // this is the buffer offset for the last line of vertices
  27717. base = segments * points.length * 3;
  27718. for ( i = 0, j = 0; i < points.length; i ++, j += 3 ) {
  27719. // select the normal of the vertex in the first line
  27720. n1.x = normals[ j + 0 ];
  27721. n1.y = normals[ j + 1 ];
  27722. n1.z = normals[ j + 2 ];
  27723. // select the normal of the vertex in the last line
  27724. n2.x = normals[ base + j + 0 ];
  27725. n2.y = normals[ base + j + 1 ];
  27726. n2.z = normals[ base + j + 2 ];
  27727. // average normals
  27728. n.addVectors( n1, n2 ).normalize();
  27729. // assign the new values to both normals
  27730. normals[ j + 0 ] = normals[ base + j + 0 ] = n.x;
  27731. normals[ j + 1 ] = normals[ base + j + 1 ] = n.y;
  27732. normals[ j + 2 ] = normals[ base + j + 2 ] = n.z;
  27733. }
  27734. }
  27735. }
  27736. LatheBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  27737. LatheBufferGeometry.prototype.constructor = LatheBufferGeometry;
  27738. /**
  27739. * @author TristanVALCKE / https://github.com/Itee
  27740. */
  27741. /* global QUnit */
  27742. QUnit.module( 'Geometries', () => {
  27743. QUnit.module.todo( 'LatheGeometry', ( hooks ) => {
  27744. var geometries = undefined;
  27745. hooks.beforeEach( function () {
  27746. const parameters = {
  27747. points: [],
  27748. segments: 0,
  27749. phiStart: 0,
  27750. phiLength: 0
  27751. };
  27752. geometries = [
  27753. // new LatheGeometry(), // Todo: error for undefined point
  27754. new LatheGeometry( parameters.points )
  27755. ];
  27756. } );
  27757. // INHERITANCE
  27758. QUnit.test( "Extending", ( assert ) => {
  27759. assert.ok( false, "everything's gonna be alright" );
  27760. } );
  27761. // INSTANCING
  27762. QUnit.test( "Instancing", ( assert ) => {
  27763. assert.ok( false, "everything's gonna be alright" );
  27764. } );
  27765. // OTHERS
  27766. QUnit.test( 'Standard geometry tests', ( assert ) => {
  27767. runStdGeometryTests( assert, geometries );
  27768. } );
  27769. } );
  27770. QUnit.module.todo( 'LatheBufferGeometry', ( hooks ) => {
  27771. var geometries = undefined;
  27772. hooks.beforeEach( function () {
  27773. const parameters = {
  27774. points: [],
  27775. segments: 0,
  27776. phiStart: 0,
  27777. phiLength: 0
  27778. };
  27779. geometries = [
  27780. // new LatheBufferGeometry(), // Todo: error for undefined point
  27781. new LatheBufferGeometry( parameters.points )
  27782. ];
  27783. } );
  27784. // INHERITANCE
  27785. QUnit.test( "Extending", ( assert ) => {
  27786. assert.ok( false, "everything's gonna be alright" );
  27787. } );
  27788. // INSTANCING
  27789. QUnit.test( "Instancing", ( assert ) => {
  27790. assert.ok( false, "everything's gonna be alright" );
  27791. } );
  27792. // OTHERS
  27793. QUnit.test( 'Standard geometry tests', ( assert ) => {
  27794. runStdGeometryTests( assert, geometries );
  27795. } );
  27796. } );
  27797. } );
  27798. /**
  27799. * @author timothypratley / https://github.com/timothypratley
  27800. * @author Mugen87 / https://github.com/Mugen87
  27801. */
  27802. function OctahedronGeometry( radius, detail ) {
  27803. Geometry.call( this );
  27804. this.type = 'OctahedronGeometry';
  27805. this.parameters = {
  27806. radius: radius,
  27807. detail: detail
  27808. };
  27809. this.fromBufferGeometry( new OctahedronBufferGeometry( radius, detail ) );
  27810. this.mergeVertices();
  27811. }
  27812. OctahedronGeometry.prototype = Object.create( Geometry.prototype );
  27813. OctahedronGeometry.prototype.constructor = OctahedronGeometry;
  27814. // OctahedronBufferGeometry
  27815. function OctahedronBufferGeometry( radius, detail ) {
  27816. var vertices = [
  27817. 1, 0, 0, - 1, 0, 0, 0, 1, 0,
  27818. 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  27819. ];
  27820. var indices = [
  27821. 0, 2, 4, 0, 4, 3, 0, 3, 5,
  27822. 0, 5, 2, 1, 2, 5, 1, 5, 3,
  27823. 1, 3, 4, 1, 4, 2
  27824. ];
  27825. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  27826. this.type = 'OctahedronBufferGeometry';
  27827. this.parameters = {
  27828. radius: radius,
  27829. detail: detail
  27830. };
  27831. }
  27832. OctahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  27833. OctahedronBufferGeometry.prototype.constructor = OctahedronBufferGeometry;
  27834. /**
  27835. * @author TristanVALCKE / https://github.com/Itee
  27836. * @author Anonymous
  27837. */
  27838. /* global QUnit */
  27839. QUnit.module( 'Geometries', () => {
  27840. QUnit.module.todo( 'OctahedronGeometry', ( hooks ) => {
  27841. var geometries = undefined;
  27842. hooks.beforeEach( function () {
  27843. const parameters = {
  27844. radius: 10,
  27845. detail: undefined
  27846. };
  27847. geometries = [
  27848. new OctahedronGeometry(),
  27849. new OctahedronGeometry( parameters.radius ),
  27850. new OctahedronGeometry( parameters.radius, parameters.detail ),
  27851. ];
  27852. } );
  27853. // INHERITANCE
  27854. QUnit.test( "Extending", ( assert ) => {
  27855. assert.ok( false, "everything's gonna be alright" );
  27856. } );
  27857. // INSTANCING
  27858. QUnit.test( "Instancing", ( assert ) => {
  27859. assert.ok( false, "everything's gonna be alright" );
  27860. } );
  27861. // OTHERS
  27862. QUnit.test( 'Standard geometry tests', ( assert ) => {
  27863. runStdGeometryTests( assert, geometries );
  27864. } );
  27865. } );
  27866. QUnit.module.todo( 'OctahedronBufferGeometry', ( hooks ) => {
  27867. var geometries = undefined;
  27868. hooks.beforeEach( function () {
  27869. const parameters = {
  27870. radius: 10,
  27871. detail: undefined
  27872. };
  27873. geometries = [
  27874. new OctahedronBufferGeometry(),
  27875. new OctahedronBufferGeometry( parameters.radius ),
  27876. new OctahedronBufferGeometry( parameters.radius, parameters.detail ),
  27877. ];
  27878. } );
  27879. // INHERITANCE
  27880. QUnit.test( "Extending", ( assert ) => {
  27881. assert.ok( false, "everything's gonna be alright" );
  27882. } );
  27883. // INSTANCING
  27884. QUnit.test( "Instancing", ( assert ) => {
  27885. assert.ok( false, "everything's gonna be alright" );
  27886. } );
  27887. // OTHERS
  27888. QUnit.test( 'Standard geometry tests', ( assert ) => {
  27889. runStdGeometryTests( assert, geometries );
  27890. } );
  27891. } );
  27892. } );
  27893. /**
  27894. * @author zz85 / https://github.com/zz85
  27895. * @author Mugen87 / https://github.com/Mugen87
  27896. *
  27897. * Parametric Surfaces Geometry
  27898. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  27899. */
  27900. function ParametricGeometry( func, slices, stacks ) {
  27901. Geometry.call( this );
  27902. this.type = 'ParametricGeometry';
  27903. this.parameters = {
  27904. func: func,
  27905. slices: slices,
  27906. stacks: stacks
  27907. };
  27908. this.fromBufferGeometry( new ParametricBufferGeometry( func, slices, stacks ) );
  27909. this.mergeVertices();
  27910. }
  27911. ParametricGeometry.prototype = Object.create( Geometry.prototype );
  27912. ParametricGeometry.prototype.constructor = ParametricGeometry;
  27913. // ParametricBufferGeometry
  27914. function ParametricBufferGeometry( func, slices, stacks ) {
  27915. BufferGeometry.call( this );
  27916. this.type = 'ParametricBufferGeometry';
  27917. this.parameters = {
  27918. func: func,
  27919. slices: slices,
  27920. stacks: stacks
  27921. };
  27922. // buffers
  27923. var indices = [];
  27924. var vertices = [];
  27925. var normals = [];
  27926. var uvs = [];
  27927. var EPS = 0.00001;
  27928. var normal = new Vector3();
  27929. var p0 = new Vector3(), p1 = new Vector3();
  27930. var pu = new Vector3(), pv = new Vector3();
  27931. var i, j;
  27932. // generate vertices, normals and uvs
  27933. var sliceCount = slices + 1;
  27934. for ( i = 0; i <= stacks; i ++ ) {
  27935. var v = i / stacks;
  27936. for ( j = 0; j <= slices; j ++ ) {
  27937. var u = j / slices;
  27938. // vertex
  27939. p0 = func( u, v, p0 );
  27940. vertices.push( p0.x, p0.y, p0.z );
  27941. // normal
  27942. // approximate tangent vectors via finite differences
  27943. if ( u - EPS >= 0 ) {
  27944. p1 = func( u - EPS, v, p1 );
  27945. pu.subVectors( p0, p1 );
  27946. } else {
  27947. p1 = func( u + EPS, v, p1 );
  27948. pu.subVectors( p1, p0 );
  27949. }
  27950. if ( v - EPS >= 0 ) {
  27951. p1 = func( u, v - EPS, p1 );
  27952. pv.subVectors( p0, p1 );
  27953. } else {
  27954. p1 = func( u, v + EPS, p1 );
  27955. pv.subVectors( p1, p0 );
  27956. }
  27957. // cross product of tangent vectors returns surface normal
  27958. normal.crossVectors( pu, pv ).normalize();
  27959. normals.push( normal.x, normal.y, normal.z );
  27960. // uv
  27961. uvs.push( u, v );
  27962. }
  27963. }
  27964. // generate indices
  27965. for ( i = 0; i < stacks; i ++ ) {
  27966. for ( j = 0; j < slices; j ++ ) {
  27967. var a = i * sliceCount + j;
  27968. var b = i * sliceCount + j + 1;
  27969. var c = ( i + 1 ) * sliceCount + j + 1;
  27970. var d = ( i + 1 ) * sliceCount + j;
  27971. // faces one and two
  27972. indices.push( a, b, d );
  27973. indices.push( b, c, d );
  27974. }
  27975. }
  27976. // build geometry
  27977. this.setIndex( indices );
  27978. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27979. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  27980. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  27981. }
  27982. ParametricBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  27983. ParametricBufferGeometry.prototype.constructor = ParametricBufferGeometry;
  27984. /**
  27985. * @author TristanVALCKE / https://github.com/Itee
  27986. */
  27987. /* global QUnit */
  27988. QUnit.module( 'Geometries', () => {
  27989. QUnit.module.todo( 'ParametricGeometry', ( hooks ) => {
  27990. var geometries = undefined;
  27991. hooks.beforeEach( function () {
  27992. const parameters = {};
  27993. geometries = [
  27994. new ParametricGeometry()
  27995. ];
  27996. } );
  27997. // INHERITANCE
  27998. QUnit.test( "Extending", ( assert ) => {
  27999. assert.ok( false, "everything's gonna be alright" );
  28000. } );
  28001. // INSTANCING
  28002. QUnit.test( "Instancing", ( assert ) => {
  28003. assert.ok( false, "everything's gonna be alright" );
  28004. } );
  28005. // OTHERS
  28006. QUnit.test( 'Standard geometry tests', ( assert ) => {
  28007. runStdGeometryTests( assert, geometries );
  28008. } );
  28009. } );
  28010. QUnit.module.todo( 'ParametricBufferGeometry', ( hooks ) => {
  28011. var geometries = undefined;
  28012. hooks.beforeEach( function () {
  28013. const parameters = {};
  28014. geometries = [
  28015. new ParametricBufferGeometry()
  28016. ];
  28017. } );
  28018. // INHERITANCE
  28019. QUnit.test( "Extending", ( assert ) => {
  28020. assert.ok( false, "everything's gonna be alright" );
  28021. } );
  28022. // INSTANCING
  28023. QUnit.test( "Instancing", ( assert ) => {
  28024. assert.ok( false, "everything's gonna be alright" );
  28025. } );
  28026. // OTHERS
  28027. QUnit.test( 'Standard geometry tests', ( assert ) => {
  28028. runStdGeometryTests( assert, geometries );
  28029. } );
  28030. } );
  28031. } );
  28032. /**
  28033. * @author TristanVALCKE / https://github.com/Itee
  28034. * @author Anonymous
  28035. */
  28036. /* global QUnit */
  28037. QUnit.module( 'Geometries', () => {
  28038. QUnit.module.todo( 'PlaneGeometry', ( hooks ) => {
  28039. var geometries = undefined;
  28040. hooks.beforeEach( function () {
  28041. const parameters = {
  28042. width: 10,
  28043. height: 30,
  28044. widthSegments: 3,
  28045. heightSegments: 5
  28046. };
  28047. geometries = [
  28048. new PlaneGeometry(),
  28049. new PlaneGeometry( parameters.width ),
  28050. new PlaneGeometry( parameters.width, parameters.height ),
  28051. new PlaneGeometry( parameters.width, parameters.height, parameters.widthSegments ),
  28052. new PlaneGeometry( parameters.width, parameters.height, parameters.widthSegments, parameters.heightSegments ),
  28053. ];
  28054. } );
  28055. // INHERITANCE
  28056. QUnit.test( "Extending", ( assert ) => {
  28057. assert.ok( false, "everything's gonna be alright" );
  28058. } );
  28059. // INSTANCING
  28060. QUnit.test( "Instancing", ( assert ) => {
  28061. assert.ok( false, "everything's gonna be alright" );
  28062. } );
  28063. // OTHERS
  28064. QUnit.test( 'Standard geometry tests', ( assert ) => {
  28065. runStdGeometryTests( assert, geometries );
  28066. } );
  28067. } );
  28068. QUnit.module.todo( 'PlaneBufferGeometry', ( hooks ) => {
  28069. var geometries = undefined;
  28070. hooks.beforeEach( function () {
  28071. const parameters = {
  28072. width: 10,
  28073. height: 30,
  28074. widthSegments: 3,
  28075. heightSegments: 5
  28076. };
  28077. geometries = [
  28078. new PlaneBufferGeometry(),
  28079. new PlaneBufferGeometry( parameters.width ),
  28080. new PlaneBufferGeometry( parameters.width, parameters.height ),
  28081. new PlaneBufferGeometry( parameters.width, parameters.height, parameters.widthSegments ),
  28082. new PlaneBufferGeometry( parameters.width, parameters.height, parameters.widthSegments, parameters.heightSegments ),
  28083. ];
  28084. } );
  28085. // INHERITANCE
  28086. QUnit.test( "Extending", ( assert ) => {
  28087. assert.ok( false, "everything's gonna be alright" );
  28088. } );
  28089. // INSTANCING
  28090. QUnit.test( "Instancing", ( assert ) => {
  28091. assert.ok( false, "everything's gonna be alright" );
  28092. } );
  28093. // OTHERS
  28094. QUnit.test( 'Standard geometry tests', ( assert ) => {
  28095. runStdGeometryTests( assert, geometries );
  28096. } );
  28097. } );
  28098. } );
  28099. /**
  28100. * @author TristanVALCKE / https://github.com/Itee
  28101. */
  28102. /* global QUnit */
  28103. QUnit.module( 'Geometries', () => {
  28104. QUnit.module.todo( 'PolyhedronGeometry', ( hooks ) => {
  28105. var geometries = undefined;
  28106. hooks.beforeEach( function () {
  28107. const parameters = {};
  28108. geometries = [
  28109. new PolyhedronGeometry()
  28110. ];
  28111. } );
  28112. // INHERITANCE
  28113. QUnit.test( "Extending", ( assert ) => {
  28114. assert.ok( false, "everything's gonna be alright" );
  28115. } );
  28116. // INSTANCING
  28117. QUnit.test( "Instancing", ( assert ) => {
  28118. assert.ok( false, "everything's gonna be alright" );
  28119. } );
  28120. // OTHERS
  28121. QUnit.test( 'Standard geometry tests', ( assert ) => {
  28122. runStdGeometryTests( assert, geometries );
  28123. } );
  28124. } );
  28125. QUnit.module.todo( 'PolyhedronBufferGeometry', ( hooks ) => {
  28126. var geometries = undefined;
  28127. hooks.beforeEach( function () {
  28128. const parameters = {};
  28129. geometries = [
  28130. new PolyhedronBufferGeometry()
  28131. ];
  28132. } );
  28133. // INHERITANCE
  28134. QUnit.test( "Extending", ( assert ) => {
  28135. assert.ok( false, "everything's gonna be alright" );
  28136. } );
  28137. // INSTANCING
  28138. QUnit.test( "Instancing", ( assert ) => {
  28139. assert.ok( false, "everything's gonna be alright" );
  28140. } );
  28141. // OTHERS
  28142. QUnit.test( 'Standard geometry tests', ( assert ) => {
  28143. runStdGeometryTests( assert, geometries );
  28144. } );
  28145. } );
  28146. } );
  28147. /**
  28148. * @author Kaleb Murphy
  28149. * @author Mugen87 / https://github.com/Mugen87
  28150. */
  28151. function RingGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  28152. Geometry.call( this );
  28153. this.type = 'RingGeometry';
  28154. this.parameters = {
  28155. innerRadius: innerRadius,
  28156. outerRadius: outerRadius,
  28157. thetaSegments: thetaSegments,
  28158. phiSegments: phiSegments,
  28159. thetaStart: thetaStart,
  28160. thetaLength: thetaLength
  28161. };
  28162. this.fromBufferGeometry( new RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) );
  28163. this.mergeVertices();
  28164. }
  28165. RingGeometry.prototype = Object.create( Geometry.prototype );
  28166. RingGeometry.prototype.constructor = RingGeometry;
  28167. // RingBufferGeometry
  28168. function RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  28169. BufferGeometry.call( this );
  28170. this.type = 'RingBufferGeometry';
  28171. this.parameters = {
  28172. innerRadius: innerRadius,
  28173. outerRadius: outerRadius,
  28174. thetaSegments: thetaSegments,
  28175. phiSegments: phiSegments,
  28176. thetaStart: thetaStart,
  28177. thetaLength: thetaLength
  28178. };
  28179. innerRadius = innerRadius || 0.5;
  28180. outerRadius = outerRadius || 1;
  28181. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  28182. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  28183. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  28184. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 1;
  28185. // buffers
  28186. var indices = [];
  28187. var vertices = [];
  28188. var normals = [];
  28189. var uvs = [];
  28190. // some helper variables
  28191. var segment;
  28192. var radius = innerRadius;
  28193. var radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  28194. var vertex = new Vector3();
  28195. var uv = new Vector2();
  28196. var j, i;
  28197. // generate vertices, normals and uvs
  28198. for ( j = 0; j <= phiSegments; j ++ ) {
  28199. for ( i = 0; i <= thetaSegments; i ++ ) {
  28200. // values are generate from the inside of the ring to the outside
  28201. segment = thetaStart + i / thetaSegments * thetaLength;
  28202. // vertex
  28203. vertex.x = radius * Math.cos( segment );
  28204. vertex.y = radius * Math.sin( segment );
  28205. vertices.push( vertex.x, vertex.y, vertex.z );
  28206. // normal
  28207. normals.push( 0, 0, 1 );
  28208. // uv
  28209. uv.x = ( vertex.x / outerRadius + 1 ) / 2;
  28210. uv.y = ( vertex.y / outerRadius + 1 ) / 2;
  28211. uvs.push( uv.x, uv.y );
  28212. }
  28213. // increase the radius for next row of vertices
  28214. radius += radiusStep;
  28215. }
  28216. // indices
  28217. for ( j = 0; j < phiSegments; j ++ ) {
  28218. var thetaSegmentLevel = j * ( thetaSegments + 1 );
  28219. for ( i = 0; i < thetaSegments; i ++ ) {
  28220. segment = i + thetaSegmentLevel;
  28221. var a = segment;
  28222. var b = segment + thetaSegments + 1;
  28223. var c = segment + thetaSegments + 2;
  28224. var d = segment + 1;
  28225. // faces
  28226. indices.push( a, b, d );
  28227. indices.push( b, c, d );
  28228. }
  28229. }
  28230. // build geometry
  28231. this.setIndex( indices );
  28232. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28233. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  28234. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  28235. }
  28236. RingBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  28237. RingBufferGeometry.prototype.constructor = RingBufferGeometry;
  28238. /**
  28239. * @author TristanVALCKE / https://github.com/Itee
  28240. * @author Anonymous
  28241. */
  28242. /* global QUnit */
  28243. QUnit.module( 'Geometries', () => {
  28244. QUnit.module.todo( 'RingGeometry', ( hooks ) => {
  28245. var geometries = undefined;
  28246. hooks.beforeEach( function () {
  28247. const parameters = {
  28248. innerRadius: 10,
  28249. outerRadius: 60,
  28250. thetaSegments: 12,
  28251. phiSegments: 14,
  28252. thetaStart: 0.1,
  28253. thetaLength: 2.0
  28254. };
  28255. geometries = [
  28256. new RingGeometry(),
  28257. new RingGeometry( parameters.innerRadius ),
  28258. new RingGeometry( parameters.innerRadius, parameters.outerRadius ),
  28259. new RingGeometry( parameters.innerRadius, parameters.outerRadius, parameters.thetaSegments ),
  28260. new RingGeometry( parameters.innerRadius, parameters.outerRadius, parameters.thetaSegments, parameters.phiSegments ),
  28261. new RingGeometry( parameters.innerRadius, parameters.outerRadius, parameters.thetaSegments, parameters.phiSegments, parameters.thetaStart ),
  28262. new RingGeometry( parameters.innerRadius, parameters.outerRadius, parameters.thetaSegments, parameters.phiSegments, parameters.thetaStart, parameters.thetaLength ),
  28263. ];
  28264. } );
  28265. // INHERITANCE
  28266. QUnit.test( "Extending", ( assert ) => {
  28267. assert.ok( false, "everything's gonna be alright" );
  28268. } );
  28269. // INSTANCING
  28270. QUnit.test( "Instancing", ( assert ) => {
  28271. assert.ok( false, "everything's gonna be alright" );
  28272. } );
  28273. // OTHERS
  28274. QUnit.test( 'Standard geometry tests', ( assert ) => {
  28275. runStdGeometryTests( assert, geometries );
  28276. } );
  28277. } );
  28278. QUnit.module.todo( 'RingBufferGeometry', ( hooks ) => {
  28279. var geometries = undefined;
  28280. hooks.beforeEach( function () {
  28281. const parameters = {
  28282. innerRadius: 10,
  28283. outerRadius: 60,
  28284. thetaSegments: 12,
  28285. phiSegments: 14,
  28286. thetaStart: 0.1,
  28287. thetaLength: 2.0
  28288. };
  28289. geometries = [
  28290. new RingBufferGeometry(),
  28291. new RingBufferGeometry( parameters.innerRadius ),
  28292. new RingBufferGeometry( parameters.innerRadius, parameters.outerRadius ),
  28293. new RingBufferGeometry( parameters.innerRadius, parameters.outerRadius, parameters.thetaSegments ),
  28294. new RingBufferGeometry( parameters.innerRadius, parameters.outerRadius, parameters.thetaSegments, parameters.phiSegments ),
  28295. new RingBufferGeometry( parameters.innerRadius, parameters.outerRadius, parameters.thetaSegments, parameters.phiSegments, parameters.thetaStart ),
  28296. new RingBufferGeometry( parameters.innerRadius, parameters.outerRadius, parameters.thetaSegments, parameters.phiSegments, parameters.thetaStart, parameters.thetaLength ),
  28297. ];
  28298. } );
  28299. // INHERITANCE
  28300. QUnit.test( "Extending", ( assert ) => {
  28301. assert.ok( false, "everything's gonna be alright" );
  28302. } );
  28303. // INSTANCING
  28304. QUnit.test( "Instancing", ( assert ) => {
  28305. assert.ok( false, "everything's gonna be alright" );
  28306. } );
  28307. // OTHERS
  28308. QUnit.test( 'Standard geometry tests', ( assert ) => {
  28309. runStdGeometryTests( assert, geometries );
  28310. } );
  28311. } );
  28312. } );
  28313. /**
  28314. * @author jonobr1 / http://jonobr1.com
  28315. * @author Mugen87 / https://github.com/Mugen87
  28316. */
  28317. function ShapeGeometry( shapes, curveSegments ) {
  28318. Geometry.call( this );
  28319. this.type = 'ShapeGeometry';
  28320. if ( typeof curveSegments === 'object' ) {
  28321. console.warn( 'THREE.ShapeGeometry: Options parameter has been removed.' );
  28322. curveSegments = curveSegments.curveSegments;
  28323. }
  28324. this.parameters = {
  28325. shapes: shapes,
  28326. curveSegments: curveSegments
  28327. };
  28328. this.fromBufferGeometry( new ShapeBufferGeometry( shapes, curveSegments ) );
  28329. this.mergeVertices();
  28330. }
  28331. ShapeGeometry.prototype = Object.create( Geometry.prototype );
  28332. ShapeGeometry.prototype.constructor = ShapeGeometry;
  28333. // ShapeBufferGeometry
  28334. function ShapeBufferGeometry( shapes, curveSegments ) {
  28335. BufferGeometry.call( this );
  28336. this.type = 'ShapeBufferGeometry';
  28337. this.parameters = {
  28338. shapes: shapes,
  28339. curveSegments: curveSegments
  28340. };
  28341. curveSegments = curveSegments || 12;
  28342. // buffers
  28343. var indices = [];
  28344. var vertices = [];
  28345. var normals = [];
  28346. var uvs = [];
  28347. // helper variables
  28348. var groupStart = 0;
  28349. var groupCount = 0;
  28350. // allow single and array values for "shapes" parameter
  28351. if ( Array.isArray( shapes ) === false ) {
  28352. addShape( shapes );
  28353. } else {
  28354. for ( var i = 0; i < shapes.length; i ++ ) {
  28355. addShape( shapes[ i ] );
  28356. this.addGroup( groupStart, groupCount, i ); // enables MultiMaterial support
  28357. groupStart += groupCount;
  28358. groupCount = 0;
  28359. }
  28360. }
  28361. // build geometry
  28362. this.setIndex( indices );
  28363. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28364. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  28365. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  28366. // helper functions
  28367. function addShape( shape ) {
  28368. var i, l, shapeHole;
  28369. var indexOffset = vertices.length / 3;
  28370. var points = shape.extractPoints( curveSegments );
  28371. var shapeVertices = points.shape;
  28372. var shapeHoles = points.holes;
  28373. // check direction of vertices
  28374. if ( ShapeUtils.isClockWise( shapeVertices ) === false ) {
  28375. shapeVertices = shapeVertices.reverse();
  28376. // also check if holes are in the opposite direction
  28377. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  28378. shapeHole = shapeHoles[ i ];
  28379. if ( ShapeUtils.isClockWise( shapeHole ) === true ) {
  28380. shapeHoles[ i ] = shapeHole.reverse();
  28381. }
  28382. }
  28383. }
  28384. var faces = ShapeUtils.triangulateShape( shapeVertices, shapeHoles );
  28385. // join vertices of inner and outer paths to a single array
  28386. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  28387. shapeHole = shapeHoles[ i ];
  28388. shapeVertices = shapeVertices.concat( shapeHole );
  28389. }
  28390. // vertices, normals, uvs
  28391. for ( i = 0, l = shapeVertices.length; i < l; i ++ ) {
  28392. var vertex = shapeVertices[ i ];
  28393. vertices.push( vertex.x, vertex.y, 0 );
  28394. normals.push( 0, 0, 1 );
  28395. uvs.push( vertex.x, vertex.y ); // world uvs
  28396. }
  28397. // incides
  28398. for ( i = 0, l = faces.length; i < l; i ++ ) {
  28399. var face = faces[ i ];
  28400. var a = face[ 0 ] + indexOffset;
  28401. var b = face[ 1 ] + indexOffset;
  28402. var c = face[ 2 ] + indexOffset;
  28403. indices.push( a, b, c );
  28404. groupCount += 3;
  28405. }
  28406. }
  28407. }
  28408. ShapeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  28409. ShapeBufferGeometry.prototype.constructor = ShapeBufferGeometry;
  28410. /**
  28411. * @author TristanVALCKE / https://github.com/Itee
  28412. */
  28413. /* global QUnit */
  28414. QUnit.module( 'Geometries', () => {
  28415. QUnit.module.todo( 'ShapeGeometry', ( hooks ) => {
  28416. var geometries = undefined;
  28417. hooks.beforeEach( function () {
  28418. const parameters = {};
  28419. geometries = [
  28420. new ShapeGeometry()
  28421. ];
  28422. } );
  28423. // INHERITANCE
  28424. QUnit.test( "Extending", ( assert ) => {
  28425. assert.ok( false, "everything's gonna be alright" );
  28426. } );
  28427. // INSTANCING
  28428. QUnit.test( "Instancing", ( assert ) => {
  28429. assert.ok( false, "everything's gonna be alright" );
  28430. } );
  28431. // OTHERS
  28432. QUnit.test( 'Standard geometry tests', ( assert ) => {
  28433. runStdGeometryTests( assert, geometries );
  28434. } );
  28435. } );
  28436. QUnit.module.todo( 'ShapeBufferGeometry', ( hooks ) => {
  28437. var geometries = undefined;
  28438. hooks.beforeEach( function () {
  28439. const parameters = {};
  28440. geometries = [
  28441. new ShapeBufferGeometry()
  28442. ];
  28443. } );
  28444. // INHERITANCE
  28445. QUnit.test( "Extending", ( assert ) => {
  28446. assert.ok( false, "everything's gonna be alright" );
  28447. } );
  28448. // INSTANCING
  28449. QUnit.test( "Instancing", ( assert ) => {
  28450. assert.ok( false, "everything's gonna be alright" );
  28451. } );
  28452. // OTHERS
  28453. QUnit.test( 'Standard geometry tests', ( assert ) => {
  28454. runStdGeometryTests( assert, geometries );
  28455. } );
  28456. } );
  28457. } );
  28458. /**
  28459. * @author TristanVALCKE / https://github.com/Itee
  28460. * @author Anonymous
  28461. */
  28462. /* global QUnit */
  28463. QUnit.module( 'Geometries', () => {
  28464. QUnit.module.todo( 'SphereGeometry', ( hooks ) => {
  28465. var geometries = undefined;
  28466. hooks.beforeEach( function () {
  28467. const parameters = {
  28468. radius: 10,
  28469. widthSegments: 20,
  28470. heightSegments: 30,
  28471. phiStart: 0.5,
  28472. phiLength: 1.0,
  28473. thetaStart: 0.4,
  28474. thetaLength: 2.0,
  28475. };
  28476. geometries = [
  28477. new SphereGeometry(),
  28478. new SphereGeometry( parameters.radius ),
  28479. new SphereGeometry( parameters.radius, parameters.widthSegments ),
  28480. new SphereGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments ),
  28481. new SphereGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart ),
  28482. new SphereGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart, parameters.phiLength ),
  28483. new SphereGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart, parameters.phiLength, parameters.thetaStart ),
  28484. new SphereGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart, parameters.phiLength, parameters.thetaStart, parameters.thetaLength ),
  28485. ];
  28486. } );
  28487. // INHERITANCE
  28488. QUnit.test( "Extending", ( assert ) => {
  28489. assert.ok( false, "everything's gonna be alright" );
  28490. } );
  28491. // INSTANCING
  28492. QUnit.test( "Instancing", ( assert ) => {
  28493. assert.ok( false, "everything's gonna be alright" );
  28494. } );
  28495. // OTHERS
  28496. QUnit.test( 'Standard geometry tests', ( assert ) => {
  28497. runStdGeometryTests( assert, geometries );
  28498. } );
  28499. } );
  28500. QUnit.module.todo( 'SphereBufferGeometry', ( hooks ) => {
  28501. var geometries = undefined;
  28502. hooks.beforeEach( function () {
  28503. const parameters = {
  28504. radius: 10,
  28505. widthSegments: 20,
  28506. heightSegments: 30,
  28507. phiStart: 0.5,
  28508. phiLength: 1.0,
  28509. thetaStart: 0.4,
  28510. thetaLength: 2.0,
  28511. };
  28512. geometries = [
  28513. new SphereBufferGeometry(),
  28514. new SphereBufferGeometry( parameters.radius ),
  28515. new SphereBufferGeometry( parameters.radius, parameters.widthSegments ),
  28516. new SphereBufferGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments ),
  28517. new SphereBufferGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart ),
  28518. new SphereBufferGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart, parameters.phiLength ),
  28519. new SphereBufferGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart, parameters.phiLength, parameters.thetaStart ),
  28520. new SphereBufferGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart, parameters.phiLength, parameters.thetaStart, parameters.thetaLength ),
  28521. ];
  28522. } );
  28523. // INHERITANCE
  28524. QUnit.test( "Extending", ( assert ) => {
  28525. assert.ok( false, "everything's gonna be alright" );
  28526. } );
  28527. // INSTANCING
  28528. QUnit.test( "Instancing", ( assert ) => {
  28529. assert.ok( false, "everything's gonna be alright" );
  28530. } );
  28531. // OTHERS
  28532. QUnit.test( 'Standard geometry tests', ( assert ) => {
  28533. runStdGeometryTests( assert, geometries );
  28534. } );
  28535. } );
  28536. } );
  28537. /**
  28538. * @author timothypratley / https://github.com/timothypratley
  28539. * @author Mugen87 / https://github.com/Mugen87
  28540. */
  28541. function TetrahedronGeometry( radius, detail ) {
  28542. Geometry.call( this );
  28543. this.type = 'TetrahedronGeometry';
  28544. this.parameters = {
  28545. radius: radius,
  28546. detail: detail
  28547. };
  28548. this.fromBufferGeometry( new TetrahedronBufferGeometry( radius, detail ) );
  28549. this.mergeVertices();
  28550. }
  28551. TetrahedronGeometry.prototype = Object.create( Geometry.prototype );
  28552. TetrahedronGeometry.prototype.constructor = TetrahedronGeometry;
  28553. // TetrahedronBufferGeometry
  28554. function TetrahedronBufferGeometry( radius, detail ) {
  28555. var vertices = [
  28556. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  28557. ];
  28558. var indices = [
  28559. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  28560. ];
  28561. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  28562. this.type = 'TetrahedronBufferGeometry';
  28563. this.parameters = {
  28564. radius: radius,
  28565. detail: detail
  28566. };
  28567. }
  28568. TetrahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  28569. TetrahedronBufferGeometry.prototype.constructor = TetrahedronBufferGeometry;
  28570. /**
  28571. * @author TristanVALCKE / https://github.com/Itee
  28572. * @author Anonymous
  28573. */
  28574. /* global QUnit */
  28575. QUnit.module( 'Geometries', () => {
  28576. QUnit.module.todo( 'TetrahedronGeometry', ( hooks ) => {
  28577. var geometries = undefined;
  28578. hooks.beforeEach( function () {
  28579. const parameters = {
  28580. radius: 10,
  28581. detail: undefined
  28582. };
  28583. geometries = [
  28584. new TetrahedronGeometry(),
  28585. new TetrahedronGeometry( parameters.radius ),
  28586. new TetrahedronGeometry( parameters.radius, parameters.widthSegments ),
  28587. new TetrahedronGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments ),
  28588. new TetrahedronGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart ),
  28589. new TetrahedronGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart, parameters.phiLength ),
  28590. new TetrahedronGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart, parameters.phiLength, parameters.thetaStart ),
  28591. new TetrahedronGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart, parameters.phiLength, parameters.thetaStart, parameters.thetaLength ),
  28592. ];
  28593. } );
  28594. // INHERITANCE
  28595. QUnit.test( "Extending", ( assert ) => {
  28596. assert.ok( false, "everything's gonna be alright" );
  28597. } );
  28598. // INSTANCING
  28599. QUnit.test( "Instancing", ( assert ) => {
  28600. assert.ok( false, "everything's gonna be alright" );
  28601. } );
  28602. // OTHERS
  28603. QUnit.test( 'Standard geometry tests', ( assert ) => {
  28604. runStdGeometryTests( assert, geometries );
  28605. } );
  28606. } );
  28607. QUnit.module.todo( 'SphereBufferGeometry', ( hooks ) => {
  28608. var geometries = undefined;
  28609. hooks.beforeEach( function () {
  28610. const parameters = {
  28611. radius: 10,
  28612. detail: undefined
  28613. };
  28614. geometries = [
  28615. new TetrahedronBufferGeometry(),
  28616. new TetrahedronBufferGeometry( parameters.radius ),
  28617. new TetrahedronBufferGeometry( parameters.radius, parameters.widthSegments ),
  28618. new TetrahedronBufferGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments ),
  28619. new TetrahedronBufferGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart ),
  28620. new TetrahedronBufferGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart, parameters.phiLength ),
  28621. new TetrahedronBufferGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart, parameters.phiLength, parameters.thetaStart ),
  28622. new TetrahedronBufferGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart, parameters.phiLength, parameters.thetaStart, parameters.thetaLength ),
  28623. ];
  28624. } );
  28625. // INHERITANCE
  28626. QUnit.test( "Extending", ( assert ) => {
  28627. assert.ok( false, "everything's gonna be alright" );
  28628. } );
  28629. // INSTANCING
  28630. QUnit.test( "Instancing", ( assert ) => {
  28631. assert.ok( false, "everything's gonna be alright" );
  28632. } );
  28633. // OTHERS
  28634. QUnit.test( 'Standard geometry tests', ( assert ) => {
  28635. runStdGeometryTests( assert, geometries );
  28636. } );
  28637. } );
  28638. } );
  28639. /**
  28640. * @author zz85 / http://www.lab4games.net/zz85/blog
  28641. * @author alteredq / http://alteredqualia.com/
  28642. *
  28643. * Text = 3D Text
  28644. *
  28645. * parameters = {
  28646. * font: <THREE.Font>, // font
  28647. *
  28648. * size: <float>, // size of the text
  28649. * height: <float>, // thickness to extrude text
  28650. * curveSegments: <int>, // number of points on the curves
  28651. *
  28652. * bevelEnabled: <bool>, // turn on bevel
  28653. * bevelThickness: <float>, // how deep into text bevel goes
  28654. * bevelSize: <float> // how far from text outline is bevel
  28655. * }
  28656. */
  28657. function TextGeometry( text, parameters ) {
  28658. Geometry.call( this );
  28659. this.type = 'TextGeometry';
  28660. this.parameters = {
  28661. text: text,
  28662. parameters: parameters
  28663. };
  28664. this.fromBufferGeometry( new TextBufferGeometry( text, parameters ) );
  28665. this.mergeVertices();
  28666. }
  28667. TextGeometry.prototype = Object.create( Geometry.prototype );
  28668. TextGeometry.prototype.constructor = TextGeometry;
  28669. // TextBufferGeometry
  28670. function TextBufferGeometry( text, parameters ) {
  28671. parameters = parameters || {};
  28672. var font = parameters.font;
  28673. if ( ! ( font && font.isFont ) ) {
  28674. console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
  28675. return new Geometry();
  28676. }
  28677. var shapes = font.generateShapes( text, parameters.size, parameters.curveSegments );
  28678. // translate parameters to ExtrudeGeometry API
  28679. parameters.amount = parameters.height !== undefined ? parameters.height : 50;
  28680. // defaults
  28681. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  28682. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  28683. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  28684. ExtrudeBufferGeometry.call( this, shapes, parameters );
  28685. this.type = 'TextBufferGeometry';
  28686. }
  28687. TextBufferGeometry.prototype = Object.create( ExtrudeBufferGeometry.prototype );
  28688. TextBufferGeometry.prototype.constructor = TextBufferGeometry;
  28689. /**
  28690. * @author TristanVALCKE / https://github.com/Itee
  28691. */
  28692. /* global QUnit */
  28693. QUnit.module( 'Geometries', () => {
  28694. QUnit.module.todo( 'TextGeometry', ( hooks ) => {
  28695. var geometries = undefined;
  28696. hooks.beforeEach( function () {
  28697. // TODO: we cannot load any font from Threejs package :S
  28698. const parameters = {
  28699. font: undefined
  28700. };
  28701. geometries = [
  28702. new TextGeometry()
  28703. ];
  28704. } );
  28705. // INHERITANCE
  28706. QUnit.test( "Extending", ( assert ) => {
  28707. assert.ok( false, "everything's gonna be alright" );
  28708. } );
  28709. // INSTANCING
  28710. QUnit.test( "Instancing", ( assert ) => {
  28711. assert.ok( false, "everything's gonna be alright" );
  28712. } );
  28713. // OTHERS
  28714. QUnit.test( 'Standard geometry tests', ( assert ) => {
  28715. runStdGeometryTests( assert, geometries );
  28716. } );
  28717. } );
  28718. QUnit.module.todo( 'TextBufferGeometry', ( hooks ) => {
  28719. var geometries = undefined;
  28720. hooks.beforeEach( function () {
  28721. const parameters = {};
  28722. geometries = [
  28723. new TextBufferGeometry()
  28724. ];
  28725. } );
  28726. // INHERITANCE
  28727. QUnit.test( "Extending", ( assert ) => {
  28728. assert.ok( false, "everything's gonna be alright" );
  28729. } );
  28730. // INSTANCING
  28731. QUnit.test( "Instancing", ( assert ) => {
  28732. assert.ok( false, "everything's gonna be alright" );
  28733. } );
  28734. // OTHERS
  28735. QUnit.test( 'Standard geometry tests', ( assert ) => {
  28736. runStdGeometryTests( assert, geometries );
  28737. } );
  28738. } );
  28739. } );
  28740. /**
  28741. * @author oosmoxiecode
  28742. * @author mrdoob / http://mrdoob.com/
  28743. * @author Mugen87 / https://github.com/Mugen87
  28744. */
  28745. function TorusGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  28746. Geometry.call( this );
  28747. this.type = 'TorusGeometry';
  28748. this.parameters = {
  28749. radius: radius,
  28750. tube: tube,
  28751. radialSegments: radialSegments,
  28752. tubularSegments: tubularSegments,
  28753. arc: arc
  28754. };
  28755. this.fromBufferGeometry( new TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) );
  28756. this.mergeVertices();
  28757. }
  28758. TorusGeometry.prototype = Object.create( Geometry.prototype );
  28759. TorusGeometry.prototype.constructor = TorusGeometry;
  28760. // TorusBufferGeometry
  28761. function TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  28762. BufferGeometry.call( this );
  28763. this.type = 'TorusBufferGeometry';
  28764. this.parameters = {
  28765. radius: radius,
  28766. tube: tube,
  28767. radialSegments: radialSegments,
  28768. tubularSegments: tubularSegments,
  28769. arc: arc
  28770. };
  28771. radius = radius || 1;
  28772. tube = tube || 0.4;
  28773. radialSegments = Math.floor( radialSegments ) || 8;
  28774. tubularSegments = Math.floor( tubularSegments ) || 6;
  28775. arc = arc || Math.PI * 2;
  28776. // buffers
  28777. var indices = [];
  28778. var vertices = [];
  28779. var normals = [];
  28780. var uvs = [];
  28781. // helper variables
  28782. var center = new Vector3();
  28783. var vertex = new Vector3();
  28784. var normal = new Vector3();
  28785. var j, i;
  28786. // generate vertices, normals and uvs
  28787. for ( j = 0; j <= radialSegments; j ++ ) {
  28788. for ( i = 0; i <= tubularSegments; i ++ ) {
  28789. var u = i / tubularSegments * arc;
  28790. var v = j / radialSegments * Math.PI * 2;
  28791. // vertex
  28792. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  28793. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  28794. vertex.z = tube * Math.sin( v );
  28795. vertices.push( vertex.x, vertex.y, vertex.z );
  28796. // normal
  28797. center.x = radius * Math.cos( u );
  28798. center.y = radius * Math.sin( u );
  28799. normal.subVectors( vertex, center ).normalize();
  28800. normals.push( normal.x, normal.y, normal.z );
  28801. // uv
  28802. uvs.push( i / tubularSegments );
  28803. uvs.push( j / radialSegments );
  28804. }
  28805. }
  28806. // generate indices
  28807. for ( j = 1; j <= radialSegments; j ++ ) {
  28808. for ( i = 1; i <= tubularSegments; i ++ ) {
  28809. // indices
  28810. var a = ( tubularSegments + 1 ) * j + i - 1;
  28811. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  28812. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  28813. var d = ( tubularSegments + 1 ) * j + i;
  28814. // faces
  28815. indices.push( a, b, d );
  28816. indices.push( b, c, d );
  28817. }
  28818. }
  28819. // build geometry
  28820. this.setIndex( indices );
  28821. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28822. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  28823. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  28824. }
  28825. TorusBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  28826. TorusBufferGeometry.prototype.constructor = TorusBufferGeometry;
  28827. /**
  28828. * @author TristanVALCKE / https://github.com/Itee
  28829. * @author Anonymous
  28830. */
  28831. /* global QUnit */
  28832. QUnit.module( 'Geometries', () => {
  28833. QUnit.module.todo( 'TorusGeometry', ( hooks ) => {
  28834. var geometries = undefined;
  28835. hooks.beforeEach( function () {
  28836. const parameters = {
  28837. radius: 10,
  28838. tube: 20,
  28839. radialSegments: 30,
  28840. tubularSegments: 10,
  28841. arc: 2.0,
  28842. };
  28843. geometries = [
  28844. new TorusGeometry(),
  28845. new TorusGeometry( parameters.radius ),
  28846. new TorusGeometry( parameters.radius, parameters.tube ),
  28847. new TorusGeometry( parameters.radius, parameters.tube, parameters.radialSegments ),
  28848. new TorusGeometry( parameters.radius, parameters.tube, parameters.radialSegments, parameters.tubularSegments ),
  28849. new TorusGeometry( parameters.radius, parameters.tube, parameters.radialSegments, parameters.tubularSegments, parameters.arc ),
  28850. ];
  28851. } );
  28852. // INHERITANCE
  28853. QUnit.test( "Extending", ( assert ) => {
  28854. assert.ok( false, "everything's gonna be alright" );
  28855. } );
  28856. // INSTANCING
  28857. QUnit.test( "Instancing", ( assert ) => {
  28858. assert.ok( false, "everything's gonna be alright" );
  28859. } );
  28860. // OTHERS
  28861. QUnit.test( 'Standard geometry tests', ( assert ) => {
  28862. runStdGeometryTests( assert, geometries );
  28863. } );
  28864. } );
  28865. QUnit.module.todo( 'TorusBufferGeometry', ( hooks ) => {
  28866. var geometries = undefined;
  28867. hooks.beforeEach( function () {
  28868. const parameters = {
  28869. radius: 10,
  28870. tube: 20,
  28871. radialSegments: 30,
  28872. tubularSegments: 10,
  28873. arc: 2.0,
  28874. };
  28875. geometries = [
  28876. new TorusBufferGeometry(),
  28877. new TorusBufferGeometry( parameters.radius ),
  28878. new TorusBufferGeometry( parameters.radius, parameters.tube ),
  28879. new TorusBufferGeometry( parameters.radius, parameters.tube, parameters.radialSegments ),
  28880. new TorusBufferGeometry( parameters.radius, parameters.tube, parameters.radialSegments, parameters.tubularSegments ),
  28881. new TorusBufferGeometry( parameters.radius, parameters.tube, parameters.radialSegments, parameters.tubularSegments, parameters.arc ),
  28882. ];
  28883. } );
  28884. // INHERITANCE
  28885. QUnit.test( "Extending", ( assert ) => {
  28886. assert.ok( false, "everything's gonna be alright" );
  28887. } );
  28888. // INSTANCING
  28889. QUnit.test( "Instancing", ( assert ) => {
  28890. assert.ok( false, "everything's gonna be alright" );
  28891. } );
  28892. // OTHERS
  28893. QUnit.test( 'Standard geometry tests', ( assert ) => {
  28894. runStdGeometryTests( assert, geometries );
  28895. } );
  28896. } );
  28897. } );
  28898. /**
  28899. * @author oosmoxiecode
  28900. * @author Mugen87 / https://github.com/Mugen87
  28901. *
  28902. * based on http://www.blackpawn.com/texts/pqtorus/
  28903. */
  28904. function TorusKnotGeometry( radius, tube, tubularSegments, radialSegments, p, q, heightScale ) {
  28905. Geometry.call( this );
  28906. this.type = 'TorusKnotGeometry';
  28907. this.parameters = {
  28908. radius: radius,
  28909. tube: tube,
  28910. tubularSegments: tubularSegments,
  28911. radialSegments: radialSegments,
  28912. p: p,
  28913. q: q
  28914. };
  28915. if ( heightScale !== undefined ) console.warn( 'THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.' );
  28916. this.fromBufferGeometry( new TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) );
  28917. this.mergeVertices();
  28918. }
  28919. TorusKnotGeometry.prototype = Object.create( Geometry.prototype );
  28920. TorusKnotGeometry.prototype.constructor = TorusKnotGeometry;
  28921. // TorusKnotBufferGeometry
  28922. function TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) {
  28923. BufferGeometry.call( this );
  28924. this.type = 'TorusKnotBufferGeometry';
  28925. this.parameters = {
  28926. radius: radius,
  28927. tube: tube,
  28928. tubularSegments: tubularSegments,
  28929. radialSegments: radialSegments,
  28930. p: p,
  28931. q: q
  28932. };
  28933. radius = radius || 1;
  28934. tube = tube || 0.4;
  28935. tubularSegments = Math.floor( tubularSegments ) || 64;
  28936. radialSegments = Math.floor( radialSegments ) || 8;
  28937. p = p || 2;
  28938. q = q || 3;
  28939. // buffers
  28940. var indices = [];
  28941. var vertices = [];
  28942. var normals = [];
  28943. var uvs = [];
  28944. // helper variables
  28945. var i, j;
  28946. var vertex = new Vector3();
  28947. var normal = new Vector3();
  28948. var P1 = new Vector3();
  28949. var P2 = new Vector3();
  28950. var B = new Vector3();
  28951. var T = new Vector3();
  28952. var N = new Vector3();
  28953. // generate vertices, normals and uvs
  28954. for ( i = 0; i <= tubularSegments; ++ i ) {
  28955. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  28956. var u = i / tubularSegments * p * Math.PI * 2;
  28957. // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
  28958. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  28959. calculatePositionOnCurve( u, p, q, radius, P1 );
  28960. calculatePositionOnCurve( u + 0.01, p, q, radius, P2 );
  28961. // calculate orthonormal basis
  28962. T.subVectors( P2, P1 );
  28963. N.addVectors( P2, P1 );
  28964. B.crossVectors( T, N );
  28965. N.crossVectors( B, T );
  28966. // normalize B, N. T can be ignored, we don't use it
  28967. B.normalize();
  28968. N.normalize();
  28969. for ( j = 0; j <= radialSegments; ++ j ) {
  28970. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  28971. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  28972. var v = j / radialSegments * Math.PI * 2;
  28973. var cx = - tube * Math.cos( v );
  28974. var cy = tube * Math.sin( v );
  28975. // now calculate the final vertex position.
  28976. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  28977. vertex.x = P1.x + ( cx * N.x + cy * B.x );
  28978. vertex.y = P1.y + ( cx * N.y + cy * B.y );
  28979. vertex.z = P1.z + ( cx * N.z + cy * B.z );
  28980. vertices.push( vertex.x, vertex.y, vertex.z );
  28981. // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
  28982. normal.subVectors( vertex, P1 ).normalize();
  28983. normals.push( normal.x, normal.y, normal.z );
  28984. // uv
  28985. uvs.push( i / tubularSegments );
  28986. uvs.push( j / radialSegments );
  28987. }
  28988. }
  28989. // generate indices
  28990. for ( j = 1; j <= tubularSegments; j ++ ) {
  28991. for ( i = 1; i <= radialSegments; i ++ ) {
  28992. // indices
  28993. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  28994. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  28995. var c = ( radialSegments + 1 ) * j + i;
  28996. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  28997. // faces
  28998. indices.push( a, b, d );
  28999. indices.push( b, c, d );
  29000. }
  29001. }
  29002. // build geometry
  29003. this.setIndex( indices );
  29004. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  29005. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  29006. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  29007. // this function calculates the current position on the torus curve
  29008. function calculatePositionOnCurve( u, p, q, radius, position ) {
  29009. var cu = Math.cos( u );
  29010. var su = Math.sin( u );
  29011. var quOverP = q / p * u;
  29012. var cs = Math.cos( quOverP );
  29013. position.x = radius * ( 2 + cs ) * 0.5 * cu;
  29014. position.y = radius * ( 2 + cs ) * su * 0.5;
  29015. position.z = radius * Math.sin( quOverP ) * 0.5;
  29016. }
  29017. }
  29018. TorusKnotBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  29019. TorusKnotBufferGeometry.prototype.constructor = TorusKnotBufferGeometry;
  29020. /**
  29021. * @author TristanVALCKE / https://github.com/Itee
  29022. * @author Anonymous
  29023. */
  29024. /* global QUnit */
  29025. QUnit.module( 'Geometries', () => {
  29026. QUnit.module.todo( 'SphereGeometry', ( hooks ) => {
  29027. var geometries = undefined;
  29028. hooks.beforeEach( function () {
  29029. const parameters = {
  29030. radius: 10,
  29031. tube: 20,
  29032. tubularSegments: 30,
  29033. radialSegments: 10,
  29034. p: 3,
  29035. q: 2
  29036. };
  29037. geometries = [
  29038. new TorusKnotGeometry(),
  29039. new TorusKnotGeometry( parameters.radius ),
  29040. new TorusKnotGeometry( parameters.radius, parameters.tube ),
  29041. new TorusKnotGeometry( parameters.radius, parameters.tube, parameters.tubularSegments ),
  29042. new TorusKnotGeometry( parameters.radius, parameters.tube, parameters.tubularSegments, parameters.radialSegments ),
  29043. new TorusKnotGeometry( parameters.radius, parameters.tube, parameters.tubularSegments, parameters.radialSegments, parameters.p, parameters.q ),
  29044. ];
  29045. } );
  29046. // INHERITANCE
  29047. QUnit.test( "Extending", ( assert ) => {
  29048. assert.ok( false, "everything's gonna be alright" );
  29049. } );
  29050. // INSTANCING
  29051. QUnit.test( "Instancing", ( assert ) => {
  29052. assert.ok( false, "everything's gonna be alright" );
  29053. } );
  29054. // OTHERS
  29055. QUnit.test( 'Standard geometry tests', ( assert ) => {
  29056. runStdGeometryTests( assert, geometries );
  29057. } );
  29058. } );
  29059. QUnit.module.todo( 'TorusKnotBufferGeometry', ( hooks ) => {
  29060. var geometries = undefined;
  29061. hooks.beforeEach( function () {
  29062. const parameters = {
  29063. radius: 10,
  29064. tube: 20,
  29065. tubularSegments: 30,
  29066. radialSegments: 10,
  29067. p: 3,
  29068. q: 2
  29069. };
  29070. geometries = [
  29071. new TorusKnotBufferGeometry(),
  29072. new TorusKnotBufferGeometry( parameters.radius ),
  29073. new TorusKnotBufferGeometry( parameters.radius, parameters.tube ),
  29074. new TorusKnotBufferGeometry( parameters.radius, parameters.tube, parameters.tubularSegments ),
  29075. new TorusKnotBufferGeometry( parameters.radius, parameters.tube, parameters.tubularSegments, parameters.radialSegments ),
  29076. new TorusKnotBufferGeometry( parameters.radius, parameters.tube, parameters.tubularSegments, parameters.radialSegments, parameters.p, parameters.q ),
  29077. ];
  29078. } );
  29079. // INHERITANCE
  29080. QUnit.test( "Extending", ( assert ) => {
  29081. assert.ok( false, "everything's gonna be alright" );
  29082. } );
  29083. // INSTANCING
  29084. QUnit.test( "Instancing", ( assert ) => {
  29085. assert.ok( false, "everything's gonna be alright" );
  29086. } );
  29087. // OTHERS
  29088. QUnit.test( 'Standard geometry tests', ( assert ) => {
  29089. runStdGeometryTests( assert, geometries );
  29090. } );
  29091. } );
  29092. } );
  29093. /**
  29094. * @author oosmoxiecode / https://github.com/oosmoxiecode
  29095. * @author WestLangley / https://github.com/WestLangley
  29096. * @author zz85 / https://github.com/zz85
  29097. * @author miningold / https://github.com/miningold
  29098. * @author jonobr1 / https://github.com/jonobr1
  29099. * @author Mugen87 / https://github.com/Mugen87
  29100. *
  29101. */
  29102. function TubeGeometry( path, tubularSegments, radius, radialSegments, closed, taper ) {
  29103. Geometry.call( this );
  29104. this.type = 'TubeGeometry';
  29105. this.parameters = {
  29106. path: path,
  29107. tubularSegments: tubularSegments,
  29108. radius: radius,
  29109. radialSegments: radialSegments,
  29110. closed: closed
  29111. };
  29112. if ( taper !== undefined ) console.warn( 'THREE.TubeGeometry: taper has been removed.' );
  29113. var bufferGeometry = new TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed );
  29114. // expose internals
  29115. this.tangents = bufferGeometry.tangents;
  29116. this.normals = bufferGeometry.normals;
  29117. this.binormals = bufferGeometry.binormals;
  29118. // create geometry
  29119. this.fromBufferGeometry( bufferGeometry );
  29120. this.mergeVertices();
  29121. }
  29122. TubeGeometry.prototype = Object.create( Geometry.prototype );
  29123. TubeGeometry.prototype.constructor = TubeGeometry;
  29124. // TubeBufferGeometry
  29125. function TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed ) {
  29126. BufferGeometry.call( this );
  29127. this.type = 'TubeBufferGeometry';
  29128. this.parameters = {
  29129. path: path,
  29130. tubularSegments: tubularSegments,
  29131. radius: radius,
  29132. radialSegments: radialSegments,
  29133. closed: closed
  29134. };
  29135. tubularSegments = tubularSegments || 64;
  29136. radius = radius || 1;
  29137. radialSegments = radialSegments || 8;
  29138. closed = closed || false;
  29139. var frames = path.computeFrenetFrames( tubularSegments, closed );
  29140. // expose internals
  29141. this.tangents = frames.tangents;
  29142. this.normals = frames.normals;
  29143. this.binormals = frames.binormals;
  29144. // helper variables
  29145. var vertex = new Vector3();
  29146. var normal = new Vector3();
  29147. var uv = new Vector2();
  29148. var P = new Vector3();
  29149. var i, j;
  29150. // buffer
  29151. var vertices = [];
  29152. var normals = [];
  29153. var uvs = [];
  29154. var indices = [];
  29155. // create buffer data
  29156. generateBufferData();
  29157. // build geometry
  29158. this.setIndex( indices );
  29159. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  29160. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  29161. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  29162. // functions
  29163. function generateBufferData() {
  29164. for ( i = 0; i < tubularSegments; i ++ ) {
  29165. generateSegment( i );
  29166. }
  29167. // if the geometry is not closed, generate the last row of vertices and normals
  29168. // at the regular position on the given path
  29169. //
  29170. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  29171. generateSegment( ( closed === false ) ? tubularSegments : 0 );
  29172. // uvs are generated in a separate function.
  29173. // this makes it easy compute correct values for closed geometries
  29174. generateUVs();
  29175. // finally create faces
  29176. generateIndices();
  29177. }
  29178. function generateSegment( i ) {
  29179. // we use getPointAt to sample evenly distributed points from the given path
  29180. P = path.getPointAt( i / tubularSegments, P );
  29181. // retrieve corresponding normal and binormal
  29182. var N = frames.normals[ i ];
  29183. var B = frames.binormals[ i ];
  29184. // generate normals and vertices for the current segment
  29185. for ( j = 0; j <= radialSegments; j ++ ) {
  29186. var v = j / radialSegments * Math.PI * 2;
  29187. var sin = Math.sin( v );
  29188. var cos = - Math.cos( v );
  29189. // normal
  29190. normal.x = ( cos * N.x + sin * B.x );
  29191. normal.y = ( cos * N.y + sin * B.y );
  29192. normal.z = ( cos * N.z + sin * B.z );
  29193. normal.normalize();
  29194. normals.push( normal.x, normal.y, normal.z );
  29195. // vertex
  29196. vertex.x = P.x + radius * normal.x;
  29197. vertex.y = P.y + radius * normal.y;
  29198. vertex.z = P.z + radius * normal.z;
  29199. vertices.push( vertex.x, vertex.y, vertex.z );
  29200. }
  29201. }
  29202. function generateIndices() {
  29203. for ( j = 1; j <= tubularSegments; j ++ ) {
  29204. for ( i = 1; i <= radialSegments; i ++ ) {
  29205. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  29206. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  29207. var c = ( radialSegments + 1 ) * j + i;
  29208. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  29209. // faces
  29210. indices.push( a, b, d );
  29211. indices.push( b, c, d );
  29212. }
  29213. }
  29214. }
  29215. function generateUVs() {
  29216. for ( i = 0; i <= tubularSegments; i ++ ) {
  29217. for ( j = 0; j <= radialSegments; j ++ ) {
  29218. uv.x = i / tubularSegments;
  29219. uv.y = j / radialSegments;
  29220. uvs.push( uv.x, uv.y );
  29221. }
  29222. }
  29223. }
  29224. }
  29225. TubeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  29226. TubeBufferGeometry.prototype.constructor = TubeBufferGeometry;
  29227. /**
  29228. * @author TristanVALCKE / https://github.com/Itee
  29229. */
  29230. /* global QUnit */
  29231. QUnit.module( 'Geometries', () => {
  29232. QUnit.module.todo( 'TubeGeometry', ( hooks ) => {
  29233. var geometries = undefined;
  29234. hooks.beforeEach( function () {
  29235. const parameters = {};
  29236. geometries = [
  29237. new TubeGeometry()
  29238. ];
  29239. } );
  29240. // INHERITANCE
  29241. QUnit.test( "Extending", ( assert ) => {
  29242. assert.ok( false, "everything's gonna be alright" );
  29243. } );
  29244. // INSTANCING
  29245. QUnit.test( "Instancing", ( assert ) => {
  29246. assert.ok( false, "everything's gonna be alright" );
  29247. } );
  29248. // OTHERS
  29249. QUnit.test( 'Standard geometry tests', ( assert ) => {
  29250. runStdGeometryTests( assert, geometries );
  29251. } );
  29252. } );
  29253. QUnit.module.todo( 'TubeBufferGeometry', ( hooks ) => {
  29254. var geometries = undefined;
  29255. hooks.beforeEach( function () {
  29256. const parameters = {};
  29257. geometries = [
  29258. new TubeBufferGeometry()
  29259. ];
  29260. } );
  29261. // INHERITANCE
  29262. QUnit.test( "Extending", ( assert ) => {
  29263. assert.ok( false, "everything's gonna be alright" );
  29264. } );
  29265. // INSTANCING
  29266. QUnit.test( "Instancing", ( assert ) => {
  29267. assert.ok( false, "everything's gonna be alright" );
  29268. } );
  29269. // OTHERS
  29270. QUnit.test( 'Standard geometry tests', ( assert ) => {
  29271. runStdGeometryTests( assert, geometries );
  29272. } );
  29273. } );
  29274. } );
  29275. /**
  29276. * @author mrdoob / http://mrdoob.com/
  29277. * @author Mugen87 / https://github.com/Mugen87
  29278. */
  29279. function WireframeGeometry( geometry ) {
  29280. BufferGeometry.call( this );
  29281. this.type = 'WireframeGeometry';
  29282. // buffer
  29283. var vertices = [];
  29284. // helper variables
  29285. var i, j, l, o, ol;
  29286. var edge = [ 0, 0 ], edges = {}, e, edge1, edge2;
  29287. var key, keys = [ 'a', 'b', 'c' ];
  29288. var vertex;
  29289. // different logic for Geometry and BufferGeometry
  29290. if ( geometry && geometry.isGeometry ) {
  29291. // create a data structure that contains all edges without duplicates
  29292. var faces = geometry.faces;
  29293. for ( i = 0, l = faces.length; i < l; i ++ ) {
  29294. var face = faces[ i ];
  29295. for ( j = 0; j < 3; j ++ ) {
  29296. edge1 = face[ keys[ j ] ];
  29297. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  29298. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  29299. edge[ 1 ] = Math.max( edge1, edge2 );
  29300. key = edge[ 0 ] + ',' + edge[ 1 ];
  29301. if ( edges[ key ] === undefined ) {
  29302. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  29303. }
  29304. }
  29305. }
  29306. // generate vertices
  29307. for ( key in edges ) {
  29308. e = edges[ key ];
  29309. vertex = geometry.vertices[ e.index1 ];
  29310. vertices.push( vertex.x, vertex.y, vertex.z );
  29311. vertex = geometry.vertices[ e.index2 ];
  29312. vertices.push( vertex.x, vertex.y, vertex.z );
  29313. }
  29314. } else if ( geometry && geometry.isBufferGeometry ) {
  29315. var position, indices, groups;
  29316. var group, start, count;
  29317. var index1, index2;
  29318. vertex = new Vector3();
  29319. if ( geometry.index !== null ) {
  29320. // indexed BufferGeometry
  29321. position = geometry.attributes.position;
  29322. indices = geometry.index;
  29323. groups = geometry.groups;
  29324. if ( groups.length === 0 ) {
  29325. groups = [ { start: 0, count: indices.count, materialIndex: 0 } ];
  29326. }
  29327. // create a data structure that contains all eges without duplicates
  29328. for ( o = 0, ol = groups.length; o < ol; ++ o ) {
  29329. group = groups[ o ];
  29330. start = group.start;
  29331. count = group.count;
  29332. for ( i = start, l = ( start + count ); i < l; i += 3 ) {
  29333. for ( j = 0; j < 3; j ++ ) {
  29334. edge1 = indices.getX( i + j );
  29335. edge2 = indices.getX( i + ( j + 1 ) % 3 );
  29336. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  29337. edge[ 1 ] = Math.max( edge1, edge2 );
  29338. key = edge[ 0 ] + ',' + edge[ 1 ];
  29339. if ( edges[ key ] === undefined ) {
  29340. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  29341. }
  29342. }
  29343. }
  29344. }
  29345. // generate vertices
  29346. for ( key in edges ) {
  29347. e = edges[ key ];
  29348. vertex.fromBufferAttribute( position, e.index1 );
  29349. vertices.push( vertex.x, vertex.y, vertex.z );
  29350. vertex.fromBufferAttribute( position, e.index2 );
  29351. vertices.push( vertex.x, vertex.y, vertex.z );
  29352. }
  29353. } else {
  29354. // non-indexed BufferGeometry
  29355. position = geometry.attributes.position;
  29356. for ( i = 0, l = ( position.count / 3 ); i < l; i ++ ) {
  29357. for ( j = 0; j < 3; j ++ ) {
  29358. // three edges per triangle, an edge is represented as (index1, index2)
  29359. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  29360. index1 = 3 * i + j;
  29361. vertex.fromBufferAttribute( position, index1 );
  29362. vertices.push( vertex.x, vertex.y, vertex.z );
  29363. index2 = 3 * i + ( ( j + 1 ) % 3 );
  29364. vertex.fromBufferAttribute( position, index2 );
  29365. vertices.push( vertex.x, vertex.y, vertex.z );
  29366. }
  29367. }
  29368. }
  29369. }
  29370. // build geometry
  29371. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  29372. }
  29373. WireframeGeometry.prototype = Object.create( BufferGeometry.prototype );
  29374. WireframeGeometry.prototype.constructor = WireframeGeometry;
  29375. /**
  29376. * @author TristanVALCKE / https://github.com/Itee
  29377. */
  29378. /* global QUnit */
  29379. QUnit.module( 'Geometries', () => {
  29380. QUnit.module.todo( 'WireframeGeometry', ( hooks ) => {
  29381. var geometries = undefined;
  29382. hooks.beforeEach( function () {
  29383. const parameters = {};
  29384. geometries = [
  29385. new WireframeGeometry()
  29386. ];
  29387. } );
  29388. // INHERITANCE
  29389. QUnit.test( "Extending", ( assert ) => {
  29390. assert.ok( false, "everything's gonna be alright" );
  29391. } );
  29392. // INSTANCING
  29393. QUnit.test( "Instancing", ( assert ) => {
  29394. assert.ok( false, "everything's gonna be alright" );
  29395. } );
  29396. // OTHERS
  29397. QUnit.test( 'Standard geometry tests', ( assert ) => {
  29398. runStdGeometryTests( assert, geometries );
  29399. } );
  29400. } );
  29401. } );
  29402. /**
  29403. * @author WestLangley / http://github.com/WestLangley
  29404. * @author zz85 / http://github.com/zz85
  29405. * @author bhouston / http://clara.io
  29406. *
  29407. * Creates an arrow for visualizing directions
  29408. *
  29409. * Parameters:
  29410. * dir - Vector3
  29411. * origin - Vector3
  29412. * length - Number
  29413. * color - color in hex value
  29414. * headLength - Number
  29415. * headWidth - Number
  29416. */
  29417. /**
  29418. * @author TristanVALCKE / https://github.com/Itee
  29419. */
  29420. /* global QUnit */
  29421. QUnit.module( 'Helpers', () => {
  29422. QUnit.module.todo( 'ArrowHelper', () => {
  29423. // INHERITANCE
  29424. QUnit.test( "Extending", ( assert ) => {
  29425. assert.ok( false, "everything's gonna be alright" );
  29426. } );
  29427. // INSTANCING
  29428. QUnit.test( "Instancing", ( assert ) => {
  29429. assert.ok( false, "everything's gonna be alright" );
  29430. } );
  29431. // PUBLIC STUFF
  29432. QUnit.test( "setDirection", ( assert ) => {
  29433. assert.ok( false, "everything's gonna be alright" );
  29434. } );
  29435. QUnit.test( "setLength", ( assert ) => {
  29436. assert.ok( false, "everything's gonna be alright" );
  29437. } );
  29438. QUnit.test( "setColor", ( assert ) => {
  29439. assert.ok( false, "everything's gonna be alright" );
  29440. } );
  29441. } );
  29442. } );
  29443. /**
  29444. * @author sroucheray / http://sroucheray.org/
  29445. * @author mrdoob / http://mrdoob.com/
  29446. */
  29447. /**
  29448. * @author TristanVALCKE / https://github.com/Itee
  29449. */
  29450. /* global QUnit */
  29451. QUnit.module( 'Helpers', () => {
  29452. QUnit.module.todo( 'AxesHelper', () => {
  29453. // INHERITANCE
  29454. QUnit.test( "Extending", ( assert ) => {
  29455. assert.ok( false, "everything's gonna be alright" );
  29456. } );
  29457. // INSTANCING
  29458. QUnit.test( "Instancing", ( assert ) => {
  29459. assert.ok( false, "everything's gonna be alright" );
  29460. } );
  29461. } );
  29462. } );
  29463. /**
  29464. * @author WestLangley / http://github.com/WestLangley
  29465. */
  29466. /**
  29467. * @author TristanVALCKE / https://github.com/Itee
  29468. */
  29469. /* global QUnit */
  29470. QUnit.module( 'Helpers', () => {
  29471. QUnit.module.todo( 'Box3Helper', () => {
  29472. // INHERITANCE
  29473. QUnit.test( "Extending", ( assert ) => {
  29474. assert.ok( false, "everything's gonna be alright" );
  29475. } );
  29476. // INSTANCING
  29477. QUnit.test( "Instancing", ( assert ) => {
  29478. assert.ok( false, "everything's gonna be alright" );
  29479. } );
  29480. // PUBLIC STUFF
  29481. QUnit.test( "updateMatrixWorld", ( assert ) => {
  29482. assert.ok( false, "everything's gonna be alright" );
  29483. } );
  29484. } );
  29485. } );
  29486. /**
  29487. * @author mrdoob / http://mrdoob.com/
  29488. * @author Mugen87 / http://github.com/Mugen87
  29489. */
  29490. function BoxHelper( object, color ) {
  29491. this.object = object;
  29492. if ( color === undefined ) color = 0xffff00;
  29493. var indices = new Uint16Array( [ 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7 ] );
  29494. var positions = new Float32Array( 8 * 3 );
  29495. var geometry = new BufferGeometry();
  29496. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  29497. geometry.addAttribute( 'position', new BufferAttribute( positions, 3 ) );
  29498. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  29499. this.matrixAutoUpdate = false;
  29500. this.update();
  29501. }
  29502. BoxHelper.prototype = Object.create( LineSegments.prototype );
  29503. BoxHelper.prototype.constructor = BoxHelper;
  29504. BoxHelper.prototype.update = ( function () {
  29505. var box = new Box3();
  29506. return function update( object ) {
  29507. if ( object !== undefined ) {
  29508. console.warn( 'THREE.BoxHelper: .update() has no longer arguments.' );
  29509. }
  29510. if ( this.object !== undefined ) {
  29511. box.setFromObject( this.object );
  29512. }
  29513. if ( box.isEmpty() ) return;
  29514. var min = box.min;
  29515. var max = box.max;
  29516. /*
  29517. 5____4
  29518. 1/___0/|
  29519. | 6__|_7
  29520. 2/___3/
  29521. 0: max.x, max.y, max.z
  29522. 1: min.x, max.y, max.z
  29523. 2: min.x, min.y, max.z
  29524. 3: max.x, min.y, max.z
  29525. 4: max.x, max.y, min.z
  29526. 5: min.x, max.y, min.z
  29527. 6: min.x, min.y, min.z
  29528. 7: max.x, min.y, min.z
  29529. */
  29530. var position = this.geometry.attributes.position;
  29531. var array = position.array;
  29532. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  29533. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  29534. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  29535. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  29536. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  29537. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  29538. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  29539. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  29540. position.needsUpdate = true;
  29541. this.geometry.computeBoundingSphere();
  29542. };
  29543. } )();
  29544. BoxHelper.prototype.setFromObject = function ( object ) {
  29545. this.object = object;
  29546. this.update();
  29547. return this;
  29548. };
  29549. /**
  29550. * @author TristanVALCKE / https://github.com/Itee
  29551. * @author Anonymous
  29552. */
  29553. /* global QUnit */
  29554. QUnit.module( 'Helpers', () => {
  29555. QUnit.module.todo( 'BoxHelper', ( hooks ) => {
  29556. var geometries = undefined;
  29557. hooks.beforeEach( function () {
  29558. const parameters = {
  29559. radius: 10,
  29560. widthSegments: 20,
  29561. heightSegments: 30,
  29562. phiStart: 0.5,
  29563. phiLength: 1.0,
  29564. thetaStart: 0.4,
  29565. thetaLength: 2.0,
  29566. };
  29567. // Test with a normal cube and a box helper
  29568. var boxGeometry = new BoxGeometry( parameters.diameter );
  29569. var box = new Mesh( boxGeometry );
  29570. var boxHelper = new BoxHelper( box );
  29571. // The same should happen with a comparable sphere
  29572. var sphereGeometry = new SphereGeometry( parameters.diameter / 2 );
  29573. var sphere = new Mesh( sphereGeometry );
  29574. var sphereBoxHelper = new BoxHelper( sphere );
  29575. // Note that unlike what I'd like to, these doesn't check the equivalency of the two generated geometries
  29576. geometries = [ boxHelper.geometry, sphereBoxHelper.geometry ];
  29577. } );
  29578. // INHERITANCE
  29579. QUnit.test( "Extending", ( assert ) => {
  29580. assert.ok( false, "everything's gonna be alright" );
  29581. } );
  29582. // INSTANCING
  29583. QUnit.test( "Instancing", ( assert ) => {
  29584. assert.ok( false, "everything's gonna be alright" );
  29585. } );
  29586. // PUBLIC STUFF
  29587. QUnit.test( "update", ( assert ) => {
  29588. assert.ok( false, "everything's gonna be alright" );
  29589. } );
  29590. QUnit.test( "setFromObject", ( assert ) => {
  29591. assert.ok( false, "everything's gonna be alright" );
  29592. } );
  29593. // OTHERS
  29594. QUnit.test( 'Standard geometry tests', ( assert ) => {
  29595. runStdGeometryTests( assert, geometries );
  29596. } );
  29597. } );
  29598. } );
  29599. /**
  29600. * @author alteredq / http://alteredqualia.com/
  29601. * @author Mugen87 / https://github.com/Mugen87
  29602. *
  29603. * - shows frustum, line of sight and up of the camera
  29604. * - suitable for fast updates
  29605. * - based on frustum visualization in lightgl.js shadowmap example
  29606. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  29607. */
  29608. function CameraHelper( camera ) {
  29609. var geometry = new BufferGeometry();
  29610. var material = new LineBasicMaterial( { color: 0xffffff, vertexColors: FaceColors } );
  29611. var vertices = [];
  29612. var colors = [];
  29613. var pointMap = {};
  29614. // colors
  29615. var colorFrustum = new Color( 0xffaa00 );
  29616. var colorCone = new Color( 0xff0000 );
  29617. var colorUp = new Color( 0x00aaff );
  29618. var colorTarget = new Color( 0xffffff );
  29619. var colorCross = new Color( 0x333333 );
  29620. // near
  29621. addLine( 'n1', 'n2', colorFrustum );
  29622. addLine( 'n2', 'n4', colorFrustum );
  29623. addLine( 'n4', 'n3', colorFrustum );
  29624. addLine( 'n3', 'n1', colorFrustum );
  29625. // far
  29626. addLine( 'f1', 'f2', colorFrustum );
  29627. addLine( 'f2', 'f4', colorFrustum );
  29628. addLine( 'f4', 'f3', colorFrustum );
  29629. addLine( 'f3', 'f1', colorFrustum );
  29630. // sides
  29631. addLine( 'n1', 'f1', colorFrustum );
  29632. addLine( 'n2', 'f2', colorFrustum );
  29633. addLine( 'n3', 'f3', colorFrustum );
  29634. addLine( 'n4', 'f4', colorFrustum );
  29635. // cone
  29636. addLine( 'p', 'n1', colorCone );
  29637. addLine( 'p', 'n2', colorCone );
  29638. addLine( 'p', 'n3', colorCone );
  29639. addLine( 'p', 'n4', colorCone );
  29640. // up
  29641. addLine( 'u1', 'u2', colorUp );
  29642. addLine( 'u2', 'u3', colorUp );
  29643. addLine( 'u3', 'u1', colorUp );
  29644. // target
  29645. addLine( 'c', 't', colorTarget );
  29646. addLine( 'p', 'c', colorCross );
  29647. // cross
  29648. addLine( 'cn1', 'cn2', colorCross );
  29649. addLine( 'cn3', 'cn4', colorCross );
  29650. addLine( 'cf1', 'cf2', colorCross );
  29651. addLine( 'cf3', 'cf4', colorCross );
  29652. function addLine( a, b, color ) {
  29653. addPoint( a, color );
  29654. addPoint( b, color );
  29655. }
  29656. function addPoint( id, color ) {
  29657. vertices.push( 0, 0, 0 );
  29658. colors.push( color.r, color.g, color.b );
  29659. if ( pointMap[ id ] === undefined ) {
  29660. pointMap[ id ] = [];
  29661. }
  29662. pointMap[ id ].push( ( vertices.length / 3 ) - 1 );
  29663. }
  29664. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  29665. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  29666. LineSegments.call( this, geometry, material );
  29667. this.camera = camera;
  29668. if ( this.camera.updateProjectionMatrix ) this.camera.updateProjectionMatrix();
  29669. this.matrix = camera.matrixWorld;
  29670. this.matrixAutoUpdate = false;
  29671. this.pointMap = pointMap;
  29672. this.update();
  29673. }
  29674. CameraHelper.prototype = Object.create( LineSegments.prototype );
  29675. CameraHelper.prototype.constructor = CameraHelper;
  29676. CameraHelper.prototype.update = function () {
  29677. var geometry, pointMap;
  29678. var vector = new Vector3();
  29679. var camera = new Camera();
  29680. function setPoint( point, x, y, z ) {
  29681. vector.set( x, y, z ).unproject( camera );
  29682. var points = pointMap[ point ];
  29683. if ( points !== undefined ) {
  29684. var position = geometry.getAttribute( 'position' );
  29685. for ( var i = 0, l = points.length; i < l; i ++ ) {
  29686. position.setXYZ( points[ i ], vector.x, vector.y, vector.z );
  29687. }
  29688. }
  29689. }
  29690. return function update() {
  29691. geometry = this.geometry;
  29692. pointMap = this.pointMap;
  29693. var w = 1, h = 1;
  29694. // we need just camera projection matrix
  29695. // world matrix must be identity
  29696. camera.projectionMatrix.copy( this.camera.projectionMatrix );
  29697. // center / target
  29698. setPoint( 'c', 0, 0, - 1 );
  29699. setPoint( 't', 0, 0, 1 );
  29700. // near
  29701. setPoint( 'n1', - w, - h, - 1 );
  29702. setPoint( 'n2', w, - h, - 1 );
  29703. setPoint( 'n3', - w, h, - 1 );
  29704. setPoint( 'n4', w, h, - 1 );
  29705. // far
  29706. setPoint( 'f1', - w, - h, 1 );
  29707. setPoint( 'f2', w, - h, 1 );
  29708. setPoint( 'f3', - w, h, 1 );
  29709. setPoint( 'f4', w, h, 1 );
  29710. // up
  29711. setPoint( 'u1', w * 0.7, h * 1.1, - 1 );
  29712. setPoint( 'u2', - w * 0.7, h * 1.1, - 1 );
  29713. setPoint( 'u3', 0, h * 2, - 1 );
  29714. // cross
  29715. setPoint( 'cf1', - w, 0, 1 );
  29716. setPoint( 'cf2', w, 0, 1 );
  29717. setPoint( 'cf3', 0, - h, 1 );
  29718. setPoint( 'cf4', 0, h, 1 );
  29719. setPoint( 'cn1', - w, 0, - 1 );
  29720. setPoint( 'cn2', w, 0, - 1 );
  29721. setPoint( 'cn3', 0, - h, - 1 );
  29722. setPoint( 'cn4', 0, h, - 1 );
  29723. geometry.getAttribute( 'position' ).needsUpdate = true;
  29724. };
  29725. }();
  29726. /**
  29727. * @author TristanVALCKE / https://github.com/Itee
  29728. */
  29729. /* global QUnit */
  29730. QUnit.module( 'Helpers', () => {
  29731. QUnit.module.todo( 'CameraHelper', () => {
  29732. // INHERITANCE
  29733. QUnit.test( "Extending", ( assert ) => {
  29734. assert.ok( false, "everything's gonna be alright" );
  29735. } );
  29736. // INSTANCING
  29737. QUnit.test( "Instancing", ( assert ) => {
  29738. assert.ok( false, "everything's gonna be alright" );
  29739. } );
  29740. // PUBLIC STUFF
  29741. QUnit.test( "update", ( assert ) => {
  29742. assert.ok( false, "everything's gonna be alright" );
  29743. } );
  29744. } );
  29745. } );
  29746. /**
  29747. * @author alteredq / http://alteredqualia.com/
  29748. * @author mrdoob / http://mrdoob.com/
  29749. * @author WestLangley / http://github.com/WestLangley
  29750. */
  29751. /**
  29752. * @author TristanVALCKE / https://github.com/Itee
  29753. */
  29754. /* global QUnit */
  29755. QUnit.module( 'Helpers', () => {
  29756. QUnit.module.todo( 'DirectionalLightHelper', () => {
  29757. // INHERITANCE
  29758. QUnit.test( "Extending", ( assert ) => {
  29759. assert.ok( false, "everything's gonna be alright" );
  29760. } );
  29761. // INSTANCING
  29762. QUnit.test( "Instancing", ( assert ) => {
  29763. assert.ok( false, "everything's gonna be alright" );
  29764. } );
  29765. // PUBLIC STUFF
  29766. QUnit.test( "dispose", ( assert ) => {
  29767. assert.ok( false, "everything's gonna be alright" );
  29768. } );
  29769. QUnit.test( "update", ( assert ) => {
  29770. assert.ok( false, "everything's gonna be alright" );
  29771. } );
  29772. } );
  29773. } );
  29774. /**
  29775. * @author mrdoob / http://mrdoob.com/
  29776. * @author WestLangley / http://github.com/WestLangley
  29777. */
  29778. function FaceNormalsHelper( object, size, hex, linewidth ) {
  29779. // FaceNormalsHelper only supports THREE.Geometry
  29780. this.object = object;
  29781. this.size = ( size !== undefined ) ? size : 1;
  29782. var color = ( hex !== undefined ) ? hex : 0xffff00;
  29783. var width = ( linewidth !== undefined ) ? linewidth : 1;
  29784. //
  29785. var nNormals = 0;
  29786. var objGeometry = this.object.geometry;
  29787. if ( objGeometry && objGeometry.isGeometry ) {
  29788. nNormals = objGeometry.faces.length;
  29789. } else {
  29790. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  29791. }
  29792. //
  29793. var geometry = new BufferGeometry();
  29794. var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
  29795. geometry.addAttribute( 'position', positions );
  29796. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
  29797. //
  29798. this.matrixAutoUpdate = false;
  29799. this.update();
  29800. }
  29801. FaceNormalsHelper.prototype = Object.create( LineSegments.prototype );
  29802. FaceNormalsHelper.prototype.constructor = FaceNormalsHelper;
  29803. FaceNormalsHelper.prototype.update = ( function () {
  29804. var v1 = new Vector3();
  29805. var v2 = new Vector3();
  29806. var normalMatrix = new Matrix3();
  29807. return function update() {
  29808. this.object.updateMatrixWorld( true );
  29809. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  29810. var matrixWorld = this.object.matrixWorld;
  29811. var position = this.geometry.attributes.position;
  29812. //
  29813. var objGeometry = this.object.geometry;
  29814. var vertices = objGeometry.vertices;
  29815. var faces = objGeometry.faces;
  29816. var idx = 0;
  29817. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  29818. var face = faces[ i ];
  29819. var normal = face.normal;
  29820. v1.copy( vertices[ face.a ] )
  29821. .add( vertices[ face.b ] )
  29822. .add( vertices[ face.c ] )
  29823. .divideScalar( 3 )
  29824. .applyMatrix4( matrixWorld );
  29825. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  29826. position.setXYZ( idx, v1.x, v1.y, v1.z );
  29827. idx = idx + 1;
  29828. position.setXYZ( idx, v2.x, v2.y, v2.z );
  29829. idx = idx + 1;
  29830. }
  29831. position.needsUpdate = true;
  29832. };
  29833. }() );
  29834. /**
  29835. * @author TristanVALCKE / https://github.com/Itee
  29836. */
  29837. /* global QUnit */
  29838. QUnit.module( 'Helpers', () => {
  29839. QUnit.module.todo( 'FaceNormalsHelper', () => {
  29840. // INHERITANCE
  29841. QUnit.test( "Extending", ( assert ) => {
  29842. assert.ok( false, "everything's gonna be alright" );
  29843. } );
  29844. // INSTANCING
  29845. QUnit.test( "Instancing", ( assert ) => {
  29846. assert.ok( false, "everything's gonna be alright" );
  29847. } );
  29848. // PUBLIC STUFF
  29849. QUnit.test( "update", ( assert ) => {
  29850. assert.ok( false, "everything's gonna be alright" );
  29851. } );
  29852. } );
  29853. } );
  29854. /**
  29855. * @author mrdoob / http://mrdoob.com/
  29856. */
  29857. /**
  29858. * @author TristanVALCKE / https://github.com/Itee
  29859. */
  29860. /* global QUnit */
  29861. QUnit.module( 'Helpers', () => {
  29862. QUnit.module.todo( 'GridHelper', () => {
  29863. // INHERITANCE
  29864. QUnit.test( "Extending", ( assert ) => {
  29865. assert.ok( false, "everything's gonna be alright" );
  29866. } );
  29867. // INSTANCING
  29868. QUnit.test( "Instancing", ( assert ) => {
  29869. assert.ok( false, "everything's gonna be alright" );
  29870. } );
  29871. } );
  29872. } );
  29873. /**
  29874. * @author alteredq / http://alteredqualia.com/
  29875. * @author mrdoob / http://mrdoob.com/
  29876. * @author Mugen87 / https://github.com/Mugen87
  29877. */
  29878. function HemisphereLightHelper( light, size, color ) {
  29879. Object3D.call( this );
  29880. this.light = light;
  29881. this.light.updateMatrixWorld();
  29882. this.matrix = light.matrixWorld;
  29883. this.matrixAutoUpdate = false;
  29884. this.color = color;
  29885. var geometry = new OctahedronBufferGeometry( size );
  29886. geometry.rotateY( Math.PI * 0.5 );
  29887. this.material = new MeshBasicMaterial( { wireframe: true, fog: false } );
  29888. if ( this.color === undefined ) this.material.vertexColors = VertexColors;
  29889. var position = geometry.getAttribute( 'position' );
  29890. var colors = new Float32Array( position.count * 3 );
  29891. geometry.addAttribute( 'color', new BufferAttribute( colors, 3 ) );
  29892. this.add( new Mesh( geometry, this.material ) );
  29893. this.update();
  29894. }
  29895. HemisphereLightHelper.prototype = Object.create( Object3D.prototype );
  29896. HemisphereLightHelper.prototype.constructor = HemisphereLightHelper;
  29897. HemisphereLightHelper.prototype.dispose = function () {
  29898. this.children[ 0 ].geometry.dispose();
  29899. this.children[ 0 ].material.dispose();
  29900. };
  29901. HemisphereLightHelper.prototype.update = function () {
  29902. var vector = new Vector3();
  29903. var color1 = new Color();
  29904. var color2 = new Color();
  29905. return function update() {
  29906. var mesh = this.children[ 0 ];
  29907. if ( this.color !== undefined ) {
  29908. this.material.color.set( this.color );
  29909. } else {
  29910. var colors = mesh.geometry.getAttribute( 'color' );
  29911. color1.copy( this.light.color );
  29912. color2.copy( this.light.groundColor );
  29913. for ( var i = 0, l = colors.count; i < l; i ++ ) {
  29914. var color = ( i < ( l / 2 ) ) ? color1 : color2;
  29915. colors.setXYZ( i, color.r, color.g, color.b );
  29916. }
  29917. colors.needsUpdate = true;
  29918. }
  29919. mesh.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  29920. };
  29921. }();
  29922. /**
  29923. * @author TristanVALCKE / https://github.com/Itee
  29924. */
  29925. /* global QUnit */
  29926. QUnit.module( 'Helpers', () => {
  29927. QUnit.module.todo( 'HemisphereLightHelper', () => {
  29928. // INHERITANCE
  29929. QUnit.test( "Extending", ( assert ) => {
  29930. assert.ok( false, "everything's gonna be alright" );
  29931. } );
  29932. // INSTANCING
  29933. QUnit.test( "Instancing", ( assert ) => {
  29934. assert.ok( false, "everything's gonna be alright" );
  29935. } );
  29936. // PUBLIC STUFF
  29937. QUnit.test( "dispose", ( assert ) => {
  29938. assert.ok( false, "everything's gonna be alright" );
  29939. } );
  29940. QUnit.test( "update", ( assert ) => {
  29941. assert.ok( false, "everything's gonna be alright" );
  29942. } );
  29943. } );
  29944. } );
  29945. /**
  29946. * @author WestLangley / http://github.com/WestLangley
  29947. */
  29948. /**
  29949. * @author TristanVALCKE / https://github.com/Itee
  29950. */
  29951. /* global QUnit */
  29952. QUnit.module( 'Helpers', () => {
  29953. QUnit.module.todo( 'PlaneHelper', () => {
  29954. // INHERITANCE
  29955. QUnit.test( "Extending", ( assert ) => {
  29956. assert.ok( false, "everything's gonna be alright" );
  29957. } );
  29958. // INSTANCING
  29959. QUnit.test( "Instancing", ( assert ) => {
  29960. assert.ok( false, "everything's gonna be alright" );
  29961. } );
  29962. // PUBLIC STUFF
  29963. QUnit.test( "updateMatrixWorld", ( assert ) => {
  29964. assert.ok( false, "everything's gonna be alright" );
  29965. } );
  29966. } );
  29967. } );
  29968. /**
  29969. * @author alteredq / http://alteredqualia.com/
  29970. * @author mrdoob / http://mrdoob.com/
  29971. */
  29972. /**
  29973. * @author TristanVALCKE / https://github.com/Itee
  29974. */
  29975. /* global QUnit */
  29976. QUnit.module( 'Helpers', () => {
  29977. QUnit.module.todo( 'PointLightHelper', () => {
  29978. // INHERITANCE
  29979. QUnit.test( "Extending", ( assert ) => {
  29980. assert.ok( false, "everything's gonna be alright" );
  29981. } );
  29982. // INSTANCING
  29983. QUnit.test( "Instancing", ( assert ) => {
  29984. assert.ok( false, "everything's gonna be alright" );
  29985. } );
  29986. // PUBLIC STUFF
  29987. QUnit.test( "dispose", ( assert ) => {
  29988. assert.ok( false, "everything's gonna be alright" );
  29989. } );
  29990. QUnit.test( "update", ( assert ) => {
  29991. assert.ok( false, "everything's gonna be alright" );
  29992. } );
  29993. } );
  29994. } );
  29995. /**
  29996. * @author mrdoob / http://mrdoob.com/
  29997. * @author Mugen87 / http://github.com/Mugen87
  29998. * @author Hectate / http://www.github.com/Hectate
  29999. */
  30000. /**
  30001. * @author TristanVALCKE / https://github.com/Itee
  30002. */
  30003. /* global QUnit */
  30004. QUnit.module( 'Helpers', () => {
  30005. QUnit.module.todo( 'PolarGridHelper', () => {
  30006. // INHERITANCE
  30007. QUnit.test( "Extending", ( assert ) => {
  30008. assert.ok( false, "everything's gonna be alright" );
  30009. } );
  30010. // INSTANCING
  30011. QUnit.test( "Instancing", ( assert ) => {
  30012. assert.ok( false, "everything's gonna be alright" );
  30013. } );
  30014. } );
  30015. } );
  30016. /**
  30017. * @author abelnation / http://github.com/abelnation
  30018. * @author Mugen87 / http://github.com/Mugen87
  30019. * @author WestLangley / http://github.com/WestLangley
  30020. */
  30021. /**
  30022. * @author TristanVALCKE / https://github.com/Itee
  30023. */
  30024. /* global QUnit */
  30025. QUnit.module( 'Helpers', () => {
  30026. QUnit.module.todo( 'RectAreaLightHelper', () => {
  30027. // INHERITANCE
  30028. QUnit.test( "Extending", ( assert ) => {
  30029. assert.ok( false, "everything's gonna be alright" );
  30030. } );
  30031. // INSTANCING
  30032. QUnit.test( "Instancing", ( assert ) => {
  30033. assert.ok( false, "everything's gonna be alright" );
  30034. } );
  30035. // PUBLIC STUFF
  30036. QUnit.test( "dispose", ( assert ) => {
  30037. assert.ok( false, "everything's gonna be alright" );
  30038. } );
  30039. QUnit.test( "update", ( assert ) => {
  30040. assert.ok( false, "everything's gonna be alright" );
  30041. } );
  30042. } );
  30043. } );
  30044. /**
  30045. * @author Sean Griffin / http://twitter.com/sgrif
  30046. * @author Michael Guerrero / http://realitymeltdown.com
  30047. * @author mrdoob / http://mrdoob.com/
  30048. * @author ikerr / http://verold.com
  30049. * @author Mugen87 / https://github.com/Mugen87
  30050. */
  30051. function getBoneList( object ) {
  30052. var boneList = [];
  30053. if ( object && object.isBone ) {
  30054. boneList.push( object );
  30055. }
  30056. for ( var i = 0; i < object.children.length; i ++ ) {
  30057. boneList.push.apply( boneList, getBoneList( object.children[ i ] ) );
  30058. }
  30059. return boneList;
  30060. }
  30061. function SkeletonHelper( object ) {
  30062. var bones = getBoneList( object );
  30063. var geometry = new BufferGeometry();
  30064. var vertices = [];
  30065. var colors = [];
  30066. var color1 = new Color( 0, 0, 1 );
  30067. var color2 = new Color( 0, 1, 0 );
  30068. for ( var i = 0; i < bones.length; i ++ ) {
  30069. var bone = bones[ i ];
  30070. if ( bone.parent && bone.parent.isBone ) {
  30071. vertices.push( 0, 0, 0 );
  30072. vertices.push( 0, 0, 0 );
  30073. colors.push( color1.r, color1.g, color1.b );
  30074. colors.push( color2.r, color2.g, color2.b );
  30075. }
  30076. }
  30077. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  30078. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  30079. var material = new LineBasicMaterial( { vertexColors: VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  30080. LineSegments.call( this, geometry, material );
  30081. this.root = object;
  30082. this.bones = bones;
  30083. this.matrix = object.matrixWorld;
  30084. this.matrixAutoUpdate = false;
  30085. }
  30086. SkeletonHelper.prototype = Object.create( LineSegments.prototype );
  30087. SkeletonHelper.prototype.constructor = SkeletonHelper;
  30088. SkeletonHelper.prototype.updateMatrixWorld = function () {
  30089. var vector = new Vector3();
  30090. var boneMatrix = new Matrix4();
  30091. var matrixWorldInv = new Matrix4();
  30092. return function updateMatrixWorld( force ) {
  30093. var bones = this.bones;
  30094. var geometry = this.geometry;
  30095. var position = geometry.getAttribute( 'position' );
  30096. matrixWorldInv.getInverse( this.root.matrixWorld );
  30097. for ( var i = 0, j = 0; i < bones.length; i ++ ) {
  30098. var bone = bones[ i ];
  30099. if ( bone.parent && bone.parent.isBone ) {
  30100. boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
  30101. vector.setFromMatrixPosition( boneMatrix );
  30102. position.setXYZ( j, vector.x, vector.y, vector.z );
  30103. boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
  30104. vector.setFromMatrixPosition( boneMatrix );
  30105. position.setXYZ( j + 1, vector.x, vector.y, vector.z );
  30106. j += 2;
  30107. }
  30108. }
  30109. geometry.getAttribute( 'position' ).needsUpdate = true;
  30110. Object3D.prototype.updateMatrixWorld.call( this, force );
  30111. };
  30112. }();
  30113. /**
  30114. * @author TristanVALCKE / https://github.com/Itee
  30115. */
  30116. /* global QUnit */
  30117. QUnit.module( 'Helpers', () => {
  30118. QUnit.module.todo( 'SkeletonHelper', () => {
  30119. // INHERITANCE
  30120. QUnit.test( "Extending", ( assert ) => {
  30121. assert.ok( false, "everything's gonna be alright" );
  30122. } );
  30123. // INSTANCING
  30124. QUnit.test( "Instancing", ( assert ) => {
  30125. assert.ok( false, "everything's gonna be alright" );
  30126. } );
  30127. // PUBLIC STUFF
  30128. QUnit.test( "updateMatrixWorld", ( assert ) => {
  30129. assert.ok( false, "everything's gonna be alright" );
  30130. } );
  30131. } );
  30132. } );
  30133. /**
  30134. * @author alteredq / http://alteredqualia.com/
  30135. * @author mrdoob / http://mrdoob.com/
  30136. * @author WestLangley / http://github.com/WestLangley
  30137. */
  30138. /**
  30139. * @author TristanVALCKE / https://github.com/Itee
  30140. */
  30141. /* global QUnit */
  30142. QUnit.module( 'Helpers', () => {
  30143. QUnit.module.todo( 'SpotLightHelper', () => {
  30144. // INHERITANCE
  30145. QUnit.test( "Extending", ( assert ) => {
  30146. assert.ok( false, "everything's gonna be alright" );
  30147. } );
  30148. // INSTANCING
  30149. QUnit.test( "Instancing", ( assert ) => {
  30150. assert.ok( false, "everything's gonna be alright" );
  30151. } );
  30152. // PUBLIC STUFF
  30153. QUnit.test( "dispose", ( assert ) => {
  30154. assert.ok( false, "everything's gonna be alright" );
  30155. } );
  30156. QUnit.test( "update", ( assert ) => {
  30157. assert.ok( false, "everything's gonna be alright" );
  30158. } );
  30159. } );
  30160. } );
  30161. /**
  30162. * @author mrdoob / http://mrdoob.com/
  30163. * @author WestLangley / http://github.com/WestLangley
  30164. */
  30165. function VertexNormalsHelper( object, size, hex, linewidth ) {
  30166. this.object = object;
  30167. this.size = ( size !== undefined ) ? size : 1;
  30168. var color = ( hex !== undefined ) ? hex : 0xff0000;
  30169. var width = ( linewidth !== undefined ) ? linewidth : 1;
  30170. //
  30171. var nNormals = 0;
  30172. var objGeometry = this.object.geometry;
  30173. if ( objGeometry && objGeometry.isGeometry ) {
  30174. nNormals = objGeometry.faces.length * 3;
  30175. } else if ( objGeometry && objGeometry.isBufferGeometry ) {
  30176. nNormals = objGeometry.attributes.normal.count;
  30177. }
  30178. //
  30179. var geometry = new BufferGeometry();
  30180. var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
  30181. geometry.addAttribute( 'position', positions );
  30182. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
  30183. //
  30184. this.matrixAutoUpdate = false;
  30185. this.update();
  30186. }
  30187. VertexNormalsHelper.prototype = Object.create( LineSegments.prototype );
  30188. VertexNormalsHelper.prototype.constructor = VertexNormalsHelper;
  30189. VertexNormalsHelper.prototype.update = ( function () {
  30190. var v1 = new Vector3();
  30191. var v2 = new Vector3();
  30192. var normalMatrix = new Matrix3();
  30193. return function update() {
  30194. var keys = [ 'a', 'b', 'c' ];
  30195. this.object.updateMatrixWorld( true );
  30196. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  30197. var matrixWorld = this.object.matrixWorld;
  30198. var position = this.geometry.attributes.position;
  30199. //
  30200. var objGeometry = this.object.geometry;
  30201. if ( objGeometry && objGeometry.isGeometry ) {
  30202. var vertices = objGeometry.vertices;
  30203. var faces = objGeometry.faces;
  30204. var idx = 0;
  30205. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  30206. var face = faces[ i ];
  30207. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  30208. var vertex = vertices[ face[ keys[ j ] ] ];
  30209. var normal = face.vertexNormals[ j ];
  30210. v1.copy( vertex ).applyMatrix4( matrixWorld );
  30211. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  30212. position.setXYZ( idx, v1.x, v1.y, v1.z );
  30213. idx = idx + 1;
  30214. position.setXYZ( idx, v2.x, v2.y, v2.z );
  30215. idx = idx + 1;
  30216. }
  30217. }
  30218. } else if ( objGeometry && objGeometry.isBufferGeometry ) {
  30219. var objPos = objGeometry.attributes.position;
  30220. var objNorm = objGeometry.attributes.normal;
  30221. var idx = 0;
  30222. // for simplicity, ignore index and drawcalls, and render every normal
  30223. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  30224. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  30225. v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  30226. v2.applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  30227. position.setXYZ( idx, v1.x, v1.y, v1.z );
  30228. idx = idx + 1;
  30229. position.setXYZ( idx, v2.x, v2.y, v2.z );
  30230. idx = idx + 1;
  30231. }
  30232. }
  30233. position.needsUpdate = true;
  30234. };
  30235. }() );
  30236. /**
  30237. * @author TristanVALCKE / https://github.com/Itee
  30238. */
  30239. /* global QUnit */
  30240. QUnit.module( 'Helpers', () => {
  30241. QUnit.module.todo( 'VertexNormalsHelper', () => {
  30242. // INHERITANCE
  30243. QUnit.test( "Extending", ( assert ) => {
  30244. assert.ok( false, "everything's gonna be alright" );
  30245. } );
  30246. // INSTANCING
  30247. QUnit.test( "Instancing", ( assert ) => {
  30248. assert.ok( false, "everything's gonna be alright" );
  30249. } );
  30250. // PUBLIC STUFF
  30251. QUnit.test( "update", ( assert ) => {
  30252. assert.ok( false, "everything's gonna be alright" );
  30253. } );
  30254. } );
  30255. } );
  30256. function Light( color, intensity ) {
  30257. Object3D.call( this );
  30258. this.type = 'Light';
  30259. this.color = new Color( color );
  30260. this.intensity = intensity !== undefined ? intensity : 1;
  30261. this.receiveShadow = undefined;
  30262. }
  30263. Light.prototype = Object.assign( Object.create( Object3D.prototype ), {
  30264. constructor: Light,
  30265. isLight: true,
  30266. copy: function ( source ) {
  30267. Object3D.prototype.copy.call( this, source );
  30268. this.color.copy( source.color );
  30269. this.intensity = source.intensity;
  30270. return this;
  30271. },
  30272. toJSON: function ( meta ) {
  30273. var data = Object3D.prototype.toJSON.call( this, meta );
  30274. data.object.color = this.color.getHex();
  30275. data.object.intensity = this.intensity;
  30276. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  30277. if ( this.distance !== undefined ) data.object.distance = this.distance;
  30278. if ( this.angle !== undefined ) data.object.angle = this.angle;
  30279. if ( this.decay !== undefined ) data.object.decay = this.decay;
  30280. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  30281. if ( this.shadow !== undefined ) data.object.shadow = this.shadow.toJSON();
  30282. return data;
  30283. }
  30284. } );
  30285. function AmbientLight( color, intensity ) {
  30286. Light.call( this, color, intensity );
  30287. this.type = 'AmbientLight';
  30288. this.castShadow = undefined;
  30289. }
  30290. AmbientLight.prototype = Object.assign( Object.create( Light.prototype ), {
  30291. constructor: AmbientLight,
  30292. isAmbientLight: true
  30293. } );
  30294. /**
  30295. * @author TristanVALCKE / https://github.com/Itee
  30296. * @author moraxy / https://github.com/moraxy
  30297. */
  30298. /* global QUnit */
  30299. QUnit.module( 'Lights', () => {
  30300. QUnit.module.todo( 'ArrowHelper', ( hooks ) => {
  30301. var lights = undefined;
  30302. hooks.beforeEach( function () {
  30303. const parameters = {
  30304. color: 0xaaaaaa,
  30305. intensity: 0.5
  30306. };
  30307. lights = [
  30308. new AmbientLight(),
  30309. new AmbientLight( parameters.color ),
  30310. new AmbientLight( parameters.color, parameters.intensity )
  30311. ];
  30312. } );
  30313. // INHERITANCE
  30314. QUnit.test( "Extending", ( assert ) => {
  30315. assert.ok( false, "everything's gonna be alright" );
  30316. } );
  30317. // INSTANCING
  30318. QUnit.test( "Instancing", ( assert ) => {
  30319. assert.ok( false, "everything's gonna be alright" );
  30320. } );
  30321. // PUBLIC STUFF
  30322. QUnit.test( "isAmbiantLight", ( assert ) => {
  30323. assert.ok( false, "everything's gonna be alright" );
  30324. } );
  30325. // OTHERS
  30326. QUnit.test( 'Standard light tests', ( assert ) => {
  30327. runStdLightTests( assert, lights );
  30328. } );
  30329. } );
  30330. } );
  30331. function LightShadow( camera ) {
  30332. this.camera = camera;
  30333. this.bias = 0;
  30334. this.radius = 1;
  30335. this.mapSize = new Vector2( 512, 512 );
  30336. this.map = null;
  30337. this.matrix = new Matrix4();
  30338. }
  30339. Object.assign( LightShadow.prototype, {
  30340. copy: function ( source ) {
  30341. this.camera = source.camera.clone();
  30342. this.bias = source.bias;
  30343. this.radius = source.radius;
  30344. this.mapSize.copy( source.mapSize );
  30345. return this;
  30346. },
  30347. clone: function () {
  30348. return new this.constructor().copy( this );
  30349. },
  30350. toJSON: function () {
  30351. var object = {};
  30352. if ( this.bias !== 0 ) object.bias = this.bias;
  30353. if ( this.radius !== 1 ) object.radius = this.radius;
  30354. if ( this.mapSize.x !== 512 || this.mapSize.y !== 512 ) object.mapSize = this.mapSize.toArray();
  30355. object.camera = this.camera.toJSON( false ).object;
  30356. delete object.camera.matrix;
  30357. return object;
  30358. }
  30359. } );
  30360. function DirectionalLightShadow( ) {
  30361. LightShadow.call( this, new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  30362. }
  30363. DirectionalLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  30364. constructor: DirectionalLightShadow
  30365. } );
  30366. function DirectionalLight$1( color, intensity ) {
  30367. Light.call( this, color, intensity );
  30368. this.type = 'DirectionalLight';
  30369. this.position.copy( Object3D.DefaultUp );
  30370. this.updateMatrix();
  30371. this.target = new Object3D();
  30372. this.shadow = new DirectionalLightShadow();
  30373. }
  30374. DirectionalLight$1.prototype = Object.assign( Object.create( Light.prototype ), {
  30375. constructor: DirectionalLight$1,
  30376. isDirectionalLight: true,
  30377. copy: function ( source ) {
  30378. Light.prototype.copy.call( this, source );
  30379. this.target = source.target.clone();
  30380. this.shadow = source.shadow.clone();
  30381. return this;
  30382. }
  30383. } );
  30384. /**
  30385. * @author TristanVALCKE / https://github.com/Itee
  30386. * @author moraxy / https://github.com/moraxy
  30387. */
  30388. /* global QUnit */
  30389. QUnit.module( 'Lights', () => {
  30390. QUnit.module.todo( 'DirectionalLight', ( hooks ) => {
  30391. var lights = undefined;
  30392. hooks.beforeEach( function () {
  30393. const parameters = {
  30394. color: 0xaaaaaa,
  30395. intensity: 0.8
  30396. };
  30397. lights = [
  30398. new DirectionalLight$1(),
  30399. new DirectionalLight$1( parameters.color ),
  30400. new DirectionalLight$1( parameters.color, parameters.intensity )
  30401. ];
  30402. } );
  30403. // INHERITANCE
  30404. QUnit.test( "Extending", ( assert ) => {
  30405. assert.ok( false, "everything's gonna be alright" );
  30406. } );
  30407. // INSTANCING
  30408. QUnit.test( "Instancing", ( assert ) => {
  30409. assert.ok( false, "everything's gonna be alright" );
  30410. } );
  30411. // PUBLIC STUFF
  30412. QUnit.test( "isDirectionalLight", ( assert ) => {
  30413. assert.ok( false, "everything's gonna be alright" );
  30414. } );
  30415. QUnit.test( "copy", ( assert ) => {
  30416. assert.ok( false, "everything's gonna be alright" );
  30417. } );
  30418. // OTHERS
  30419. QUnit.test( 'Standard light tests', ( assert ) => {
  30420. runStdLightTests( assert, lights );
  30421. } );
  30422. } );
  30423. } );
  30424. /**
  30425. * @author TristanVALCKE / https://github.com/Itee
  30426. * @author moraxy / https://github.com/moraxy
  30427. */
  30428. /* global QUnit */
  30429. QUnit.module( 'Lights', () => {
  30430. QUnit.module.todo( 'DirectionalLightShadow', () => {
  30431. // INHERITANCE
  30432. QUnit.test( "Extending", ( assert ) => {
  30433. assert.ok( false, "everything's gonna be alright" );
  30434. } );
  30435. // INSTANCING
  30436. QUnit.test( "Instancing", ( assert ) => {
  30437. assert.ok( false, "everything's gonna be alright" );
  30438. } );
  30439. // OTHERS
  30440. QUnit.test( "clone/copy", ( assert ) => {
  30441. var a = new DirectionalLightShadow();
  30442. var b = new DirectionalLightShadow();
  30443. var c;
  30444. assert.notDeepEqual( a, b, "Newly instanced shadows are not equal" );
  30445. c = a.clone();
  30446. assert.smartEqual( a, c, "Shadows are identical after clone()" );
  30447. c.mapSize.set( 1024, 1024 );
  30448. assert.notDeepEqual( a, c, "Shadows are different again after change" );
  30449. b.copy( a );
  30450. assert.smartEqual( a, b, "Shadows are identical after copy()" );
  30451. b.mapSize.set( 512, 512 );
  30452. assert.notDeepEqual( a, b, "Shadows are different again after change" );
  30453. } );
  30454. QUnit.test( "toJSON", ( assert ) => {
  30455. var light = new DirectionalLight();
  30456. var shadow = new DirectionalLightShadow();
  30457. shadow.bias = 10;
  30458. shadow.radius = 5;
  30459. shadow.mapSize.set( 1024, 1024 );
  30460. light.shadow = shadow;
  30461. var json = light.toJSON();
  30462. var newLight = new ObjectLoader().parse( json );
  30463. assert.smartEqual( newLight.shadow, light.shadow, "Reloaded shadow is identical to the original one" );
  30464. } );
  30465. } );
  30466. } );
  30467. function HemisphereLight( skyColor, groundColor, intensity ) {
  30468. Light.call( this, skyColor, intensity );
  30469. this.type = 'HemisphereLight';
  30470. this.castShadow = undefined;
  30471. this.position.copy( Object3D.DefaultUp );
  30472. this.updateMatrix();
  30473. this.groundColor = new Color( groundColor );
  30474. }
  30475. HemisphereLight.prototype = Object.assign( Object.create( Light.prototype ), {
  30476. constructor: HemisphereLight,
  30477. isHemisphereLight: true,
  30478. copy: function ( source ) {
  30479. Light.prototype.copy.call( this, source );
  30480. this.groundColor.copy( source.groundColor );
  30481. return this;
  30482. }
  30483. } );
  30484. /**
  30485. * @author TristanVALCKE / https://github.com/Itee
  30486. * @author moraxy / https://github.com/moraxy
  30487. */
  30488. /* global QUnit */
  30489. QUnit.module( 'Lights', () => {
  30490. QUnit.module.todo( 'HemisphereLight', ( hooks ) => {
  30491. var lights = undefined;
  30492. hooks.beforeEach( function () {
  30493. const parameters = {
  30494. skyColor: 0x123456,
  30495. groundColor: 0xabc012,
  30496. intensity: 0.6
  30497. };
  30498. lights = [
  30499. new HemisphereLight(),
  30500. new HemisphereLight( parameters.skyColor ),
  30501. new HemisphereLight( parameters.skyColor, parameters.groundColor ),
  30502. new HemisphereLight( parameters.skyColor, parameters.groundColor, parameters.intensity ),
  30503. ];
  30504. } );
  30505. // INHERITANCE
  30506. QUnit.test( "Extending", ( assert ) => {
  30507. assert.ok( false, "everything's gonna be alright" );
  30508. } );
  30509. // INSTANCING
  30510. QUnit.test( "Instancing", ( assert ) => {
  30511. assert.ok( false, "everything's gonna be alright" );
  30512. } );
  30513. // PUBLIC STUFF
  30514. QUnit.test( "isHemisphereLight", ( assert ) => {
  30515. assert.ok( false, "everything's gonna be alright" );
  30516. } );
  30517. QUnit.test( "copy", ( assert ) => {
  30518. assert.ok( false, "everything's gonna be alright" );
  30519. } );
  30520. // OTHERS
  30521. QUnit.test( 'Standard light tests', ( assert ) => {
  30522. runStdLightTests( assert, lights );
  30523. } );
  30524. } );
  30525. } );
  30526. /**
  30527. * @author TristanVALCKE / https://github.com/Itee
  30528. */
  30529. /* global QUnit */
  30530. QUnit.module( 'Lights', () => {
  30531. QUnit.module.todo( 'Light', ( hooks ) => {
  30532. var lights = undefined;
  30533. hooks.beforeEach( function () {
  30534. const parameters = {
  30535. color: 0xaaaaaa,
  30536. intensity: 0.5
  30537. };
  30538. lights = [
  30539. new Light(),
  30540. new Light( parameters.color ),
  30541. new Light( parameters.color, parameters.intensity )
  30542. ];
  30543. } );
  30544. // INHERITANCE
  30545. QUnit.test( "Extending", ( assert ) => {
  30546. assert.ok( false, "everything's gonna be alright" );
  30547. } );
  30548. // INSTANCING
  30549. QUnit.test( "Instancing", ( assert ) => {
  30550. assert.ok( false, "everything's gonna be alright" );
  30551. } );
  30552. // PUBLIC STUFF
  30553. QUnit.test( "isLight", ( assert ) => {
  30554. assert.ok( false, "everything's gonna be alright" );
  30555. } );
  30556. QUnit.test( "copy", ( assert ) => {
  30557. assert.ok( false, "everything's gonna be alright" );
  30558. } );
  30559. QUnit.test( "toJSON", ( assert ) => {
  30560. assert.ok( false, "everything's gonna be alright" );
  30561. } );
  30562. // OTHERS
  30563. QUnit.test( 'Standard light tests', ( assert ) => {
  30564. runStdLightTests( assert, lights );
  30565. } );
  30566. } );
  30567. } );
  30568. /**
  30569. * @author TristanVALCKE / https://github.com/Itee
  30570. * @author moraxy / https://github.com/moraxy
  30571. */
  30572. /* global QUnit */
  30573. QUnit.module( 'Lights', () => {
  30574. QUnit.module.todo( 'LightShadow', () => {
  30575. // INSTANCING
  30576. QUnit.test( "Instancing", ( assert ) => {
  30577. assert.ok( false, "everything's gonna be alright" );
  30578. } );
  30579. // PUBLIC STUFF
  30580. QUnit.test( "clone/copy", ( assert ) => {
  30581. var a = new LightShadow( new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  30582. var b = new LightShadow( new OrthographicCamera( - 3, 3, 3, - 3, 0.3, 300 ) );
  30583. var c;
  30584. assert.notDeepEqual( a, b, "Newly instanced shadows are not equal" );
  30585. c = a.clone();
  30586. assert.smartEqual( a, c, "Shadows are identical after clone()" );
  30587. c.mapSize.set( 256, 256 );
  30588. assert.notDeepEqual( a, c, "Shadows are different again after change" );
  30589. b.copy( a );
  30590. assert.smartEqual( a, b, "Shadows are identical after copy()" );
  30591. b.mapSize.set( 512, 512 );
  30592. assert.notDeepEqual( a, b, "Shadows are different again after change" );
  30593. } );
  30594. QUnit.test( "toJSON", ( assert ) => {
  30595. assert.ok( false, "everything's gonna be alright" );
  30596. } );
  30597. } );
  30598. } );
  30599. function PointLight( color, intensity, distance, decay ) {
  30600. Light.call( this, color, intensity );
  30601. this.type = 'PointLight';
  30602. Object.defineProperty( this, 'power', {
  30603. get: function () {
  30604. // intensity = power per solid angle.
  30605. // ref: equation (15) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  30606. return this.intensity * 4 * Math.PI;
  30607. },
  30608. set: function ( power ) {
  30609. // intensity = power per solid angle.
  30610. // ref: equation (15) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  30611. this.intensity = power / ( 4 * Math.PI );
  30612. }
  30613. } );
  30614. this.distance = ( distance !== undefined ) ? distance : 0;
  30615. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  30616. this.shadow = new LightShadow( new PerspectiveCamera( 90, 1, 0.5, 500 ) );
  30617. }
  30618. PointLight.prototype = Object.assign( Object.create( Light.prototype ), {
  30619. constructor: PointLight,
  30620. isPointLight: true,
  30621. copy: function ( source ) {
  30622. Light.prototype.copy.call( this, source );
  30623. this.distance = source.distance;
  30624. this.decay = source.decay;
  30625. this.shadow = source.shadow.clone();
  30626. return this;
  30627. }
  30628. } );
  30629. /**
  30630. * @author TristanVALCKE / https://github.com/Itee
  30631. * @author moraxy / https://github.com/moraxy
  30632. */
  30633. /* global QUnit */
  30634. QUnit.module( 'Lights', () => {
  30635. QUnit.module.todo( 'PointLight', ( hooks ) => {
  30636. var lights = undefined;
  30637. hooks.beforeEach( function () {
  30638. const parameters = {
  30639. color: 0xaaaaaa,
  30640. intensity: 0.5,
  30641. distance: 100,
  30642. decay: 2
  30643. };
  30644. lights = [
  30645. new PointLight(),
  30646. new PointLight( parameters.color ),
  30647. new PointLight( parameters.color, parameters.intensity ),
  30648. new PointLight( parameters.color, parameters.intensity, parameters.distance ),
  30649. new PointLight( parameters.color, parameters.intensity, parameters.distance, parameters.decay )
  30650. ];
  30651. } );
  30652. // INHERITANCE
  30653. QUnit.test( "Extending", ( assert ) => {
  30654. assert.ok( false, "everything's gonna be alright" );
  30655. } );
  30656. // INSTANCING
  30657. QUnit.test( "Instancing", ( assert ) => {
  30658. assert.ok( false, "everything's gonna be alright" );
  30659. } );
  30660. // PROPERTIES
  30661. QUnit.test( "power", ( assert ) => {
  30662. var a = new PointLight( 0xaaaaaa );
  30663. a.intensity = 100;
  30664. assert.numEqual( a.power, 100 * Math.PI * 4, "Correct power for an intensity of 100" );
  30665. a.intensity = 40;
  30666. assert.numEqual( a.power, 40 * Math.PI * 4, "Correct power for an intensity of 40" );
  30667. a.power = 100;
  30668. assert.numEqual( a.intensity, 100 / ( 4 * Math.PI ), "Correct intensity for a power of 100" );
  30669. } );
  30670. // PUBLIC STUFF
  30671. QUnit.test( "isPointLight", ( assert ) => {
  30672. assert.ok( false, "everything's gonna be alright" );
  30673. } );
  30674. QUnit.test( "copy", ( assert ) => {
  30675. assert.ok( false, "everything's gonna be alright" );
  30676. } );
  30677. // OTHERS
  30678. QUnit.test( 'Standard light tests', ( assert ) => {
  30679. runStdLightTests( assert, lights );
  30680. } );
  30681. } );
  30682. } );
  30683. function RectAreaLight( color, intensity, width, height ) {
  30684. Light.call( this, color, intensity );
  30685. this.type = 'RectAreaLight';
  30686. this.position.set( 0, 1, 0 );
  30687. this.updateMatrix();
  30688. this.width = ( width !== undefined ) ? width : 10;
  30689. this.height = ( height !== undefined ) ? height : 10;
  30690. // TODO (abelnation): distance/decay
  30691. // TODO (abelnation): update method for RectAreaLight to update transform to lookat target
  30692. // TODO (abelnation): shadows
  30693. }
  30694. // TODO (abelnation): RectAreaLight update when light shape is changed
  30695. RectAreaLight.prototype = Object.assign( Object.create( Light.prototype ), {
  30696. constructor: RectAreaLight,
  30697. isRectAreaLight: true,
  30698. copy: function ( source ) {
  30699. Light.prototype.copy.call( this, source );
  30700. this.width = source.width;
  30701. this.height = source.height;
  30702. return this;
  30703. },
  30704. toJSON: function ( meta ) {
  30705. var data = Light.prototype.toJSON.call( this, meta );
  30706. data.object.width = this.width;
  30707. data.object.height = this.height;
  30708. return data;
  30709. }
  30710. } );
  30711. /**
  30712. * @author TristanVALCKE / https://github.com/Itee
  30713. * @author moraxy / https://github.com/moraxy
  30714. */
  30715. /* global QUnit */
  30716. QUnit.module( 'Lights', () => {
  30717. QUnit.module.todo( 'RectAreaLight', ( hooks ) => {
  30718. var lights = undefined;
  30719. hooks.beforeEach( function () {
  30720. const parameters = {
  30721. color: 0xaaaaaa,
  30722. intensity: 0.5,
  30723. width: 100,
  30724. height: 50
  30725. };
  30726. lights = [
  30727. new RectAreaLight( parameters.color ),
  30728. new RectAreaLight( parameters.color, parameters.intensity ),
  30729. new RectAreaLight( parameters.color, parameters.intensity, parameters.width ),
  30730. new RectAreaLight( parameters.color, parameters.intensity, parameters.width, parameters.height )
  30731. ];
  30732. } );
  30733. // INHERITANCE
  30734. QUnit.test( "Extending", ( assert ) => {
  30735. assert.ok( false, "everything's gonna be alright" );
  30736. } );
  30737. // INSTANCING
  30738. QUnit.test( "Instancing", ( assert ) => {
  30739. assert.ok( false, "everything's gonna be alright" );
  30740. } );
  30741. // PUBLIC STUFF
  30742. QUnit.test( "isRectAreaLight", ( assert ) => {
  30743. assert.ok( false, "everything's gonna be alright" );
  30744. } );
  30745. QUnit.test( "copy", ( assert ) => {
  30746. assert.ok( false, "everything's gonna be alright" );
  30747. } );
  30748. QUnit.test( "toJSON", ( assert ) => {
  30749. assert.ok( false, "everything's gonna be alright" );
  30750. } );
  30751. // OTHERS
  30752. QUnit.test( 'Standard light tests', ( assert ) => {
  30753. runStdLightTests( assert, lights );
  30754. } );
  30755. } );
  30756. } );
  30757. function SpotLightShadow() {
  30758. LightShadow.call( this, new PerspectiveCamera( 50, 1, 0.5, 500 ) );
  30759. }
  30760. SpotLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  30761. constructor: SpotLightShadow,
  30762. isSpotLightShadow: true,
  30763. update: function ( light ) {
  30764. var camera = this.camera;
  30765. var fov = _Math.RAD2DEG * 2 * light.angle;
  30766. var aspect = this.mapSize.width / this.mapSize.height;
  30767. var far = light.distance || camera.far;
  30768. if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) {
  30769. camera.fov = fov;
  30770. camera.aspect = aspect;
  30771. camera.far = far;
  30772. camera.updateProjectionMatrix();
  30773. }
  30774. }
  30775. } );
  30776. function SpotLight( color, intensity, distance, angle, penumbra, decay ) {
  30777. Light.call( this, color, intensity );
  30778. this.type = 'SpotLight';
  30779. this.position.copy( Object3D.DefaultUp );
  30780. this.updateMatrix();
  30781. this.target = new Object3D();
  30782. Object.defineProperty( this, 'power', {
  30783. get: function () {
  30784. // intensity = power per solid angle.
  30785. // ref: equation (17) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  30786. return this.intensity * Math.PI;
  30787. },
  30788. set: function ( power ) {
  30789. // intensity = power per solid angle.
  30790. // ref: equation (17) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  30791. this.intensity = power / Math.PI;
  30792. }
  30793. } );
  30794. this.distance = ( distance !== undefined ) ? distance : 0;
  30795. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  30796. this.penumbra = ( penumbra !== undefined ) ? penumbra : 0;
  30797. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  30798. this.shadow = new SpotLightShadow();
  30799. }
  30800. SpotLight.prototype = Object.assign( Object.create( Light.prototype ), {
  30801. constructor: SpotLight,
  30802. isSpotLight: true,
  30803. copy: function ( source ) {
  30804. Light.prototype.copy.call( this, source );
  30805. this.distance = source.distance;
  30806. this.angle = source.angle;
  30807. this.penumbra = source.penumbra;
  30808. this.decay = source.decay;
  30809. this.target = source.target.clone();
  30810. this.shadow = source.shadow.clone();
  30811. return this;
  30812. }
  30813. } );
  30814. /**
  30815. * @author TristanVALCKE / https://github.com/Itee
  30816. * @author moraxy / https://github.com/moraxy
  30817. */
  30818. /* global QUnit */
  30819. QUnit.module( 'Lights', () => {
  30820. QUnit.module.todo( 'SpotLight', ( hooks ) => {
  30821. var lights = undefined;
  30822. hooks.beforeEach( function () {
  30823. const parameters = {
  30824. color: 0xaaaaaa,
  30825. intensity: 0.5,
  30826. distance: 100,
  30827. angle: 0.8,
  30828. penumbra: 8,
  30829. decay: 2
  30830. };
  30831. lights = [
  30832. new SpotLight( parameters.color ),
  30833. new SpotLight( parameters.color, parameters.intensity ),
  30834. new SpotLight( parameters.color, parameters.intensity, parameters.distance ),
  30835. new SpotLight( parameters.color, parameters.intensity, parameters.distance, parameters.angle ),
  30836. new SpotLight( parameters.color, parameters.intensity, parameters.distance, parameters.angle, parameters.penumbra ),
  30837. new SpotLight( parameters.color, parameters.intensity, parameters.distance, parameters.angle, parameters.penumbra, parameters.decay ),
  30838. ];
  30839. } );
  30840. // INHERITANCE
  30841. QUnit.test( "Extending", ( assert ) => {
  30842. assert.ok( false, "everything's gonna be alright" );
  30843. } );
  30844. // INSTANCING
  30845. QUnit.test( "Instancing", ( assert ) => {
  30846. assert.ok( false, "everything's gonna be alright" );
  30847. } );
  30848. // PROPERTIES
  30849. QUnit.test( "power", ( assert ) => {
  30850. var a = new SpotLight( 0xaaaaaa );
  30851. a.intensity = 100;
  30852. assert.numEqual( a.power, 100 * Math.PI, "Correct power for an intensity of 100" );
  30853. a.intensity = 40;
  30854. assert.numEqual( a.power, 40 * Math.PI, "Correct power for an intensity of 40" );
  30855. a.power = 100;
  30856. assert.numEqual( a.intensity, 100 / Math.PI, "Correct intensity for a power of 100" );
  30857. } );
  30858. // PUBLIC STUFF
  30859. QUnit.test( "isSpotLight", ( assert ) => {
  30860. assert.ok( false, "everything's gonna be alright" );
  30861. } );
  30862. QUnit.test( "copy", ( assert ) => {
  30863. assert.ok( false, "everything's gonna be alright" );
  30864. } );
  30865. // OTHERS
  30866. QUnit.test( 'Standard light tests', ( assert ) => {
  30867. runStdLightTests( assert, lights );
  30868. } );
  30869. } );
  30870. } );
  30871. function Sprite( material ) {
  30872. Object3D.call( this );
  30873. this.type = 'Sprite';
  30874. this.material = ( material !== undefined ) ? material : new SpriteMaterial();
  30875. }
  30876. Sprite.prototype = Object.assign( Object.create( Object3D.prototype ), {
  30877. constructor: Sprite,
  30878. isSprite: true,
  30879. raycast: ( function () {
  30880. var intersectPoint = new Vector3();
  30881. var worldPosition = new Vector3();
  30882. var worldScale = new Vector3();
  30883. return function raycast( raycaster, intersects ) {
  30884. worldPosition.setFromMatrixPosition( this.matrixWorld );
  30885. raycaster.ray.closestPointToPoint( worldPosition, intersectPoint );
  30886. worldScale.setFromMatrixScale( this.matrixWorld );
  30887. var guessSizeSq = worldScale.x * worldScale.y / 4;
  30888. if ( worldPosition.distanceToSquared( intersectPoint ) > guessSizeSq ) return;
  30889. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  30890. if ( distance < raycaster.near || distance > raycaster.far ) return;
  30891. intersects.push( {
  30892. distance: distance,
  30893. point: intersectPoint.clone(),
  30894. face: null,
  30895. object: this
  30896. } );
  30897. };
  30898. }() ),
  30899. clone: function () {
  30900. return new this.constructor( this.material ).copy( this );
  30901. }
  30902. } );
  30903. function Points( geometry, material ) {
  30904. Object3D.call( this );
  30905. this.type = 'Points';
  30906. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  30907. this.material = material !== undefined ? material : new PointsMaterial( { color: Math.random() * 0xffffff } );
  30908. }
  30909. Points.prototype = Object.assign( Object.create( Object3D.prototype ), {
  30910. constructor: Points,
  30911. isPoints: true,
  30912. raycast: ( function () {
  30913. var inverseMatrix = new Matrix4();
  30914. var ray = new Ray();
  30915. var sphere = new Sphere();
  30916. return function raycast( raycaster, intersects ) {
  30917. var object = this;
  30918. var geometry = this.geometry;
  30919. var matrixWorld = this.matrixWorld;
  30920. var threshold = raycaster.params.Points.threshold;
  30921. // Checking boundingSphere distance to ray
  30922. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  30923. sphere.copy( geometry.boundingSphere );
  30924. sphere.applyMatrix4( matrixWorld );
  30925. sphere.radius += threshold;
  30926. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  30927. //
  30928. inverseMatrix.getInverse( matrixWorld );
  30929. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  30930. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  30931. var localThresholdSq = localThreshold * localThreshold;
  30932. var position = new Vector3();
  30933. function testPoint( point, index ) {
  30934. var rayPointDistanceSq = ray.distanceSqToPoint( point );
  30935. if ( rayPointDistanceSq < localThresholdSq ) {
  30936. var intersectPoint = ray.closestPointToPoint( point );
  30937. intersectPoint.applyMatrix4( matrixWorld );
  30938. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  30939. if ( distance < raycaster.near || distance > raycaster.far ) return;
  30940. intersects.push( {
  30941. distance: distance,
  30942. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  30943. point: intersectPoint.clone(),
  30944. index: index,
  30945. face: null,
  30946. object: object
  30947. } );
  30948. }
  30949. }
  30950. if ( geometry.isBufferGeometry ) {
  30951. var index = geometry.index;
  30952. var attributes = geometry.attributes;
  30953. var positions = attributes.position.array;
  30954. if ( index !== null ) {
  30955. var indices = index.array;
  30956. for ( var i = 0, il = indices.length; i < il; i ++ ) {
  30957. var a = indices[ i ];
  30958. position.fromArray( positions, a * 3 );
  30959. testPoint( position, a );
  30960. }
  30961. } else {
  30962. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  30963. position.fromArray( positions, i * 3 );
  30964. testPoint( position, i );
  30965. }
  30966. }
  30967. } else {
  30968. var vertices = geometry.vertices;
  30969. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  30970. testPoint( vertices[ i ], i );
  30971. }
  30972. }
  30973. };
  30974. }() ),
  30975. clone: function () {
  30976. return new this.constructor( this.geometry, this.material ).copy( this );
  30977. }
  30978. } );
  30979. function LineLoop( geometry, material ) {
  30980. Line.call( this, geometry, material );
  30981. this.type = 'LineLoop';
  30982. }
  30983. LineLoop.prototype = Object.assign( Object.create( Line.prototype ), {
  30984. constructor: LineLoop,
  30985. isLineLoop: true,
  30986. } );
  30987. function LOD() {
  30988. Object3D.call( this );
  30989. this.type = 'LOD';
  30990. Object.defineProperties( this, {
  30991. levels: {
  30992. enumerable: true,
  30993. value: []
  30994. }
  30995. } );
  30996. }
  30997. LOD.prototype = Object.assign( Object.create( Object3D.prototype ), {
  30998. constructor: LOD,
  30999. copy: function ( source ) {
  31000. Object3D.prototype.copy.call( this, source, false );
  31001. var levels = source.levels;
  31002. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  31003. var level = levels[ i ];
  31004. this.addLevel( level.object.clone(), level.distance );
  31005. }
  31006. return this;
  31007. },
  31008. addLevel: function ( object, distance ) {
  31009. if ( distance === undefined ) distance = 0;
  31010. distance = Math.abs( distance );
  31011. var levels = this.levels;
  31012. for ( var l = 0; l < levels.length; l ++ ) {
  31013. if ( distance < levels[ l ].distance ) {
  31014. break;
  31015. }
  31016. }
  31017. levels.splice( l, 0, { distance: distance, object: object } );
  31018. this.add( object );
  31019. },
  31020. getObjectForDistance: function ( distance ) {
  31021. var levels = this.levels;
  31022. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  31023. if ( distance < levels[ i ].distance ) {
  31024. break;
  31025. }
  31026. }
  31027. return levels[ i - 1 ].object;
  31028. },
  31029. raycast: ( function () {
  31030. var matrixPosition = new Vector3();
  31031. return function raycast( raycaster, intersects ) {
  31032. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  31033. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  31034. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  31035. };
  31036. }() ),
  31037. update: function () {
  31038. var v1 = new Vector3();
  31039. var v2 = new Vector3();
  31040. return function update( camera ) {
  31041. var levels = this.levels;
  31042. if ( levels.length > 1 ) {
  31043. v1.setFromMatrixPosition( camera.matrixWorld );
  31044. v2.setFromMatrixPosition( this.matrixWorld );
  31045. var distance = v1.distanceTo( v2 );
  31046. levels[ 0 ].object.visible = true;
  31047. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  31048. if ( distance >= levels[ i ].distance ) {
  31049. levels[ i - 1 ].object.visible = false;
  31050. levels[ i ].object.visible = true;
  31051. } else {
  31052. break;
  31053. }
  31054. }
  31055. for ( ; i < l; i ++ ) {
  31056. levels[ i ].object.visible = false;
  31057. }
  31058. }
  31059. };
  31060. }(),
  31061. toJSON: function ( meta ) {
  31062. var data = Object3D.prototype.toJSON.call( this, meta );
  31063. data.object.levels = [];
  31064. var levels = this.levels;
  31065. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  31066. var level = levels[ i ];
  31067. data.object.levels.push( {
  31068. object: level.object.uuid,
  31069. distance: level.distance
  31070. } );
  31071. }
  31072. return data;
  31073. }
  31074. } );
  31075. function Skeleton( bones, boneInverses ) {
  31076. // copy the bone array
  31077. bones = bones || [];
  31078. this.bones = bones.slice( 0 );
  31079. this.boneMatrices = new Float32Array( this.bones.length * 16 );
  31080. // use the supplied bone inverses or calculate the inverses
  31081. if ( boneInverses === undefined ) {
  31082. this.calculateInverses();
  31083. } else {
  31084. if ( this.bones.length === boneInverses.length ) {
  31085. this.boneInverses = boneInverses.slice( 0 );
  31086. } else {
  31087. console.warn( 'THREE.Skeleton boneInverses is the wrong length.' );
  31088. this.boneInverses = [];
  31089. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  31090. this.boneInverses.push( new Matrix4() );
  31091. }
  31092. }
  31093. }
  31094. }
  31095. Object.assign( Skeleton.prototype, {
  31096. calculateInverses: function () {
  31097. this.boneInverses = [];
  31098. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  31099. var inverse = new Matrix4();
  31100. if ( this.bones[ i ] ) {
  31101. inverse.getInverse( this.bones[ i ].matrixWorld );
  31102. }
  31103. this.boneInverses.push( inverse );
  31104. }
  31105. },
  31106. pose: function () {
  31107. var bone, i, il;
  31108. // recover the bind-time world matrices
  31109. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  31110. bone = this.bones[ i ];
  31111. if ( bone ) {
  31112. bone.matrixWorld.getInverse( this.boneInverses[ i ] );
  31113. }
  31114. }
  31115. // compute the local matrices, positions, rotations and scales
  31116. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  31117. bone = this.bones[ i ];
  31118. if ( bone ) {
  31119. if ( bone.parent && bone.parent.isBone ) {
  31120. bone.matrix.getInverse( bone.parent.matrixWorld );
  31121. bone.matrix.multiply( bone.matrixWorld );
  31122. } else {
  31123. bone.matrix.copy( bone.matrixWorld );
  31124. }
  31125. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  31126. }
  31127. }
  31128. },
  31129. update: ( function () {
  31130. var offsetMatrix = new Matrix4();
  31131. var identityMatrix = new Matrix4();
  31132. return function update() {
  31133. var bones = this.bones;
  31134. var boneInverses = this.boneInverses;
  31135. var boneMatrices = this.boneMatrices;
  31136. var boneTexture = this.boneTexture;
  31137. // flatten bone matrices to array
  31138. for ( var i = 0, il = bones.length; i < il; i ++ ) {
  31139. // compute the offset between the current and the original transform
  31140. var matrix = bones[ i ] ? bones[ i ].matrixWorld : identityMatrix;
  31141. offsetMatrix.multiplyMatrices( matrix, boneInverses[ i ] );
  31142. offsetMatrix.toArray( boneMatrices, i * 16 );
  31143. }
  31144. if ( boneTexture !== undefined ) {
  31145. boneTexture.needsUpdate = true;
  31146. }
  31147. };
  31148. } )(),
  31149. clone: function () {
  31150. return new Skeleton( this.bones, this.boneInverses );
  31151. }
  31152. } );
  31153. function Bone() {
  31154. Object3D.call( this );
  31155. this.type = 'Bone';
  31156. }
  31157. Bone.prototype = Object.assign( Object.create( Object3D.prototype ), {
  31158. constructor: Bone,
  31159. isBone: true
  31160. } );
  31161. function SkinnedMesh( geometry, material ) {
  31162. Mesh.call( this, geometry, material );
  31163. this.type = 'SkinnedMesh';
  31164. this.bindMode = 'attached';
  31165. this.bindMatrix = new Matrix4();
  31166. this.bindMatrixInverse = new Matrix4();
  31167. var bones = this.initBones();
  31168. var skeleton = new Skeleton( bones );
  31169. this.bind( skeleton, this.matrixWorld );
  31170. this.normalizeSkinWeights();
  31171. }
  31172. SkinnedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
  31173. constructor: SkinnedMesh,
  31174. isSkinnedMesh: true,
  31175. initBones: function () {
  31176. var bones = [], bone, gbone;
  31177. var i, il;
  31178. if ( this.geometry && this.geometry.bones !== undefined ) {
  31179. // first, create array of 'Bone' objects from geometry data
  31180. for ( i = 0, il = this.geometry.bones.length; i < il; i ++ ) {
  31181. gbone = this.geometry.bones[ i ];
  31182. // create new 'Bone' object
  31183. bone = new Bone();
  31184. bones.push( bone );
  31185. // apply values
  31186. bone.name = gbone.name;
  31187. bone.position.fromArray( gbone.pos );
  31188. bone.quaternion.fromArray( gbone.rotq );
  31189. if ( gbone.scl !== undefined ) bone.scale.fromArray( gbone.scl );
  31190. }
  31191. // second, create bone hierarchy
  31192. for ( i = 0, il = this.geometry.bones.length; i < il; i ++ ) {
  31193. gbone = this.geometry.bones[ i ];
  31194. if ( ( gbone.parent !== - 1 ) && ( gbone.parent !== null ) && ( bones[ gbone.parent ] !== undefined ) ) {
  31195. // subsequent bones in the hierarchy
  31196. bones[ gbone.parent ].add( bones[ i ] );
  31197. } else {
  31198. // topmost bone, immediate child of the skinned mesh
  31199. this.add( bones[ i ] );
  31200. }
  31201. }
  31202. }
  31203. // now the bones are part of the scene graph and children of the skinned mesh.
  31204. // let's update the corresponding matrices
  31205. this.updateMatrixWorld( true );
  31206. return bones;
  31207. },
  31208. bind: function ( skeleton, bindMatrix ) {
  31209. this.skeleton = skeleton;
  31210. if ( bindMatrix === undefined ) {
  31211. this.updateMatrixWorld( true );
  31212. this.skeleton.calculateInverses();
  31213. bindMatrix = this.matrixWorld;
  31214. }
  31215. this.bindMatrix.copy( bindMatrix );
  31216. this.bindMatrixInverse.getInverse( bindMatrix );
  31217. },
  31218. pose: function () {
  31219. this.skeleton.pose();
  31220. },
  31221. normalizeSkinWeights: function () {
  31222. var scale, i;
  31223. if ( this.geometry && this.geometry.isGeometry ) {
  31224. for ( i = 0; i < this.geometry.skinWeights.length; i ++ ) {
  31225. var sw = this.geometry.skinWeights[ i ];
  31226. scale = 1.0 / sw.manhattanLength();
  31227. if ( scale !== Infinity ) {
  31228. sw.multiplyScalar( scale );
  31229. } else {
  31230. sw.set( 1, 0, 0, 0 ); // do something reasonable
  31231. }
  31232. }
  31233. } else if ( this.geometry && this.geometry.isBufferGeometry ) {
  31234. var vec = new Vector4();
  31235. var skinWeight = this.geometry.attributes.skinWeight;
  31236. for ( i = 0; i < skinWeight.count; i ++ ) {
  31237. vec.x = skinWeight.getX( i );
  31238. vec.y = skinWeight.getY( i );
  31239. vec.z = skinWeight.getZ( i );
  31240. vec.w = skinWeight.getW( i );
  31241. scale = 1.0 / vec.manhattanLength();
  31242. if ( scale !== Infinity ) {
  31243. vec.multiplyScalar( scale );
  31244. } else {
  31245. vec.set( 1, 0, 0, 0 ); // do something reasonable
  31246. }
  31247. skinWeight.setXYZW( i, vec.x, vec.y, vec.z, vec.w );
  31248. }
  31249. }
  31250. },
  31251. updateMatrixWorld: function ( force ) {
  31252. Mesh.prototype.updateMatrixWorld.call( this, force );
  31253. if ( this.bindMode === 'attached' ) {
  31254. this.bindMatrixInverse.getInverse( this.matrixWorld );
  31255. } else if ( this.bindMode === 'detached' ) {
  31256. this.bindMatrixInverse.getInverse( this.bindMatrix );
  31257. } else {
  31258. console.warn( 'THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode );
  31259. }
  31260. },
  31261. clone: function () {
  31262. return new this.constructor( this.geometry, this.material ).copy( this );
  31263. }
  31264. } );
  31265. function Fog( color, near, far ) {
  31266. this.name = '';
  31267. this.color = new Color( color );
  31268. this.near = ( near !== undefined ) ? near : 1;
  31269. this.far = ( far !== undefined ) ? far : 1000;
  31270. }
  31271. Fog.prototype.isFog = true;
  31272. Fog.prototype.clone = function () {
  31273. return new Fog( this.color.getHex(), this.near, this.far );
  31274. };
  31275. Fog.prototype.toJSON = function ( /* meta */ ) {
  31276. return {
  31277. type: 'Fog',
  31278. color: this.color.getHex(),
  31279. near: this.near,
  31280. far: this.far
  31281. };
  31282. };
  31283. function FogExp2( color, density ) {
  31284. this.name = '';
  31285. this.color = new Color( color );
  31286. this.density = ( density !== undefined ) ? density : 0.00025;
  31287. }
  31288. FogExp2.prototype.isFogExp2 = true;
  31289. FogExp2.prototype.clone = function () {
  31290. return new FogExp2( this.color.getHex(), this.density );
  31291. };
  31292. FogExp2.prototype.toJSON = function ( /* meta */ ) {
  31293. return {
  31294. type: 'FogExp2',
  31295. color: this.color.getHex(),
  31296. density: this.density
  31297. };
  31298. };
  31299. function BufferGeometryLoader( manager ) {
  31300. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  31301. }
  31302. Object.assign( BufferGeometryLoader.prototype, {
  31303. load: function ( url, onLoad, onProgress, onError ) {
  31304. var scope = this;
  31305. var loader = new FileLoader( scope.manager );
  31306. loader.load( url, function ( text ) {
  31307. onLoad( scope.parse( JSON.parse( text ) ) );
  31308. }, onProgress, onError );
  31309. },
  31310. parse: function ( json ) {
  31311. var geometry = new BufferGeometry();
  31312. var index = json.data.index;
  31313. if ( index !== undefined ) {
  31314. var typedArray = new TYPED_ARRAYS[ index.type ]( index.array );
  31315. geometry.setIndex( new BufferAttribute( typedArray, 1 ) );
  31316. }
  31317. var attributes = json.data.attributes;
  31318. for ( var key in attributes ) {
  31319. var attribute = attributes[ key ];
  31320. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  31321. geometry.addAttribute( key, new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized ) );
  31322. }
  31323. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  31324. if ( groups !== undefined ) {
  31325. for ( var i = 0, n = groups.length; i !== n; ++ i ) {
  31326. var group = groups[ i ];
  31327. geometry.addGroup( group.start, group.count, group.materialIndex );
  31328. }
  31329. }
  31330. var boundingSphere = json.data.boundingSphere;
  31331. if ( boundingSphere !== undefined ) {
  31332. var center = new Vector3();
  31333. if ( boundingSphere.center !== undefined ) {
  31334. center.fromArray( boundingSphere.center );
  31335. }
  31336. geometry.boundingSphere = new Sphere( center, boundingSphere.radius );
  31337. }
  31338. return geometry;
  31339. }
  31340. } );
  31341. var TYPED_ARRAYS = {
  31342. Int8Array: Int8Array,
  31343. Uint8Array: Uint8Array,
  31344. // Workaround for IE11 pre KB2929437. See #11440
  31345. Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
  31346. Int16Array: Int16Array,
  31347. Uint16Array: Uint16Array,
  31348. Int32Array: Int32Array,
  31349. Uint32Array: Uint32Array,
  31350. Float32Array: Float32Array,
  31351. Float64Array: Float64Array
  31352. };
  31353. var Geometries = Object.freeze({
  31354. WireframeGeometry: WireframeGeometry,
  31355. ParametricGeometry: ParametricGeometry,
  31356. ParametricBufferGeometry: ParametricBufferGeometry,
  31357. TetrahedronGeometry: TetrahedronGeometry,
  31358. TetrahedronBufferGeometry: TetrahedronBufferGeometry,
  31359. OctahedronGeometry: OctahedronGeometry,
  31360. OctahedronBufferGeometry: OctahedronBufferGeometry,
  31361. IcosahedronGeometry: IcosahedronGeometry,
  31362. IcosahedronBufferGeometry: IcosahedronBufferGeometry,
  31363. DodecahedronGeometry: DodecahedronGeometry,
  31364. DodecahedronBufferGeometry: DodecahedronBufferGeometry,
  31365. PolyhedronGeometry: PolyhedronGeometry,
  31366. PolyhedronBufferGeometry: PolyhedronBufferGeometry,
  31367. TubeGeometry: TubeGeometry,
  31368. TubeBufferGeometry: TubeBufferGeometry,
  31369. TorusKnotGeometry: TorusKnotGeometry,
  31370. TorusKnotBufferGeometry: TorusKnotBufferGeometry,
  31371. TorusGeometry: TorusGeometry,
  31372. TorusBufferGeometry: TorusBufferGeometry,
  31373. TextGeometry: TextGeometry,
  31374. TextBufferGeometry: TextBufferGeometry,
  31375. SphereGeometry: SphereGeometry,
  31376. SphereBufferGeometry: SphereBufferGeometry,
  31377. RingGeometry: RingGeometry,
  31378. RingBufferGeometry: RingBufferGeometry,
  31379. PlaneGeometry: PlaneGeometry,
  31380. PlaneBufferGeometry: PlaneBufferGeometry,
  31381. LatheGeometry: LatheGeometry,
  31382. LatheBufferGeometry: LatheBufferGeometry,
  31383. ShapeGeometry: ShapeGeometry,
  31384. ShapeBufferGeometry: ShapeBufferGeometry,
  31385. ExtrudeGeometry: ExtrudeGeometry,
  31386. ExtrudeBufferGeometry: ExtrudeBufferGeometry,
  31387. EdgesGeometry: EdgesGeometry,
  31388. ConeGeometry: ConeGeometry,
  31389. ConeBufferGeometry: ConeBufferGeometry,
  31390. CylinderGeometry: CylinderGeometry,
  31391. CylinderBufferGeometry: CylinderBufferGeometry,
  31392. CircleGeometry: CircleGeometry,
  31393. CircleBufferGeometry: CircleBufferGeometry,
  31394. BoxGeometry: BoxGeometry,
  31395. BoxBufferGeometry: BoxBufferGeometry
  31396. });
  31397. function ObjectLoader$1( manager ) {
  31398. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  31399. this.texturePath = '';
  31400. }
  31401. Object.assign( ObjectLoader$1.prototype, {
  31402. load: function ( url, onLoad, onProgress, onError ) {
  31403. if ( this.texturePath === '' ) {
  31404. this.texturePath = url.substring( 0, url.lastIndexOf( '/' ) + 1 );
  31405. }
  31406. var scope = this;
  31407. var loader = new FileLoader( scope.manager );
  31408. loader.load( url, function ( text ) {
  31409. var json = null;
  31410. try {
  31411. json = JSON.parse( text );
  31412. } catch ( error ) {
  31413. if ( onError !== undefined ) onError( error );
  31414. console.error( 'THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message );
  31415. return;
  31416. }
  31417. var metadata = json.metadata;
  31418. if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) {
  31419. console.error( 'THREE.ObjectLoader: Can\'t load ' + url + '. Use THREE.JSONLoader instead.' );
  31420. return;
  31421. }
  31422. scope.parse( json, onLoad );
  31423. }, onProgress, onError );
  31424. },
  31425. setTexturePath: function ( value ) {
  31426. this.texturePath = value;
  31427. },
  31428. setCrossOrigin: function ( value ) {
  31429. this.crossOrigin = value;
  31430. },
  31431. parse: function ( json, onLoad ) {
  31432. var geometries = this.parseGeometries( json.geometries );
  31433. var images = this.parseImages( json.images, function () {
  31434. if ( onLoad !== undefined ) onLoad( object );
  31435. } );
  31436. var textures = this.parseTextures( json.textures, images );
  31437. var materials = this.parseMaterials( json.materials, textures );
  31438. var object = this.parseObject( json.object, geometries, materials );
  31439. if ( json.animations ) {
  31440. object.animations = this.parseAnimations( json.animations );
  31441. }
  31442. if ( json.images === undefined || json.images.length === 0 ) {
  31443. if ( onLoad !== undefined ) onLoad( object );
  31444. }
  31445. return object;
  31446. },
  31447. parseGeometries: function ( json ) {
  31448. var geometries = {};
  31449. if ( json !== undefined ) {
  31450. var geometryLoader = new JSONLoader();
  31451. var bufferGeometryLoader = new BufferGeometryLoader();
  31452. for ( var i = 0, l = json.length; i < l; i ++ ) {
  31453. var geometry;
  31454. var data = json[ i ];
  31455. switch ( data.type ) {
  31456. case 'PlaneGeometry':
  31457. case 'PlaneBufferGeometry':
  31458. geometry = new Geometries[ data.type ](
  31459. data.width,
  31460. data.height,
  31461. data.widthSegments,
  31462. data.heightSegments
  31463. );
  31464. break;
  31465. case 'BoxGeometry':
  31466. case 'BoxBufferGeometry':
  31467. case 'CubeGeometry': // backwards compatible
  31468. geometry = new Geometries[ data.type ](
  31469. data.width,
  31470. data.height,
  31471. data.depth,
  31472. data.widthSegments,
  31473. data.heightSegments,
  31474. data.depthSegments
  31475. );
  31476. break;
  31477. case 'CircleGeometry':
  31478. case 'CircleBufferGeometry':
  31479. geometry = new Geometries[ data.type ](
  31480. data.radius,
  31481. data.segments,
  31482. data.thetaStart,
  31483. data.thetaLength
  31484. );
  31485. break;
  31486. case 'CylinderGeometry':
  31487. case 'CylinderBufferGeometry':
  31488. geometry = new Geometries[ data.type ](
  31489. data.radiusTop,
  31490. data.radiusBottom,
  31491. data.height,
  31492. data.radialSegments,
  31493. data.heightSegments,
  31494. data.openEnded,
  31495. data.thetaStart,
  31496. data.thetaLength
  31497. );
  31498. break;
  31499. case 'ConeGeometry':
  31500. case 'ConeBufferGeometry':
  31501. geometry = new Geometries[ data.type ](
  31502. data.radius,
  31503. data.height,
  31504. data.radialSegments,
  31505. data.heightSegments,
  31506. data.openEnded,
  31507. data.thetaStart,
  31508. data.thetaLength
  31509. );
  31510. break;
  31511. case 'SphereGeometry':
  31512. case 'SphereBufferGeometry':
  31513. geometry = new Geometries[ data.type ](
  31514. data.radius,
  31515. data.widthSegments,
  31516. data.heightSegments,
  31517. data.phiStart,
  31518. data.phiLength,
  31519. data.thetaStart,
  31520. data.thetaLength
  31521. );
  31522. break;
  31523. case 'DodecahedronGeometry':
  31524. case 'DodecahedronBufferGeometry':
  31525. case 'IcosahedronGeometry':
  31526. case 'IcosahedronBufferGeometry':
  31527. case 'OctahedronGeometry':
  31528. case 'OctahedronBufferGeometry':
  31529. case 'TetrahedronGeometry':
  31530. case 'TetrahedronBufferGeometry':
  31531. geometry = new Geometries[ data.type ](
  31532. data.radius,
  31533. data.detail
  31534. );
  31535. break;
  31536. case 'RingGeometry':
  31537. case 'RingBufferGeometry':
  31538. geometry = new Geometries[ data.type ](
  31539. data.innerRadius,
  31540. data.outerRadius,
  31541. data.thetaSegments,
  31542. data.phiSegments,
  31543. data.thetaStart,
  31544. data.thetaLength
  31545. );
  31546. break;
  31547. case 'TorusGeometry':
  31548. case 'TorusBufferGeometry':
  31549. geometry = new Geometries[ data.type ](
  31550. data.radius,
  31551. data.tube,
  31552. data.radialSegments,
  31553. data.tubularSegments,
  31554. data.arc
  31555. );
  31556. break;
  31557. case 'TorusKnotGeometry':
  31558. case 'TorusKnotBufferGeometry':
  31559. geometry = new Geometries[ data.type ](
  31560. data.radius,
  31561. data.tube,
  31562. data.tubularSegments,
  31563. data.radialSegments,
  31564. data.p,
  31565. data.q
  31566. );
  31567. break;
  31568. case 'LatheGeometry':
  31569. case 'LatheBufferGeometry':
  31570. geometry = new Geometries[ data.type ](
  31571. data.points,
  31572. data.segments,
  31573. data.phiStart,
  31574. data.phiLength
  31575. );
  31576. break;
  31577. case 'PolyhedronGeometry':
  31578. case 'PolyhedronBufferGeometry':
  31579. geometry = new Geometries[ data.type ](
  31580. data.vertices,
  31581. data.indices,
  31582. data.radius,
  31583. data.details
  31584. );
  31585. break;
  31586. case 'BufferGeometry':
  31587. geometry = bufferGeometryLoader.parse( data );
  31588. break;
  31589. case 'Geometry':
  31590. geometry = geometryLoader.parse( data, this.texturePath ).geometry;
  31591. break;
  31592. default:
  31593. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  31594. continue;
  31595. }
  31596. geometry.uuid = data.uuid;
  31597. if ( data.name !== undefined ) geometry.name = data.name;
  31598. geometries[ data.uuid ] = geometry;
  31599. }
  31600. }
  31601. return geometries;
  31602. },
  31603. parseMaterials: function ( json, textures ) {
  31604. var materials = {};
  31605. if ( json !== undefined ) {
  31606. var loader = new MaterialLoader();
  31607. loader.setTextures( textures );
  31608. for ( var i = 0, l = json.length; i < l; i ++ ) {
  31609. var data = json[ i ];
  31610. if ( data.type === 'MultiMaterial' ) {
  31611. // Deprecated
  31612. var array = [];
  31613. for ( var j = 0; j < data.materials.length; j ++ ) {
  31614. array.push( loader.parse( data.materials[ j ] ) );
  31615. }
  31616. materials[ data.uuid ] = array;
  31617. } else {
  31618. materials[ data.uuid ] = loader.parse( data );
  31619. }
  31620. }
  31621. }
  31622. return materials;
  31623. },
  31624. parseAnimations: function ( json ) {
  31625. var animations = [];
  31626. for ( var i = 0; i < json.length; i ++ ) {
  31627. var clip = AnimationClip.parse( json[ i ] );
  31628. animations.push( clip );
  31629. }
  31630. return animations;
  31631. },
  31632. parseImages: function ( json, onLoad ) {
  31633. var scope = this;
  31634. var images = {};
  31635. function loadImage( url ) {
  31636. scope.manager.itemStart( url );
  31637. return loader.load( url, function () {
  31638. scope.manager.itemEnd( url );
  31639. }, undefined, function () {
  31640. scope.manager.itemEnd( url );
  31641. scope.manager.itemError( url );
  31642. } );
  31643. }
  31644. if ( json !== undefined && json.length > 0 ) {
  31645. var manager = new LoadingManager( onLoad );
  31646. var loader = new ImageLoader( manager );
  31647. loader.setCrossOrigin( this.crossOrigin );
  31648. for ( var i = 0, l = json.length; i < l; i ++ ) {
  31649. var image = json[ i ];
  31650. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.texturePath + image.url;
  31651. images[ image.uuid ] = loadImage( path );
  31652. }
  31653. }
  31654. return images;
  31655. },
  31656. parseTextures: function ( json, images ) {
  31657. function parseConstant( value, type ) {
  31658. if ( typeof value === 'number' ) return value;
  31659. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  31660. return type[ value ];
  31661. }
  31662. var textures = {};
  31663. if ( json !== undefined ) {
  31664. for ( var i = 0, l = json.length; i < l; i ++ ) {
  31665. var data = json[ i ];
  31666. if ( data.image === undefined ) {
  31667. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  31668. }
  31669. if ( images[ data.image ] === undefined ) {
  31670. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  31671. }
  31672. var texture = new Texture( images[ data.image ] );
  31673. texture.needsUpdate = true;
  31674. texture.uuid = data.uuid;
  31675. if ( data.name !== undefined ) texture.name = data.name;
  31676. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping, TEXTURE_MAPPING );
  31677. if ( data.offset !== undefined ) texture.offset.fromArray( data.offset );
  31678. if ( data.repeat !== undefined ) texture.repeat.fromArray( data.repeat );
  31679. if ( data.center !== undefined ) texture.center.fromArray( data.center );
  31680. if ( data.rotation !== undefined ) texture.rotation = data.rotation;
  31681. if ( data.wrap !== undefined ) {
  31682. texture.wrapS = parseConstant( data.wrap[ 0 ], TEXTURE_WRAPPING );
  31683. texture.wrapT = parseConstant( data.wrap[ 1 ], TEXTURE_WRAPPING );
  31684. }
  31685. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter, TEXTURE_FILTER );
  31686. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter, TEXTURE_FILTER );
  31687. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  31688. if ( data.flipY !== undefined ) texture.flipY = data.flipY;
  31689. textures[ data.uuid ] = texture;
  31690. }
  31691. }
  31692. return textures;
  31693. },
  31694. parseObject: function () {
  31695. var matrix = new Matrix4();
  31696. return function parseObject( data, geometries, materials ) {
  31697. var object;
  31698. function getGeometry( name ) {
  31699. if ( geometries[ name ] === undefined ) {
  31700. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  31701. }
  31702. return geometries[ name ];
  31703. }
  31704. function getMaterial( name ) {
  31705. if ( name === undefined ) return undefined;
  31706. if ( Array.isArray( name ) ) {
  31707. var array = [];
  31708. for ( var i = 0, l = name.length; i < l; i ++ ) {
  31709. var uuid = name[ i ];
  31710. if ( materials[ uuid ] === undefined ) {
  31711. console.warn( 'THREE.ObjectLoader: Undefined material', uuid );
  31712. }
  31713. array.push( materials[ uuid ] );
  31714. }
  31715. return array;
  31716. }
  31717. if ( materials[ name ] === undefined ) {
  31718. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  31719. }
  31720. return materials[ name ];
  31721. }
  31722. switch ( data.type ) {
  31723. case 'Scene':
  31724. object = new Scene();
  31725. if ( data.background !== undefined ) {
  31726. if ( Number.isInteger( data.background ) ) {
  31727. object.background = new Color( data.background );
  31728. }
  31729. }
  31730. if ( data.fog !== undefined ) {
  31731. if ( data.fog.type === 'Fog' ) {
  31732. object.fog = new Fog( data.fog.color, data.fog.near, data.fog.far );
  31733. } else if ( data.fog.type === 'FogExp2' ) {
  31734. object.fog = new FogExp2( data.fog.color, data.fog.density );
  31735. }
  31736. }
  31737. break;
  31738. case 'PerspectiveCamera':
  31739. object = new PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  31740. if ( data.focus !== undefined ) object.focus = data.focus;
  31741. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  31742. if ( data.filmGauge !== undefined ) object.filmGauge = data.filmGauge;
  31743. if ( data.filmOffset !== undefined ) object.filmOffset = data.filmOffset;
  31744. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  31745. break;
  31746. case 'OrthographicCamera':
  31747. object = new OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  31748. break;
  31749. case 'AmbientLight':
  31750. object = new AmbientLight( data.color, data.intensity );
  31751. break;
  31752. case 'DirectionalLight':
  31753. object = new DirectionalLight$1( data.color, data.intensity );
  31754. break;
  31755. case 'PointLight':
  31756. object = new PointLight( data.color, data.intensity, data.distance, data.decay );
  31757. break;
  31758. case 'RectAreaLight':
  31759. object = new RectAreaLight( data.color, data.intensity, data.width, data.height );
  31760. break;
  31761. case 'SpotLight':
  31762. object = new SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  31763. break;
  31764. case 'HemisphereLight':
  31765. object = new HemisphereLight( data.color, data.groundColor, data.intensity );
  31766. break;
  31767. case 'SkinnedMesh':
  31768. console.warn( 'THREE.ObjectLoader.parseObject() does not support SkinnedMesh yet.' );
  31769. case 'Mesh':
  31770. var geometry = getGeometry( data.geometry );
  31771. var material = getMaterial( data.material );
  31772. if ( geometry.bones && geometry.bones.length > 0 ) {
  31773. object = new SkinnedMesh( geometry, material );
  31774. } else {
  31775. object = new Mesh( geometry, material );
  31776. }
  31777. break;
  31778. case 'LOD':
  31779. object = new LOD();
  31780. break;
  31781. case 'Line':
  31782. object = new Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  31783. break;
  31784. case 'LineLoop':
  31785. object = new LineLoop( getGeometry( data.geometry ), getMaterial( data.material ) );
  31786. break;
  31787. case 'LineSegments':
  31788. object = new LineSegments( getGeometry( data.geometry ), getMaterial( data.material ) );
  31789. break;
  31790. case 'PointCloud':
  31791. case 'Points':
  31792. object = new Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  31793. break;
  31794. case 'Sprite':
  31795. object = new Sprite( getMaterial( data.material ) );
  31796. break;
  31797. case 'Group':
  31798. object = new Group();
  31799. break;
  31800. default:
  31801. object = new Object3D();
  31802. }
  31803. object.uuid = data.uuid;
  31804. if ( data.name !== undefined ) object.name = data.name;
  31805. if ( data.matrix !== undefined ) {
  31806. matrix.fromArray( data.matrix );
  31807. matrix.decompose( object.position, object.quaternion, object.scale );
  31808. } else {
  31809. if ( data.position !== undefined ) object.position.fromArray( data.position );
  31810. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  31811. if ( data.quaternion !== undefined ) object.quaternion.fromArray( data.quaternion );
  31812. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  31813. }
  31814. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  31815. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  31816. if ( data.shadow ) {
  31817. if ( data.shadow.bias !== undefined ) object.shadow.bias = data.shadow.bias;
  31818. if ( data.shadow.radius !== undefined ) object.shadow.radius = data.shadow.radius;
  31819. if ( data.shadow.mapSize !== undefined ) object.shadow.mapSize.fromArray( data.shadow.mapSize );
  31820. if ( data.shadow.camera !== undefined ) object.shadow.camera = this.parseObject( data.shadow.camera );
  31821. }
  31822. if ( data.visible !== undefined ) object.visible = data.visible;
  31823. if ( data.userData !== undefined ) object.userData = data.userData;
  31824. if ( data.children !== undefined ) {
  31825. var children = data.children;
  31826. for ( var i = 0; i < children.length; i ++ ) {
  31827. object.add( this.parseObject( children[ i ], geometries, materials ) );
  31828. }
  31829. }
  31830. if ( data.type === 'LOD' ) {
  31831. var levels = data.levels;
  31832. for ( var l = 0; l < levels.length; l ++ ) {
  31833. var level = levels[ l ];
  31834. var child = object.getObjectByProperty( 'uuid', level.object );
  31835. if ( child !== undefined ) {
  31836. object.addLevel( child, level.distance );
  31837. }
  31838. }
  31839. }
  31840. return object;
  31841. };
  31842. }()
  31843. } );
  31844. var TEXTURE_MAPPING = {
  31845. UVMapping: UVMapping,
  31846. CubeReflectionMapping: CubeReflectionMapping,
  31847. CubeRefractionMapping: CubeRefractionMapping,
  31848. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  31849. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  31850. SphericalReflectionMapping: SphericalReflectionMapping,
  31851. CubeUVReflectionMapping: CubeUVReflectionMapping,
  31852. CubeUVRefractionMapping: CubeUVRefractionMapping
  31853. };
  31854. var TEXTURE_WRAPPING = {
  31855. RepeatWrapping: RepeatWrapping,
  31856. ClampToEdgeWrapping: ClampToEdgeWrapping,
  31857. MirroredRepeatWrapping: MirroredRepeatWrapping
  31858. };
  31859. var TEXTURE_FILTER = {
  31860. NearestFilter: NearestFilter,
  31861. NearestMipMapNearestFilter: NearestMipMapNearestFilter,
  31862. NearestMipMapLinearFilter: NearestMipMapLinearFilter,
  31863. LinearFilter: LinearFilter,
  31864. LinearMipMapNearestFilter: LinearMipMapNearestFilter,
  31865. LinearMipMapLinearFilter: LinearMipMapLinearFilter
  31866. };
  31867. /**
  31868. * @author TristanVALCKE / https://github.com/Itee
  31869. * @author moraxy / https://github.com/moraxy
  31870. */
  31871. /* global QUnit */
  31872. QUnit.module( 'Lights', () => {
  31873. QUnit.module.todo( 'SpotLightShadow', () => {
  31874. // INHERITANCE
  31875. QUnit.test( "Extending", ( assert ) => {
  31876. assert.ok( false, "everything's gonna be alright" );
  31877. } );
  31878. // INSTANCING
  31879. QUnit.test( "Instancing", ( assert ) => {
  31880. assert.ok( false, "everything's gonna be alright" );
  31881. } );
  31882. // PUBLIC STUFF
  31883. QUnit.test( "isSpotLightShadow", ( assert ) => {
  31884. assert.ok( false, "everything's gonna be alright" );
  31885. } );
  31886. QUnit.test( "update", ( assert ) => {
  31887. assert.ok( false, "everything's gonna be alright" );
  31888. } );
  31889. // OTHERS
  31890. QUnit.test( "clone/copy", ( assert ) => {
  31891. var a = new SpotLightShadow();
  31892. var b = new SpotLightShadow();
  31893. var c;
  31894. assert.notDeepEqual( a, b, "Newly instanced shadows are not equal" );
  31895. c = a.clone();
  31896. assert.smartEqual( a, c, "Shadows are identical after clone()" );
  31897. c.mapSize.set( 256, 256 );
  31898. assert.notDeepEqual( a, c, "Shadows are different again after change" );
  31899. b.copy( a );
  31900. assert.smartEqual( a, b, "Shadows are identical after copy()" );
  31901. b.mapSize.set( 512, 512 );
  31902. assert.notDeepEqual( a, b, "Shadows are different again after change" );
  31903. } );
  31904. QUnit.test( "toJSON", ( assert ) => {
  31905. var light = new SpotLight();
  31906. var shadow = new SpotLightShadow();
  31907. shadow.bias = 10;
  31908. shadow.radius = 5;
  31909. shadow.mapSize.set( 128, 128 );
  31910. light.shadow = shadow;
  31911. var json = light.toJSON();
  31912. var newLight = new ObjectLoader$1().parse( json );
  31913. assert.smartEqual( newLight.shadow, light.shadow, "Reloaded shadow is equal to the original one" );
  31914. } );
  31915. } );
  31916. } );
  31917. function AnimationLoader( manager ) {
  31918. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  31919. }
  31920. Object.assign( AnimationLoader.prototype, {
  31921. load: function ( url, onLoad, onProgress, onError ) {
  31922. var scope = this;
  31923. var loader = new FileLoader( scope.manager );
  31924. loader.load( url, function ( text ) {
  31925. onLoad( scope.parse( JSON.parse( text ) ) );
  31926. }, onProgress, onError );
  31927. },
  31928. parse: function ( json, onLoad ) {
  31929. var animations = [];
  31930. for ( var i = 0; i < json.length; i ++ ) {
  31931. var clip = AnimationClip.parse( json[ i ] );
  31932. animations.push( clip );
  31933. }
  31934. onLoad( animations );
  31935. }
  31936. } );
  31937. /**
  31938. * @author TristanVALCKE / https://github.com/Itee
  31939. */
  31940. /* global QUnit */
  31941. QUnit.module( 'Loaders', () => {
  31942. QUnit.module.todo( 'AnimationLoader', () => {
  31943. // INSTANCING
  31944. QUnit.test( "Instancing", ( assert ) => {
  31945. assert.ok( false, "everything's gonna be alright" );
  31946. } );
  31947. // PUBLIC STUFF
  31948. QUnit.test( "load", ( assert ) => {
  31949. assert.ok( false, "everything's gonna be alright" );
  31950. } );
  31951. QUnit.test( "parse", ( assert ) => {
  31952. assert.ok( false, "everything's gonna be alright" );
  31953. } );
  31954. } );
  31955. } );
  31956. function AudioLoader( manager ) {
  31957. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  31958. }
  31959. Object.assign( AudioLoader.prototype, {
  31960. load: function ( url, onLoad, onProgress, onError ) {
  31961. var loader = new FileLoader( this.manager );
  31962. loader.setResponseType( 'arraybuffer' );
  31963. loader.load( url, function ( buffer ) {
  31964. var context = AudioContext.getContext();
  31965. context.decodeAudioData( buffer, function ( audioBuffer ) {
  31966. onLoad( audioBuffer );
  31967. } );
  31968. }, onProgress, onError );
  31969. }
  31970. } );
  31971. /**
  31972. * @author TristanVALCKE / https://github.com/Itee
  31973. */
  31974. /* global QUnit */
  31975. QUnit.module( 'Loaders', () => {
  31976. QUnit.module.todo( 'AudioLoader', () => {
  31977. // INSTANCING
  31978. QUnit.test( "Instancing", ( assert ) => {
  31979. assert.ok( false, "everything's gonna be alright" );
  31980. } );
  31981. // PUBLIC STUFF
  31982. QUnit.test( "load", ( assert ) => {
  31983. assert.ok( false, "everything's gonna be alright" );
  31984. } );
  31985. } );
  31986. } );
  31987. /**
  31988. * @author TristanVALCKE / https://github.com/Itee
  31989. */
  31990. /* global QUnit */
  31991. QUnit.module( 'Loaders', () => {
  31992. QUnit.module.todo( 'BufferGeometryLoader', () => {
  31993. // INSTANCING
  31994. QUnit.test( "Instancing", ( assert ) => {
  31995. assert.ok( false, "everything's gonna be alright" );
  31996. } );
  31997. // PUBLIC STUFF
  31998. QUnit.test( "load", ( assert ) => {
  31999. assert.ok( false, "everything's gonna be alright" );
  32000. } );
  32001. QUnit.test( "parse", ( assert ) => {
  32002. assert.ok( false, "everything's gonna be alright" );
  32003. } );
  32004. } );
  32005. } );
  32006. /**
  32007. * @author TristanVALCKE / https://github.com/Itee
  32008. */
  32009. /* global QUnit */
  32010. QUnit.module( 'Loaders', () => {
  32011. QUnit.module.todo( 'Cache', () => {
  32012. // PUBLIC STUFF
  32013. QUnit.test( "add", ( assert ) => {
  32014. assert.ok( false, "everything's gonna be alright" );
  32015. } );
  32016. QUnit.test( "get", ( assert ) => {
  32017. assert.ok( false, "everything's gonna be alright" );
  32018. } );
  32019. QUnit.test( "remove", ( assert ) => {
  32020. assert.ok( false, "everything's gonna be alright" );
  32021. } );
  32022. QUnit.test( "clear", ( assert ) => {
  32023. assert.ok( false, "everything's gonna be alright" );
  32024. } );
  32025. } );
  32026. } );
  32027. /**
  32028. * @author alteredq / http://alteredqualia.com/
  32029. */
  32030. function CompressedTexture( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  32031. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  32032. this.image = { width: width, height: height };
  32033. this.mipmaps = mipmaps;
  32034. // no flipping for cube textures
  32035. // (also flipping doesn't work for compressed textures )
  32036. this.flipY = false;
  32037. // can't generate mipmaps for compressed textures
  32038. // mips must be embedded in DDS files
  32039. this.generateMipmaps = false;
  32040. }
  32041. CompressedTexture.prototype = Object.create( Texture.prototype );
  32042. CompressedTexture.prototype.constructor = CompressedTexture;
  32043. CompressedTexture.prototype.isCompressedTexture = true;
  32044. function CompressedTextureLoader( manager ) {
  32045. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  32046. // override in sub classes
  32047. this._parser = null;
  32048. }
  32049. Object.assign( CompressedTextureLoader.prototype, {
  32050. load: function ( url, onLoad, onProgress, onError ) {
  32051. var scope = this;
  32052. var images = [];
  32053. var texture = new CompressedTexture();
  32054. texture.image = images;
  32055. var loader = new FileLoader( this.manager );
  32056. loader.setPath( this.path );
  32057. loader.setResponseType( 'arraybuffer' );
  32058. function loadTexture( i ) {
  32059. loader.load( url[ i ], function ( buffer ) {
  32060. var texDatas = scope._parser( buffer, true );
  32061. images[ i ] = {
  32062. width: texDatas.width,
  32063. height: texDatas.height,
  32064. format: texDatas.format,
  32065. mipmaps: texDatas.mipmaps
  32066. };
  32067. loaded += 1;
  32068. if ( loaded === 6 ) {
  32069. if ( texDatas.mipmapCount === 1 )
  32070. texture.minFilter = LinearFilter;
  32071. texture.format = texDatas.format;
  32072. texture.needsUpdate = true;
  32073. if ( onLoad ) onLoad( texture );
  32074. }
  32075. }, onProgress, onError );
  32076. }
  32077. if ( Array.isArray( url ) ) {
  32078. var loaded = 0;
  32079. for ( var i = 0, il = url.length; i < il; ++ i ) {
  32080. loadTexture( i );
  32081. }
  32082. } else {
  32083. // compressed cubemap texture stored in a single DDS file
  32084. loader.load( url, function ( buffer ) {
  32085. var texDatas = scope._parser( buffer, true );
  32086. if ( texDatas.isCubemap ) {
  32087. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  32088. for ( var f = 0; f < faces; f ++ ) {
  32089. images[ f ] = { mipmaps: [] };
  32090. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  32091. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  32092. images[ f ].format = texDatas.format;
  32093. images[ f ].width = texDatas.width;
  32094. images[ f ].height = texDatas.height;
  32095. }
  32096. }
  32097. } else {
  32098. texture.image.width = texDatas.width;
  32099. texture.image.height = texDatas.height;
  32100. texture.mipmaps = texDatas.mipmaps;
  32101. }
  32102. if ( texDatas.mipmapCount === 1 ) {
  32103. texture.minFilter = LinearFilter;
  32104. }
  32105. texture.format = texDatas.format;
  32106. texture.needsUpdate = true;
  32107. if ( onLoad ) onLoad( texture );
  32108. }, onProgress, onError );
  32109. }
  32110. return texture;
  32111. },
  32112. setPath: function ( value ) {
  32113. this.path = value;
  32114. return this;
  32115. }
  32116. } );
  32117. /**
  32118. * @author TristanVALCKE / https://github.com/Itee
  32119. */
  32120. /* global QUnit */
  32121. QUnit.module( 'Loaders', () => {
  32122. QUnit.module.todo( 'CompressedTextureLoader', () => {
  32123. // INSTANCING
  32124. QUnit.test( "Instancing", ( assert ) => {
  32125. assert.ok( false, "everything's gonna be alright" );
  32126. } );
  32127. // PUBLIC STUFF
  32128. QUnit.test( "load", ( assert ) => {
  32129. assert.ok( false, "everything's gonna be alright" );
  32130. } );
  32131. QUnit.test( "setPath", ( assert ) => {
  32132. assert.ok( false, "everything's gonna be alright" );
  32133. } );
  32134. } );
  32135. } );
  32136. function CubeTextureLoader( manager ) {
  32137. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  32138. }
  32139. Object.assign( CubeTextureLoader.prototype, {
  32140. crossOrigin: 'Anonymous',
  32141. load: function ( urls, onLoad, onProgress, onError ) {
  32142. var texture = new CubeTexture();
  32143. var loader = new ImageLoader( this.manager );
  32144. loader.setCrossOrigin( this.crossOrigin );
  32145. loader.setPath( this.path );
  32146. var loaded = 0;
  32147. function loadTexture( i ) {
  32148. loader.load( urls[ i ], function ( image ) {
  32149. texture.images[ i ] = image;
  32150. loaded ++;
  32151. if ( loaded === 6 ) {
  32152. texture.needsUpdate = true;
  32153. if ( onLoad ) onLoad( texture );
  32154. }
  32155. }, undefined, onError );
  32156. }
  32157. for ( var i = 0; i < urls.length; ++ i ) {
  32158. loadTexture( i );
  32159. }
  32160. return texture;
  32161. },
  32162. setCrossOrigin: function ( value ) {
  32163. this.crossOrigin = value;
  32164. return this;
  32165. },
  32166. setPath: function ( value ) {
  32167. this.path = value;
  32168. return this;
  32169. }
  32170. } );
  32171. /**
  32172. * @author TristanVALCKE / https://github.com/Itee
  32173. */
  32174. /* global QUnit */
  32175. QUnit.module( 'Loaders', () => {
  32176. QUnit.module.todo( 'CubeTextureLoader', () => {
  32177. // INSTANCING
  32178. QUnit.test( "Instancing", ( assert ) => {
  32179. assert.ok( false, "everything's gonna be alright" );
  32180. } );
  32181. // PUBLIC STUFF
  32182. QUnit.test( "load", ( assert ) => {
  32183. assert.ok( false, "everything's gonna be alright" );
  32184. } );
  32185. QUnit.test( "setCrossOrigin", ( assert ) => {
  32186. assert.ok( false, "everything's gonna be alright" );
  32187. } );
  32188. QUnit.test( "setPath", ( assert ) => {
  32189. assert.ok( false, "everything's gonna be alright" );
  32190. } );
  32191. } );
  32192. } );
  32193. function DataTextureLoader( manager ) {
  32194. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  32195. // override in sub classes
  32196. this._parser = null;
  32197. }
  32198. Object.assign( DataTextureLoader.prototype, {
  32199. load: function ( url, onLoad, onProgress, onError ) {
  32200. var scope = this;
  32201. var texture = new DataTexture();
  32202. var loader = new FileLoader( this.manager );
  32203. loader.setResponseType( 'arraybuffer' );
  32204. loader.load( url, function ( buffer ) {
  32205. var texData = scope._parser( buffer );
  32206. if ( ! texData ) return;
  32207. if ( undefined !== texData.image ) {
  32208. texture.image = texData.image;
  32209. } else if ( undefined !== texData.data ) {
  32210. texture.image.width = texData.width;
  32211. texture.image.height = texData.height;
  32212. texture.image.data = texData.data;
  32213. }
  32214. texture.wrapS = undefined !== texData.wrapS ? texData.wrapS : ClampToEdgeWrapping;
  32215. texture.wrapT = undefined !== texData.wrapT ? texData.wrapT : ClampToEdgeWrapping;
  32216. texture.magFilter = undefined !== texData.magFilter ? texData.magFilter : LinearFilter;
  32217. texture.minFilter = undefined !== texData.minFilter ? texData.minFilter : LinearMipMapLinearFilter;
  32218. texture.anisotropy = undefined !== texData.anisotropy ? texData.anisotropy : 1;
  32219. if ( undefined !== texData.format ) {
  32220. texture.format = texData.format;
  32221. }
  32222. if ( undefined !== texData.type ) {
  32223. texture.type = texData.type;
  32224. }
  32225. if ( undefined !== texData.mipmaps ) {
  32226. texture.mipmaps = texData.mipmaps;
  32227. }
  32228. if ( 1 === texData.mipmapCount ) {
  32229. texture.minFilter = LinearFilter;
  32230. }
  32231. texture.needsUpdate = true;
  32232. if ( onLoad ) onLoad( texture, texData );
  32233. }, onProgress, onError );
  32234. return texture;
  32235. }
  32236. } );
  32237. /**
  32238. * @author TristanVALCKE / https://github.com/Itee
  32239. */
  32240. /* global QUnit */
  32241. QUnit.module( 'Loaders', () => {
  32242. QUnit.module.todo( 'DataTextureLoader', () => {
  32243. // INSTANCING
  32244. QUnit.test( "Instancing", ( assert ) => {
  32245. assert.ok( false, "everything's gonna be alright" );
  32246. } );
  32247. // PUBLIC STUFF
  32248. QUnit.test( "load", ( assert ) => {
  32249. assert.ok( false, "everything's gonna be alright" );
  32250. } );
  32251. } );
  32252. } );
  32253. /**
  32254. * @author TristanVALCKE / https://github.com/Itee
  32255. */
  32256. /* global QUnit */
  32257. QUnit.module( 'Loaders', () => {
  32258. QUnit.module.todo( 'FileLoader', () => {
  32259. // INSTANCING
  32260. QUnit.test( "Instancing", ( assert ) => {
  32261. assert.ok( false, "everything's gonna be alright" );
  32262. } );
  32263. // PUBLIC STUFF
  32264. QUnit.test( "load", ( assert ) => {
  32265. assert.ok( false, "everything's gonna be alright" );
  32266. } );
  32267. QUnit.test( "setPath", ( assert ) => {
  32268. assert.ok( false, "everything's gonna be alright" );
  32269. } );
  32270. QUnit.test( "setResponseType", ( assert ) => {
  32271. assert.ok( false, "everything's gonna be alright" );
  32272. } );
  32273. QUnit.test( "setWithCredentials", ( assert ) => {
  32274. assert.ok( false, "everything's gonna be alright" );
  32275. } );
  32276. QUnit.test( "setMimeType", ( assert ) => {
  32277. assert.ok( false, "everything's gonna be alright" );
  32278. } );
  32279. QUnit.test( "setRequestHeader", ( assert ) => {
  32280. assert.ok( false, "everything's gonna be alright" );
  32281. } );
  32282. } );
  32283. } );
  32284. function FontLoader( manager ) {
  32285. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  32286. }
  32287. Object.assign( FontLoader.prototype, {
  32288. load: function ( url, onLoad, onProgress, onError ) {
  32289. var scope = this;
  32290. var loader = new FileLoader( this.manager );
  32291. loader.setPath( this.path );
  32292. loader.load( url, function ( text ) {
  32293. var json;
  32294. try {
  32295. json = JSON.parse( text );
  32296. } catch ( e ) {
  32297. console.warn( 'THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.' );
  32298. json = JSON.parse( text.substring( 65, text.length - 2 ) );
  32299. }
  32300. var font = scope.parse( json );
  32301. if ( onLoad ) onLoad( font );
  32302. }, onProgress, onError );
  32303. },
  32304. parse: function ( json ) {
  32305. return new Font( json );
  32306. },
  32307. setPath: function ( value ) {
  32308. this.path = value;
  32309. return this;
  32310. }
  32311. } );
  32312. /**
  32313. * @author TristanVALCKE / https://github.com/Itee
  32314. */
  32315. /* global QUnit */
  32316. QUnit.module( 'Loaders', () => {
  32317. QUnit.module.todo( 'FontLoader', () => {
  32318. // INSTANCING
  32319. QUnit.test( "Instancing", ( assert ) => {
  32320. assert.ok( false, "everything's gonna be alright" );
  32321. } );
  32322. // PUBLIC STUFF
  32323. QUnit.test( "load", ( assert ) => {
  32324. assert.ok( false, "everything's gonna be alright" );
  32325. } );
  32326. QUnit.test( "parse", ( assert ) => {
  32327. assert.ok( false, "everything's gonna be alright" );
  32328. } );
  32329. QUnit.test( "setPath", ( assert ) => {
  32330. assert.ok( false, "everything's gonna be alright" );
  32331. } );
  32332. } );
  32333. } );
  32334. /**
  32335. * @author TristanVALCKE / https://github.com/Itee
  32336. */
  32337. /* global QUnit */
  32338. QUnit.module( 'Loaders', () => {
  32339. QUnit.module.todo( 'ImageLoader', () => {
  32340. // INSTANCING
  32341. QUnit.test( "Instancing", ( assert ) => {
  32342. assert.ok( false, "everything's gonna be alright" );
  32343. } );
  32344. // PUBLIC STUFF
  32345. QUnit.test( "load", ( assert ) => {
  32346. assert.ok( false, "everything's gonna be alright" );
  32347. } );
  32348. QUnit.test( "setCrossOrigin", ( assert ) => {
  32349. assert.ok( false, "everything's gonna be alright" );
  32350. } );
  32351. QUnit.test( "setPath", ( assert ) => {
  32352. assert.ok( false, "everything's gonna be alright" );
  32353. } );
  32354. } );
  32355. } );
  32356. /**
  32357. * @author TristanVALCKE / https://github.com/Itee
  32358. */
  32359. /* global QUnit */
  32360. QUnit.module( 'Loaders', () => {
  32361. QUnit.module.todo( 'JSONLoader', () => {
  32362. // INSTANCING
  32363. QUnit.test( "Instancing", ( assert ) => {
  32364. assert.ok( false, "everything's gonna be alright" );
  32365. } );
  32366. // PUBLIC STUFF
  32367. QUnit.test( "load", ( assert ) => {
  32368. assert.ok( false, "everything's gonna be alright" );
  32369. } );
  32370. QUnit.test( "setTexturePath", ( assert ) => {
  32371. assert.ok( false, "everything's gonna be alright" );
  32372. } );
  32373. QUnit.test( "parse", ( assert ) => {
  32374. assert.ok( false, "everything's gonna be alright" );
  32375. } );
  32376. } );
  32377. } );
  32378. /**
  32379. * @author TristanVALCKE / https://github.com/Itee
  32380. */
  32381. /* global QUnit */
  32382. QUnit.module( 'Loaders', () => {
  32383. QUnit.module.todo( 'Loader', () => {
  32384. // INSTANCING
  32385. QUnit.test( "Instancing", ( assert ) => {
  32386. assert.ok( false, "everything's gonna be alright" );
  32387. } );
  32388. // STATIC STUFF
  32389. QUnit.test( "Handlers.add", ( assert ) => {
  32390. assert.ok( false, "everything's gonna be alright" );
  32391. } );
  32392. QUnit.test( "Handlers.get", ( assert ) => {
  32393. assert.ok( false, "everything's gonna be alright" );
  32394. } );
  32395. // PUBLIC STUFF
  32396. QUnit.test( "extractUrlBase", ( assert ) => {
  32397. assert.ok( false, "everything's gonna be alright" );
  32398. } );
  32399. QUnit.test( "initMaterials", ( assert ) => {
  32400. assert.ok( false, "everything's gonna be alright" );
  32401. } );
  32402. QUnit.test( "createMaterial", ( assert ) => {
  32403. assert.ok( false, "everything's gonna be alright" );
  32404. } );
  32405. } );
  32406. } );
  32407. /**
  32408. * @author TristanVALCKE / https://github.com/Itee
  32409. */
  32410. /* global QUnit */
  32411. QUnit.module( 'Loaders', () => {
  32412. QUnit.module.todo( 'LoadingManager', () => {
  32413. // INSTANCING
  32414. QUnit.test( "Instancing", ( assert ) => {
  32415. assert.ok( false, "everything's gonna be alright" );
  32416. } );
  32417. // PUBLIC STUFF
  32418. QUnit.test( "onStart", ( assert ) => {
  32419. assert.ok( false, "everything's gonna be alright" );
  32420. } );
  32421. QUnit.test( "onLoad", ( assert ) => {
  32422. assert.ok( false, "everything's gonna be alright" );
  32423. } );
  32424. QUnit.test( "onProgress", ( assert ) => {
  32425. assert.ok( false, "everything's gonna be alright" );
  32426. } );
  32427. QUnit.test( "onError", ( assert ) => {
  32428. assert.ok( false, "everything's gonna be alright" );
  32429. } );
  32430. QUnit.test( "itemStart", ( assert ) => {
  32431. assert.ok( false, "everything's gonna be alright" );
  32432. } );
  32433. QUnit.test( "itemEnd", ( assert ) => {
  32434. assert.ok( false, "everything's gonna be alright" );
  32435. } );
  32436. QUnit.test( "itemError", ( assert ) => {
  32437. assert.ok( false, "everything's gonna be alright" );
  32438. } );
  32439. } );
  32440. } );
  32441. /**
  32442. * @author TristanVALCKE / https://github.com/Itee
  32443. */
  32444. /* global QUnit */
  32445. QUnit.module( 'Loaders', () => {
  32446. QUnit.module.todo( 'MaterialLoader', () => {
  32447. // INSTANCING
  32448. QUnit.test( "Instancing", ( assert ) => {
  32449. assert.ok( false, "everything's gonna be alright" );
  32450. } );
  32451. // PUBLIC STUFF
  32452. QUnit.test( "load", ( assert ) => {
  32453. assert.ok( false, "everything's gonna be alright" );
  32454. } );
  32455. QUnit.test( "setTextures", ( assert ) => {
  32456. assert.ok( false, "everything's gonna be alright" );
  32457. } );
  32458. QUnit.test( "parse", ( assert ) => {
  32459. assert.ok( false, "everything's gonna be alright" );
  32460. } );
  32461. } );
  32462. } );
  32463. /**
  32464. * @author TristanVALCKE / https://github.com/Itee
  32465. */
  32466. /* global QUnit */
  32467. QUnit.module( 'Loaders', () => {
  32468. QUnit.module.todo( 'ObjectLoader', () => {
  32469. // INSTANCING
  32470. QUnit.test( "Instancing", ( assert ) => {
  32471. assert.ok( false, "everything's gonna be alright" );
  32472. } );
  32473. // PUBLIC STUFF
  32474. QUnit.test( "load", ( assert ) => {
  32475. assert.ok( false, "everything's gonna be alright" );
  32476. } );
  32477. QUnit.test( "setTexturePath", ( assert ) => {
  32478. assert.ok( false, "everything's gonna be alright" );
  32479. } );
  32480. QUnit.test( "setCrossOrigin", ( assert ) => {
  32481. assert.ok( false, "everything's gonna be alright" );
  32482. } );
  32483. QUnit.test( "parse", ( assert ) => {
  32484. assert.ok( false, "everything's gonna be alright" );
  32485. } );
  32486. QUnit.test( "parseGeometries", ( assert ) => {
  32487. assert.ok( false, "everything's gonna be alright" );
  32488. } );
  32489. QUnit.test( "parseMaterials", ( assert ) => {
  32490. assert.ok( false, "everything's gonna be alright" );
  32491. } );
  32492. QUnit.test( "parseAnimations", ( assert ) => {
  32493. assert.ok( false, "everything's gonna be alright" );
  32494. } );
  32495. QUnit.test( "parseImages", ( assert ) => {
  32496. assert.ok( false, "everything's gonna be alright" );
  32497. } );
  32498. QUnit.test( "parseTextures", ( assert ) => {
  32499. assert.ok( false, "everything's gonna be alright" );
  32500. } );
  32501. QUnit.test( "parseObject", ( assert ) => {
  32502. assert.ok( false, "everything's gonna be alright" );
  32503. } );
  32504. } );
  32505. } );
  32506. /**
  32507. * @author TristanVALCKE / https://github.com/Itee
  32508. */
  32509. /* global QUnit */
  32510. QUnit.module( 'Loaders', () => {
  32511. QUnit.module.todo( 'TextureLoader', () => {
  32512. // INSTANCING
  32513. QUnit.test( "Instancing", ( assert ) => {
  32514. assert.ok( false, "everything's gonna be alright" );
  32515. } );
  32516. // PUBLIC STUFF
  32517. QUnit.test( "load", ( assert ) => {
  32518. assert.ok( false, "everything's gonna be alright" );
  32519. } );
  32520. QUnit.test( "setCrossOrigin", ( assert ) => {
  32521. assert.ok( false, "everything's gonna be alright" );
  32522. } );
  32523. QUnit.test( "setPath", ( assert ) => {
  32524. assert.ok( false, "everything's gonna be alright" );
  32525. } );
  32526. } );
  32527. } );
  32528. /**
  32529. * @author TristanVALCKE / https://github.com/Itee
  32530. */
  32531. /* global QUnit */
  32532. QUnit.module( 'Materials', () => {
  32533. QUnit.module.todo( 'LineBasicMaterial', () => {
  32534. // INHERITANCE
  32535. QUnit.test( "Extending", ( assert ) => {
  32536. assert.ok( false, "everything's gonna be alright" );
  32537. } );
  32538. // INSTANCING
  32539. QUnit.test( "Instancing", ( assert ) => {
  32540. assert.ok( false, "everything's gonna be alright" );
  32541. } );
  32542. // PUBLIC STUFF
  32543. QUnit.test( "isLineBasicMaterial", ( assert ) => {
  32544. assert.ok( false, "everything's gonna be alright" );
  32545. } );
  32546. QUnit.test( "copy", ( assert ) => {
  32547. assert.ok( false, "everything's gonna be alright" );
  32548. } );
  32549. } );
  32550. } );
  32551. /**
  32552. * @author TristanVALCKE / https://github.com/Itee
  32553. */
  32554. /* global QUnit */
  32555. QUnit.module( 'Materials', () => {
  32556. QUnit.module.todo( 'LineDashedMaterial', () => {
  32557. // INHERITANCE
  32558. QUnit.test( "Extending", ( assert ) => {
  32559. assert.ok( false, "everything's gonna be alright" );
  32560. } );
  32561. // INSTANCING
  32562. QUnit.test( "Instancing", ( assert ) => {
  32563. assert.ok( false, "everything's gonna be alright" );
  32564. } );
  32565. // PUBLIC STUFF
  32566. QUnit.test( "isLineDashedMaterial", ( assert ) => {
  32567. assert.ok( false, "everything's gonna be alright" );
  32568. } );
  32569. QUnit.test( "copy", ( assert ) => {
  32570. assert.ok( false, "everything's gonna be alright" );
  32571. } );
  32572. } );
  32573. } );
  32574. /**
  32575. * @author TristanVALCKE / https://github.com/Itee
  32576. */
  32577. /* global QUnit */
  32578. QUnit.module( 'Materials', () => {
  32579. QUnit.module.todo( 'Material', () => {
  32580. // INSTANCING
  32581. QUnit.test( "Instancing", ( assert ) => {
  32582. assert.ok( false, "everything's gonna be alright" );
  32583. } );
  32584. // PUBLIC STUFF
  32585. QUnit.test( "isMaterial", ( assert ) => {
  32586. assert.ok( false, "everything's gonna be alright" );
  32587. } );
  32588. QUnit.test( "onBeforeCompile", ( assert ) => {
  32589. assert.ok( false, "everything's gonna be alright" );
  32590. } );
  32591. QUnit.test( "setValues", ( assert ) => {
  32592. assert.ok( false, "everything's gonna be alright" );
  32593. } );
  32594. QUnit.test( "toJSON", ( assert ) => {
  32595. assert.ok( false, "everything's gonna be alright" );
  32596. } );
  32597. QUnit.test( "clone", ( assert ) => {
  32598. assert.ok( false, "everything's gonna be alright" );
  32599. } );
  32600. QUnit.test( "copy", ( assert ) => {
  32601. assert.ok( false, "everything's gonna be alright" );
  32602. } );
  32603. QUnit.test( "dispose", ( assert ) => {
  32604. assert.ok( false, "everything's gonna be alright" );
  32605. } );
  32606. } );
  32607. } );
  32608. /**
  32609. * @author TristanVALCKE / https://github.com/Itee
  32610. */
  32611. /* global QUnit */
  32612. QUnit.module( 'Materials', () => {
  32613. QUnit.module.todo( 'MeshBasicMaterial', () => {
  32614. // INHERITANCE
  32615. QUnit.test( "Extending", ( assert ) => {
  32616. assert.ok( false, "everything's gonna be alright" );
  32617. } );
  32618. // INSTANCING
  32619. QUnit.test( "Instancing", ( assert ) => {
  32620. assert.ok( false, "everything's gonna be alright" );
  32621. } );
  32622. // PUBLIC STUFF
  32623. QUnit.test( "isMeshBasicMaterial", ( assert ) => {
  32624. assert.ok( false, "everything's gonna be alright" );
  32625. } );
  32626. QUnit.test( "copy", ( assert ) => {
  32627. assert.ok( false, "everything's gonna be alright" );
  32628. } );
  32629. } );
  32630. } );
  32631. /**
  32632. * @author TristanVALCKE / https://github.com/Itee
  32633. */
  32634. /* global QUnit */
  32635. QUnit.module( 'Materials', () => {
  32636. QUnit.module.todo( 'MeshDepthMaterial', () => {
  32637. // INHERITANCE
  32638. QUnit.test( "Extending", ( assert ) => {
  32639. assert.ok( false, "everything's gonna be alright" );
  32640. } );
  32641. // INSTANCING
  32642. QUnit.test( "Instancing", ( assert ) => {
  32643. assert.ok( false, "everything's gonna be alright" );
  32644. } );
  32645. // PUBLIC STUFF
  32646. QUnit.test( "isMeshDepthMaterial", ( assert ) => {
  32647. assert.ok( false, "everything's gonna be alright" );
  32648. } );
  32649. QUnit.test( "copy", ( assert ) => {
  32650. assert.ok( false, "everything's gonna be alright" );
  32651. } );
  32652. } );
  32653. } );
  32654. /**
  32655. * @author TristanVALCKE / https://github.com/Itee
  32656. */
  32657. /* global QUnit */
  32658. QUnit.module( 'Materials', () => {
  32659. QUnit.module.todo( 'MeshDistanceMaterial', () => {
  32660. // INHERITANCE
  32661. QUnit.test( "Extending", ( assert ) => {
  32662. assert.ok( false, "everything's gonna be alright" );
  32663. } );
  32664. // INSTANCING
  32665. QUnit.test( "Instancing", ( assert ) => {
  32666. assert.ok( false, "everything's gonna be alright" );
  32667. } );
  32668. // PUBLIC STUFF
  32669. QUnit.test( "isMeshDistanceMaterial", ( assert ) => {
  32670. assert.ok( false, "everything's gonna be alright" );
  32671. } );
  32672. QUnit.test( "copy", ( assert ) => {
  32673. assert.ok( false, "everything's gonna be alright" );
  32674. } );
  32675. } );
  32676. } );
  32677. /**
  32678. * @author TristanVALCKE / https://github.com/Itee
  32679. */
  32680. /* global QUnit */
  32681. QUnit.module( 'Materials', () => {
  32682. QUnit.module.todo( 'MeshLambertMaterial', () => {
  32683. // INHERITANCE
  32684. QUnit.test( "Extending", ( assert ) => {
  32685. assert.ok( false, "everything's gonna be alright" );
  32686. } );
  32687. // INSTANCING
  32688. QUnit.test( "Instancing", ( assert ) => {
  32689. assert.ok( false, "everything's gonna be alright" );
  32690. } );
  32691. // PUBLIC STUFF
  32692. QUnit.test( "isMeshLambertMaterial", ( assert ) => {
  32693. assert.ok( false, "everything's gonna be alright" );
  32694. } );
  32695. QUnit.test( "copy", ( assert ) => {
  32696. assert.ok( false, "everything's gonna be alright" );
  32697. } );
  32698. } );
  32699. } );
  32700. /**
  32701. * @author TristanVALCKE / https://github.com/Itee
  32702. */
  32703. /* global QUnit */
  32704. QUnit.module( 'Materials', () => {
  32705. QUnit.module.todo( 'MeshNormalMaterial', () => {
  32706. // INHERITANCE
  32707. QUnit.test( "Extending", ( assert ) => {
  32708. assert.ok( false, "everything's gonna be alright" );
  32709. } );
  32710. // INSTANCING
  32711. QUnit.test( "Instancing", ( assert ) => {
  32712. assert.ok( false, "everything's gonna be alright" );
  32713. } );
  32714. // PUBLIC STUFF
  32715. QUnit.test( "isMeshNormalMaterial", ( assert ) => {
  32716. assert.ok( false, "everything's gonna be alright" );
  32717. } );
  32718. QUnit.test( "copy", ( assert ) => {
  32719. assert.ok( false, "everything's gonna be alright" );
  32720. } );
  32721. } );
  32722. } );
  32723. /**
  32724. * @author TristanVALCKE / https://github.com/Itee
  32725. */
  32726. /* global QUnit */
  32727. QUnit.module( 'Materials', () => {
  32728. QUnit.module.todo( 'MeshPhongMaterial', () => {
  32729. // INHERITANCE
  32730. QUnit.test( "Extending", ( assert ) => {
  32731. assert.ok( false, "everything's gonna be alright" );
  32732. } );
  32733. // INSTANCING
  32734. QUnit.test( "Instancing", ( assert ) => {
  32735. assert.ok( false, "everything's gonna be alright" );
  32736. } );
  32737. // PUBLIC STUFF
  32738. QUnit.test( "isMeshPhongMaterial", ( assert ) => {
  32739. assert.ok( false, "everything's gonna be alright" );
  32740. } );
  32741. QUnit.test( "copy", ( assert ) => {
  32742. assert.ok( false, "everything's gonna be alright" );
  32743. } );
  32744. } );
  32745. } );
  32746. /**
  32747. * @author TristanVALCKE / https://github.com/Itee
  32748. */
  32749. /* global QUnit */
  32750. QUnit.module( 'Materials', () => {
  32751. QUnit.module.todo( 'MeshPhysicalMaterial', () => {
  32752. // INHERITANCE
  32753. QUnit.test( "Extending", ( assert ) => {
  32754. assert.ok( false, "everything's gonna be alright" );
  32755. } );
  32756. // INSTANCING
  32757. QUnit.test( "Instancing", ( assert ) => {
  32758. assert.ok( false, "everything's gonna be alright" );
  32759. } );
  32760. // PUBLIC STUFF
  32761. QUnit.test( "isMeshPhysicalMaterial", ( assert ) => {
  32762. assert.ok( false, "everything's gonna be alright" );
  32763. } );
  32764. QUnit.test( "copy", ( assert ) => {
  32765. assert.ok( false, "everything's gonna be alright" );
  32766. } );
  32767. } );
  32768. } );
  32769. /**
  32770. * @author TristanVALCKE / https://github.com/Itee
  32771. */
  32772. /* global QUnit */
  32773. QUnit.module( 'Materials', () => {
  32774. QUnit.module.todo( 'MeshStandardMaterial', () => {
  32775. // INHERITANCE
  32776. QUnit.test( "Extending", ( assert ) => {
  32777. assert.ok( false, "everything's gonna be alright" );
  32778. } );
  32779. // INSTANCING
  32780. QUnit.test( "Instancing", ( assert ) => {
  32781. assert.ok( false, "everything's gonna be alright" );
  32782. } );
  32783. // PUBLIC STUFF
  32784. QUnit.test( "isMeshStandardMaterial", ( assert ) => {
  32785. assert.ok( false, "everything's gonna be alright" );
  32786. } );
  32787. QUnit.test( "copy", ( assert ) => {
  32788. assert.ok( false, "everything's gonna be alright" );
  32789. } );
  32790. } );
  32791. } );
  32792. /**
  32793. * @author TristanVALCKE / https://github.com/Itee
  32794. */
  32795. /* global QUnit */
  32796. QUnit.module( 'Materials', () => {
  32797. QUnit.module.todo( 'MeshToonMaterial', () => {
  32798. // INHERITANCE
  32799. QUnit.test( "Extending", ( assert ) => {
  32800. assert.ok( false, "everything's gonna be alright" );
  32801. } );
  32802. // INSTANCING
  32803. QUnit.test( "Instancing", ( assert ) => {
  32804. assert.ok( false, "everything's gonna be alright" );
  32805. } );
  32806. // PUBLIC STUFF
  32807. QUnit.test( "isMeshToonMaterial", ( assert ) => {
  32808. assert.ok( false, "everything's gonna be alright" );
  32809. } );
  32810. QUnit.test( "copy", ( assert ) => {
  32811. assert.ok( false, "everything's gonna be alright" );
  32812. } );
  32813. } );
  32814. } );
  32815. /**
  32816. * @author TristanVALCKE / https://github.com/Itee
  32817. */
  32818. /* global QUnit */
  32819. QUnit.module( 'Materials', () => {
  32820. QUnit.module.todo( 'PointsMaterial', () => {
  32821. // INHERITANCE
  32822. QUnit.test( "Extending", ( assert ) => {
  32823. assert.ok( false, "everything's gonna be alright" );
  32824. } );
  32825. // INSTANCING
  32826. QUnit.test( "Instancing", ( assert ) => {
  32827. assert.ok( false, "everything's gonna be alright" );
  32828. } );
  32829. // PUBLIC STUFF
  32830. QUnit.test( "isPointsMaterial", ( assert ) => {
  32831. assert.ok( false, "everything's gonna be alright" );
  32832. } );
  32833. QUnit.test( "copy", ( assert ) => {
  32834. assert.ok( false, "everything's gonna be alright" );
  32835. } );
  32836. } );
  32837. } );
  32838. /**
  32839. * @author TristanVALCKE / https://github.com/Itee
  32840. */
  32841. /* global QUnit */
  32842. QUnit.module( 'Materials', () => {
  32843. QUnit.module.todo( 'RawShaderMaterial', () => {
  32844. // INHERITANCE
  32845. QUnit.test( "Extending", ( assert ) => {
  32846. assert.ok( false, "everything's gonna be alright" );
  32847. } );
  32848. // INSTANCING
  32849. QUnit.test( "Instancing", ( assert ) => {
  32850. assert.ok( false, "everything's gonna be alright" );
  32851. } );
  32852. // PUBLIC STUFF
  32853. QUnit.test( "isRawShaderMaterial", ( assert ) => {
  32854. assert.ok( false, "everything's gonna be alright" );
  32855. } );
  32856. } );
  32857. } );
  32858. /**
  32859. * @author TristanVALCKE / https://github.com/Itee
  32860. */
  32861. /* global QUnit */
  32862. QUnit.module( 'Materials', () => {
  32863. QUnit.module.todo( 'ShaderMaterial', () => {
  32864. // INHERITANCE
  32865. QUnit.test( "Extending", ( assert ) => {
  32866. assert.ok( false, "everything's gonna be alright" );
  32867. } );
  32868. // INSTANCING
  32869. QUnit.test( "Instancing", ( assert ) => {
  32870. assert.ok( false, "everything's gonna be alright" );
  32871. } );
  32872. // PUBLIC STUFF
  32873. QUnit.test( "isShaderwMaterial", ( assert ) => {
  32874. assert.ok( false, "everything's gonna be alright" );
  32875. } );
  32876. QUnit.test( "copy", ( assert ) => {
  32877. assert.ok( false, "everything's gonna be alright" );
  32878. } );
  32879. QUnit.test( "toJSON", ( assert ) => {
  32880. assert.ok( false, "everything's gonna be alright" );
  32881. } );
  32882. } );
  32883. } );
  32884. /**
  32885. * @author TristanVALCKE / https://github.com/Itee
  32886. */
  32887. /* global QUnit */
  32888. QUnit.module( 'Materials', () => {
  32889. QUnit.module.todo( 'LineBasicMaterial', () => {
  32890. // INHERITANCE
  32891. QUnit.test( "Extending", ( assert ) => {
  32892. assert.ok( false, "everything's gonna be alright" );
  32893. } );
  32894. // INSTANCING
  32895. QUnit.test( "Instancing", ( assert ) => {
  32896. assert.ok( false, "everything's gonna be alright" );
  32897. } );
  32898. // PUBLIC STUFF
  32899. QUnit.test( "isShadowMaterial", ( assert ) => {
  32900. assert.ok( false, "everything's gonna be alright" );
  32901. } );
  32902. } );
  32903. } );
  32904. /**
  32905. * @author TristanVALCKE / https://github.com/Itee
  32906. */
  32907. /* global QUnit */
  32908. QUnit.module( 'Materials', () => {
  32909. QUnit.module.todo( 'SpriteMaterial', () => {
  32910. // INHERITANCE
  32911. QUnit.test( "Extending", ( assert ) => {
  32912. assert.ok( false, "everything's gonna be alright" );
  32913. } );
  32914. // INSTANCING
  32915. QUnit.test( "Instancing", ( assert ) => {
  32916. assert.ok( false, "everything's gonna be alright" );
  32917. } );
  32918. // PUBLIC STUFF
  32919. QUnit.test( "isSpriteMaterial", ( assert ) => {
  32920. assert.ok( false, "everything's gonna be alright" );
  32921. } );
  32922. QUnit.test( "copy", ( assert ) => {
  32923. assert.ok( false, "everything's gonna be alright" );
  32924. } );
  32925. } );
  32926. } );
  32927. /**
  32928. * @author bhouston / http://exocortex.com
  32929. * @author TristanVALCKE / https://github.com/Itee
  32930. */
  32931. /* global QUnit */
  32932. QUnit.module( 'Maths', () => {
  32933. QUnit.module.todo( 'Box2', () => {
  32934. // INSTANCING
  32935. QUnit.test( "Instancing", ( assert ) => {
  32936. var a = new Box2();
  32937. assert.ok( a.min.equals( posInf2 ), "Passed!" );
  32938. assert.ok( a.max.equals( negInf2 ), "Passed!" );
  32939. var a = new Box2( zero2.clone(), zero2.clone() );
  32940. assert.ok( a.min.equals( zero2 ), "Passed!" );
  32941. assert.ok( a.max.equals( zero2 ), "Passed!" );
  32942. var a = new Box2( zero2.clone(), one2.clone() );
  32943. assert.ok( a.min.equals( zero2 ), "Passed!" );
  32944. assert.ok( a.max.equals( one2 ), "Passed!" );
  32945. } );
  32946. // PUBLIC STUFF
  32947. QUnit.test( "set", ( assert ) => {
  32948. var a = new Box2();
  32949. a.set( zero2, one2 );
  32950. assert.ok( a.min.equals( zero2 ), "Passed!" );
  32951. assert.ok( a.max.equals( one2 ), "Passed!" );
  32952. } );
  32953. QUnit.test( "setFromPoints", ( assert ) => {
  32954. var a = new Box2();
  32955. a.setFromPoints( [ zero2, one2, two2 ] );
  32956. assert.ok( a.min.equals( zero2 ), "Passed!" );
  32957. assert.ok( a.max.equals( two2 ), "Passed!" );
  32958. a.setFromPoints( [ one2 ] );
  32959. assert.ok( a.min.equals( one2 ), "Passed!" );
  32960. assert.ok( a.max.equals( one2 ), "Passed!" );
  32961. a.setFromPoints( [] );
  32962. assert.ok( a.isEmpty(), "Passed!" );
  32963. } );
  32964. QUnit.test( "setFromCenterAndSize", ( assert ) => {
  32965. assert.ok( false, "everything's gonna be alright" );
  32966. } );
  32967. QUnit.test( "clone", ( assert ) => {
  32968. assert.ok( false, "everything's gonna be alright" );
  32969. } );
  32970. QUnit.test( "copy", ( assert ) => {
  32971. var a = new Box2( zero2.clone(), one2.clone() );
  32972. var b = new Box2().copy( a );
  32973. assert.ok( b.min.equals( zero2 ), "Passed!" );
  32974. assert.ok( b.max.equals( one2 ), "Passed!" );
  32975. // ensure that it is a true copy
  32976. a.min = zero2;
  32977. a.max = one2;
  32978. assert.ok( b.min.equals( zero2 ), "Passed!" );
  32979. assert.ok( b.max.equals( one2 ), "Passed!" );
  32980. } );
  32981. QUnit.test( "empty/makeEmpty", ( assert ) => {
  32982. var a = new Box2();
  32983. assert.ok( a.isEmpty(), "Passed!" );
  32984. var a = new Box2( zero2.clone(), one2.clone() );
  32985. assert.ok( ! a.isEmpty(), "Passed!" );
  32986. a.makeEmpty();
  32987. assert.ok( a.isEmpty(), "Passed!" );
  32988. } );
  32989. QUnit.test( "isEmpty", ( assert ) => {
  32990. assert.ok( false, "everything's gonna be alright" );
  32991. } );
  32992. QUnit.test( "getCenter", ( assert ) => {
  32993. var a = new Box2( zero2.clone(), zero2.clone() );
  32994. assert.ok( a.getCenter().equals( zero2 ), "Passed!" );
  32995. var a = new Box2( zero2, one2 );
  32996. var midpoint = one2.clone().multiplyScalar( 0.5 );
  32997. assert.ok( a.getCenter().equals( midpoint ), "Passed!" );
  32998. } );
  32999. QUnit.test( "getSize", ( assert ) => {
  33000. var a = new Box2( zero2.clone(), zero2.clone() );
  33001. assert.ok( a.getSize().equals( zero2 ), "Passed!" );
  33002. var a = new Box2( zero2.clone(), one2.clone() );
  33003. assert.ok( a.getSize().equals( one2 ), "Passed!" );
  33004. } );
  33005. QUnit.test( "expandByPoint", ( assert ) => {
  33006. var a = new Box2( zero2.clone(), zero2.clone() );
  33007. a.expandByPoint( zero2 );
  33008. assert.ok( a.getSize().equals( zero2 ), "Passed!" );
  33009. a.expandByPoint( one2 );
  33010. assert.ok( a.getSize().equals( one2 ), "Passed!" );
  33011. a.expandByPoint( one2.clone().negate() );
  33012. assert.ok( a.getSize().equals( one2.clone().multiplyScalar( 2 ) ), "Passed!" );
  33013. assert.ok( a.getCenter().equals( zero2 ), "Passed!" );
  33014. } );
  33015. QUnit.test( "expandByVector", ( assert ) => {
  33016. var a = new Box2( zero2.clone(), zero2.clone() );
  33017. a.expandByVector( zero2 );
  33018. assert.ok( a.getSize().equals( zero2 ), "Passed!" );
  33019. a.expandByVector( one2 );
  33020. assert.ok( a.getSize().equals( one2.clone().multiplyScalar( 2 ) ), "Passed!" );
  33021. assert.ok( a.getCenter().equals( zero2 ), "Passed!" );
  33022. } );
  33023. QUnit.test( "expandByScalar", ( assert ) => {
  33024. var a = new Box2( zero2.clone(), zero2.clone() );
  33025. a.expandByScalar( 0 );
  33026. assert.ok( a.getSize().equals( zero2 ), "Passed!" );
  33027. a.expandByScalar( 1 );
  33028. assert.ok( a.getSize().equals( one2.clone().multiplyScalar( 2 ) ), "Passed!" );
  33029. assert.ok( a.getCenter().equals( zero2 ), "Passed!" );
  33030. } );
  33031. QUnit.test( "containsPoint", ( assert ) => {
  33032. var a = new Box2( zero2.clone(), zero2.clone() );
  33033. assert.ok( a.containsPoint( zero2 ), "Passed!" );
  33034. assert.ok( ! a.containsPoint( one2 ), "Passed!" );
  33035. a.expandByScalar( 1 );
  33036. assert.ok( a.containsPoint( zero2 ), "Passed!" );
  33037. assert.ok( a.containsPoint( one2 ), "Passed!" );
  33038. assert.ok( a.containsPoint( one2.clone().negate() ), "Passed!" );
  33039. } );
  33040. QUnit.test( "containsBox", ( assert ) => {
  33041. var a = new Box2( zero2.clone(), zero2.clone() );
  33042. var b = new Box2( zero2.clone(), one2.clone() );
  33043. var c = new Box2( one2.clone().negate(), one2.clone() );
  33044. assert.ok( a.containsBox( a ), "Passed!" );
  33045. assert.ok( ! a.containsBox( b ), "Passed!" );
  33046. assert.ok( ! a.containsBox( c ), "Passed!" );
  33047. assert.ok( b.containsBox( a ), "Passed!" );
  33048. assert.ok( c.containsBox( a ), "Passed!" );
  33049. assert.ok( ! b.containsBox( c ), "Passed!" );
  33050. } );
  33051. QUnit.test( "getParameter", ( assert ) => {
  33052. var a = new Box2( zero2.clone(), one2.clone() );
  33053. var b = new Box2( one2.clone().negate(), one2.clone() );
  33054. assert.ok( a.getParameter( new Vector2( 0, 0 ) ).equals( new Vector2( 0, 0 ) ), "Passed!" );
  33055. assert.ok( a.getParameter( new Vector2( 1, 1 ) ).equals( new Vector2( 1, 1 ) ), "Passed!" );
  33056. assert.ok( b.getParameter( new Vector2( - 1, - 1 ) ).equals( new Vector2( 0, 0 ) ), "Passed!" );
  33057. assert.ok( b.getParameter( new Vector2( 0, 0 ) ).equals( new Vector2( 0.5, 0.5 ) ), "Passed!" );
  33058. assert.ok( b.getParameter( new Vector2( 1, 1 ) ).equals( new Vector2( 1, 1 ) ), "Passed!" );
  33059. } );
  33060. QUnit.test( "intersectsBox", ( assert ) => {
  33061. var a = new Box2( zero2.clone(), zero2.clone() );
  33062. var b = new Box2( zero2.clone(), one2.clone() );
  33063. var c = new Box2( one2.clone().negate(), one2.clone() );
  33064. assert.ok( a.intersectsBox( a ), "Passed!" );
  33065. assert.ok( a.intersectsBox( b ), "Passed!" );
  33066. assert.ok( a.intersectsBox( c ), "Passed!" );
  33067. assert.ok( b.intersectsBox( a ), "Passed!" );
  33068. assert.ok( c.intersectsBox( a ), "Passed!" );
  33069. assert.ok( b.intersectsBox( c ), "Passed!" );
  33070. b.translate( new Vector2( 2, 2 ) );
  33071. assert.ok( ! a.intersectsBox( b ), "Passed!" );
  33072. assert.ok( ! b.intersectsBox( a ), "Passed!" );
  33073. assert.ok( ! b.intersectsBox( c ), "Passed!" );
  33074. } );
  33075. QUnit.test( "clampPoint", ( assert ) => {
  33076. var a = new Box2( zero2.clone(), zero2.clone() );
  33077. var b = new Box2( one2.clone().negate(), one2.clone() );
  33078. assert.ok( a.clampPoint( new Vector2( 0, 0 ) ).equals( new Vector2( 0, 0 ) ), "Passed!" );
  33079. assert.ok( a.clampPoint( new Vector2( 1, 1 ) ).equals( new Vector2( 0, 0 ) ), "Passed!" );
  33080. assert.ok( a.clampPoint( new Vector2( - 1, - 1 ) ).equals( new Vector2( 0, 0 ) ), "Passed!" );
  33081. assert.ok( b.clampPoint( new Vector2( 2, 2 ) ).equals( new Vector2( 1, 1 ) ), "Passed!" );
  33082. assert.ok( b.clampPoint( new Vector2( 1, 1 ) ).equals( new Vector2( 1, 1 ) ), "Passed!" );
  33083. assert.ok( b.clampPoint( new Vector2( 0, 0 ) ).equals( new Vector2( 0, 0 ) ), "Passed!" );
  33084. assert.ok( b.clampPoint( new Vector2( - 1, - 1 ) ).equals( new Vector2( - 1, - 1 ) ), "Passed!" );
  33085. assert.ok( b.clampPoint( new Vector2( - 2, - 2 ) ).equals( new Vector2( - 1, - 1 ) ), "Passed!" );
  33086. } );
  33087. QUnit.test( "distanceToPoint", ( assert ) => {
  33088. var a = new Box2( zero2.clone(), zero2.clone() );
  33089. var b = new Box2( one2.clone().negate(), one2.clone() );
  33090. assert.ok( a.distanceToPoint( new Vector2( 0, 0 ) ) == 0, "Passed!" );
  33091. assert.ok( a.distanceToPoint( new Vector2( 1, 1 ) ) == Math.sqrt( 2 ), "Passed!" );
  33092. assert.ok( a.distanceToPoint( new Vector2( - 1, - 1 ) ) == Math.sqrt( 2 ), "Passed!" );
  33093. assert.ok( b.distanceToPoint( new Vector2( 2, 2 ) ) == Math.sqrt( 2 ), "Passed!" );
  33094. assert.ok( b.distanceToPoint( new Vector2( 1, 1 ) ) == 0, "Passed!" );
  33095. assert.ok( b.distanceToPoint( new Vector2( 0, 0 ) ) == 0, "Passed!" );
  33096. assert.ok( b.distanceToPoint( new Vector2( - 1, - 1 ) ) == 0, "Passed!" );
  33097. assert.ok( b.distanceToPoint( new Vector2( - 2, - 2 ) ) == Math.sqrt( 2 ), "Passed!" );
  33098. } );
  33099. QUnit.test( "intersect", ( assert ) => {
  33100. var a = new Box2( zero2.clone(), zero2.clone() );
  33101. var b = new Box2( zero2.clone(), one2.clone() );
  33102. var c = new Box2( one2.clone().negate(), one2.clone() );
  33103. assert.ok( a.clone().intersect( a ).equals( a ), "Passed!" );
  33104. assert.ok( a.clone().intersect( b ).equals( a ), "Passed!" );
  33105. assert.ok( b.clone().intersect( b ).equals( b ), "Passed!" );
  33106. assert.ok( a.clone().intersect( c ).equals( a ), "Passed!" );
  33107. assert.ok( b.clone().intersect( c ).equals( b ), "Passed!" );
  33108. assert.ok( c.clone().intersect( c ).equals( c ), "Passed!" );
  33109. } );
  33110. QUnit.test( "union", ( assert ) => {
  33111. var a = new Box2( zero2.clone(), zero2.clone() );
  33112. var b = new Box2( zero2.clone(), one2.clone() );
  33113. var c = new Box2( one2.clone().negate(), one2.clone() );
  33114. assert.ok( a.clone().union( a ).equals( a ), "Passed!" );
  33115. assert.ok( a.clone().union( b ).equals( b ), "Passed!" );
  33116. assert.ok( a.clone().union( c ).equals( c ), "Passed!" );
  33117. assert.ok( b.clone().union( c ).equals( c ), "Passed!" );
  33118. } );
  33119. QUnit.test( "translate", ( assert ) => {
  33120. var a = new Box2( zero2.clone(), zero2.clone() );
  33121. var b = new Box2( zero2.clone(), one2.clone() );
  33122. var c = new Box2( one2.clone().negate(), one2.clone() );
  33123. var d = new Box2( one2.clone().negate(), zero2.clone() );
  33124. assert.ok( a.clone().translate( one2 ).equals( new Box2( one2, one2 ) ), "Passed!" );
  33125. assert.ok( a.clone().translate( one2 ).translate( one2.clone().negate() ).equals( a ), "Passed!" );
  33126. assert.ok( d.clone().translate( one2 ).equals( b ), "Passed!" );
  33127. assert.ok( b.clone().translate( one2.clone().negate() ).equals( d ), "Passed!" );
  33128. } );
  33129. QUnit.test( "equals", ( assert ) => {
  33130. assert.ok( false, "everything's gonna be alright" );
  33131. } );
  33132. } );
  33133. } );
  33134. /**
  33135. * @author bhouston / http://exocortex.com
  33136. * @author TristanVALCKE / https://github.com/Itee
  33137. */
  33138. /* global QUnit */
  33139. function compareBox( a, b, threshold ) {
  33140. threshold = threshold || 0.0001;
  33141. return ( a.min.distanceTo( b.min ) < threshold &&
  33142. a.max.distanceTo( b.max ) < threshold );
  33143. }
  33144. QUnit.module( 'Maths', () => {
  33145. QUnit.module.todo( 'Box3', () => {
  33146. // INSTANCING
  33147. QUnit.test( "Instancing", ( assert ) => {
  33148. var a = new Box3();
  33149. assert.ok( a.min.equals( posInf3 ), "Passed!" );
  33150. assert.ok( a.max.equals( negInf3 ), "Passed!" );
  33151. var a = new Box3( zero3.clone(), zero3.clone() );
  33152. assert.ok( a.min.equals( zero3 ), "Passed!" );
  33153. assert.ok( a.max.equals( zero3 ), "Passed!" );
  33154. var a = new Box3( zero3.clone(), one3.clone() );
  33155. assert.ok( a.min.equals( zero3 ), "Passed!" );
  33156. assert.ok( a.max.equals( one3 ), "Passed!" );
  33157. } );
  33158. // PUBLIC STUFF
  33159. QUnit.test( "isBox3", ( assert ) => {
  33160. assert.ok( false, "everything's gonna be alright" );
  33161. } );
  33162. QUnit.test( "set", ( assert ) => {
  33163. var a = new Box3();
  33164. a.set( zero3, one3 );
  33165. assert.ok( a.min.equals( zero3 ), "Passed!" );
  33166. assert.ok( a.max.equals( one3 ), "Passed!" );
  33167. } );
  33168. QUnit.test( "setFromArray", ( assert ) => {
  33169. assert.ok( false, "everything's gonna be alright" );
  33170. } );
  33171. QUnit.test( "setFromBufferAttribute", ( assert ) => {
  33172. var a = new Box3( zero3.clone(), one3.clone() );
  33173. var bigger = new BufferAttribute( new Float32Array( [
  33174. - 2, - 2, - 2, 2, 2, 2, 1.5, 1.5, 1.5, 0, 0, 0
  33175. ] ), 3 );
  33176. var smaller = new BufferAttribute( new Float32Array( [
  33177. - 0.5, - 0.5, - 0.5, 0.5, 0.5, 0.5, 0, 0, 0
  33178. ] ), 3 );
  33179. var newMin = new Vector3( - 2, - 2, - 2 );
  33180. var newMax = new Vector3( 2, 2, 2 );
  33181. a.setFromBufferAttribute( bigger );
  33182. assert.ok( a.min.equals( newMin ), "Bigger box: correct new minimum" );
  33183. assert.ok( a.max.equals( newMax ), "Bigger box: correct new maximum" );
  33184. newMin.set( - 0.5, - 0.5, - 0.5 );
  33185. newMax.set( 0.5, 0.5, 0.5 );
  33186. a.setFromBufferAttribute( smaller );
  33187. assert.ok( a.min.equals( newMin ), "Smaller box: correct new minimum" );
  33188. assert.ok( a.max.equals( newMax ), "Smaller box: correct new maximum" );
  33189. } );
  33190. QUnit.test( "setFromPoints", ( assert ) => {
  33191. var a = new Box3();
  33192. a.setFromPoints( [ zero3, one3, two3 ] );
  33193. assert.ok( a.min.equals( zero3 ), "Passed!" );
  33194. assert.ok( a.max.equals( two3 ), "Passed!" );
  33195. a.setFromPoints( [ one3 ] );
  33196. assert.ok( a.min.equals( one3 ), "Passed!" );
  33197. assert.ok( a.max.equals( one3 ), "Passed!" );
  33198. a.setFromPoints( [] );
  33199. assert.ok( a.isEmpty(), "Passed!" );
  33200. } );
  33201. QUnit.test( "setFromCenterAndSize", ( assert ) => {
  33202. var a = new Box3( zero3.clone(), one3.clone() );
  33203. var b = a.clone();
  33204. var newCenter = one3;
  33205. var newSize = two3;
  33206. a.setFromCenterAndSize( a.getCenter(), a.getSize() );
  33207. assert.ok( a.equals( b ), "Same values: no changes" );
  33208. a.setFromCenterAndSize( newCenter, a.getSize() );
  33209. assert.ok( a.getCenter().equals( newCenter ), "Move center: correct new center" );
  33210. assert.ok( a.getSize().equals( b.getSize() ), "Move center: no change in size" );
  33211. assert.notOk( a.equals( b ), "Move center: no longer equal to old values" );
  33212. a.setFromCenterAndSize( a.getCenter(), newSize );
  33213. assert.ok( a.getCenter().equals( newCenter ), "Resize: no change to center" );
  33214. assert.ok( a.getSize().equals( newSize ), "Resize: correct new size" );
  33215. assert.notOk( a.equals( b ), "Resize: no longer equal to old values" );
  33216. } );
  33217. QUnit.test( "setFromObject/BufferGeometry", ( assert ) => {
  33218. var a = new Box3( zero3.clone(), one3.clone() );
  33219. var object = new Mesh( new BoxBufferGeometry( 2, 2, 2 ) );
  33220. var child = new Mesh( new BoxBufferGeometry( 1, 1, 1 ) );
  33221. object.add( child );
  33222. a.setFromObject( object );
  33223. assert.ok( a.min.equals( new Vector3( - 1, - 1, - 1 ) ), "Correct new minimum" );
  33224. assert.ok( a.max.equals( new Vector3( 1, 1, 1 ) ), "Correct new maximum" );
  33225. } );
  33226. QUnit.test( "clone", ( assert ) => {
  33227. assert.ok( false, "everything's gonna be alright" );
  33228. } );
  33229. QUnit.test( "copy", ( assert ) => {
  33230. var a = new Box3( zero3.clone(), one3.clone() );
  33231. var b = new Box3().copy( a );
  33232. assert.ok( b.min.equals( zero3 ), "Passed!" );
  33233. assert.ok( b.max.equals( one3 ), "Passed!" );
  33234. // ensure that it is a true copy
  33235. a.min = zero3;
  33236. a.max = one3;
  33237. assert.ok( b.min.equals( zero3 ), "Passed!" );
  33238. assert.ok( b.max.equals( one3 ), "Passed!" );
  33239. } );
  33240. QUnit.test( "empty/makeEmpty", ( assert ) => {
  33241. var a = new Box3();
  33242. assert.ok( a.isEmpty(), "Passed!" );
  33243. var a = new Box3( zero3.clone(), one3.clone() );
  33244. assert.ok( ! a.isEmpty(), "Passed!" );
  33245. a.makeEmpty();
  33246. assert.ok( a.isEmpty(), "Passed!" );
  33247. } );
  33248. QUnit.test( "isEmpty", ( assert ) => {
  33249. assert.ok( false, "everything's gonna be alright" );
  33250. } );
  33251. QUnit.test( "getCenter", ( assert ) => {
  33252. var a = new Box3( zero3.clone(), zero3.clone() );
  33253. assert.ok( a.getCenter().equals( zero3 ), "Passed!" );
  33254. var a = new Box3( zero3.clone(), one3.clone() );
  33255. var midpoint = one3.clone().multiplyScalar( 0.5 );
  33256. assert.ok( a.getCenter().equals( midpoint ), "Passed!" );
  33257. } );
  33258. QUnit.test( "getSize", ( assert ) => {
  33259. var a = new Box3( zero3.clone(), zero3.clone() );
  33260. assert.ok( a.getSize().equals( zero3 ), "Passed!" );
  33261. var a = new Box3( zero3.clone(), one3.clone() );
  33262. assert.ok( a.getSize().equals( one3 ), "Passed!" );
  33263. } );
  33264. QUnit.test( "expandByPoint", ( assert ) => {
  33265. var a = new Box3( zero3.clone(), zero3.clone() );
  33266. a.expandByPoint( zero3 );
  33267. assert.ok( a.getSize().equals( zero3 ), "Passed!" );
  33268. a.expandByPoint( one3 );
  33269. assert.ok( a.getSize().equals( one3 ), "Passed!" );
  33270. a.expandByPoint( one3.clone().negate() );
  33271. assert.ok( a.getSize().equals( one3.clone().multiplyScalar( 2 ) ), "Passed!" );
  33272. assert.ok( a.getCenter().equals( zero3 ), "Passed!" );
  33273. } );
  33274. QUnit.test( "expandByVector", ( assert ) => {
  33275. var a = new Box3( zero3.clone(), zero3.clone() );
  33276. a.expandByVector( zero3 );
  33277. assert.ok( a.getSize().equals( zero3 ), "Passed!" );
  33278. a.expandByVector( one3 );
  33279. assert.ok( a.getSize().equals( one3.clone().multiplyScalar( 2 ) ), "Passed!" );
  33280. assert.ok( a.getCenter().equals( zero3 ), "Passed!" );
  33281. } );
  33282. QUnit.test( "expandByScalar", ( assert ) => {
  33283. var a = new Box3( zero3.clone(), zero3.clone() );
  33284. a.expandByScalar( 0 );
  33285. assert.ok( a.getSize().equals( zero3 ), "Passed!" );
  33286. a.expandByScalar( 1 );
  33287. assert.ok( a.getSize().equals( one3.clone().multiplyScalar( 2 ) ), "Passed!" );
  33288. assert.ok( a.getCenter().equals( zero3 ), "Passed!" );
  33289. } );
  33290. QUnit.test( "expandByObject", ( assert ) => {
  33291. var a = new Box3( zero3.clone(), one3.clone() );
  33292. var b = a.clone();
  33293. var bigger = new Mesh( new BoxGeometry( 2, 2, 2 ) );
  33294. var smaller = new Mesh( new BoxGeometry( 0.5, 0.5, 0.5 ) );
  33295. var child = new Mesh( new BoxGeometry( 1, 1, 1 ) );
  33296. // just a bigger box to begin with
  33297. a.expandByObject( bigger );
  33298. assert.ok( a.min.equals( new Vector3( - 1, - 1, - 1 ) ), "Bigger box: correct new minimum" );
  33299. assert.ok( a.max.equals( new Vector3( 1, 1, 1 ) ), "Bigger box: correct new maximum" );
  33300. // a translated, bigger box
  33301. a.copy( b );
  33302. bigger.translateX( 2 );
  33303. a.expandByObject( bigger );
  33304. assert.ok( a.min.equals( new Vector3( 0, - 1, - 1 ) ), "Translated, bigger box: correct new minimum" );
  33305. assert.ok( a.max.equals( new Vector3( 3, 1, 1 ) ), "Translated, bigger box: correct new maximum" );
  33306. // a translated, bigger box with child
  33307. a.copy( b );
  33308. bigger.add( child );
  33309. a.expandByObject( bigger );
  33310. assert.ok( a.min.equals( new Vector3( 0, - 1, - 1 ) ), "Translated, bigger box with child: correct new minimum" );
  33311. assert.ok( a.max.equals( new Vector3( 3, 1, 1 ) ), "Translated, bigger box with child: correct new maximum" );
  33312. // a translated, bigger box with a translated child
  33313. a.copy( b );
  33314. child.translateX( 2 );
  33315. a.expandByObject( bigger );
  33316. assert.ok( a.min.equals( new Vector3( 0, - 1, - 1 ) ), "Translated, bigger box with translated child: correct new minimum" );
  33317. assert.ok( a.max.equals( new Vector3( 4.5, 1, 1 ) ), "Translated, bigger box with translated child: correct new maximum" );
  33318. // a smaller box
  33319. a.copy( b );
  33320. a.expandByObject( smaller );
  33321. assert.ok( a.min.equals( new Vector3( - 0.25, - 0.25, - 0.25 ) ), "Smaller box: correct new minimum" );
  33322. assert.ok( a.max.equals( new Vector3( 1, 1, 1 ) ), "Smaller box: correct new maximum" );
  33323. } );
  33324. QUnit.test( "containsPoint", ( assert ) => {
  33325. var a = new Box3( zero3.clone(), zero3.clone() );
  33326. assert.ok( a.containsPoint( zero3 ), "Passed!" );
  33327. assert.ok( ! a.containsPoint( one3 ), "Passed!" );
  33328. a.expandByScalar( 1 );
  33329. assert.ok( a.containsPoint( zero3 ), "Passed!" );
  33330. assert.ok( a.containsPoint( one3 ), "Passed!" );
  33331. assert.ok( a.containsPoint( one3.clone().negate() ), "Passed!" );
  33332. } );
  33333. QUnit.test( "containsBox", ( assert ) => {
  33334. var a = new Box3( zero3.clone(), zero3.clone() );
  33335. var b = new Box3( zero3.clone(), one3.clone() );
  33336. var c = new Box3( one3.clone().negate(), one3.clone() );
  33337. assert.ok( a.containsBox( a ), "Passed!" );
  33338. assert.ok( ! a.containsBox( b ), "Passed!" );
  33339. assert.ok( ! a.containsBox( c ), "Passed!" );
  33340. assert.ok( b.containsBox( a ), "Passed!" );
  33341. assert.ok( c.containsBox( a ), "Passed!" );
  33342. assert.ok( ! b.containsBox( c ), "Passed!" );
  33343. } );
  33344. QUnit.test( "getParameter", ( assert ) => {
  33345. var a = new Box3( zero3.clone(), one3.clone() );
  33346. var b = new Box3( one3.clone().negate(), one3.clone() );
  33347. assert.ok( a.getParameter( new Vector3( 0, 0, 0 ) ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
  33348. assert.ok( a.getParameter( new Vector3( 1, 1, 1 ) ).equals( new Vector3( 1, 1, 1 ) ), "Passed!" );
  33349. assert.ok( b.getParameter( new Vector3( - 1, - 1, - 1 ) ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
  33350. assert.ok( b.getParameter( new Vector3( 0, 0, 0 ) ).equals( new Vector3( 0.5, 0.5, 0.5 ) ), "Passed!" );
  33351. assert.ok( b.getParameter( new Vector3( 1, 1, 1 ) ).equals( new Vector3( 1, 1, 1 ) ), "Passed!" );
  33352. } );
  33353. QUnit.test( "intersectsBox", ( assert ) => {
  33354. var a = new Box3( zero3.clone(), zero3.clone() );
  33355. var b = new Box3( zero3.clone(), one3.clone() );
  33356. var c = new Box3( one3.clone().negate(), one3.clone() );
  33357. assert.ok( a.intersectsBox( a ), "Passed!" );
  33358. assert.ok( a.intersectsBox( b ), "Passed!" );
  33359. assert.ok( a.intersectsBox( c ), "Passed!" );
  33360. assert.ok( b.intersectsBox( a ), "Passed!" );
  33361. assert.ok( c.intersectsBox( a ), "Passed!" );
  33362. assert.ok( b.intersectsBox( c ), "Passed!" );
  33363. b.translate( new Vector3( 2, 2, 2 ) );
  33364. assert.ok( ! a.intersectsBox( b ), "Passed!" );
  33365. assert.ok( ! b.intersectsBox( a ), "Passed!" );
  33366. assert.ok( ! b.intersectsBox( c ), "Passed!" );
  33367. } );
  33368. QUnit.test( "intersectsSphere", ( assert ) => {
  33369. var a = new Box3( zero3.clone(), one3.clone() );
  33370. var b = new Sphere( zero3.clone(), 1 );
  33371. assert.ok( a.intersectsSphere( b ), "Passed!" );
  33372. b.translate( new Vector3( 2, 2, 2 ) );
  33373. assert.ok( ! a.intersectsSphere( b ), "Passed!" );
  33374. } );
  33375. QUnit.test( "intersectsPlane", ( assert ) => {
  33376. var a = new Box3( zero3.clone(), one3.clone() );
  33377. var b = new Plane( new Vector3( 0, 1, 0 ), 1 );
  33378. var c = new Plane( new Vector3( 0, 1, 0 ), 1.25 );
  33379. var d = new Plane( new Vector3( 0, - 1, 0 ), 1.25 );
  33380. assert.ok( a.intersectsPlane( b ), "Passed!" );
  33381. assert.ok( ! a.intersectsPlane( c ), "Passed!" );
  33382. assert.ok( ! a.intersectsPlane( d ), "Passed!" );
  33383. } );
  33384. QUnit.test( "clampPoint", ( assert ) => {
  33385. var a = new Box3( zero3.clone(), zero3.clone() );
  33386. var b = new Box3( one3.clone().negate(), one3.clone() );
  33387. assert.ok( a.clampPoint( new Vector3( 0, 0, 0 ) ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
  33388. assert.ok( a.clampPoint( new Vector3( 1, 1, 1 ) ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
  33389. assert.ok( a.clampPoint( new Vector3( - 1, - 1, - 1 ) ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
  33390. assert.ok( b.clampPoint( new Vector3( 2, 2, 2 ) ).equals( new Vector3( 1, 1, 1 ) ), "Passed!" );
  33391. assert.ok( b.clampPoint( new Vector3( 1, 1, 1 ) ).equals( new Vector3( 1, 1, 1 ) ), "Passed!" );
  33392. assert.ok( b.clampPoint( new Vector3( 0, 0, 0 ) ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
  33393. assert.ok( b.clampPoint( new Vector3( - 1, - 1, - 1 ) ).equals( new Vector3( - 1, - 1, - 1 ) ), "Passed!" );
  33394. assert.ok( b.clampPoint( new Vector3( - 2, - 2, - 2 ) ).equals( new Vector3( - 1, - 1, - 1 ) ), "Passed!" );
  33395. } );
  33396. QUnit.test( "distanceToPoint", ( assert ) => {
  33397. var a = new Box3( zero3.clone(), zero3.clone() );
  33398. var b = new Box3( one3.clone().negate(), one3.clone() );
  33399. assert.ok( a.distanceToPoint( new Vector3( 0, 0, 0 ) ) == 0, "Passed!" );
  33400. assert.ok( a.distanceToPoint( new Vector3( 1, 1, 1 ) ) == Math.sqrt( 3 ), "Passed!" );
  33401. assert.ok( a.distanceToPoint( new Vector3( - 1, - 1, - 1 ) ) == Math.sqrt( 3 ), "Passed!" );
  33402. assert.ok( b.distanceToPoint( new Vector3( 2, 2, 2 ) ) == Math.sqrt( 3 ), "Passed!" );
  33403. assert.ok( b.distanceToPoint( new Vector3( 1, 1, 1 ) ) == 0, "Passed!" );
  33404. assert.ok( b.distanceToPoint( new Vector3( 0, 0, 0 ) ) == 0, "Passed!" );
  33405. assert.ok( b.distanceToPoint( new Vector3( - 1, - 1, - 1 ) ) == 0, "Passed!" );
  33406. assert.ok( b.distanceToPoint( new Vector3( - 2, - 2, - 2 ) ) == Math.sqrt( 3 ), "Passed!" );
  33407. } );
  33408. QUnit.test( "getBoundingSphere", ( assert ) => {
  33409. var a = new Box3( zero3.clone(), zero3.clone() );
  33410. var b = new Box3( zero3.clone(), one3.clone() );
  33411. var c = new Box3( one3.clone().negate(), one3.clone() );
  33412. assert.ok( a.getBoundingSphere().equals( new Sphere( zero3, 0 ) ), "Passed!" );
  33413. assert.ok( b.getBoundingSphere().equals( new Sphere( one3.clone().multiplyScalar( 0.5 ), Math.sqrt( 3 ) * 0.5 ) ), "Passed!" );
  33414. assert.ok( c.getBoundingSphere().equals( new Sphere( zero3, Math.sqrt( 12 ) * 0.5 ) ), "Passed!" );
  33415. } );
  33416. QUnit.test( "intersect", ( assert ) => {
  33417. var a = new Box3( zero3.clone(), zero3.clone() );
  33418. var b = new Box3( zero3.clone(), one3.clone() );
  33419. var c = new Box3( one3.clone().negate(), one3.clone() );
  33420. assert.ok( a.clone().intersect( a ).equals( a ), "Passed!" );
  33421. assert.ok( a.clone().intersect( b ).equals( a ), "Passed!" );
  33422. assert.ok( b.clone().intersect( b ).equals( b ), "Passed!" );
  33423. assert.ok( a.clone().intersect( c ).equals( a ), "Passed!" );
  33424. assert.ok( b.clone().intersect( c ).equals( b ), "Passed!" );
  33425. assert.ok( c.clone().intersect( c ).equals( c ), "Passed!" );
  33426. } );
  33427. QUnit.test( "union", ( assert ) => {
  33428. var a = new Box3( zero3.clone(), zero3.clone() );
  33429. var b = new Box3( zero3.clone(), one3.clone() );
  33430. var c = new Box3( one3.clone().negate(), one3.clone() );
  33431. assert.ok( a.clone().union( a ).equals( a ), "Passed!" );
  33432. assert.ok( a.clone().union( b ).equals( b ), "Passed!" );
  33433. assert.ok( a.clone().union( c ).equals( c ), "Passed!" );
  33434. assert.ok( b.clone().union( c ).equals( c ), "Passed!" );
  33435. } );
  33436. QUnit.test( "applyMatrix4", ( assert ) => {
  33437. var a = new Box3( zero3.clone(), zero3.clone() );
  33438. var b = new Box3( zero3.clone(), one3.clone() );
  33439. var c = new Box3( one3.clone().negate(), one3.clone() );
  33440. var d = new Box3( one3.clone().negate(), zero3.clone() );
  33441. var m = new Matrix4().makeTranslation( 1, - 2, 1 );
  33442. var t1 = new Vector3( 1, - 2, 1 );
  33443. assert.ok( compareBox( a.clone().applyMatrix4( m ), a.clone().translate( t1 ) ), "Passed!" );
  33444. assert.ok( compareBox( b.clone().applyMatrix4( m ), b.clone().translate( t1 ) ), "Passed!" );
  33445. assert.ok( compareBox( c.clone().applyMatrix4( m ), c.clone().translate( t1 ) ), "Passed!" );
  33446. assert.ok( compareBox( d.clone().applyMatrix4( m ), d.clone().translate( t1 ) ), "Passed!" );
  33447. } );
  33448. QUnit.test( "translate", ( assert ) => {
  33449. var a = new Box3( zero3.clone(), zero3.clone() );
  33450. var b = new Box3( zero3.clone(), one3.clone() );
  33451. var c = new Box3( one3.clone().negate(), one3.clone() );
  33452. var d = new Box3( one3.clone().negate(), zero3.clone() );
  33453. assert.ok( a.clone().translate( one3 ).equals( new Box3( one3, one3 ) ), "Passed!" );
  33454. assert.ok( a.clone().translate( one3 ).translate( one3.clone().negate() ).equals( a ), "Passed!" );
  33455. assert.ok( d.clone().translate( one3 ).equals( b ), "Passed!" );
  33456. assert.ok( b.clone().translate( one3.clone().negate() ).equals( d ), "Passed!" );
  33457. } );
  33458. QUnit.test( "equals", ( assert ) => {
  33459. assert.ok( false, "everything's gonna be alright" );
  33460. } );
  33461. } );
  33462. } );
  33463. /**
  33464. * @author bhouston / http://exocortex.com
  33465. * @author TristanVALCKE / https://github.com/Itee
  33466. */
  33467. /* global QUnit */
  33468. QUnit.module( 'Maths', () => {
  33469. QUnit.module.todo( 'Color', () => {
  33470. // INSTANCING
  33471. QUnit.test( "Instancing", ( assert ) => {
  33472. // default ctor
  33473. var c = new Color();
  33474. assert.ok( c.r, "Red: " + c.r );
  33475. assert.ok( c.g, "Green: " + c.g );
  33476. assert.ok( c.b, "Blue: " + c.b );
  33477. // rgb ctor
  33478. var c = new Color( 1, 1, 1 );
  33479. assert.ok( c.r == 1, "Passed" );
  33480. assert.ok( c.g == 1, "Passed" );
  33481. assert.ok( c.b == 1, "Passed" );
  33482. } );
  33483. // PUBLIC STUFF
  33484. QUnit.test( "isColor", ( assert ) => {
  33485. assert.ok( false, "everything's gonna be alright" );
  33486. } );
  33487. QUnit.test( "set", ( assert ) => {
  33488. var a = new Color();
  33489. var b = new Color( 0.5, 0, 0 );
  33490. var c = new Color( 0xFF0000 );
  33491. var d = new Color( 0, 1.0, 0 );
  33492. a.set( b );
  33493. assert.ok( a.equals( b ), "Set with Color instance" );
  33494. a.set( 0xFF0000 );
  33495. assert.ok( a.equals( c ), "Set with number" );
  33496. a.set( "rgb(0,255,0)" );
  33497. assert.ok( a.equals( d ), "Set with style" );
  33498. } );
  33499. QUnit.test( "setScalar", ( assert ) => {
  33500. assert.ok( false, "everything's gonna be alright" );
  33501. } );
  33502. QUnit.test( "setHex", ( assert ) => {
  33503. var c = new Color();
  33504. c.setHex( 0xFA8072 );
  33505. assert.ok( c.getHex() == 0xFA8072, "Hex: " + c.getHex() );
  33506. } );
  33507. QUnit.test( "setRGB", ( assert ) => {
  33508. assert.ok( false, "everything's gonna be alright" );
  33509. } );
  33510. QUnit.test( "setHSL", ( assert ) => {
  33511. var c = new Color();
  33512. c.setHSL( 0.75, 1.0, 0.25 );
  33513. var hsl = c.getHSL();
  33514. assert.ok( hsl.h == 0.75, "hue: " + hsl.h );
  33515. assert.ok( hsl.s == 1.00, "saturation: " + hsl.s );
  33516. assert.ok( hsl.l == 0.25, "lightness: " + hsl.l );
  33517. } );
  33518. QUnit.test( "setStyle", ( assert ) => {
  33519. assert.ok( false, "everything's gonna be alright" );
  33520. } );
  33521. QUnit.test( "clone", ( assert ) => {
  33522. var c = new Color( 'teal' );
  33523. var c2 = c.clone();
  33524. assert.ok( c2.getHex() == 0x008080, "Hex c2: " + c2.getHex() );
  33525. } );
  33526. QUnit.test( "copy", ( assert ) => {
  33527. assert.ok( false, "everything's gonna be alright" );
  33528. } );
  33529. QUnit.test( "copyGammaToLinear", ( assert ) => {
  33530. var c = new Color();
  33531. var c2 = new Color();
  33532. c2.setRGB( 0.3, 0.5, 0.9 );
  33533. c.copyGammaToLinear( c2 );
  33534. assert.ok( c.r == 0.09, "Red c: " + c.r + " Red c2: " + c2.r );
  33535. assert.ok( c.g == 0.25, "Green c: " + c.g + " Green c2: " + c2.g );
  33536. assert.ok( c.b == 0.81, "Blue c: " + c.b + " Blue c2: " + c2.b );
  33537. } );
  33538. QUnit.test( "copyLinearToGamma", ( assert ) => {
  33539. var c = new Color();
  33540. var c2 = new Color();
  33541. c2.setRGB( 0.09, 0.25, 0.81 );
  33542. c.copyLinearToGamma( c2 );
  33543. assert.ok( c.r == 0.3, "Red c: " + c.r + " Red c2: " + c2.r );
  33544. assert.ok( c.g == 0.5, "Green c: " + c.g + " Green c2: " + c2.g );
  33545. assert.ok( c.b == 0.9, "Blue c: " + c.b + " Blue c2: " + c2.b );
  33546. } );
  33547. QUnit.test( "convertGammaToLinear", ( assert ) => {
  33548. var c = new Color();
  33549. c.setRGB( 0.3, 0.5, 0.9 );
  33550. c.convertGammaToLinear();
  33551. assert.ok( c.r == 0.09, "Red: " + c.r );
  33552. assert.ok( c.g == 0.25, "Green: " + c.g );
  33553. assert.ok( c.b == 0.81, "Blue: " + c.b );
  33554. } );
  33555. QUnit.test( "convertLinearToGamma", ( assert ) => {
  33556. var c = new Color();
  33557. c.setRGB( 4, 9, 16 );
  33558. c.convertLinearToGamma();
  33559. assert.ok( c.r == 2, "Red: " + c.r );
  33560. assert.ok( c.g == 3, "Green: " + c.g );
  33561. assert.ok( c.b == 4, "Blue: " + c.b );
  33562. } );
  33563. QUnit.test( "getHex", ( assert ) => {
  33564. var c = new Color( 'red' );
  33565. var res = c.getHex();
  33566. assert.ok( res == 0xFF0000, "Hex: " + res );
  33567. } );
  33568. QUnit.test( "getHexString", ( assert ) => {
  33569. var c = new Color( 'tomato' );
  33570. var res = c.getHexString();
  33571. assert.ok( res == 'ff6347', "Hex: " + res );
  33572. } );
  33573. QUnit.test( "getHSL", ( assert ) => {
  33574. var c = new Color( 0x80ffff );
  33575. var hsl = c.getHSL();
  33576. assert.ok( hsl.h == 0.5, "hue: " + hsl.h );
  33577. assert.ok( hsl.s == 1.0, "saturation: " + hsl.s );
  33578. assert.ok( ( Math.round( parseFloat( hsl.l ) * 100 ) / 100 ) == 0.75, "lightness: " + hsl.l );
  33579. } );
  33580. QUnit.test( "getStyle", ( assert ) => {
  33581. var c = new Color( 'plum' );
  33582. var res = c.getStyle();
  33583. assert.ok( res == 'rgb(221,160,221)', "style: " + res );
  33584. } );
  33585. QUnit.test( "offsetHSL", ( assert ) => {
  33586. var a = new Color( "hsl(120,50%,50%)" );
  33587. var b = new Color( 0.36, 0.84, 0.648 );
  33588. a.offsetHSL( 0.1, 0.1, 0.1 );
  33589. assert.ok( Math.abs( a.r - b.r ) <= eps, "Check r" );
  33590. assert.ok( Math.abs( a.g - b.g ) <= eps, "Check g" );
  33591. assert.ok( Math.abs( a.b - b.b ) <= eps, "Check b" );
  33592. } );
  33593. QUnit.test( "add", ( assert ) => {
  33594. var a = new Color( 0x0000FF );
  33595. var b = new Color( 0xFF0000 );
  33596. var c = new Color( 0xFF00FF );
  33597. a.add( b );
  33598. assert.ok( a.equals( c ), "Check new value" );
  33599. } );
  33600. QUnit.test( "addColors", ( assert ) => {
  33601. assert.ok( false, "everything's gonna be alright" );
  33602. } );
  33603. QUnit.test( "addScalar", ( assert ) => {
  33604. var a = new Color( 0.1, 0.0, 0.0 );
  33605. var b = new Color( 0.6, 0.5, 0.5 );
  33606. a.addScalar( 0.5 );
  33607. assert.ok( a.equals( b ), "Check new value" );
  33608. } );
  33609. QUnit.test( "sub", ( assert ) => {
  33610. var a = new Color( 0x0000CC );
  33611. var b = new Color( 0xFF0000 );
  33612. var c = new Color( 0x0000AA );
  33613. a.sub( b );
  33614. assert.strictEqual( a.getHex(), 0xCC, "Difference too large" );
  33615. a.sub( c );
  33616. assert.strictEqual( a.getHex(), 0x22, "Difference fine" );
  33617. } );
  33618. QUnit.test( "multiply", ( assert ) => {
  33619. var a = new Color( 1, 0, 0.5 );
  33620. var b = new Color( 0.5, 1, 0.5 );
  33621. var c = new Color( 0.5, 0, 0.25 );
  33622. a.multiply( b );
  33623. assert.ok( a.equals( c ), "Check new value" );
  33624. } );
  33625. QUnit.test( "multiplyScalar", ( assert ) => {
  33626. var a = new Color( 0.25, 0, 0.5 );
  33627. var b = new Color( 0.5, 0, 1 );
  33628. a.multiplyScalar( 2 );
  33629. assert.ok( a.equals( b ), "Check new value" );
  33630. } );
  33631. QUnit.test( "copyHex", ( assert ) => {
  33632. var c = new Color();
  33633. var c2 = new Color( 0xF5FFFA );
  33634. c.copy( c2 );
  33635. assert.ok( c.getHex() == c2.getHex(), "Hex c: " + c.getHex() + " Hex c2: " + c2.getHex() );
  33636. } );
  33637. QUnit.test( "copyColorString", ( assert ) => {
  33638. var c = new Color();
  33639. var c2 = new Color( 'ivory' );
  33640. c.copy( c2 );
  33641. assert.ok( c.getHex() == c2.getHex(), "Hex c: " + c.getHex() + " Hex c2: " + c2.getHex() );
  33642. } );
  33643. QUnit.test( "setRGB", ( assert ) => {
  33644. var c = new Color();
  33645. c.setRGB( 1, 0.2, 0.1 );
  33646. assert.ok( c.r == 1, "Red: " + c.r );
  33647. assert.ok( c.g == 0.2, "Green: " + c.g );
  33648. assert.ok( c.b == 0.1, "Blue: " + c.b );
  33649. } );
  33650. QUnit.test( "lerp", ( assert ) => {
  33651. var c = new Color();
  33652. var c2 = new Color();
  33653. c.setRGB( 0, 0, 0 );
  33654. c.lerp( c2, 0.2 );
  33655. assert.ok( c.r == 0.2, "Red: " + c.r );
  33656. assert.ok( c.g == 0.2, "Green: " + c.g );
  33657. assert.ok( c.b == 0.2, "Blue: " + c.b );
  33658. } );
  33659. QUnit.test( "equals", ( assert ) => {
  33660. var a = new Color( 0.5, 0.0, 1.0 );
  33661. var b = new Color( 0.5, 1.0, 0.0 );
  33662. assert.strictEqual( a.r, b.r, "Components: r is equal" );
  33663. assert.notStrictEqual( a.g, b.g, "Components: g is not equal" );
  33664. assert.notStrictEqual( a.b, b.b, "Components: b is not equal" );
  33665. assert.notOk( a.equals( b ), "equals(): a not equal b" );
  33666. assert.notOk( b.equals( a ), "equals(): b not equal a" );
  33667. a.copy( b );
  33668. assert.strictEqual( a.r, b.r, "Components after copy(): r is equal" );
  33669. assert.strictEqual( a.g, b.g, "Components after copy(): g is equal" );
  33670. assert.strictEqual( a.b, b.b, "Components after copy(): b is equal" );
  33671. assert.ok( a.equals( b ), "equals() after copy(): a equals b" );
  33672. assert.ok( b.equals( a ), "equals() after copy(): b equals a" );
  33673. } );
  33674. QUnit.test( "fromArray", ( assert ) => {
  33675. var a = new Color();
  33676. var array = [ 0.5, 0.6, 0.7, 0, 1, 0 ];
  33677. a.fromArray( array );
  33678. assert.strictEqual( a.r, 0.5, "No offset: check r" );
  33679. assert.strictEqual( a.g, 0.6, "No offset: check g" );
  33680. assert.strictEqual( a.b, 0.7, "No offset: check b" );
  33681. a.fromArray( array, 3 );
  33682. assert.strictEqual( a.r, 0, "With offset: check r" );
  33683. assert.strictEqual( a.g, 1, "With offset: check g" );
  33684. assert.strictEqual( a.b, 0, "With offset: check b" );
  33685. } );
  33686. QUnit.test( "toArray", ( assert ) => {
  33687. var r = 0.5, g = 1.0, b = 0.0;
  33688. var a = new Color( r, g, b );
  33689. var array = a.toArray();
  33690. assert.strictEqual( array[ 0 ], r, "No array, no offset: check r" );
  33691. assert.strictEqual( array[ 1 ], g, "No array, no offset: check g" );
  33692. assert.strictEqual( array[ 2 ], b, "No array, no offset: check b" );
  33693. var array = [];
  33694. a.toArray( array );
  33695. assert.strictEqual( array[ 0 ], r, "With array, no offset: check r" );
  33696. assert.strictEqual( array[ 1 ], g, "With array, no offset: check g" );
  33697. assert.strictEqual( array[ 2 ], b, "With array, no offset: check b" );
  33698. var array = [];
  33699. a.toArray( array, 1 );
  33700. assert.strictEqual( array[ 0 ], undefined, "With array and offset: check [0]" );
  33701. assert.strictEqual( array[ 1 ], r, "With array and offset: check r" );
  33702. assert.strictEqual( array[ 2 ], g, "With array and offset: check g" );
  33703. assert.strictEqual( array[ 3 ], b, "With array and offset: check b" );
  33704. } );
  33705. QUnit.test( "toJSON", ( assert ) => {
  33706. var a = new Color( 0.0, 0.0, 0.0 );
  33707. var b = new Color( 0.0, 0.5, 0.0 );
  33708. var c = new Color( 1.0, 0.0, 0.0 );
  33709. var d = new Color( 1.0, 1.0, 1.0 );
  33710. assert.strictEqual( a.toJSON(), 0x000000, "Check black" );
  33711. assert.strictEqual( b.toJSON(), 0x007F00, "Check half-blue" );
  33712. assert.strictEqual( c.toJSON(), 0xFF0000, "Check red" );
  33713. assert.strictEqual( d.toJSON(), 0xFFFFFF, "Check white" );
  33714. } );
  33715. // OTHERS
  33716. QUnit.test( "setWithNum", ( assert ) => {
  33717. var c = new Color();
  33718. c.set( 0xFF0000 );
  33719. assert.ok( c.r == 1, "Red: " + c.r );
  33720. assert.ok( c.g === 0, "Green: " + c.g );
  33721. assert.ok( c.b === 0, "Blue: " + c.b );
  33722. } );
  33723. QUnit.test( "setWithString", ( assert ) => {
  33724. var c = new Color();
  33725. c.set( 'silver' );
  33726. assert.ok( c.getHex() == 0xC0C0C0, "Hex c: " + c.getHex() );
  33727. } );
  33728. QUnit.test( "setStyleRGBRed", ( assert ) => {
  33729. var c = new Color();
  33730. c.setStyle( 'rgb(255,0,0)' );
  33731. assert.ok( c.r == 1, "Red: " + c.r );
  33732. assert.ok( c.g === 0, "Green: " + c.g );
  33733. assert.ok( c.b === 0, "Blue: " + c.b );
  33734. } );
  33735. QUnit.test( "setStyleRGBARed", ( assert ) => {
  33736. var c = new Color();
  33737. c.setStyle( 'rgba(255,0,0,0.5)' );
  33738. assert.ok( c.r == 1, "Red: " + c.r );
  33739. assert.ok( c.g === 0, "Green: " + c.g );
  33740. assert.ok( c.b === 0, "Blue: " + c.b );
  33741. } );
  33742. QUnit.test( "setStyleRGBRedWithSpaces", ( assert ) => {
  33743. var c = new Color();
  33744. c.setStyle( 'rgb( 255 , 0, 0 )' );
  33745. assert.ok( c.r == 1, "Red: " + c.r );
  33746. assert.ok( c.g === 0, "Green: " + c.g );
  33747. assert.ok( c.b === 0, "Blue: " + c.b );
  33748. } );
  33749. QUnit.test( "setStyleRGBARedWithSpaces", ( assert ) => {
  33750. var c = new Color();
  33751. c.setStyle( 'rgba( 255, 0, 0 , 1 )' );
  33752. assert.ok( c.r == 1, "Red: " + c.r );
  33753. assert.ok( c.g === 0, "Green: " + c.g );
  33754. assert.ok( c.b === 0, "Blue: " + c.b );
  33755. } );
  33756. QUnit.test( "setStyleRGBPercent", ( assert ) => {
  33757. var c = new Color();
  33758. c.setStyle( 'rgb(100%,50%,10%)' );
  33759. assert.ok( c.r == 1, "Red: " + c.r );
  33760. assert.ok( c.g == 0.5, "Green: " + c.g );
  33761. assert.ok( c.b == 0.1, "Blue: " + c.b );
  33762. } );
  33763. QUnit.test( "setStyleRGBAPercent", ( assert ) => {
  33764. var c = new Color();
  33765. c.setStyle( 'rgba(100%,50%,10%, 0.5)' );
  33766. assert.ok( c.r == 1, "Red: " + c.r );
  33767. assert.ok( c.g == 0.5, "Green: " + c.g );
  33768. assert.ok( c.b == 0.1, "Blue: " + c.b );
  33769. } );
  33770. QUnit.test( "setStyleRGBPercentWithSpaces", ( assert ) => {
  33771. var c = new Color();
  33772. c.setStyle( 'rgb( 100% ,50% , 10% )' );
  33773. assert.ok( c.r == 1, "Red: " + c.r );
  33774. assert.ok( c.g == 0.5, "Green: " + c.g );
  33775. assert.ok( c.b == 0.1, "Blue: " + c.b );
  33776. } );
  33777. QUnit.test( "setStyleRGBAPercentWithSpaces", ( assert ) => {
  33778. var c = new Color();
  33779. c.setStyle( 'rgba( 100% ,50% , 10%, 0.5 )' );
  33780. assert.ok( c.r == 1, "Red: " + c.r );
  33781. assert.ok( c.g == 0.5, "Green: " + c.g );
  33782. assert.ok( c.b == 0.1, "Blue: " + c.b );
  33783. } );
  33784. QUnit.test( "setStyleHSLRed", ( assert ) => {
  33785. var c = new Color();
  33786. c.setStyle( 'hsl(360,100%,50%)' );
  33787. assert.ok( c.r == 1, "Red: " + c.r );
  33788. assert.ok( c.g === 0, "Green: " + c.g );
  33789. assert.ok( c.b === 0, "Blue: " + c.b );
  33790. } );
  33791. QUnit.test( "setStyleHSLARed", ( assert ) => {
  33792. var c = new Color();
  33793. c.setStyle( 'hsla(360,100%,50%,0.5)' );
  33794. assert.ok( c.r == 1, "Red: " + c.r );
  33795. assert.ok( c.g === 0, "Green: " + c.g );
  33796. assert.ok( c.b === 0, "Blue: " + c.b );
  33797. } );
  33798. QUnit.test( "setStyleHSLRedWithSpaces", ( assert ) => {
  33799. var c = new Color();
  33800. c.setStyle( 'hsl(360, 100% , 50% )' );
  33801. assert.ok( c.r == 1, "Red: " + c.r );
  33802. assert.ok( c.g === 0, "Green: " + c.g );
  33803. assert.ok( c.b === 0, "Blue: " + c.b );
  33804. } );
  33805. QUnit.test( "setStyleHSLARedWithSpaces", ( assert ) => {
  33806. var c = new Color();
  33807. c.setStyle( 'hsla( 360, 100% , 50%, 0.5 )' );
  33808. assert.ok( c.r == 1, "Red: " + c.r );
  33809. assert.ok( c.g === 0, "Green: " + c.g );
  33810. assert.ok( c.b === 0, "Blue: " + c.b );
  33811. } );
  33812. QUnit.test( "setStyleHexSkyBlue", ( assert ) => {
  33813. var c = new Color();
  33814. c.setStyle( '#87CEEB' );
  33815. assert.ok( c.getHex() == 0x87CEEB, "Hex c: " + c.getHex() );
  33816. } );
  33817. QUnit.test( "setStyleHexSkyBlueMixed", ( assert ) => {
  33818. var c = new Color();
  33819. c.setStyle( '#87cEeB' );
  33820. assert.ok( c.getHex() == 0x87CEEB, "Hex c: " + c.getHex() );
  33821. } );
  33822. QUnit.test( "setStyleHex2Olive", ( assert ) => {
  33823. var c = new Color();
  33824. c.setStyle( '#F00' );
  33825. assert.ok( c.getHex() == 0xFF0000, "Hex c: " + c.getHex() );
  33826. } );
  33827. QUnit.test( "setStyleHex2OliveMixed", ( assert ) => {
  33828. var c = new Color();
  33829. c.setStyle( '#f00' );
  33830. assert.ok( c.getHex() == 0xFF0000, "Hex c: " + c.getHex() );
  33831. } );
  33832. QUnit.test( "setStyleColorName", ( assert ) => {
  33833. var c = new Color();
  33834. c.setStyle( 'powderblue' );
  33835. assert.ok( c.getHex() == 0xB0E0E6, "Hex c: " + c.getHex() );
  33836. } );
  33837. } );
  33838. } );
  33839. /**
  33840. * @author Mugen87 / https://github.com/Mugen87
  33841. *
  33842. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  33843. *
  33844. */
  33845. function Cylindrical( radius, theta, y ) {
  33846. this.radius = ( radius !== undefined ) ? radius : 1.0; // distance from the origin to a point in the x-z plane
  33847. this.theta = ( theta !== undefined ) ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  33848. this.y = ( y !== undefined ) ? y : 0; // height above the x-z plane
  33849. return this;
  33850. }
  33851. Object.assign( Cylindrical.prototype, {
  33852. set: function ( radius, theta, y ) {
  33853. this.radius = radius;
  33854. this.theta = theta;
  33855. this.y = y;
  33856. return this;
  33857. },
  33858. clone: function () {
  33859. return new this.constructor().copy( this );
  33860. },
  33861. copy: function ( other ) {
  33862. this.radius = other.radius;
  33863. this.theta = other.theta;
  33864. this.y = other.y;
  33865. return this;
  33866. },
  33867. setFromVector3: function ( vec3 ) {
  33868. this.radius = Math.sqrt( vec3.x * vec3.x + vec3.z * vec3.z );
  33869. this.theta = Math.atan2( vec3.x, vec3.z );
  33870. this.y = vec3.y;
  33871. return this;
  33872. }
  33873. } );
  33874. /**
  33875. * @author moraxy / https://github.com/moraxy
  33876. * @author TristanVALCKE / https://github.com/Itee
  33877. */
  33878. /* global QUnit */
  33879. QUnit.module( 'Maths', () => {
  33880. QUnit.module.todo( 'Cylindrical', () => {
  33881. // INSTANCING
  33882. QUnit.test( "Instancing", ( assert ) => {
  33883. var a = new Cylindrical();
  33884. var radius = 10.0;
  33885. var theta = Math.PI;
  33886. var y$$1 = 5;
  33887. assert.strictEqual( a.radius, 1.0, "Default values: check radius" );
  33888. assert.strictEqual( a.theta, 0, "Default values: check theta" );
  33889. assert.strictEqual( a.y, 0, "Default values: check y" );
  33890. var a = new Cylindrical( radius, theta, y$$1 );
  33891. assert.strictEqual( a.radius, radius, "Custom values: check radius" );
  33892. assert.strictEqual( a.theta, theta, "Custom values: check theta" );
  33893. assert.strictEqual( a.y, y$$1, "Custom values: check y" );
  33894. } );
  33895. // PUBLIC STUFF
  33896. QUnit.test( "set", ( assert ) => {
  33897. var a = new Cylindrical();
  33898. var radius = 10.0;
  33899. var theta = Math.PI;
  33900. var y$$1 = 5;
  33901. a.set( radius, theta, y$$1 );
  33902. assert.strictEqual( a.radius, radius, "Check radius" );
  33903. assert.strictEqual( a.theta, theta, "Check theta" );
  33904. assert.strictEqual( a.y, y$$1, "Check y" );
  33905. } );
  33906. QUnit.test( "clone", ( assert ) => {
  33907. var radius = 10.0;
  33908. var theta = Math.PI;
  33909. var y$$1 = 5;
  33910. var a = new Cylindrical( radius, theta, y$$1 );
  33911. var b = a.clone();
  33912. assert.propEqual( a, b, "Check a and b are equal after clone()" );
  33913. a.radius = 1;
  33914. assert.notPropEqual( a, b, "Check a and b are not equal after modification" );
  33915. } );
  33916. QUnit.test( "copy", ( assert ) => {
  33917. var radius = 10.0;
  33918. var theta = Math.PI;
  33919. var y$$1 = 5;
  33920. var a = new Cylindrical( radius, theta, y$$1 );
  33921. var b = new Cylindrical().copy( a );
  33922. assert.propEqual( a, b, "Check a and b are equal after copy()" );
  33923. a.radius = 1;
  33924. assert.notPropEqual( a, b, "Check a and b are not equal after modification" );
  33925. } );
  33926. QUnit.test( "setFromVector3", ( assert ) => {
  33927. var a = new Cylindrical( 1, 1, 1 );
  33928. var b = new Vector3( 0, 0, 0 );
  33929. var c = new Vector3( 3, - 1, - 3 );
  33930. var expected = new Cylindrical( Math.sqrt( 9 + 9 ), Math.atan2( 3, - 3 ), - 1 );
  33931. a.setFromVector3( b );
  33932. assert.strictEqual( a.radius, 0, "Zero-length vector: check radius" );
  33933. assert.strictEqual( a.theta, 0, "Zero-length vector: check theta" );
  33934. assert.strictEqual( a.y, 0, "Zero-length vector: check y" );
  33935. a.setFromVector3( c );
  33936. assert.ok( Math.abs( a.radius - expected.radius ) <= eps, "Normal vector: check radius" );
  33937. assert.ok( Math.abs( a.theta - expected.theta ) <= eps, "Normal vector: check theta" );
  33938. assert.ok( Math.abs( a.y - expected.y ) <= eps, "Normal vector: check y" );
  33939. } );
  33940. } );
  33941. } );
  33942. /**
  33943. * @author bhouston / http://exocortex.com
  33944. * @author TristanVALCKE / https://github.com/Itee
  33945. */
  33946. /* global QUnit */
  33947. const eulerZero = new Euler( 0, 0, 0, "XYZ" );
  33948. const eulerAxyz = new Euler( 1, 0, 0, "XYZ" );
  33949. const eulerAzyx = new Euler( 0, 1, 0, "ZYX" );
  33950. function matrixEquals4( a, b, tolerance ) {
  33951. tolerance = tolerance || 0.0001;
  33952. if ( a.elements.length != b.elements.length ) {
  33953. return false;
  33954. }
  33955. for ( var i = 0, il = a.elements.length; i < il; i ++ ) {
  33956. var delta = a.elements[ i ] - b.elements[ i ];
  33957. if ( delta > tolerance ) {
  33958. return false;
  33959. }
  33960. }
  33961. return true;
  33962. }
  33963. function eulerEquals( a, b, tolerance ) {
  33964. tolerance = tolerance || 0.0001;
  33965. var diff = Math.abs( a.x - b.x ) + Math.abs( a.y - b.y ) + Math.abs( a.z - b.z );
  33966. return ( diff < tolerance );
  33967. }
  33968. function quatEquals( a, b, tolerance ) {
  33969. tolerance = tolerance || 0.0001;
  33970. var diff = Math.abs( a.x - b.x ) + Math.abs( a.y - b.y ) + Math.abs( a.z - b.z ) + Math.abs( a.w - b.w );
  33971. return ( diff < tolerance );
  33972. }
  33973. QUnit.module( 'Maths', () => {
  33974. QUnit.module.todo( 'Euler', () => {
  33975. // INSTANCING
  33976. QUnit.test( "Instancing", ( assert ) => {
  33977. var a = new Euler();
  33978. assert.ok( a.equals( eulerZero ), "Passed!" );
  33979. assert.ok( ! a.equals( eulerAxyz ), "Passed!" );
  33980. assert.ok( ! a.equals( eulerAzyx ), "Passed!" );
  33981. } );
  33982. // STATIC STUFF
  33983. QUnit.test( "RotationOrders", ( assert ) => {
  33984. assert.ok( false, "everything's gonna be alright" );
  33985. } );
  33986. QUnit.test( "DefaultOrder", ( assert ) => {
  33987. assert.ok( false, "everything's gonna be alright" );
  33988. } );
  33989. // PROPERTIES STUFF
  33990. QUnit.test( "x", ( assert ) => {
  33991. assert.ok( false, "everything's gonna be alright" );
  33992. } );
  33993. QUnit.test( "y", ( assert ) => {
  33994. assert.ok( false, "everything's gonna be alright" );
  33995. } );
  33996. QUnit.test( "z", ( assert ) => {
  33997. assert.ok( false, "everything's gonna be alright" );
  33998. } );
  33999. QUnit.test( "order", ( assert ) => {
  34000. assert.ok( false, "everything's gonna be alright" );
  34001. } );
  34002. // PUBLIC STUFF
  34003. QUnit.test( "isEuler", ( assert ) => {
  34004. assert.ok( false, "everything's gonna be alright" );
  34005. } );
  34006. QUnit.test( "set/setFromVector3/toVector3", ( assert ) => {
  34007. var a = new Euler();
  34008. a.set( 0, 1, 0, "ZYX" );
  34009. assert.ok( a.equals( eulerAzyx ), "Passed!" );
  34010. assert.ok( ! a.equals( eulerAxyz ), "Passed!" );
  34011. assert.ok( ! a.equals( eulerZero ), "Passed!" );
  34012. var vec = new Vector3( 0, 1, 0 );
  34013. var b = new Euler().setFromVector3( vec, "ZYX" );
  34014. assert.ok( a.equals( b ), "Passed!" );
  34015. var c = b.toVector3();
  34016. assert.ok( c.equals( vec ), "Passed!" );
  34017. } );
  34018. QUnit.test( "clone/copy/equals", ( assert ) => {
  34019. var a = eulerAxyz.clone();
  34020. assert.ok( a.equals( eulerAxyz ), "Passed!" );
  34021. assert.ok( ! a.equals( eulerZero ), "Passed!" );
  34022. assert.ok( ! a.equals( eulerAzyx ), "Passed!" );
  34023. a.copy( eulerAzyx );
  34024. assert.ok( a.equals( eulerAzyx ), "Passed!" );
  34025. assert.ok( ! a.equals( eulerAxyz ), "Passed!" );
  34026. assert.ok( ! a.equals( eulerZero ), "Passed!" );
  34027. } );
  34028. QUnit.test( "Quaternion.setFromEuler/Euler.fromQuaternion", ( assert ) => {
  34029. var testValues = [ eulerZero, eulerAxyz, eulerAzyx ];
  34030. for ( var i = 0; i < testValues.length; i ++ ) {
  34031. var v = testValues[ i ];
  34032. var q = new Quaternion().setFromEuler( v );
  34033. var v2 = new Euler().setFromQuaternion( q, v.order );
  34034. var q2 = new Quaternion().setFromEuler( v2 );
  34035. assert.ok( quatEquals( q, q2 ), "Passed!" );
  34036. }
  34037. } );
  34038. QUnit.test( "Matrix4.setFromEuler/Euler.fromRotationMatrix", ( assert ) => {
  34039. var testValues = [ eulerZero, eulerAxyz, eulerAzyx ];
  34040. for ( var i = 0; i < testValues.length; i ++ ) {
  34041. var v = testValues[ i ];
  34042. var m = new Matrix4().makeRotationFromEuler( v );
  34043. var v2 = new Euler().setFromRotationMatrix( m, v.order );
  34044. var m2 = new Matrix4().makeRotationFromEuler( v2 );
  34045. assert.ok( matrixEquals4( m, m2, 0.0001 ), "Passed!" );
  34046. }
  34047. } );
  34048. QUnit.test( "reorder", ( assert ) => {
  34049. var testValues = [ eulerZero, eulerAxyz, eulerAzyx ];
  34050. for ( var i = 0; i < testValues.length; i ++ ) {
  34051. var v = testValues[ i ];
  34052. var q = new Quaternion().setFromEuler( v );
  34053. v.reorder( 'YZX' );
  34054. var q2 = new Quaternion().setFromEuler( v );
  34055. assert.ok( quatEquals( q, q2 ), "Passed!" );
  34056. v.reorder( 'ZXY' );
  34057. var q3 = new Quaternion().setFromEuler( v );
  34058. assert.ok( quatEquals( q, q3 ), "Passed!" );
  34059. }
  34060. } );
  34061. QUnit.test( "set/get properties, check callbacks", ( assert ) => {
  34062. var a = new Euler();
  34063. a.onChange( function () {
  34064. assert.step( "set: onChange called" );
  34065. } );
  34066. assert.expect( 8 );
  34067. // should be 4 calls to onChangeCallback
  34068. a.x = 1;
  34069. a.y = 2;
  34070. a.z = 3;
  34071. a.order = "ZYX";
  34072. assert.strictEqual( a.x, 1, "get: check x" );
  34073. assert.strictEqual( a.y, 2, "get: check y" );
  34074. assert.strictEqual( a.z, 3, "get: check z" );
  34075. assert.strictEqual( a.order, "ZYX", "get: check order" );
  34076. } );
  34077. QUnit.test( "clone/copy, check callbacks", ( assert ) => {
  34078. assert.expect( 3 );
  34079. var a = new Euler( 1, 2, 3, "ZXY" );
  34080. var b = new Euler( 4, 5, 6, "XZY" );
  34081. var cb = function () {
  34082. assert.step( "onChange called" );
  34083. };
  34084. a.onChange( cb );
  34085. b.onChange( cb );
  34086. // clone doesn't trigger onChange
  34087. var a = b.clone();
  34088. assert.ok( a.equals( b ), "clone: check if a equals b" );
  34089. // copy triggers onChange once
  34090. var a = new Euler( 1, 2, 3, "ZXY" );
  34091. a.onChange( cb );
  34092. a.copy( b );
  34093. assert.ok( a.equals( b ), "copy: check if a equals b" );
  34094. } );
  34095. QUnit.test( "toArray", ( assert ) => {
  34096. var order = "YXZ";
  34097. var a = new Euler( x, y, z, order );
  34098. var array = a.toArray();
  34099. assert.strictEqual( array[ 0 ], x, "No array, no offset: check x" );
  34100. assert.strictEqual( array[ 1 ], y, "No array, no offset: check y" );
  34101. assert.strictEqual( array[ 2 ], z, "No array, no offset: check z" );
  34102. assert.strictEqual( array[ 3 ], order, "No array, no offset: check order" );
  34103. var array = [];
  34104. a.toArray( array );
  34105. assert.strictEqual( array[ 0 ], x, "With array, no offset: check x" );
  34106. assert.strictEqual( array[ 1 ], y, "With array, no offset: check y" );
  34107. assert.strictEqual( array[ 2 ], z, "With array, no offset: check z" );
  34108. assert.strictEqual( array[ 3 ], order, "With array, no offset: check order" );
  34109. var array = [];
  34110. a.toArray( array, 1 );
  34111. assert.strictEqual( array[ 0 ], undefined, "With array and offset: check [0]" );
  34112. assert.strictEqual( array[ 1 ], x, "With array and offset: check x" );
  34113. assert.strictEqual( array[ 2 ], y, "With array and offset: check y" );
  34114. assert.strictEqual( array[ 3 ], z, "With array and offset: check z" );
  34115. assert.strictEqual( array[ 4 ], order, "With array and offset: check order" );
  34116. } );
  34117. QUnit.test( "fromArray", ( assert ) => {
  34118. assert.expect( 10 );
  34119. var a = new Euler();
  34120. var array = [ x, y, z ];
  34121. var cb = function () {
  34122. assert.step( "onChange called" );
  34123. };
  34124. a.onChange( cb );
  34125. a.fromArray( array );
  34126. assert.strictEqual( a.x, x, "No order: check x" );
  34127. assert.strictEqual( a.y, y, "No order: check y" );
  34128. assert.strictEqual( a.z, z, "No order: check z" );
  34129. assert.strictEqual( a.order, "XYZ", "No order: check order" );
  34130. var a = new Euler();
  34131. var array = [ x, y, z, "ZXY" ];
  34132. a.onChange( cb );
  34133. a.fromArray( array );
  34134. assert.strictEqual( a.x, x, "With order: check x" );
  34135. assert.strictEqual( a.y, y, "With order: check y" );
  34136. assert.strictEqual( a.z, z, "With order: check z" );
  34137. assert.strictEqual( a.order, "ZXY", "With order: check order" );
  34138. } );
  34139. QUnit.test( "onChange", ( assert ) => {
  34140. assert.ok( false, "everything's gonna be alright" );
  34141. } );
  34142. QUnit.test( "onChangeCallback", ( assert ) => {
  34143. assert.ok( false, "everything's gonna be alright" );
  34144. } );
  34145. // OTHERS
  34146. QUnit.test( "gimbalLocalQuat", ( assert ) => {
  34147. // known problematic quaternions
  34148. var q1 = new Quaternion( 0.5207769385244341, - 0.4783214164122354, 0.520776938524434, 0.47832141641223547 );
  34149. var q2 = new Quaternion( 0.11284905712620674, 0.6980437630368944, - 0.11284905712620674, 0.6980437630368944 );
  34150. var eulerOrder = "ZYX";
  34151. // create Euler directly from a Quaternion
  34152. var eViaQ1 = new Euler().setFromQuaternion( q1, eulerOrder ); // there is likely a bug here
  34153. // create Euler from Quaternion via an intermediate Matrix4
  34154. var mViaQ1 = new Matrix4().makeRotationFromQuaternion( q1 );
  34155. var eViaMViaQ1 = new Euler().setFromRotationMatrix( mViaQ1, eulerOrder );
  34156. // the results here are different
  34157. assert.ok( eulerEquals( eViaQ1, eViaMViaQ1 ), "Passed!" ); // this result is correct
  34158. } );
  34159. } );
  34160. } );
  34161. /**
  34162. * @author bhouston / http://exocortex.com
  34163. * @author TristanVALCKE / https://github.com/Itee
  34164. */
  34165. /* global QUnit */
  34166. const unit3 = new Vector3( 1, 0, 0 );
  34167. QUnit.module( 'Maths', () => {
  34168. QUnit.module.todo( 'Frustum', () => {
  34169. // INSTANCING
  34170. QUnit.test( "Instancing", ( assert ) => {
  34171. var a = new Frustum();
  34172. assert.ok( a.planes !== undefined, "Passed!" );
  34173. assert.ok( a.planes.length === 6, "Passed!" );
  34174. var pDefault = new Plane();
  34175. for ( var i = 0; i < 6; i ++ ) {
  34176. assert.ok( a.planes[ i ].equals( pDefault ), "Passed!" );
  34177. }
  34178. var p0 = new Plane( unit3, - 1 );
  34179. var p1 = new Plane( unit3, 1 );
  34180. var p2 = new Plane( unit3, 2 );
  34181. var p3 = new Plane( unit3, 3 );
  34182. var p4 = new Plane( unit3, 4 );
  34183. var p5 = new Plane( unit3, 5 );
  34184. var a = new Frustum( p0, p1, p2, p3, p4, p5 );
  34185. assert.ok( a.planes[ 0 ].equals( p0 ), "Passed!" );
  34186. assert.ok( a.planes[ 1 ].equals( p1 ), "Passed!" );
  34187. assert.ok( a.planes[ 2 ].equals( p2 ), "Passed!" );
  34188. assert.ok( a.planes[ 3 ].equals( p3 ), "Passed!" );
  34189. assert.ok( a.planes[ 4 ].equals( p4 ), "Passed!" );
  34190. assert.ok( a.planes[ 5 ].equals( p5 ), "Passed!" );
  34191. } );
  34192. // PUBLIC STUFF
  34193. QUnit.test( "set", ( assert ) => {
  34194. var a = new Frustum();
  34195. var p0 = new Plane( unit3, - 1 );
  34196. var p1 = new Plane( unit3, 1 );
  34197. var p2 = new Plane( unit3, 2 );
  34198. var p3 = new Plane( unit3, 3 );
  34199. var p4 = new Plane( unit3, 4 );
  34200. var p5 = new Plane( unit3, 5 );
  34201. a.set( p0, p1, p2, p3, p4, p5 );
  34202. assert.ok( a.planes[ 0 ].equals( p0 ), "Check plane #0" );
  34203. assert.ok( a.planes[ 1 ].equals( p1 ), "Check plane #1" );
  34204. assert.ok( a.planes[ 2 ].equals( p2 ), "Check plane #2" );
  34205. assert.ok( a.planes[ 3 ].equals( p3 ), "Check plane #3" );
  34206. assert.ok( a.planes[ 4 ].equals( p4 ), "Check plane #4" );
  34207. assert.ok( a.planes[ 5 ].equals( p5 ), "Check plane #5" );
  34208. } );
  34209. QUnit.test( "clone", ( assert ) => {
  34210. var p0 = new Plane( unit3, - 1 );
  34211. var p1 = new Plane( unit3, 1 );
  34212. var p2 = new Plane( unit3, 2 );
  34213. var p3 = new Plane( unit3, 3 );
  34214. var p4 = new Plane( unit3, 4 );
  34215. var p5 = new Plane( unit3, 5 );
  34216. var b = new Frustum( p0, p1, p2, p3, p4, p5 );
  34217. var a = b.clone();
  34218. assert.ok( a.planes[ 0 ].equals( p0 ), "Passed!" );
  34219. assert.ok( a.planes[ 1 ].equals( p1 ), "Passed!" );
  34220. assert.ok( a.planes[ 2 ].equals( p2 ), "Passed!" );
  34221. assert.ok( a.planes[ 3 ].equals( p3 ), "Passed!" );
  34222. assert.ok( a.planes[ 4 ].equals( p4 ), "Passed!" );
  34223. assert.ok( a.planes[ 5 ].equals( p5 ), "Passed!" );
  34224. // ensure it is a true copy by modifying source
  34225. a.planes[ 0 ].copy( p1 );
  34226. assert.ok( b.planes[ 0 ].equals( p0 ), "Passed!" );
  34227. } );
  34228. QUnit.test( "copy", ( assert ) => {
  34229. var p0 = new Plane( unit3, - 1 );
  34230. var p1 = new Plane( unit3, 1 );
  34231. var p2 = new Plane( unit3, 2 );
  34232. var p3 = new Plane( unit3, 3 );
  34233. var p4 = new Plane( unit3, 4 );
  34234. var p5 = new Plane( unit3, 5 );
  34235. var b = new Frustum( p0, p1, p2, p3, p4, p5 );
  34236. var a = new Frustum().copy( b );
  34237. assert.ok( a.planes[ 0 ].equals( p0 ), "Passed!" );
  34238. assert.ok( a.planes[ 1 ].equals( p1 ), "Passed!" );
  34239. assert.ok( a.planes[ 2 ].equals( p2 ), "Passed!" );
  34240. assert.ok( a.planes[ 3 ].equals( p3 ), "Passed!" );
  34241. assert.ok( a.planes[ 4 ].equals( p4 ), "Passed!" );
  34242. assert.ok( a.planes[ 5 ].equals( p5 ), "Passed!" );
  34243. // ensure it is a true copy by modifying source
  34244. b.planes[ 0 ] = p1;
  34245. assert.ok( a.planes[ 0 ].equals( p0 ), "Passed!" );
  34246. } );
  34247. QUnit.test( "setFromMatrix/makeOrthographic/containsPoint", ( assert ) => {
  34248. var m = new Matrix4().makeOrthographic( - 1, 1, - 1, 1, 1, 100 );
  34249. var a = new Frustum().setFromMatrix( m );
  34250. assert.ok( ! a.containsPoint( new Vector3( 0, 0, 0 ) ), "Passed!" );
  34251. assert.ok( a.containsPoint( new Vector3( 0, 0, - 50 ) ), "Passed!" );
  34252. assert.ok( a.containsPoint( new Vector3( 0, 0, - 1.001 ) ), "Passed!" );
  34253. assert.ok( a.containsPoint( new Vector3( - 1, - 1, - 1.001 ) ), "Passed!" );
  34254. assert.ok( ! a.containsPoint( new Vector3( - 1.1, - 1.1, - 1.001 ) ), "Passed!" );
  34255. assert.ok( a.containsPoint( new Vector3( 1, 1, - 1.001 ) ), "Passed!" );
  34256. assert.ok( ! a.containsPoint( new Vector3( 1.1, 1.1, - 1.001 ) ), "Passed!" );
  34257. assert.ok( a.containsPoint( new Vector3( 0, 0, - 100 ) ), "Passed!" );
  34258. assert.ok( a.containsPoint( new Vector3( - 1, - 1, - 100 ) ), "Passed!" );
  34259. assert.ok( ! a.containsPoint( new Vector3( - 1.1, - 1.1, - 100.1 ) ), "Passed!" );
  34260. assert.ok( a.containsPoint( new Vector3( 1, 1, - 100 ) ), "Passed!" );
  34261. assert.ok( ! a.containsPoint( new Vector3( 1.1, 1.1, - 100.1 ) ), "Passed!" );
  34262. assert.ok( ! a.containsPoint( new Vector3( 0, 0, - 101 ) ), "Passed!" );
  34263. } );
  34264. QUnit.test( "setFromMatrix/makePerspective/containsPoint", ( assert ) => {
  34265. var m = new Matrix4().makePerspective( - 1, 1, 1, - 1, 1, 100 );
  34266. var a = new Frustum().setFromMatrix( m );
  34267. assert.ok( ! a.containsPoint( new Vector3( 0, 0, 0 ) ), "Passed!" );
  34268. assert.ok( a.containsPoint( new Vector3( 0, 0, - 50 ) ), "Passed!" );
  34269. assert.ok( a.containsPoint( new Vector3( 0, 0, - 1.001 ) ), "Passed!" );
  34270. assert.ok( a.containsPoint( new Vector3( - 1, - 1, - 1.001 ) ), "Passed!" );
  34271. assert.ok( ! a.containsPoint( new Vector3( - 1.1, - 1.1, - 1.001 ) ), "Passed!" );
  34272. assert.ok( a.containsPoint( new Vector3( 1, 1, - 1.001 ) ), "Passed!" );
  34273. assert.ok( ! a.containsPoint( new Vector3( 1.1, 1.1, - 1.001 ) ), "Passed!" );
  34274. assert.ok( a.containsPoint( new Vector3( 0, 0, - 99.999 ) ), "Passed!" );
  34275. assert.ok( a.containsPoint( new Vector3( - 99.999, - 99.999, - 99.999 ) ), "Passed!" );
  34276. assert.ok( ! a.containsPoint( new Vector3( - 100.1, - 100.1, - 100.1 ) ), "Passed!" );
  34277. assert.ok( a.containsPoint( new Vector3( 99.999, 99.999, - 99.999 ) ), "Passed!" );
  34278. assert.ok( ! a.containsPoint( new Vector3( 100.1, 100.1, - 100.1 ) ), "Passed!" );
  34279. assert.ok( ! a.containsPoint( new Vector3( 0, 0, - 101 ) ), "Passed!" );
  34280. } );
  34281. QUnit.test( "setFromMatrix/makePerspective/intersectsSphere", ( assert ) => {
  34282. var m = new Matrix4().makePerspective( - 1, 1, 1, - 1, 1, 100 );
  34283. var a = new Frustum().setFromMatrix( m );
  34284. assert.ok( ! a.intersectsSphere( new Sphere( new Vector3( 0, 0, 0 ), 0 ) ), "Passed!" );
  34285. assert.ok( ! a.intersectsSphere( new Sphere( new Vector3( 0, 0, 0 ), 0.9 ) ), "Passed!" );
  34286. assert.ok( a.intersectsSphere( new Sphere( new Vector3( 0, 0, 0 ), 1.1 ) ), "Passed!" );
  34287. assert.ok( a.intersectsSphere( new Sphere( new Vector3( 0, 0, - 50 ), 0 ) ), "Passed!" );
  34288. assert.ok( a.intersectsSphere( new Sphere( new Vector3( 0, 0, - 1.001 ), 0 ) ), "Passed!" );
  34289. assert.ok( a.intersectsSphere( new Sphere( new Vector3( - 1, - 1, - 1.001 ), 0 ) ), "Passed!" );
  34290. assert.ok( ! a.intersectsSphere( new Sphere( new Vector3( - 1.1, - 1.1, - 1.001 ), 0 ) ), "Passed!" );
  34291. assert.ok( a.intersectsSphere( new Sphere( new Vector3( - 1.1, - 1.1, - 1.001 ), 0.5 ) ), "Passed!" );
  34292. assert.ok( a.intersectsSphere( new Sphere( new Vector3( 1, 1, - 1.001 ), 0 ) ), "Passed!" );
  34293. assert.ok( ! a.intersectsSphere( new Sphere( new Vector3( 1.1, 1.1, - 1.001 ), 0 ) ), "Passed!" );
  34294. assert.ok( a.intersectsSphere( new Sphere( new Vector3( 1.1, 1.1, - 1.001 ), 0.5 ) ), "Passed!" );
  34295. assert.ok( a.intersectsSphere( new Sphere( new Vector3( 0, 0, - 99.999 ), 0 ) ), "Passed!" );
  34296. assert.ok( a.intersectsSphere( new Sphere( new Vector3( - 99.999, - 99.999, - 99.999 ), 0 ) ), "Passed!" );
  34297. assert.ok( ! a.intersectsSphere( new Sphere( new Vector3( - 100.1, - 100.1, - 100.1 ), 0 ) ), "Passed!" );
  34298. assert.ok( a.intersectsSphere( new Sphere( new Vector3( - 100.1, - 100.1, - 100.1 ), 0.5 ) ), "Passed!" );
  34299. assert.ok( a.intersectsSphere( new Sphere( new Vector3( 99.999, 99.999, - 99.999 ), 0 ) ), "Passed!" );
  34300. assert.ok( ! a.intersectsSphere( new Sphere( new Vector3( 100.1, 100.1, - 100.1 ), 0 ) ), "Passed!" );
  34301. assert.ok( a.intersectsSphere( new Sphere( new Vector3( 100.1, 100.1, - 100.1 ), 0.2 ) ), "Passed!" );
  34302. assert.ok( ! a.intersectsSphere( new Sphere( new Vector3( 0, 0, - 101 ), 0 ) ), "Passed!" );
  34303. assert.ok( a.intersectsSphere( new Sphere( new Vector3( 0, 0, - 101 ), 1.1 ) ), "Passed!" );
  34304. } );
  34305. QUnit.test( "intersectsObject", ( assert ) => {
  34306. var m = new Matrix4().makePerspective( - 1, 1, 1, - 1, 1, 100 );
  34307. var a = new Frustum().setFromMatrix( m );
  34308. var object = new Mesh( new BoxGeometry( 1, 1, 1 ) );
  34309. var intersects;
  34310. intersects = a.intersectsObject( object );
  34311. assert.notOk( intersects, "No intersection" );
  34312. object.position.set( - 1, - 1, - 1 );
  34313. object.updateMatrixWorld();
  34314. intersects = a.intersectsObject( object );
  34315. assert.ok( intersects, "Successful intersection" );
  34316. object.position.set( 1, 1, 1 );
  34317. object.updateMatrixWorld();
  34318. intersects = a.intersectsObject( object );
  34319. assert.notOk( intersects, "No intersection" );
  34320. } );
  34321. QUnit.test( "intersectsSprite", ( assert ) => {
  34322. var m = new Matrix4().makePerspective( - 1, 1, 1, - 1, 1, 100 );
  34323. var a = new Frustum().setFromMatrix( m );
  34324. var sprite = new Sprite();
  34325. var intersects;
  34326. intersects = a.intersectsSprite( sprite );
  34327. assert.notOk( intersects, "No intersection" );
  34328. sprite.position.set( - 1, - 1, - 1 );
  34329. sprite.updateMatrixWorld();
  34330. intersects = a.intersectsSprite( sprite );
  34331. assert.ok( intersects, "Successful intersection" );
  34332. } );
  34333. QUnit.test( "intersectsSphere", ( assert ) => {
  34334. assert.ok( false, "everything's gonna be alright" );
  34335. } );
  34336. QUnit.test( "intersectsBox", ( assert ) => {
  34337. var m = new Matrix4().makePerspective( - 1, 1, 1, - 1, 1, 100 );
  34338. var a = new Frustum().setFromMatrix( m );
  34339. var box = new Box3( zero3.clone(), one3.clone() );
  34340. var intersects;
  34341. intersects = a.intersectsBox( box );
  34342. assert.notOk( intersects, "No intersection" );
  34343. box.translate( - 1, - 1, - 1 );
  34344. intersects = a.intersectsBox( box );
  34345. assert.ok( intersects, "Successful intersection" );
  34346. } );
  34347. QUnit.test( "containsPoint", ( assert ) => {
  34348. assert.ok( false, "everything's gonna be alright" );
  34349. } );
  34350. } );
  34351. } );
  34352. /**
  34353. * @author tschw
  34354. * @author TristanVALCKE / https://github.com/Itee
  34355. */
  34356. /* global QUnit */
  34357. QUnit.module( 'Maths', () => {
  34358. QUnit.module.todo( 'Interpolant', () => {
  34359. // Since this is an abstract base class, we have to make it concrete in order
  34360. // to QUnit.test its functionality...
  34361. function Mock( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  34362. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  34363. }
  34364. Mock.prototype = Object.create( Interpolant.prototype );
  34365. Mock.prototype.intervalChanged_ = function intervalChanged( i1, t0, t1 ) {
  34366. Mock.captureCall( arguments );
  34367. };
  34368. Mock.prototype.interpolate_ = function interpolate( i1, t0, t, t1 ) {
  34369. Mock.captureCall( arguments );
  34370. return this.copySampleValue_( i1 - 1 );
  34371. };
  34372. Mock.prototype.beforeStart_ = function beforeStart( i, t, t0 ) {
  34373. Mock.captureCall( arguments );
  34374. return this.copySampleValue_( i );
  34375. };
  34376. Mock.prototype.afterEnd_ = function afterEnd( i, tN, t ) {
  34377. Mock.captureCall( arguments );
  34378. return this.copySampleValue_( i );
  34379. };
  34380. // Call capturing facility
  34381. Mock.calls = null;
  34382. Mock.captureCall = function ( args ) {
  34383. if ( Mock.calls !== null ) {
  34384. Mock.calls.push( {
  34385. func: Mock.captureCall.caller.name,
  34386. args: Array.prototype.slice.call( args )
  34387. } );
  34388. }
  34389. };
  34390. // Tests
  34391. // INSTANCING
  34392. QUnit.test( "Instancing", ( assert ) => {
  34393. assert.ok( false, "everything's gonna be alright" );
  34394. } );
  34395. // PUBLIC STUFF
  34396. QUnit.test( "evaluate", ( assert ) => {
  34397. assert.ok( false, "everything's gonna be alright" );
  34398. } );
  34399. // PRIVATE STUFF
  34400. QUnit.test( "DefaultSettings_", ( assert ) => {
  34401. assert.ok( false, "everything's gonna be alright" );
  34402. } );
  34403. QUnit.test( "getSettings_", ( assert ) => {
  34404. assert.ok( false, "everything's gonna be alright" );
  34405. } );
  34406. QUnit.test( "copySampleValue_", ( assert ) => {
  34407. var interpolant = new Mock( null, [ 1, 11, 2, 22, 3, 33 ], 2, [] );
  34408. assert.deepEqual( interpolant.copySampleValue_( 0 ), [ 1, 11 ], "sample fetch (0)" );
  34409. assert.deepEqual( interpolant.copySampleValue_( 1 ), [ 2, 22 ], "sample fetch (1)" );
  34410. assert.deepEqual( interpolant.copySampleValue_( 2 ), [ 3, 33 ], "first sample (2)" );
  34411. } );
  34412. QUnit.test( "evaluate -> intervalChanged_ / interpolate_", ( assert ) => {
  34413. var actual, expect;
  34414. var interpolant = new Mock( [ 11, 22, 33, 44, 55, 66, 77, 88, 99 ], null, 0, null );
  34415. Mock.calls = [];
  34416. interpolant.evaluate( 11 );
  34417. actual = Mock.calls[ 0 ];
  34418. expect = {
  34419. func: 'intervalChanged',
  34420. args: [ 1, 11, 22 ]
  34421. };
  34422. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  34423. actual = Mock.calls[ 1 ];
  34424. expect = {
  34425. func: 'interpolate',
  34426. args: [ 1, 11, 11, 22 ]
  34427. };
  34428. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  34429. assert.ok( Mock.calls.length === 2, "no further calls" );
  34430. Mock.calls = [];
  34431. interpolant.evaluate( 12 ); // same interval
  34432. actual = Mock.calls[ 0 ];
  34433. expect = {
  34434. func: 'interpolate',
  34435. args: [ 1, 11, 12, 22 ]
  34436. };
  34437. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  34438. assert.ok( Mock.calls.length === 1, "no further calls" );
  34439. Mock.calls = [];
  34440. interpolant.evaluate( 22 ); // step forward
  34441. actual = Mock.calls[ 0 ];
  34442. expect = {
  34443. func: 'intervalChanged',
  34444. args: [ 2, 22, 33 ]
  34445. };
  34446. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  34447. actual = Mock.calls[ 1 ];
  34448. expect = {
  34449. func: 'interpolate',
  34450. args: [ 2, 22, 22, 33 ]
  34451. };
  34452. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  34453. assert.ok( Mock.calls.length === 2 );
  34454. Mock.calls = [];
  34455. interpolant.evaluate( 21 ); // step back
  34456. actual = Mock.calls[ 0 ];
  34457. expect = {
  34458. func: 'intervalChanged',
  34459. args: [ 1, 11, 22 ]
  34460. };
  34461. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  34462. actual = Mock.calls[ 1 ];
  34463. expect = {
  34464. func: 'interpolate',
  34465. args: [ 1, 11, 21, 22 ]
  34466. };
  34467. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  34468. assert.ok( Mock.calls.length === 2, "no further calls" );
  34469. Mock.calls = [];
  34470. interpolant.evaluate( 20 ); // same interval
  34471. actual = Mock.calls[ 0 ];
  34472. expect = {
  34473. func: 'interpolate',
  34474. args: [ 1, 11, 20, 22 ]
  34475. };
  34476. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  34477. assert.ok( Mock.calls.length === 1, "no further calls" );
  34478. Mock.calls = [];
  34479. interpolant.evaluate( 43 ); // two steps forward
  34480. actual = Mock.calls[ 0 ];
  34481. expect = {
  34482. func: 'intervalChanged',
  34483. args: [ 3, 33, 44 ]
  34484. };
  34485. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  34486. actual = Mock.calls[ 1 ];
  34487. expect = {
  34488. func: 'interpolate',
  34489. args: [ 3, 33, 43, 44 ]
  34490. };
  34491. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  34492. assert.ok( Mock.calls.length === 2, "no further calls" );
  34493. Mock.calls = [];
  34494. interpolant.evaluate( 12 ); // two steps back
  34495. actual = Mock.calls[ 0 ];
  34496. expect = {
  34497. func: 'intervalChanged',
  34498. args: [ 1, 11, 22 ]
  34499. };
  34500. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  34501. actual = Mock.calls[ 1 ];
  34502. expect = {
  34503. func: 'interpolate',
  34504. args: [ 1, 11, 12, 22 ]
  34505. };
  34506. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  34507. assert.ok( Mock.calls.length === 2, "no further calls" );
  34508. Mock.calls = [];
  34509. interpolant.evaluate( 77 ); // random access
  34510. actual = Mock.calls[ 0 ];
  34511. expect = {
  34512. func: 'intervalChanged',
  34513. args: [ 7, 77, 88 ]
  34514. };
  34515. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  34516. actual = Mock.calls[ 1 ];
  34517. expect = {
  34518. func: 'interpolate',
  34519. args: [ 7, 77, 77, 88 ]
  34520. };
  34521. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  34522. assert.ok( Mock.calls.length === 2, "no further calls" );
  34523. Mock.calls = [];
  34524. interpolant.evaluate( 80 ); // same interval
  34525. actual = Mock.calls[ 0 ];
  34526. expect = {
  34527. func: 'interpolate',
  34528. args: [ 7, 77, 80, 88 ]
  34529. };
  34530. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  34531. assert.ok( Mock.calls.length === 1, "no further calls" );
  34532. Mock.calls = [];
  34533. interpolant.evaluate( 36 ); // random access
  34534. actual = Mock.calls[ 0 ];
  34535. expect = {
  34536. func: 'intervalChanged',
  34537. args: [ 3, 33, 44 ]
  34538. };
  34539. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  34540. actual = Mock.calls[ 1 ];
  34541. expect = {
  34542. func: 'interpolate',
  34543. args: [ 3, 33, 36, 44 ]
  34544. };
  34545. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  34546. assert.ok( Mock.calls.length === 2, "no further calls" );
  34547. Mock.calls = [];
  34548. interpolant.evaluate( 24 ); // fast reset / loop (2nd)
  34549. actual = Mock.calls[ 0 ];
  34550. expect = {
  34551. func: 'intervalChanged',
  34552. args: [ 2, 22, 33 ]
  34553. };
  34554. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  34555. actual = Mock.calls[ 1 ];
  34556. expect = {
  34557. func: 'interpolate',
  34558. args: [ 2, 22, 24, 33 ]
  34559. };
  34560. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  34561. assert.ok( Mock.calls.length === 2, "no further calls" );
  34562. Mock.calls = [];
  34563. interpolant.evaluate( 16 ); // fast reset / loop (2nd)
  34564. actual = Mock.calls[ 0 ];
  34565. expect = {
  34566. func: 'intervalChanged',
  34567. args: [ 1, 11, 22 ]
  34568. };
  34569. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  34570. actual = Mock.calls[ 1 ];
  34571. expect = {
  34572. func: 'interpolate',
  34573. args: [ 1, 11, 16, 22 ]
  34574. };
  34575. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  34576. assert.ok( Mock.calls.length === 2, "no further calls" );
  34577. } );
  34578. QUnit.test( "evaulate -> beforeStart_ [once]", ( assert ) => {
  34579. var actual, expect;
  34580. var interpolant = new Mock( [ 11, 22, 33 ], null, 0, null );
  34581. Mock.calls = [];
  34582. interpolant.evaluate( 10 );
  34583. actual = Mock.calls[ 0 ];
  34584. expect = {
  34585. func: 'beforeStart',
  34586. args: [ 0, 10, 11 ]
  34587. };
  34588. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  34589. assert.ok( Mock.calls.length === 1, "no further calls" );
  34590. // Check operation resumes normally and intervalChanged gets called
  34591. Mock.calls = [];
  34592. interpolant.evaluate( 11 );
  34593. actual = Mock.calls[ 0 ];
  34594. expect = {
  34595. func: 'intervalChanged',
  34596. args: [ 1, 11, 22 ]
  34597. };
  34598. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  34599. actual = Mock.calls[ 1 ];
  34600. expect = {
  34601. func: 'interpolate',
  34602. args: [ 1, 11, 11, 22 ]
  34603. };
  34604. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  34605. assert.ok( Mock.calls.length === 2, "no further calls" );
  34606. // Back off-bounds
  34607. Mock.calls = [];
  34608. interpolant.evaluate( 10 );
  34609. actual = Mock.calls[ 0 ];
  34610. expect = {
  34611. func: 'beforeStart',
  34612. args: [ 0, 10, 11 ]
  34613. };
  34614. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  34615. assert.ok( Mock.calls.length === 1, "no further calls" );
  34616. } );
  34617. QUnit.test( "evaluate -> beforeStart_ [twice]", ( assert ) => {
  34618. var actual, expect;
  34619. var interpolant = new Mock( [ 11, 22, 33 ], null, 0, null );
  34620. Mock.calls = [];
  34621. interpolant.evaluate( 10 );
  34622. actual = Mock.calls[ 0 ];
  34623. expect = {
  34624. func: 'beforeStart',
  34625. args: [ 0, 10, 11 ]
  34626. };
  34627. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  34628. assert.ok( Mock.calls.length === 1, "no further calls" );
  34629. Mock.calls = []; // again - consider changed state
  34630. interpolant.evaluate( 10 );
  34631. actual = Mock.calls[ 0 ];
  34632. expect = {
  34633. func: 'beforeStart',
  34634. args: [ 0, 10, 11 ]
  34635. };
  34636. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  34637. assert.ok( Mock.calls.length === 1, "no further calls" );
  34638. // Check operation resumes normally and intervalChanged gets called
  34639. Mock.calls = [];
  34640. interpolant.evaluate( 11 );
  34641. actual = Mock.calls[ 0 ];
  34642. expect = {
  34643. func: 'intervalChanged',
  34644. args: [ 1, 11, 22 ]
  34645. };
  34646. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  34647. actual = Mock.calls[ 1 ];
  34648. expect = {
  34649. func: 'interpolate',
  34650. args: [ 1, 11, 11, 22 ]
  34651. };
  34652. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  34653. assert.ok( Mock.calls.length === 2, "no further calls" );
  34654. } );
  34655. QUnit.test( "evaluate -> afterEnd_ [once]", ( assert ) => {
  34656. var actual, expect;
  34657. var interpolant = new Mock( [ 11, 22, 33 ], null, 0, null );
  34658. Mock.calls = [];
  34659. interpolant.evaluate( 33 );
  34660. actual = Mock.calls[ 0 ];
  34661. expect = {
  34662. func: 'afterEnd',
  34663. args: [ 2, 33, 33 ]
  34664. };
  34665. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  34666. assert.ok( Mock.calls.length === 1, "no further calls" );
  34667. // Check operation resumes normally and intervalChanged gets called
  34668. Mock.calls = [];
  34669. interpolant.evaluate( 32 );
  34670. actual = Mock.calls[ 0 ];
  34671. expect = {
  34672. func: 'intervalChanged',
  34673. args: [ 2, 22, 33 ]
  34674. };
  34675. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  34676. actual = Mock.calls[ 1 ];
  34677. expect = {
  34678. func: 'interpolate',
  34679. args: [ 2, 22, 32, 33 ]
  34680. };
  34681. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  34682. assert.ok( Mock.calls.length === 2, "no further calls" );
  34683. // Back off-bounds
  34684. Mock.calls = [];
  34685. interpolant.evaluate( 33 );
  34686. actual = Mock.calls[ 0 ];
  34687. expect = {
  34688. func: 'afterEnd',
  34689. args: [ 2, 33, 33 ]
  34690. };
  34691. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  34692. assert.ok( Mock.calls.length === 1, "no further calls" );
  34693. } );
  34694. QUnit.test( "evaluate -> afterEnd_ [twice]", ( assert ) => {
  34695. var actual, expect;
  34696. var interpolant = new Mock( [ 11, 22, 33 ], null, 0, null );
  34697. Mock.calls = [];
  34698. interpolant.evaluate( 33 );
  34699. actual = Mock.calls[ 0 ];
  34700. expect = {
  34701. func: 'afterEnd',
  34702. args: [ 2, 33, 33 ]
  34703. };
  34704. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  34705. assert.ok( Mock.calls.length === 1, "no further calls" );
  34706. Mock.calls = []; // again - consider changed state
  34707. interpolant.evaluate( 33 );
  34708. actual = Mock.calls[ 0 ];
  34709. expect = {
  34710. func: 'afterEnd',
  34711. args: [ 2, 33, 33 ]
  34712. };
  34713. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  34714. assert.ok( Mock.calls.length === 1, "no further calls" );
  34715. // Check operation resumes normally and intervalChanged gets called
  34716. Mock.calls = [];
  34717. interpolant.evaluate( 32 );
  34718. actual = Mock.calls[ 0 ];
  34719. expect = {
  34720. func: 'intervalChanged',
  34721. args: [ 2, 22, 33 ]
  34722. };
  34723. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  34724. actual = Mock.calls[ 1 ];
  34725. expect = {
  34726. func: 'interpolate',
  34727. args: [ 2, 22, 32, 33 ]
  34728. };
  34729. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  34730. assert.ok( Mock.calls.length === 2, "no further calls" );
  34731. } );
  34732. } );
  34733. } );
  34734. /**
  34735. * @author bhouston / http://exocortex.com
  34736. * @author TristanVALCKE / https://github.com/Itee
  34737. */
  34738. /* global QUnit */
  34739. QUnit.module( 'Maths', () => {
  34740. QUnit.module.todo( 'Line3', () => {
  34741. // INSTANCING
  34742. QUnit.test( "Instancing", ( assert ) => {
  34743. var a = new Line3();
  34744. assert.ok( a.start.equals( zero3 ), "Passed!" );
  34745. assert.ok( a.end.equals( zero3 ), "Passed!" );
  34746. var a = new Line3( two3.clone(), one3.clone() );
  34747. assert.ok( a.start.equals( two3 ), "Passed!" );
  34748. assert.ok( a.end.equals( one3 ), "Passed!" );
  34749. } );
  34750. // PUBLIC STUFF
  34751. QUnit.test( "set", ( assert ) => {
  34752. var a = new Line3();
  34753. a.set( one3, one3 );
  34754. assert.ok( a.start.equals( one3 ), "Passed!" );
  34755. assert.ok( a.end.equals( one3 ), "Passed!" );
  34756. } );
  34757. QUnit.test( "copy/equals", ( assert ) => {
  34758. var a = new Line3( zero3.clone(), one3.clone() );
  34759. var b = new Line3().copy( a );
  34760. assert.ok( b.start.equals( zero3 ), "Passed!" );
  34761. assert.ok( b.end.equals( one3 ), "Passed!" );
  34762. // ensure that it is a true copy
  34763. a.start = zero3;
  34764. a.end = one3;
  34765. assert.ok( b.start.equals( zero3 ), "Passed!" );
  34766. assert.ok( b.end.equals( one3 ), "Passed!" );
  34767. } );
  34768. QUnit.test( "clone/equal", ( assert ) => {
  34769. var a = new Line3();
  34770. var b = new Line3( zero3, new Vector3( 1, 1, 1 ) );
  34771. var c = new Line3( zero3, new Vector3( 1, 1, 0 ) );
  34772. assert.notOk( a.equals( b ), "Check a and b aren't equal" );
  34773. assert.notOk( a.equals( c ), "Check a and c aren't equal" );
  34774. assert.notOk( b.equals( c ), "Check b and c aren't equal" );
  34775. var a = b.clone();
  34776. assert.ok( a.equals( b ), "Check a and b are equal after clone()" );
  34777. assert.notOk( a.equals( c ), "Check a and c aren't equal after clone()" );
  34778. a.set( zero3, zero3 );
  34779. assert.notOk( a.equals( b ), "Check a and b are not equal after modification" );
  34780. } );
  34781. QUnit.test( "getCenter", ( assert ) => {
  34782. assert.ok( false, "everything's gonna be alright" );
  34783. } );
  34784. QUnit.test( "delta", ( assert ) => {
  34785. assert.ok( false, "everything's gonna be alright" );
  34786. } );
  34787. QUnit.test( "distanceSq", ( assert ) => {
  34788. assert.ok( false, "everything's gonna be alright" );
  34789. } );
  34790. QUnit.test( "distance", ( assert ) => {
  34791. var a = new Line3( zero3, zero3 );
  34792. var b = new Line3( zero3, one3 );
  34793. var c = new Line3( one3.clone().negate(), one3 );
  34794. var d = new Line3( two3.clone().multiplyScalar( - 2 ), two3.clone().negate() );
  34795. assert.numEqual( a.distance(), 0, "Check distance for zero-length line" );
  34796. assert.numEqual( b.distance(), Math.sqrt( 3 ), "Check distance for simple line" );
  34797. assert.numEqual( c.distance(), Math.sqrt( 12 ), "Check distance for negative to positive endpoints" );
  34798. assert.numEqual( d.distance(), Math.sqrt( 12 ), "Check distance for negative to negative endpoints" );
  34799. } );
  34800. QUnit.test( "at", ( assert ) => {
  34801. var a = new Line3( one3.clone(), new Vector3( 1, 1, 2 ) );
  34802. assert.ok( a.at( - 1 ).distanceTo( new Vector3( 1, 1, 0 ) ) < 0.0001, "Passed!" );
  34803. assert.ok( a.at( 0 ).distanceTo( one3.clone() ) < 0.0001, "Passed!" );
  34804. assert.ok( a.at( 1 ).distanceTo( new Vector3( 1, 1, 2 ) ) < 0.0001, "Passed!" );
  34805. assert.ok( a.at( 2 ).distanceTo( new Vector3( 1, 1, 3 ) ) < 0.0001, "Passed!" );
  34806. } );
  34807. QUnit.test( "closestPointToPoint/closestPointToPointParameter", ( assert ) => {
  34808. var a = new Line3( one3.clone(), new Vector3( 1, 1, 2 ) );
  34809. // nearby the ray
  34810. assert.ok( a.closestPointToPointParameter( zero3.clone(), true ) == 0, "Passed!" );
  34811. var b1 = a.closestPointToPoint( zero3.clone(), true );
  34812. assert.ok( b1.distanceTo( new Vector3( 1, 1, 1 ) ) < 0.0001, "Passed!" );
  34813. // nearby the ray
  34814. assert.ok( a.closestPointToPointParameter( zero3.clone(), false ) == - 1, "Passed!" );
  34815. var b2 = a.closestPointToPoint( zero3.clone(), false );
  34816. assert.ok( b2.distanceTo( new Vector3( 1, 1, 0 ) ) < 0.0001, "Passed!" );
  34817. // nearby the ray
  34818. assert.ok( a.closestPointToPointParameter( new Vector3( 1, 1, 5 ), true ) == 1, "Passed!" );
  34819. var b = a.closestPointToPoint( new Vector3( 1, 1, 5 ), true );
  34820. assert.ok( b.distanceTo( new Vector3( 1, 1, 2 ) ) < 0.0001, "Passed!" );
  34821. // exactly on the ray
  34822. assert.ok( a.closestPointToPointParameter( one3.clone(), true ) == 0, "Passed!" );
  34823. var c = a.closestPointToPoint( one3.clone(), true );
  34824. assert.ok( c.distanceTo( one3.clone() ) < 0.0001, "Passed!" );
  34825. } );
  34826. QUnit.test( "applyMatrix4", ( assert ) => {
  34827. var a = new Line3( zero3.clone(), two3.clone() );
  34828. var b = new Vector4( two3.x, two3.y, two3.z, 1 );
  34829. var m = new Matrix4().makeTranslation( x, y, z );
  34830. var v = new Vector3( x, y, z );
  34831. a.applyMatrix4( m );
  34832. assert.ok( a.start.equals( v ), "Translation: check start" );
  34833. assert.ok( a.end.equals( new Vector3( 2 + x, 2 + y, 2 + z ) ), "Translation: check start" );
  34834. // reset starting conditions
  34835. a.set( zero3.clone(), two3.clone() );
  34836. m.makeRotationX( Math.PI );
  34837. a.applyMatrix4( m );
  34838. b.applyMatrix4( m );
  34839. assert.ok( a.start.equals( zero3 ), "Rotation: check start" );
  34840. assert.numEqual( a.end.x, b.x / b.w, "Rotation: check end.x" );
  34841. assert.numEqual( a.end.y, b.y / b.w, "Rotation: check end.y" );
  34842. assert.numEqual( a.end.z, b.z / b.w, "Rotation: check end.z" );
  34843. // reset starting conditions
  34844. a.set( zero3.clone(), two3.clone() );
  34845. b.set( two3.x, two3.y, two3.z, 1 );
  34846. m.setPosition( v );
  34847. a.applyMatrix4( m );
  34848. b.applyMatrix4( m );
  34849. assert.ok( a.start.equals( v ), "Both: check start" );
  34850. assert.numEqual( a.end.x, b.x / b.w, "Both: check end.x" );
  34851. assert.numEqual( a.end.y, b.y / b.w, "Both: check end.y" );
  34852. assert.numEqual( a.end.z, b.z / b.w, "Both: check end.z" );
  34853. } );
  34854. QUnit.test( "equals", ( assert ) => {
  34855. assert.ok( false, "everything's gonna be alright" );
  34856. } );
  34857. } );
  34858. } );
  34859. /**
  34860. * @author humbletim / https://github.com/humbletim
  34861. * @author TristanVALCKE / https://github.com/Itee
  34862. */
  34863. /* global QUnit */
  34864. QUnit.module( 'Maths', () => {
  34865. QUnit.module.todo( 'Math', () => {
  34866. // PUBLIC STUFF
  34867. QUnit.test( "generateUUID", ( assert ) => {
  34868. var a = _Math.generateUUID();
  34869. var regex = /[A-Z0-9]{8}-[A-Z0-9]{4}-4[A-Z0-9]{3}-[A-Z0-9]{4}-[A-Z0-9]{12}/i;
  34870. // note the fixed '4' here ----------^
  34871. assert.ok( regex.test( a ), "Generated UUID matches the expected pattern" );
  34872. } );
  34873. QUnit.test( "clamp", ( assert ) => {
  34874. assert.strictEqual( _Math.clamp( 0.5, 0, 1 ), 0.5, "Value already within limits" );
  34875. assert.strictEqual( _Math.clamp( 0, 0, 1 ), 0, "Value equal to one limit" );
  34876. assert.strictEqual( _Math.clamp( - 0.1, 0, 1 ), 0, "Value too low" );
  34877. assert.strictEqual( _Math.clamp( 1.1, 0, 1 ), 1, "Value too high" );
  34878. } );
  34879. QUnit.test( "euclideanModulo", ( assert ) => {
  34880. assert.ok( isNaN( _Math.euclideanModulo( 6, 0 ) ), "Division by zero returns NaN" );
  34881. assert.strictEqual( _Math.euclideanModulo( 6, 1 ), 0, "Divison by trivial divisor" );
  34882. assert.strictEqual( _Math.euclideanModulo( 6, 2 ), 0, "Divison by non-trivial divisor" );
  34883. assert.strictEqual( _Math.euclideanModulo( 6, 5 ), 1, "Divison by itself - 1" );
  34884. assert.strictEqual( _Math.euclideanModulo( 6, 6 ), 0, "Divison by itself" );
  34885. assert.strictEqual( _Math.euclideanModulo( 6, 7 ), 6, "Divison by itself + 1" );
  34886. } );
  34887. QUnit.test( "mapLinear", ( assert ) => {
  34888. assert.strictEqual( _Math.mapLinear( 0.5, 0, 1, 0, 10 ), 5, "Value within range" );
  34889. assert.strictEqual( _Math.mapLinear( 0.0, 0, 1, 0, 10 ), 0, "Value equal to lower boundary" );
  34890. assert.strictEqual( _Math.mapLinear( 1.0, 0, 1, 0, 10 ), 10, "Value equal to upper boundary" );
  34891. } );
  34892. QUnit.test( "lerp", ( assert ) => {
  34893. assert.ok( false, "everything's gonna be alright" );
  34894. } );
  34895. QUnit.test( "smoothstep", ( assert ) => {
  34896. assert.strictEqual( _Math.smoothstep( - 1, 0, 2 ), 0, "Value lower than minimum" );
  34897. assert.strictEqual( _Math.smoothstep( 0, 0, 2 ), 0, "Value equal to minimum" );
  34898. assert.strictEqual( _Math.smoothstep( 0.5, 0, 2 ), 0.15625, "Value within limits" );
  34899. assert.strictEqual( _Math.smoothstep( 1, 0, 2 ), 0.5, "Value within limits" );
  34900. assert.strictEqual( _Math.smoothstep( 1.5, 0, 2 ), 0.84375, "Value within limits" );
  34901. assert.strictEqual( _Math.smoothstep( 2, 0, 2 ), 1, "Value equal to maximum" );
  34902. assert.strictEqual( _Math.smoothstep( 3, 0, 2 ), 1, "Value highter than maximum" );
  34903. } );
  34904. QUnit.test( "smootherstep", ( assert ) => {
  34905. assert.ok( false, "everything's gonna be alright" );
  34906. } );
  34907. QUnit.test( "randInt", ( assert ) => {
  34908. var low = 1, high = 3;
  34909. var a = _Math.randInt( low, high );
  34910. assert.ok( a >= low, "Value equal to or higher than lower limit" );
  34911. assert.ok( a <= high, "Value equal to or lower than upper limit" );
  34912. } );
  34913. QUnit.test( "randFloat", ( assert ) => {
  34914. var low = 1, high = 3;
  34915. var a = _Math.randFloat( low, high );
  34916. assert.ok( a >= low, "Value equal to or higher than lower limit" );
  34917. assert.ok( a <= high, "Value equal to or lower than upper limit" );
  34918. } );
  34919. QUnit.test( "randFloatSpread", ( assert ) => {
  34920. var a = _Math.randFloatSpread( 3 );
  34921. assert.ok( a > - 3 / 2, "Value higher than lower limit" );
  34922. assert.ok( a < 3 / 2, "Value lower than upper limit" );
  34923. } );
  34924. QUnit.test( "degToRad", ( assert ) => {
  34925. assert.strictEqual( _Math.degToRad( 0 ), 0, "0 degrees" );
  34926. assert.strictEqual( _Math.degToRad( 90 ), Math.PI / 2, "90 degrees" );
  34927. assert.strictEqual( _Math.degToRad( 180 ), Math.PI, "180 degrees" );
  34928. assert.strictEqual( _Math.degToRad( 360 ), Math.PI * 2, "360 degrees" );
  34929. } );
  34930. QUnit.test( "radToDeg", ( assert ) => {
  34931. assert.strictEqual( _Math.radToDeg( 0 ), 0, "0 radians" );
  34932. assert.strictEqual( _Math.radToDeg( Math.PI / 2 ), 90, "Math.PI / 2 radians" );
  34933. assert.strictEqual( _Math.radToDeg( Math.PI ), 180, "Math.PI radians" );
  34934. assert.strictEqual( _Math.radToDeg( Math.PI * 2 ), 360, "Math.PI * 2 radians" );
  34935. } );
  34936. QUnit.test( "isPowerOfTwo", ( assert ) => {
  34937. assert.strictEqual( _Math.isPowerOfTwo( 0 ), false, "0 is not a PoT" );
  34938. assert.strictEqual( _Math.isPowerOfTwo( 1 ), true, "1 is a PoT" );
  34939. assert.strictEqual( _Math.isPowerOfTwo( 2 ), true, "2 is a PoT" );
  34940. assert.strictEqual( _Math.isPowerOfTwo( 3 ), false, "3 is not a PoT" );
  34941. assert.strictEqual( _Math.isPowerOfTwo( 4 ), true, "4 is a PoT" );
  34942. } );
  34943. QUnit.test( "ceilPowerOfTwo", ( assert ) => {
  34944. assert.strictEqual( _Math.ceilPowerOfTwo( 1 ), 1, "Closest higher PoT to 1 is 1" );
  34945. assert.strictEqual( _Math.ceilPowerOfTwo( 3 ), 4, "Closest higher PoT to 3 is 4" );
  34946. assert.strictEqual( _Math.ceilPowerOfTwo( 4 ), 4, "Closest higher PoT to 4 is 4" );
  34947. } );
  34948. QUnit.test( "floorPowerOfTwo", ( assert ) => {
  34949. assert.strictEqual( _Math.floorPowerOfTwo( 1 ), 1, "Closest lower PoT to 1 is 1" );
  34950. assert.strictEqual( _Math.floorPowerOfTwo( 3 ), 2, "Closest lower PoT to 3 is 2" );
  34951. assert.strictEqual( _Math.floorPowerOfTwo( 4 ), 4, "Closest lower PoT to 4 is 4" );
  34952. } );
  34953. } );
  34954. } );
  34955. /**
  34956. * @author bhouston / http://exocortex.com
  34957. * @author TristanVALCKE / https://github.com/Itee
  34958. */
  34959. /* global QUnit */
  34960. function matrixEquals3( a, b, tolerance ) {
  34961. tolerance = tolerance || 0.0001;
  34962. if ( a.elements.length != b.elements.length ) {
  34963. return false;
  34964. }
  34965. for ( var i = 0, il = a.elements.length; i < il; i ++ ) {
  34966. var delta = a.elements[ i ] - b.elements[ i ];
  34967. if ( delta > tolerance ) {
  34968. return false;
  34969. }
  34970. }
  34971. return true;
  34972. }
  34973. function toMatrix4( m3 ) {
  34974. var result = new Matrix4();
  34975. var re = result.elements;
  34976. var me = m3.elements;
  34977. re[ 0 ] = me[ 0 ];
  34978. re[ 1 ] = me[ 1 ];
  34979. re[ 2 ] = me[ 2 ];
  34980. re[ 4 ] = me[ 3 ];
  34981. re[ 5 ] = me[ 4 ];
  34982. re[ 6 ] = me[ 5 ];
  34983. re[ 8 ] = me[ 6 ];
  34984. re[ 9 ] = me[ 7 ];
  34985. re[ 10 ] = me[ 8 ];
  34986. return result;
  34987. }
  34988. QUnit.module( 'Maths', () => {
  34989. QUnit.module.todo( 'Matrix3', () => {
  34990. // INSTANCING
  34991. QUnit.test( "Instancing", ( assert ) => {
  34992. var a = new Matrix3();
  34993. assert.ok( a.determinant() == 1, "Passed!" );
  34994. var b = new Matrix3().set( 0, 1, 2, 3, 4, 5, 6, 7, 8 );
  34995. assert.ok( b.elements[ 0 ] == 0 );
  34996. assert.ok( b.elements[ 1 ] == 3 );
  34997. assert.ok( b.elements[ 2 ] == 6 );
  34998. assert.ok( b.elements[ 3 ] == 1 );
  34999. assert.ok( b.elements[ 4 ] == 4 );
  35000. assert.ok( b.elements[ 5 ] == 7 );
  35001. assert.ok( b.elements[ 6 ] == 2 );
  35002. assert.ok( b.elements[ 7 ] == 5 );
  35003. assert.ok( b.elements[ 8 ] == 8 );
  35004. assert.ok( ! matrixEquals3( a, b ), "Passed!" );
  35005. } );
  35006. // PUBLIC STUFF
  35007. QUnit.test( "isMatrix3", ( assert ) => {
  35008. assert.ok( false, "everything's gonna be alright" );
  35009. } );
  35010. QUnit.test( "set", ( assert ) => {
  35011. var b = new Matrix3();
  35012. assert.ok( b.determinant() == 1, "Passed!" );
  35013. b.set( 0, 1, 2, 3, 4, 5, 6, 7, 8 );
  35014. assert.ok( b.elements[ 0 ] == 0 );
  35015. assert.ok( b.elements[ 1 ] == 3 );
  35016. assert.ok( b.elements[ 2 ] == 6 );
  35017. assert.ok( b.elements[ 3 ] == 1 );
  35018. assert.ok( b.elements[ 4 ] == 4 );
  35019. assert.ok( b.elements[ 5 ] == 7 );
  35020. assert.ok( b.elements[ 6 ] == 2 );
  35021. assert.ok( b.elements[ 7 ] == 5 );
  35022. assert.ok( b.elements[ 8 ] == 8 );
  35023. } );
  35024. QUnit.test( "identity", ( assert ) => {
  35025. var b = new Matrix3().set( 0, 1, 2, 3, 4, 5, 6, 7, 8 );
  35026. assert.ok( b.elements[ 0 ] == 0 );
  35027. assert.ok( b.elements[ 1 ] == 3 );
  35028. assert.ok( b.elements[ 2 ] == 6 );
  35029. assert.ok( b.elements[ 3 ] == 1 );
  35030. assert.ok( b.elements[ 4 ] == 4 );
  35031. assert.ok( b.elements[ 5 ] == 7 );
  35032. assert.ok( b.elements[ 6 ] == 2 );
  35033. assert.ok( b.elements[ 7 ] == 5 );
  35034. assert.ok( b.elements[ 8 ] == 8 );
  35035. var a = new Matrix3();
  35036. assert.ok( ! matrixEquals3( a, b ), "Passed!" );
  35037. b.identity();
  35038. assert.ok( matrixEquals3( a, b ), "Passed!" );
  35039. } );
  35040. QUnit.test( "clone", ( assert ) => {
  35041. var a = new Matrix3().set( 0, 1, 2, 3, 4, 5, 6, 7, 8 );
  35042. var b = a.clone();
  35043. assert.ok( matrixEquals3( a, b ), "Passed!" );
  35044. // ensure that it is a true copy
  35045. a.elements[ 0 ] = 2;
  35046. assert.ok( ! matrixEquals3( a, b ), "Passed!" );
  35047. } );
  35048. QUnit.test( "copy", ( assert ) => {
  35049. var a = new Matrix3().set( 0, 1, 2, 3, 4, 5, 6, 7, 8 );
  35050. var b = new Matrix3().copy( a );
  35051. assert.ok( matrixEquals3( a, b ), "Passed!" );
  35052. // ensure that it is a true copy
  35053. a.elements[ 0 ] = 2;
  35054. assert.ok( ! matrixEquals3( a, b ), "Passed!" );
  35055. } );
  35056. QUnit.test( "setFromMatrix4", ( assert ) => {
  35057. assert.ok( false, "everything's gonna be alright" );
  35058. } );
  35059. QUnit.test( "applyToBufferAttribute", ( assert ) => {
  35060. var a = new Matrix3().set( 1, 2, 3, 4, 5, 6, 7, 8, 9 );
  35061. var attr = new Float32BufferAttribute( [ 1, 2, 1, 3, 0, 3 ], 3 );
  35062. var expected = new Float32Array( [ 8, 20, 32, 12, 30, 48 ] );
  35063. var applied = a.applyToBufferAttribute( attr );
  35064. assert.deepEqual( applied.array, expected, "Check resulting buffer" );
  35065. } );
  35066. QUnit.test( "multiply/premultiply", ( assert ) => {
  35067. // both simply just wrap multiplyMatrices
  35068. var a = new Matrix3().set( 2, 3, 5, 7, 11, 13, 17, 19, 23 );
  35069. var b = new Matrix3().set( 29, 31, 37, 41, 43, 47, 53, 59, 61 );
  35070. var expectedMultiply = [ 446, 1343, 2491, 486, 1457, 2701, 520, 1569, 2925 ];
  35071. var expectedPremultiply = [ 904, 1182, 1556, 1131, 1489, 1967, 1399, 1845, 2435 ];
  35072. a.multiply( b );
  35073. assert.deepEqual( a.elements, expectedMultiply, "multiply: check result" );
  35074. a.set( 2, 3, 5, 7, 11, 13, 17, 19, 23 );
  35075. a.premultiply( b );
  35076. assert.deepEqual( a.elements, expectedPremultiply, "premultiply: check result" );
  35077. } );
  35078. QUnit.test( "multiplyMatrices", ( assert ) => {
  35079. // Reference:
  35080. //
  35081. // #!/usr/bin/env python
  35082. // from __future__ import print_function
  35083. // import numpy as np
  35084. // print(
  35085. // np.dot(
  35086. // np.reshape([2, 3, 5, 7, 11, 13, 17, 19, 23], (3, 3)),
  35087. // np.reshape([29, 31, 37, 41, 43, 47, 53, 59, 61], (3, 3))
  35088. // )
  35089. // )
  35090. //
  35091. // [[ 446 486 520]
  35092. // [1343 1457 1569]
  35093. // [2491 2701 2925]]
  35094. var lhs = new Matrix3().set( 2, 3, 5, 7, 11, 13, 17, 19, 23 );
  35095. var rhs = new Matrix3().set( 29, 31, 37, 41, 43, 47, 53, 59, 61 );
  35096. var ans = new Matrix3();
  35097. ans.multiplyMatrices( lhs, rhs );
  35098. assert.ok( ans.elements[ 0 ] == 446 );
  35099. assert.ok( ans.elements[ 1 ] == 1343 );
  35100. assert.ok( ans.elements[ 2 ] == 2491 );
  35101. assert.ok( ans.elements[ 3 ] == 486 );
  35102. assert.ok( ans.elements[ 4 ] == 1457 );
  35103. assert.ok( ans.elements[ 5 ] == 2701 );
  35104. assert.ok( ans.elements[ 6 ] == 520 );
  35105. assert.ok( ans.elements[ 7 ] == 1569 );
  35106. assert.ok( ans.elements[ 8 ] == 2925 );
  35107. } );
  35108. QUnit.test( "multiplyScalar", ( assert ) => {
  35109. var b = new Matrix3().set( 0, 1, 2, 3, 4, 5, 6, 7, 8 );
  35110. assert.ok( b.elements[ 0 ] == 0 );
  35111. assert.ok( b.elements[ 1 ] == 3 );
  35112. assert.ok( b.elements[ 2 ] == 6 );
  35113. assert.ok( b.elements[ 3 ] == 1 );
  35114. assert.ok( b.elements[ 4 ] == 4 );
  35115. assert.ok( b.elements[ 5 ] == 7 );
  35116. assert.ok( b.elements[ 6 ] == 2 );
  35117. assert.ok( b.elements[ 7 ] == 5 );
  35118. assert.ok( b.elements[ 8 ] == 8 );
  35119. b.multiplyScalar( 2 );
  35120. assert.ok( b.elements[ 0 ] == 0 * 2 );
  35121. assert.ok( b.elements[ 1 ] == 3 * 2 );
  35122. assert.ok( b.elements[ 2 ] == 6 * 2 );
  35123. assert.ok( b.elements[ 3 ] == 1 * 2 );
  35124. assert.ok( b.elements[ 4 ] == 4 * 2 );
  35125. assert.ok( b.elements[ 5 ] == 7 * 2 );
  35126. assert.ok( b.elements[ 6 ] == 2 * 2 );
  35127. assert.ok( b.elements[ 7 ] == 5 * 2 );
  35128. assert.ok( b.elements[ 8 ] == 8 * 2 );
  35129. } );
  35130. QUnit.test( "determinant", ( assert ) => {
  35131. var a = new Matrix3();
  35132. assert.ok( a.determinant() == 1, "Passed!" );
  35133. a.elements[ 0 ] = 2;
  35134. assert.ok( a.determinant() == 2, "Passed!" );
  35135. a.elements[ 0 ] = 0;
  35136. assert.ok( a.determinant() == 0, "Passed!" );
  35137. // calculated via http://www.euclideanspace.com/maths/algebra/matrix/functions/determinant/threeD/index.htm
  35138. a.set( 2, 3, 4, 5, 13, 7, 8, 9, 11 );
  35139. assert.ok( a.determinant() == - 73, "Passed!" );
  35140. } );
  35141. QUnit.test( "getInverse", ( assert ) => {
  35142. var identity = new Matrix3();
  35143. var identity4 = new Matrix4();
  35144. var a = new Matrix3();
  35145. var b = new Matrix3().set( 0, 0, 0, 0, 0, 0, 0, 0, 0 );
  35146. var c = new Matrix3().set( 0, 0, 0, 0, 0, 0, 0, 0, 0 );
  35147. b.getInverse( a, false );
  35148. assert.ok( matrixEquals3( a, identity ), "Matrix a is identity matrix" );
  35149. try {
  35150. b.getInverse( c, true );
  35151. assert.ok( false, "Should never get here !" ); // should never get here.
  35152. } catch ( err ) {
  35153. assert.ok( true, "Passed: " + err );
  35154. }
  35155. var testMatrices = [
  35156. new Matrix4().makeRotationX( 0.3 ),
  35157. new Matrix4().makeRotationX( - 0.3 ),
  35158. new Matrix4().makeRotationY( 0.3 ),
  35159. new Matrix4().makeRotationY( - 0.3 ),
  35160. new Matrix4().makeRotationZ( 0.3 ),
  35161. new Matrix4().makeRotationZ( - 0.3 ),
  35162. new Matrix4().makeScale( 1, 2, 3 ),
  35163. new Matrix4().makeScale( 1 / 8, 1 / 2, 1 / 3 )
  35164. ];
  35165. for ( var i = 0, il = testMatrices.length; i < il; i ++ ) {
  35166. var m = testMatrices[ i ];
  35167. a.setFromMatrix4( m );
  35168. var mInverse3 = b.getInverse( a );
  35169. var mInverse = toMatrix4( mInverse3 );
  35170. // the determinant of the inverse should be the reciprocal
  35171. assert.ok( Math.abs( a.determinant() * mInverse3.determinant() - 1 ) < 0.0001, "Passed!" );
  35172. assert.ok( Math.abs( m.determinant() * mInverse.determinant() - 1 ) < 0.0001, "Passed!" );
  35173. var mProduct = new Matrix4().multiplyMatrices( m, mInverse );
  35174. assert.ok( Math.abs( mProduct.determinant() - 1 ) < 0.0001, "Passed!" );
  35175. assert.ok( matrixEquals3( mProduct, identity4 ), "Passed!" );
  35176. }
  35177. } );
  35178. QUnit.test( "transpose", ( assert ) => {
  35179. var a = new Matrix3();
  35180. var b = a.clone().transpose();
  35181. assert.ok( matrixEquals3( a, b ), "Passed!" );
  35182. var b = new Matrix3().set( 0, 1, 2, 3, 4, 5, 6, 7, 8 );
  35183. var c = b.clone().transpose();
  35184. assert.ok( ! matrixEquals3( b, c ), "Passed!" );
  35185. c.transpose();
  35186. assert.ok( matrixEquals3( b, c ), "Passed!" );
  35187. } );
  35188. QUnit.test( "getNormalMatrix", ( assert ) => {
  35189. var a = new Matrix3();
  35190. var b = new Matrix4().set(
  35191. 2, 3, 5, 7,
  35192. 11, 13, 17, 19,
  35193. 23, 29, 31, 37,
  35194. 41, 43, 47, 57
  35195. );
  35196. var expected = new Matrix3().set(
  35197. - 1.2857142857142856, 0.7142857142857143, 0.2857142857142857,
  35198. 0.7428571428571429, - 0.7571428571428571, 0.15714285714285714,
  35199. - 0.19999999999999998, 0.3, - 0.09999999999999999
  35200. );
  35201. a.getNormalMatrix( b );
  35202. assert.ok( matrixEquals3( a, expected ), "Check resulting Matrix3" );
  35203. } );
  35204. QUnit.test( "transposeIntoArray", ( assert ) => {
  35205. assert.ok( false, "everything's gonna be alright" );
  35206. } );
  35207. QUnit.test( "setUvTransform", ( assert ) => {
  35208. var a = new Matrix3().set(
  35209. 0.1767766952966369, 0.17677669529663687, 0.32322330470336313,
  35210. - 0.17677669529663687, 0.1767766952966369, 0.5,
  35211. 0, 0, 1
  35212. );
  35213. var b = new Matrix3();
  35214. var params = {
  35215. centerX: 0.5,
  35216. centerY: 0.5,
  35217. offsetX: 0,
  35218. offsetY: 0,
  35219. repeatX: 0.25,
  35220. repeatY: 0.25,
  35221. rotation: 0.7753981633974483
  35222. };
  35223. var expected = new Matrix3().set(
  35224. 0.1785355940258599, 0.17500011904519763, 0.32323214346447127,
  35225. - 0.17500011904519763, 0.1785355940258599, 0.4982322625096689,
  35226. 0, 0, 1
  35227. );
  35228. a.setUvTransform(
  35229. params.offsetX, params.offsetY,
  35230. params.repeatX, params.repeatY,
  35231. params.rotation,
  35232. params.centerX, params.centerY
  35233. );
  35234. b.identity()
  35235. .translate( - params.centerX, - params.centerY )
  35236. .rotate( params.rotation )
  35237. .scale( params.repeatX, params.repeatY )
  35238. .translate( params.centerX, params.centerY )
  35239. .translate( params.offsetX, params.offsetY );
  35240. assert.ok( matrixEquals3( a, expected ), "Check direct method" );
  35241. assert.ok( matrixEquals3( b, expected ), "Check indirect method" );
  35242. } );
  35243. QUnit.test( "scale", ( assert ) => {
  35244. var a = new Matrix3().set( 1, 2, 3, 4, 5, 6, 7, 8, 9 );
  35245. var expected = new Matrix3().set(
  35246. 0.25, 0.5, 0.75,
  35247. 1, 1.25, 1.5,
  35248. 7, 8, 9
  35249. );
  35250. a.scale( 0.25, 0.25 );
  35251. assert.ok( matrixEquals3( a, expected ), "Check scaling result" );
  35252. } );
  35253. QUnit.test( "rotate", ( assert ) => {
  35254. var a = new Matrix3().set( 1, 2, 3, 4, 5, 6, 7, 8, 9 );
  35255. var expected = new Matrix3().set(
  35256. 3.5355339059327373, 4.949747468305833, 6.363961030678928,
  35257. 2.121320343559643, 2.121320343559643, 2.1213203435596433,
  35258. 7, 8, 9
  35259. );
  35260. a.rotate( Math.PI / 4 );
  35261. assert.ok( matrixEquals3( a, expected ), "Check rotated result" );
  35262. } );
  35263. QUnit.test( "translate", ( assert ) => {
  35264. var a = new Matrix3().set( 1, 2, 3, 4, 5, 6, 7, 8, 9 );
  35265. var expected = new Matrix3().set( 22, 26, 30, 53, 61, 69, 7, 8, 9 );
  35266. a.translate( 3, 7 );
  35267. assert.ok( matrixEquals3( a, expected ), "Check translation result" );
  35268. } );
  35269. QUnit.test( "equals", ( assert ) => {
  35270. var a = new Matrix3().set( 0, 1, 2, 3, 4, 5, 6, 7, 8 );
  35271. var b = new Matrix3().set( 0, - 1, 2, 3, 4, 5, 6, 7, 8 );
  35272. assert.notOk( a.equals( b ), "Check that a does not equal b" );
  35273. assert.notOk( b.equals( a ), "Check that b does not equal a" );
  35274. a.copy( b );
  35275. assert.ok( a.equals( b ), "Check that a equals b after copy()" );
  35276. assert.ok( b.equals( a ), "Check that b equals a after copy()" );
  35277. } );
  35278. QUnit.test( "fromArray", ( assert ) => {
  35279. assert.ok( false, "everything's gonna be alright" );
  35280. } );
  35281. QUnit.test( "toArray", ( assert ) => {
  35282. var a = new Matrix3().set( 1, 2, 3, 4, 5, 6, 7, 8, 9 );
  35283. var noOffset = [ 1, 4, 7, 2, 5, 8, 3, 6, 9 ];
  35284. var withOffset = [ undefined, 1, 4, 7, 2, 5, 8, 3, 6, 9 ];
  35285. var array = a.toArray();
  35286. assert.deepEqual( array, noOffset, "No array, no offset" );
  35287. var array = [];
  35288. a.toArray( array );
  35289. assert.deepEqual( array, noOffset, "With array, no offset" );
  35290. var array = [];
  35291. a.toArray( array, 1 );
  35292. assert.deepEqual( array, withOffset, "With array, with offset" );
  35293. } );
  35294. } );
  35295. } );
  35296. /**
  35297. * @author bhouston / http://exocortex.com
  35298. * @author TristanVALCKE / https://github.com/Itee
  35299. */
  35300. /* global QUnit */
  35301. function matrixEquals4$1( a, b, tolerance ) {
  35302. tolerance = tolerance || 0.0001;
  35303. if ( a.elements.length != b.elements.length ) {
  35304. return false;
  35305. }
  35306. for ( var i = 0, il = a.elements.length; i < il; i ++ ) {
  35307. var delta = a.elements[ i ] - b.elements[ i ];
  35308. if ( delta > tolerance ) {
  35309. return false;
  35310. }
  35311. }
  35312. return true;
  35313. }
  35314. // from Euler.js
  35315. function eulerEquals$1( a, b, tolerance ) {
  35316. tolerance = tolerance || 0.0001;
  35317. var diff = Math.abs( a.x - b.x ) + Math.abs( a.y - b.y ) + Math.abs( a.z - b.z );
  35318. return ( diff < tolerance );
  35319. }
  35320. QUnit.module( 'Maths', () => {
  35321. QUnit.module.todo( 'Matrix4', () => {
  35322. // INSTANCING
  35323. QUnit.test( "Instancing", ( assert ) => {
  35324. var a = new Matrix4();
  35325. assert.ok( a.determinant() == 1, "Passed!" );
  35326. var b = new Matrix4().set( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 );
  35327. assert.ok( b.elements[ 0 ] == 0 );
  35328. assert.ok( b.elements[ 1 ] == 4 );
  35329. assert.ok( b.elements[ 2 ] == 8 );
  35330. assert.ok( b.elements[ 3 ] == 12 );
  35331. assert.ok( b.elements[ 4 ] == 1 );
  35332. assert.ok( b.elements[ 5 ] == 5 );
  35333. assert.ok( b.elements[ 6 ] == 9 );
  35334. assert.ok( b.elements[ 7 ] == 13 );
  35335. assert.ok( b.elements[ 8 ] == 2 );
  35336. assert.ok( b.elements[ 9 ] == 6 );
  35337. assert.ok( b.elements[ 10 ] == 10 );
  35338. assert.ok( b.elements[ 11 ] == 14 );
  35339. assert.ok( b.elements[ 12 ] == 3 );
  35340. assert.ok( b.elements[ 13 ] == 7 );
  35341. assert.ok( b.elements[ 14 ] == 11 );
  35342. assert.ok( b.elements[ 15 ] == 15 );
  35343. assert.ok( ! matrixEquals4$1( a, b ), "Passed!" );
  35344. } );
  35345. // PUBLIC STUFF
  35346. QUnit.test( "isMatrix4", ( assert ) => {
  35347. assert.ok( false, "everything's gonna be alright" );
  35348. } );
  35349. QUnit.test( "set", ( assert ) => {
  35350. var b = new Matrix4();
  35351. assert.ok( b.determinant() == 1, "Passed!" );
  35352. b.set( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 );
  35353. assert.ok( b.elements[ 0 ] == 0 );
  35354. assert.ok( b.elements[ 1 ] == 4 );
  35355. assert.ok( b.elements[ 2 ] == 8 );
  35356. assert.ok( b.elements[ 3 ] == 12 );
  35357. assert.ok( b.elements[ 4 ] == 1 );
  35358. assert.ok( b.elements[ 5 ] == 5 );
  35359. assert.ok( b.elements[ 6 ] == 9 );
  35360. assert.ok( b.elements[ 7 ] == 13 );
  35361. assert.ok( b.elements[ 8 ] == 2 );
  35362. assert.ok( b.elements[ 9 ] == 6 );
  35363. assert.ok( b.elements[ 10 ] == 10 );
  35364. assert.ok( b.elements[ 11 ] == 14 );
  35365. assert.ok( b.elements[ 12 ] == 3 );
  35366. assert.ok( b.elements[ 13 ] == 7 );
  35367. assert.ok( b.elements[ 14 ] == 11 );
  35368. assert.ok( b.elements[ 15 ] == 15 );
  35369. } );
  35370. QUnit.test( "identity", ( assert ) => {
  35371. var b = new Matrix4().set( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 );
  35372. assert.ok( b.elements[ 0 ] == 0 );
  35373. assert.ok( b.elements[ 1 ] == 4 );
  35374. assert.ok( b.elements[ 2 ] == 8 );
  35375. assert.ok( b.elements[ 3 ] == 12 );
  35376. assert.ok( b.elements[ 4 ] == 1 );
  35377. assert.ok( b.elements[ 5 ] == 5 );
  35378. assert.ok( b.elements[ 6 ] == 9 );
  35379. assert.ok( b.elements[ 7 ] == 13 );
  35380. assert.ok( b.elements[ 8 ] == 2 );
  35381. assert.ok( b.elements[ 9 ] == 6 );
  35382. assert.ok( b.elements[ 10 ] == 10 );
  35383. assert.ok( b.elements[ 11 ] == 14 );
  35384. assert.ok( b.elements[ 12 ] == 3 );
  35385. assert.ok( b.elements[ 13 ] == 7 );
  35386. assert.ok( b.elements[ 14 ] == 11 );
  35387. assert.ok( b.elements[ 15 ] == 15 );
  35388. var a = new Matrix4();
  35389. assert.ok( ! matrixEquals4$1( a, b ), "Passed!" );
  35390. b.identity();
  35391. assert.ok( matrixEquals4$1( a, b ), "Passed!" );
  35392. } );
  35393. QUnit.test( "clone", ( assert ) => {
  35394. var a = new Matrix4().set( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 );
  35395. var b = a.clone();
  35396. assert.ok( matrixEquals4$1( a, b ), "Passed!" );
  35397. // ensure that it is a true copy
  35398. a.elements[ 0 ] = 2;
  35399. assert.ok( ! matrixEquals4$1( a, b ), "Passed!" );
  35400. } );
  35401. QUnit.test( "copy", ( assert ) => {
  35402. var a = new Matrix4().set( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 );
  35403. var b = new Matrix4().copy( a );
  35404. assert.ok( matrixEquals4$1( a, b ), "Passed!" );
  35405. // ensure that it is a true copy
  35406. a.elements[ 0 ] = 2;
  35407. assert.ok( ! matrixEquals4$1( a, b ), "Passed!" );
  35408. } );
  35409. QUnit.test( "copyPosition", ( assert ) => {
  35410. var a = new Matrix4().set( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 );
  35411. var b = new Matrix4().set( 1, 2, 3, 0, 5, 6, 7, 0, 9, 10, 11, 0, 13, 14, 15, 16 );
  35412. assert.notOk( matrixEquals4$1( a, b ), "a and b initially not equal" );
  35413. b.copyPosition( a );
  35414. assert.ok( matrixEquals4$1( a, b ), "a and b equal after copyPosition()" );
  35415. } );
  35416. QUnit.test( "makeBasis/extractBasis", ( assert ) => {
  35417. var identityBasis = [ new Vector3( 1, 0, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ) ];
  35418. var a = new Matrix4().makeBasis( identityBasis[ 0 ], identityBasis[ 1 ], identityBasis[ 2 ] );
  35419. var identity = new Matrix4();
  35420. assert.ok( matrixEquals4$1( a, identity ), "Passed!" );
  35421. var testBases = [[ new Vector3( 0, 1, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ) ]];
  35422. for ( var i = 0; i < testBases.length; i ++ ) {
  35423. var testBasis = testBases[ i ];
  35424. var b = new Matrix4().makeBasis( testBasis[ 0 ], testBasis[ 1 ], testBasis[ 2 ] );
  35425. var outBasis = [ new Vector3(), new Vector3(), new Vector3() ];
  35426. b.extractBasis( outBasis[ 0 ], outBasis[ 1 ], outBasis[ 2 ] );
  35427. // check what goes in, is what comes out.
  35428. for ( var j = 0; j < outBasis.length; j ++ ) {
  35429. assert.ok( outBasis[ j ].equals( testBasis[ j ] ), "Passed!" );
  35430. }
  35431. // get the basis out the hard war
  35432. for ( var j = 0; j < identityBasis.length; j ++ ) {
  35433. outBasis[ j ].copy( identityBasis[ j ] );
  35434. outBasis[ j ].applyMatrix4( b );
  35435. }
  35436. // did the multiply method of basis extraction work?
  35437. for ( var j = 0; j < outBasis.length; j ++ ) {
  35438. assert.ok( outBasis[ j ].equals( testBasis[ j ] ), "Passed!" );
  35439. }
  35440. }
  35441. } );
  35442. QUnit.test( "extractRotation", ( assert ) => {
  35443. assert.ok( false, "everything's gonna be alright" );
  35444. } );
  35445. QUnit.test( "makeRotationFromEuler/extractRotation", ( assert ) => {
  35446. var testValues = [
  35447. new Euler( 0, 0, 0, "XYZ" ),
  35448. new Euler( 1, 0, 0, "XYZ" ),
  35449. new Euler( 0, 1, 0, "ZYX" ),
  35450. new Euler( 0, 0, 0.5, "YZX" ),
  35451. new Euler( 0, 0, - 0.5, "YZX" )
  35452. ];
  35453. for ( var i = 0; i < testValues.length; i ++ ) {
  35454. var v = testValues[ i ];
  35455. var m = new Matrix4().makeRotationFromEuler( v );
  35456. var v2 = new Euler().setFromRotationMatrix( m, v.order );
  35457. var m2 = new Matrix4().makeRotationFromEuler( v2 );
  35458. assert.ok( matrixEquals4$1( m, m2, eps ), "makeRotationFromEuler #" + i + ": original and Euler-derived matrices are equal" );
  35459. assert.ok( eulerEquals$1( v, v2, eps ), "makeRotationFromEuler #" + i + ": original and matrix-derived Eulers are equal" );
  35460. var m3 = new Matrix4().extractRotation( m2 );
  35461. var v3 = new Euler().setFromRotationMatrix( m3, v.order );
  35462. assert.ok( matrixEquals4$1( m, m3, eps ), "extractRotation #" + i + ": original and extracted matrices are equal" );
  35463. assert.ok( eulerEquals$1( v, v3, eps ), "extractRotation #" + i + ": original and extracted Eulers are equal" );
  35464. }
  35465. } );
  35466. QUnit.test( "lookAt", ( assert ) => {
  35467. var a = new Matrix4();
  35468. var expected = new Matrix4().identity();
  35469. var eye = new Vector3( 0, 0, 0 );
  35470. var target = new Vector3( 0, 1, - 1 );
  35471. var up = new Vector3( 0, 1, 0 );
  35472. a.lookAt( eye, target, up );
  35473. var rotation = new Euler().setFromRotationMatrix( a );
  35474. assert.numEqual( rotation.x * ( 180 / Math.PI ), 45, "Check the rotation" );
  35475. // eye and target are in the same position
  35476. eye.copy( target );
  35477. a.lookAt( eye, target, up );
  35478. assert.ok( matrixEquals4$1( a, expected ), "Check the result for eye == target" );
  35479. // up and z are parallel
  35480. eye.set( 0, 1, 0 );
  35481. target.set( 0, 0, 0 );
  35482. a.lookAt( eye, target, up );
  35483. expected.set(
  35484. 1, 0, 0, 0,
  35485. 0, 0.0001, 1, 0,
  35486. 0, - 1, 0.0001, 0,
  35487. 0, 0, 0, 1
  35488. );
  35489. assert.ok( matrixEquals4$1( a, expected ), "Check the result for when up and z are parallel" );
  35490. } );
  35491. QUnit.test( "multiply", ( assert ) => {
  35492. assert.ok( false, "everything's gonna be alright" );
  35493. } );
  35494. QUnit.test( "premultiply", ( assert ) => {
  35495. assert.ok( false, "everything's gonna be alright" );
  35496. } );
  35497. QUnit.test( "multiplyMatrices", ( assert ) => {
  35498. // Reference:
  35499. //
  35500. // #!/usr/bin/env python
  35501. // from __future__ import print_function
  35502. // import numpy as np
  35503. // print(
  35504. // np.dot(
  35505. // np.reshape([2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53], (4, 4)),
  35506. // np.reshape([59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131], (4, 4))
  35507. // )
  35508. // )
  35509. //
  35510. // [[ 1585 1655 1787 1861]
  35511. // [ 5318 5562 5980 6246]
  35512. // [10514 11006 11840 12378]
  35513. // [15894 16634 17888 18710]]
  35514. var lhs = new Matrix4().set( 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53 );
  35515. var rhs = new Matrix4().set( 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131 );
  35516. var ans = new Matrix4();
  35517. ans.multiplyMatrices( lhs, rhs );
  35518. assert.ok( ans.elements[ 0 ] == 1585 );
  35519. assert.ok( ans.elements[ 1 ] == 5318 );
  35520. assert.ok( ans.elements[ 2 ] == 10514 );
  35521. assert.ok( ans.elements[ 3 ] == 15894 );
  35522. assert.ok( ans.elements[ 4 ] == 1655 );
  35523. assert.ok( ans.elements[ 5 ] == 5562 );
  35524. assert.ok( ans.elements[ 6 ] == 11006 );
  35525. assert.ok( ans.elements[ 7 ] == 16634 );
  35526. assert.ok( ans.elements[ 8 ] == 1787 );
  35527. assert.ok( ans.elements[ 9 ] == 5980 );
  35528. assert.ok( ans.elements[ 10 ] == 11840 );
  35529. assert.ok( ans.elements[ 11 ] == 17888 );
  35530. assert.ok( ans.elements[ 12 ] == 1861 );
  35531. assert.ok( ans.elements[ 13 ] == 6246 );
  35532. assert.ok( ans.elements[ 14 ] == 12378 );
  35533. assert.ok( ans.elements[ 15 ] == 18710 );
  35534. } );
  35535. QUnit.test( "multiplyScalar", ( assert ) => {
  35536. var b = new Matrix4().set( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 );
  35537. assert.ok( b.elements[ 0 ] == 0 );
  35538. assert.ok( b.elements[ 1 ] == 4 );
  35539. assert.ok( b.elements[ 2 ] == 8 );
  35540. assert.ok( b.elements[ 3 ] == 12 );
  35541. assert.ok( b.elements[ 4 ] == 1 );
  35542. assert.ok( b.elements[ 5 ] == 5 );
  35543. assert.ok( b.elements[ 6 ] == 9 );
  35544. assert.ok( b.elements[ 7 ] == 13 );
  35545. assert.ok( b.elements[ 8 ] == 2 );
  35546. assert.ok( b.elements[ 9 ] == 6 );
  35547. assert.ok( b.elements[ 10 ] == 10 );
  35548. assert.ok( b.elements[ 11 ] == 14 );
  35549. assert.ok( b.elements[ 12 ] == 3 );
  35550. assert.ok( b.elements[ 13 ] == 7 );
  35551. assert.ok( b.elements[ 14 ] == 11 );
  35552. assert.ok( b.elements[ 15 ] == 15 );
  35553. b.multiplyScalar( 2 );
  35554. assert.ok( b.elements[ 0 ] == 0 * 2 );
  35555. assert.ok( b.elements[ 1 ] == 4 * 2 );
  35556. assert.ok( b.elements[ 2 ] == 8 * 2 );
  35557. assert.ok( b.elements[ 3 ] == 12 * 2 );
  35558. assert.ok( b.elements[ 4 ] == 1 * 2 );
  35559. assert.ok( b.elements[ 5 ] == 5 * 2 );
  35560. assert.ok( b.elements[ 6 ] == 9 * 2 );
  35561. assert.ok( b.elements[ 7 ] == 13 * 2 );
  35562. assert.ok( b.elements[ 8 ] == 2 * 2 );
  35563. assert.ok( b.elements[ 9 ] == 6 * 2 );
  35564. assert.ok( b.elements[ 10 ] == 10 * 2 );
  35565. assert.ok( b.elements[ 11 ] == 14 * 2 );
  35566. assert.ok( b.elements[ 12 ] == 3 * 2 );
  35567. assert.ok( b.elements[ 13 ] == 7 * 2 );
  35568. assert.ok( b.elements[ 14 ] == 11 * 2 );
  35569. assert.ok( b.elements[ 15 ] == 15 * 2 );
  35570. } );
  35571. QUnit.test( "applyToBufferAttribute", ( assert ) => {
  35572. var a = new Matrix4().set( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 );
  35573. var attr = new Float32BufferAttribute( [ 1, 2, 1, 3, 0, 3 ], 3 );
  35574. var expected = new Float32BufferAttribute( [
  35575. 0.1666666716337204, 0.4444444477558136, 0.7222222089767456,
  35576. 0.1599999964237213, 0.4399999976158142, 0.7200000286102295
  35577. ], 3 );
  35578. var applied = a.applyToBufferAttribute( attr );
  35579. assert.strictEqual( expected.count, applied.count, "Applied buffer and expected buffer have the same number of entries" );
  35580. for ( var i = 0, l = expected.count; i < l; i ++ ) {
  35581. assert.ok( Math.abs( applied.getX( i ) - expected.getX( i ) ) <= eps, "Check x" );
  35582. assert.ok( Math.abs( applied.getY( i ) - expected.getY( i ) ) <= eps, "Check y" );
  35583. assert.ok( Math.abs( applied.getZ( i ) - expected.getZ( i ) ) <= eps, "Check z" );
  35584. }
  35585. } );
  35586. QUnit.test( "determinant", ( assert ) => {
  35587. var a = new Matrix4();
  35588. assert.ok( a.determinant() == 1, "Passed!" );
  35589. a.elements[ 0 ] = 2;
  35590. assert.ok( a.determinant() == 2, "Passed!" );
  35591. a.elements[ 0 ] = 0;
  35592. assert.ok( a.determinant() == 0, "Passed!" );
  35593. // calculated via http://www.euclideanspace.com/maths/algebra/matrix/functions/determinant/fourD/index.htm
  35594. a.set( 2, 3, 4, 5, - 1, - 21, - 3, - 4, 6, 7, 8, 10, - 8, - 9, - 10, - 12 );
  35595. assert.ok( a.determinant() == 76, "Passed!" );
  35596. } );
  35597. QUnit.test( "transpose", ( assert ) => {
  35598. var a = new Matrix4();
  35599. var b = a.clone().transpose();
  35600. assert.ok( matrixEquals4$1( a, b ), "Passed!" );
  35601. var b = new Matrix4().set( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 );
  35602. var c = b.clone().transpose();
  35603. assert.ok( ! matrixEquals4$1( b, c ), "Passed!" );
  35604. c.transpose();
  35605. assert.ok( matrixEquals4$1( b, c ), "Passed!" );
  35606. } );
  35607. QUnit.test( "setPosition", ( assert ) => {
  35608. assert.ok( false, "everything's gonna be alright" );
  35609. } );
  35610. QUnit.test( "getInverse", ( assert ) => {
  35611. var identity = new Matrix4();
  35612. var a = new Matrix4();
  35613. var b = new Matrix4().set( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
  35614. var c = new Matrix4().set( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
  35615. assert.ok( ! matrixEquals4$1( a, b ), "Passed!" );
  35616. b.getInverse( a, false );
  35617. assert.ok( matrixEquals4$1( b, new Matrix4() ), "Passed!" );
  35618. try {
  35619. b.getInverse( c, true );
  35620. assert.ok( false, "Passed!" ); // should never get here.
  35621. } catch ( err ) {
  35622. assert.ok( true, "Passed!" );
  35623. }
  35624. var testMatrices = [
  35625. new Matrix4().makeRotationX( 0.3 ),
  35626. new Matrix4().makeRotationX( - 0.3 ),
  35627. new Matrix4().makeRotationY( 0.3 ),
  35628. new Matrix4().makeRotationY( - 0.3 ),
  35629. new Matrix4().makeRotationZ( 0.3 ),
  35630. new Matrix4().makeRotationZ( - 0.3 ),
  35631. new Matrix4().makeScale( 1, 2, 3 ),
  35632. new Matrix4().makeScale( 1 / 8, 1 / 2, 1 / 3 ),
  35633. new Matrix4().makePerspective( - 1, 1, 1, - 1, 1, 1000 ),
  35634. new Matrix4().makePerspective( - 16, 16, 9, - 9, 0.1, 10000 ),
  35635. new Matrix4().makeTranslation( 1, 2, 3 )
  35636. ];
  35637. for ( var i = 0, il = testMatrices.length; i < il; i ++ ) {
  35638. var m = testMatrices[ i ];
  35639. var mInverse = new Matrix4().getInverse( m );
  35640. var mSelfInverse = m.clone();
  35641. mSelfInverse.getInverse( mSelfInverse );
  35642. // self-inverse should the same as inverse
  35643. assert.ok( matrixEquals4$1( mSelfInverse, mInverse ), "Passed!" );
  35644. // the determinant of the inverse should be the reciprocal
  35645. assert.ok( Math.abs( m.determinant() * mInverse.determinant() - 1 ) < 0.0001, "Passed!" );
  35646. var mProduct = new Matrix4().multiplyMatrices( m, mInverse );
  35647. // the determinant of the identity matrix is 1
  35648. assert.ok( Math.abs( mProduct.determinant() - 1 ) < 0.0001, "Passed!" );
  35649. assert.ok( matrixEquals4$1( mProduct, identity ), "Passed!" );
  35650. }
  35651. } );
  35652. QUnit.test( "scale", ( assert ) => {
  35653. assert.ok( false, "everything's gonna be alright" );
  35654. } );
  35655. QUnit.test( "getMaxScaleOnAxis", ( assert ) => {
  35656. var a = new Matrix4().set( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 );
  35657. var expected = Math.sqrt( 3 * 3 + 7 * 7 + 11 * 11 );
  35658. assert.ok( Math.abs( a.getMaxScaleOnAxis() - expected ) <= eps, "Check result" );
  35659. } );
  35660. QUnit.test( "makeTranslation", ( assert ) => {
  35661. assert.ok( false, "everything's gonna be alright" );
  35662. } );
  35663. QUnit.test( "makeRotationX", ( assert ) => {
  35664. assert.ok( false, "everything's gonna be alright" );
  35665. } );
  35666. QUnit.test( "makeRotationY", ( assert ) => {
  35667. assert.ok( false, "everything's gonna be alright" );
  35668. } );
  35669. QUnit.test( "makeRotationZ", ( assert ) => {
  35670. assert.ok( false, "everything's gonna be alright" );
  35671. } );
  35672. QUnit.test( "makeRotationAxis", ( assert ) => {
  35673. var axis = new Vector3( 1.5, 0.0, 1.0 ).normalize();
  35674. var radians = _Math.degToRad( 45 );
  35675. var a = new Matrix4().makeRotationAxis( axis, radians );
  35676. var expected = new Matrix4().set(
  35677. 0.9098790095958609, - 0.39223227027636803, 0.13518148560620882, 0,
  35678. 0.39223227027636803, 0.7071067811865476, - 0.588348405414552, 0,
  35679. 0.13518148560620882, 0.588348405414552, 0.7972277715906868, 0,
  35680. 0, 0, 0, 1
  35681. );
  35682. assert.ok( matrixEquals4$1( a, expected ), "Check numeric result" );
  35683. } );
  35684. QUnit.test( "makeScale", ( assert ) => {
  35685. assert.ok( false, "everything's gonna be alright" );
  35686. } );
  35687. QUnit.test( "makeShear", ( assert ) => {
  35688. assert.ok( false, "everything's gonna be alright" );
  35689. } );
  35690. QUnit.test( "compose/decompose", ( assert ) => {
  35691. var tValues = [
  35692. new Vector3(),
  35693. new Vector3( 3, 0, 0 ),
  35694. new Vector3( 0, 4, 0 ),
  35695. new Vector3( 0, 0, 5 ),
  35696. new Vector3( - 6, 0, 0 ),
  35697. new Vector3( 0, - 7, 0 ),
  35698. new Vector3( 0, 0, - 8 ),
  35699. new Vector3( - 2, 5, - 9 ),
  35700. new Vector3( - 2, - 5, - 9 )
  35701. ];
  35702. var sValues = [
  35703. new Vector3( 1, 1, 1 ),
  35704. new Vector3( 2, 2, 2 ),
  35705. new Vector3( 1, - 1, 1 ),
  35706. new Vector3( - 1, 1, 1 ),
  35707. new Vector3( 1, 1, - 1 ),
  35708. new Vector3( 2, - 2, 1 ),
  35709. new Vector3( - 1, 2, - 2 ),
  35710. new Vector3( - 1, - 1, - 1 ),
  35711. new Vector3( - 2, - 2, - 2 )
  35712. ];
  35713. var rValues = [
  35714. new Quaternion(),
  35715. new Quaternion().setFromEuler( new Euler( 1, 1, 0 ) ),
  35716. new Quaternion().setFromEuler( new Euler( 1, - 1, 1 ) ),
  35717. new Quaternion( 0, 0.9238795292366128, 0, 0.38268342717215614 )
  35718. ];
  35719. for ( var ti = 0; ti < tValues.length; ti ++ ) {
  35720. for ( var si = 0; si < sValues.length; si ++ ) {
  35721. for ( var ri = 0; ri < rValues.length; ri ++ ) {
  35722. var t = tValues[ ti ];
  35723. var s = sValues[ si ];
  35724. var r = rValues[ ri ];
  35725. var m = new Matrix4().compose( t, r, s );
  35726. var t2 = new Vector3();
  35727. var r2 = new Quaternion();
  35728. var s2 = new Vector3();
  35729. m.decompose( t2, r2, s2 );
  35730. var m2 = new Matrix4().compose( t2, r2, s2 );
  35731. /*
  35732. // debug code
  35733. var matrixIsSame = matrixEquals4( m, m2 );
  35734. if ( ! matrixIsSame ) {
  35735. console.log( t, s, r );
  35736. console.log( t2, s2, r2 );
  35737. console.log( m, m2 );
  35738. }
  35739. */
  35740. assert.ok( matrixEquals4$1( m, m2 ), "Passed!" );
  35741. }
  35742. }
  35743. }
  35744. } );
  35745. QUnit.test( "makePerspective", ( assert ) => {
  35746. assert.ok( false, "everything's gonna be alright" );
  35747. } );
  35748. QUnit.test( "makeOrthographic", ( assert ) => {
  35749. var a = new Matrix4().makeOrthographic( - 1, 1, - 1, 1, 1, 100 );
  35750. var expected = new Matrix4().set(
  35751. 1, 0, 0, 0,
  35752. 0, - 1, 0, 0,
  35753. 0, 0, - 2 / 99, - 101 / 99,
  35754. 0, 0, 0, 1
  35755. );
  35756. assert.ok( matrixEquals4$1( a, expected ), "Check result" );
  35757. } );
  35758. QUnit.test( "equals", ( assert ) => {
  35759. var a = new Matrix4().set( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 );
  35760. var b = new Matrix4().set( 0, - 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 );
  35761. assert.notOk( a.equals( b ), "Check that a does not equal b" );
  35762. assert.notOk( b.equals( a ), "Check that b does not equal a" );
  35763. a.copy( b );
  35764. assert.ok( a.equals( b ), "Check that a equals b after copy()" );
  35765. assert.ok( b.equals( a ), "Check that b equals a after copy()" );
  35766. } );
  35767. QUnit.test( "fromArray", ( assert ) => {
  35768. assert.ok( false, "everything's gonna be alright" );
  35769. } );
  35770. QUnit.test( "toArray", ( assert ) => {
  35771. var a = new Matrix4().set( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 );
  35772. var noOffset = [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ];
  35773. var withOffset = [ undefined, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ];
  35774. var array = a.toArray();
  35775. assert.deepEqual( array, noOffset, "No array, no offset" );
  35776. var array = [];
  35777. a.toArray( array );
  35778. assert.deepEqual( array, noOffset, "With array, no offset" );
  35779. var array = [];
  35780. a.toArray( array, 1 );
  35781. assert.deepEqual( array, withOffset, "With array, with offset" );
  35782. } );
  35783. } );
  35784. } );
  35785. /**
  35786. * @author bhouston / http://exocortex.com
  35787. * @author TristanVALCKE / https://github.com/Itee
  35788. */
  35789. /* global QUnit */
  35790. function comparePlane( a, b, threshold ) {
  35791. threshold = threshold || 0.0001;
  35792. return ( a.normal.distanceTo( b.normal ) < threshold &&
  35793. Math.abs( a.constant - b.constant ) < threshold );
  35794. }
  35795. QUnit.module( 'Maths', () => {
  35796. QUnit.module.todo( 'Plane', () => {
  35797. // INSTANCING
  35798. QUnit.test( "Instancing", ( assert ) => {
  35799. var a = new Plane();
  35800. assert.ok( a.normal.x == 1, "Passed!" );
  35801. assert.ok( a.normal.y == 0, "Passed!" );
  35802. assert.ok( a.normal.z == 0, "Passed!" );
  35803. assert.ok( a.constant == 0, "Passed!" );
  35804. var a = new Plane( one3.clone(), 0 );
  35805. assert.ok( a.normal.x == 1, "Passed!" );
  35806. assert.ok( a.normal.y == 1, "Passed!" );
  35807. assert.ok( a.normal.z == 1, "Passed!" );
  35808. assert.ok( a.constant == 0, "Passed!" );
  35809. var a = new Plane( one3.clone(), 1 );
  35810. assert.ok( a.normal.x == 1, "Passed!" );
  35811. assert.ok( a.normal.y == 1, "Passed!" );
  35812. assert.ok( a.normal.z == 1, "Passed!" );
  35813. assert.ok( a.constant == 1, "Passed!" );
  35814. } );
  35815. // PUBLIC STUFF
  35816. QUnit.test( "isPlane", ( assert ) => {
  35817. assert.ok( false, "everything's gonna be alright" );
  35818. } );
  35819. QUnit.test( "set", ( assert ) => {
  35820. var a = new Plane();
  35821. assert.ok( a.normal.x == 1, "Passed!" );
  35822. assert.ok( a.normal.y == 0, "Passed!" );
  35823. assert.ok( a.normal.z == 0, "Passed!" );
  35824. assert.ok( a.constant == 0, "Passed!" );
  35825. var b = a.clone().set( new Vector3( x, y, z ), w );
  35826. assert.ok( b.normal.x == x, "Passed!" );
  35827. assert.ok( b.normal.y == y, "Passed!" );
  35828. assert.ok( b.normal.z == z, "Passed!" );
  35829. assert.ok( b.constant == w, "Passed!" );
  35830. } );
  35831. QUnit.test( "setComponents", ( assert ) => {
  35832. var a = new Plane();
  35833. assert.ok( a.normal.x == 1, "Passed!" );
  35834. assert.ok( a.normal.y == 0, "Passed!" );
  35835. assert.ok( a.normal.z == 0, "Passed!" );
  35836. assert.ok( a.constant == 0, "Passed!" );
  35837. var b = a.clone().setComponents( x, y, z, w );
  35838. assert.ok( b.normal.x == x, "Passed!" );
  35839. assert.ok( b.normal.y == y, "Passed!" );
  35840. assert.ok( b.normal.z == z, "Passed!" );
  35841. assert.ok( b.constant == w, "Passed!" );
  35842. } );
  35843. QUnit.test( "setFromNormalAndCoplanarPoint", ( assert ) => {
  35844. var normal = one3.clone().normalize();
  35845. var a = new Plane().setFromNormalAndCoplanarPoint( normal, zero3 );
  35846. assert.ok( a.normal.equals( normal ), "Passed!" );
  35847. assert.ok( a.constant == 0, "Passed!" );
  35848. } );
  35849. QUnit.test( "setFromCoplanarPoints", ( assert ) => {
  35850. var a = new Plane();
  35851. var v1 = new Vector3( 2.0, 0.5, 0.25 );
  35852. var v2 = new Vector3( 2.0, - 0.5, 1.25 );
  35853. var v3 = new Vector3( 2.0, - 3.5, 2.2 );
  35854. var normal = new Vector3( 1, 0, 0 );
  35855. var constant = - 2;
  35856. a.setFromCoplanarPoints( v1, v2, v3 );
  35857. assert.ok( a.normal.equals( normal ), "Check normal" );
  35858. assert.strictEqual( a.constant, constant, "Check constant" );
  35859. } );
  35860. QUnit.test( "clone", ( assert ) => {
  35861. assert.ok( false, "everything's gonna be alright" );
  35862. } );
  35863. QUnit.test( "copy", ( assert ) => {
  35864. var a = new Plane( new Vector3( x, y, z ), w );
  35865. var b = new Plane().copy( a );
  35866. assert.ok( b.normal.x == x, "Passed!" );
  35867. assert.ok( b.normal.y == y, "Passed!" );
  35868. assert.ok( b.normal.z == z, "Passed!" );
  35869. assert.ok( b.constant == w, "Passed!" );
  35870. // ensure that it is a true copy
  35871. a.normal.x = 0;
  35872. a.normal.y = - 1;
  35873. a.normal.z = - 2;
  35874. a.constant = - 3;
  35875. assert.ok( b.normal.x == x, "Passed!" );
  35876. assert.ok( b.normal.y == y, "Passed!" );
  35877. assert.ok( b.normal.z == z, "Passed!" );
  35878. assert.ok( b.constant == w, "Passed!" );
  35879. } );
  35880. QUnit.test( "normalize", ( assert ) => {
  35881. var a = new Plane( new Vector3( 2, 0, 0 ), 2 );
  35882. a.normalize();
  35883. assert.ok( a.normal.length() == 1, "Passed!" );
  35884. assert.ok( a.normal.equals( new Vector3( 1, 0, 0 ) ), "Passed!" );
  35885. assert.ok( a.constant == 1, "Passed!" );
  35886. } );
  35887. QUnit.test( "negate/distanceToPoint", ( assert ) => {
  35888. var a = new Plane( new Vector3( 2, 0, 0 ), - 2 );
  35889. a.normalize();
  35890. assert.ok( a.distanceToPoint( new Vector3( 4, 0, 0 ) ) === 3, "Passed!" );
  35891. assert.ok( a.distanceToPoint( new Vector3( 1, 0, 0 ) ) === 0, "Passed!" );
  35892. a.negate();
  35893. assert.ok( a.distanceToPoint( new Vector3( 4, 0, 0 ) ) === - 3, "Passed!" );
  35894. assert.ok( a.distanceToPoint( new Vector3( 1, 0, 0 ) ) === 0, "Passed!" );
  35895. } );
  35896. QUnit.test( "distanceToPoint", ( assert ) => {
  35897. var a = new Plane( new Vector3( 2, 0, 0 ), - 2 );
  35898. a.normalize();
  35899. assert.ok( a.distanceToPoint( a.projectPoint( zero3.clone() ) ) === 0, "Passed!" );
  35900. assert.ok( a.distanceToPoint( new Vector3( 4, 0, 0 ) ) === 3, "Passed!" );
  35901. } );
  35902. QUnit.test( "distanceToSphere", ( assert ) => {
  35903. var a = new Plane( new Vector3( 1, 0, 0 ), 0 );
  35904. var b = new Sphere( new Vector3( 2, 0, 0 ), 1 );
  35905. assert.ok( a.distanceToSphere( b ) === 1, "Passed!" );
  35906. a.set( new Vector3( 1, 0, 0 ), 2 );
  35907. assert.ok( a.distanceToSphere( b ) === 3, "Passed!" );
  35908. a.set( new Vector3( 1, 0, 0 ), - 2 );
  35909. assert.ok( a.distanceToSphere( b ) === - 1, "Passed!" );
  35910. } );
  35911. QUnit.test( "projectPoint", ( assert ) => {
  35912. var a = new Plane( new Vector3( 1, 0, 0 ), 0 );
  35913. assert.ok( a.projectPoint( new Vector3( 10, 0, 0 ) ).equals( zero3 ), "Passed!" );
  35914. assert.ok( a.projectPoint( new Vector3( - 10, 0, 0 ) ).equals( zero3 ), "Passed!" );
  35915. var a = new Plane( new Vector3( 0, 1, 0 ), - 1 );
  35916. assert.ok( a.projectPoint( new Vector3( 0, 0, 0 ) ).equals( new Vector3( 0, 1, 0 ) ), "Passed!" );
  35917. assert.ok( a.projectPoint( new Vector3( 0, 1, 0 ) ).equals( new Vector3( 0, 1, 0 ) ), "Passed!" );
  35918. } );
  35919. QUnit.test( "isInterestionLine/intersectLine", ( assert ) => {
  35920. var a = new Plane( new Vector3( 1, 0, 0 ), 0 );
  35921. var l1 = new Line3( new Vector3( - 10, 0, 0 ), new Vector3( 10, 0, 0 ) );
  35922. assert.ok( a.intersectsLine( l1 ), "Passed!" );
  35923. assert.ok( a.intersectLine( l1 ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
  35924. var a = new Plane( new Vector3( 1, 0, 0 ), - 3 );
  35925. assert.ok( a.intersectsLine( l1 ), "Passed!" );
  35926. assert.ok( a.intersectLine( l1 ).equals( new Vector3( 3, 0, 0 ) ), "Passed!" );
  35927. var a = new Plane( new Vector3( 1, 0, 0 ), - 11 );
  35928. assert.ok( ! a.intersectsLine( l1 ), "Passed!" );
  35929. assert.ok( a.intersectLine( l1 ) === undefined, "Passed!" );
  35930. var a = new Plane( new Vector3( 1, 0, 0 ), 11 );
  35931. assert.ok( ! a.intersectsLine( l1 ), "Passed!" );
  35932. assert.ok( a.intersectLine( l1 ) === undefined, "Passed!" );
  35933. } );
  35934. QUnit.test( "intersectsBox", ( assert ) => {
  35935. assert.ok( false, "everything's gonna be alright" );
  35936. } );
  35937. QUnit.test( "intersectsSphere", ( assert ) => {
  35938. assert.ok( false, "everything's gonna be alright" );
  35939. } );
  35940. QUnit.test( "coplanarPoint", ( assert ) => {
  35941. var a = new Plane( new Vector3( 1, 0, 0 ), 0 );
  35942. assert.ok( a.distanceToPoint( a.coplanarPoint() ) === 0, "Passed!" );
  35943. var a = new Plane( new Vector3( 0, 1, 0 ), - 1 );
  35944. assert.ok( a.distanceToPoint( a.coplanarPoint() ) === 0, "Passed!" );
  35945. } );
  35946. QUnit.test( "applyMatrix4/translate", ( assert ) => {
  35947. var a = new Plane( new Vector3( 1, 0, 0 ), 0 );
  35948. var m = new Matrix4();
  35949. m.makeRotationZ( Math.PI * 0.5 );
  35950. assert.ok( comparePlane( a.clone().applyMatrix4( m ), new Plane( new Vector3( 0, 1, 0 ), 0 ) ), "Passed!" );
  35951. var a = new Plane( new Vector3( 0, 1, 0 ), - 1 );
  35952. assert.ok( comparePlane( a.clone().applyMatrix4( m ), new Plane( new Vector3( - 1, 0, 0 ), - 1 ) ), "Passed!" );
  35953. m.makeTranslation( 1, 1, 1 );
  35954. assert.ok( comparePlane( a.clone().applyMatrix4( m ), a.clone().translate( new Vector3( 1, 1, 1 ) ) ), "Passed!" );
  35955. } );
  35956. QUnit.test( "equals", ( assert ) => {
  35957. var a = new Plane( new Vector3( 1, 0, 0 ), 0 );
  35958. var b = new Plane( new Vector3( 1, 0, 0 ), 1 );
  35959. var c = new Plane( new Vector3( 0, 1, 0 ), 0 );
  35960. assert.ok( a.normal.equals( b.normal ), "Normals: equal" );
  35961. assert.notOk( a.normal.equals( c.normal ), "Normals: not equal" );
  35962. assert.notStrictEqual( a.constant, b.constant, "Constants: not equal" );
  35963. assert.strictEqual( a.constant, c.constant, "Constants: equal" );
  35964. assert.notOk( a.equals( b ), "Planes: not equal" );
  35965. assert.notOk( a.equals( c ), "Planes: not equal" );
  35966. a.copy( b );
  35967. assert.ok( a.normal.equals( b.normal ), "Normals after copy(): equal" );
  35968. assert.strictEqual( a.constant, b.constant, "Constants after copy(): equal" );
  35969. assert.ok( a.equals( b ), "Planes after copy(): equal" );
  35970. } );
  35971. } );
  35972. } );
  35973. QUnit.module( "Plane" );
  35974. /**
  35975. * @author bhouston / http://exocortex.com
  35976. * @author tschw
  35977. * @author TristanVALCKE / https://github.com/Itee
  35978. */
  35979. /* global QUnit */
  35980. const orders = [ 'XYZ', 'YXZ', 'ZXY', 'ZYX', 'YZX', 'XZY' ];
  35981. const eulerAngles = new Euler( 0.1, - 0.3, 0.25 );
  35982. function qSub( a, b ) {
  35983. var result = new Quaternion();
  35984. result.copy( a );
  35985. result.x -= b.x;
  35986. result.y -= b.y;
  35987. result.z -= b.z;
  35988. result.w -= b.w;
  35989. return result;
  35990. }
  35991. function doSlerpObject( aArr, bArr, t ) {
  35992. var a = new Quaternion().fromArray( aArr ),
  35993. b = new Quaternion().fromArray( bArr ),
  35994. c = new Quaternion().fromArray( aArr );
  35995. c.slerp( b, t );
  35996. return {
  35997. equals: function ( x$$1, y$$1, z$$1, w$$1, maxError ) {
  35998. if ( maxError === undefined ) maxError = Number.EPSILON;
  35999. return Math.abs( x$$1 - c.x ) <= maxError &&
  36000. Math.abs( y$$1 - c.y ) <= maxError &&
  36001. Math.abs( z$$1 - c.z ) <= maxError &&
  36002. Math.abs( w$$1 - c.w ) <= maxError;
  36003. },
  36004. length: c.length(),
  36005. dotA: c.dot( a ),
  36006. dotB: c.dot( b )
  36007. };
  36008. }
  36009. function doSlerpArray( a, b, t ) {
  36010. var result = [ 0, 0, 0, 0 ];
  36011. Quaternion.slerpFlat( result, 0, a, 0, b, 0, t );
  36012. function arrDot( a, b ) {
  36013. return a[ 0 ] * b[ 0 ] + a[ 1 ] * b[ 1 ] +
  36014. a[ 2 ] * b[ 2 ] + a[ 3 ] * b[ 3 ];
  36015. }
  36016. return {
  36017. equals: function ( x$$1, y$$1, z$$1, w$$1, maxError ) {
  36018. if ( maxError === undefined ) maxError = Number.EPSILON;
  36019. return Math.abs( x$$1 - result[ 0 ] ) <= maxError &&
  36020. Math.abs( y$$1 - result[ 1 ] ) <= maxError &&
  36021. Math.abs( z$$1 - result[ 2 ] ) <= maxError &&
  36022. Math.abs( w$$1 - result[ 3 ] ) <= maxError;
  36023. },
  36024. length: Math.sqrt( arrDot( result, result ) ),
  36025. dotA: arrDot( result, a ),
  36026. dotB: arrDot( result, b )
  36027. };
  36028. }
  36029. function slerpTestSkeleton( doSlerp, maxError, assert ) {
  36030. var a, b, result;
  36031. a = [
  36032. 0.6753410084407496,
  36033. 0.4087830051091744,
  36034. 0.32856700410659473,
  36035. 0.5185120064806223
  36036. ];
  36037. b = [
  36038. 0.6602792107657797,
  36039. 0.43647413932562285,
  36040. 0.35119011210236006,
  36041. 0.5001871596632682
  36042. ];
  36043. var maxNormError = 0;
  36044. function isNormal( result ) {
  36045. var normError = Math.abs( 1 - result.length );
  36046. maxNormError = Math.max( maxNormError, normError );
  36047. return normError <= maxError;
  36048. }
  36049. result = doSlerp( a, b, 0 );
  36050. assert.ok( result.equals(
  36051. a[ 0 ], a[ 1 ], a[ 2 ], a[ 3 ], 0 ), "Exactly A @ t = 0" );
  36052. result = doSlerp( a, b, 1 );
  36053. assert.ok( result.equals(
  36054. b[ 0 ], b[ 1 ], b[ 2 ], b[ 3 ], 0 ), "Exactly B @ t = 1" );
  36055. result = doSlerp( a, b, 0.5 );
  36056. assert.ok( Math.abs( result.dotA - result.dotB ) <= Number.EPSILON, "Symmetry at 0.5" );
  36057. assert.ok( isNormal( result ), "Approximately normal (at 0.5)" );
  36058. result = doSlerp( a, b, 0.25 );
  36059. assert.ok( result.dotA > result.dotB, "Interpolating at 0.25" );
  36060. assert.ok( isNormal( result ), "Approximately normal (at 0.25)" );
  36061. result = doSlerp( a, b, 0.75 );
  36062. assert.ok( result.dotA < result.dotB, "Interpolating at 0.75" );
  36063. assert.ok( isNormal( result ), "Approximately normal (at 0.75)" );
  36064. var D = Math.SQRT1_2;
  36065. result = doSlerp( [ 1, 0, 0, 0 ], [ 0, 0, 1, 0 ], 0.5 );
  36066. assert.ok( result.equals( D, 0, D, 0 ), "X/Z diagonal from axes" );
  36067. assert.ok( isNormal( result ), "Approximately normal (X/Z diagonal)" );
  36068. result = doSlerp( [ 0, D, 0, D ], [ 0, - D, 0, D ], 0.5 );
  36069. assert.ok( result.equals( 0, 0, 0, 1 ), "W-Unit from diagonals" );
  36070. assert.ok( isNormal( result ), "Approximately normal (W-Unit)" );
  36071. }
  36072. QUnit.module( 'Maths', () => {
  36073. QUnit.module.todo( 'Quaternion', () => {
  36074. // INSTANCING
  36075. QUnit.test( "Instancing", ( assert ) => {
  36076. var a = new Quaternion();
  36077. assert.ok( a.x == 0, "Passed!" );
  36078. assert.ok( a.y == 0, "Passed!" );
  36079. assert.ok( a.z == 0, "Passed!" );
  36080. assert.ok( a.w == 1, "Passed!" );
  36081. var a = new Quaternion( x, y, z, w );
  36082. assert.ok( a.x === x, "Passed!" );
  36083. assert.ok( a.y === y, "Passed!" );
  36084. assert.ok( a.z === z, "Passed!" );
  36085. assert.ok( a.w === w, "Passed!" );
  36086. } );
  36087. // STATIC STUFF
  36088. QUnit.test( "slerp", ( assert ) => {
  36089. slerpTestSkeleton( doSlerpObject, Number.EPSILON, assert );
  36090. } );
  36091. QUnit.test( "slerpFlat", ( assert ) => {
  36092. slerpTestSkeleton( doSlerpArray, Number.EPSILON, assert );
  36093. } );
  36094. // PROPERTIES
  36095. QUnit.test( "properties", ( assert ) => {
  36096. assert.expect( 8 );
  36097. var a = new Quaternion();
  36098. a.onChange( function () {
  36099. assert.ok( true, "onChange called" );
  36100. } );
  36101. a.x = x;
  36102. a.y = y;
  36103. a.z = z;
  36104. a.w = w;
  36105. assert.strictEqual( a.x, x, "Check x" );
  36106. assert.strictEqual( a.y, y, "Check y" );
  36107. assert.strictEqual( a.z, z, "Check z" );
  36108. assert.strictEqual( a.w, w, "Check w" );
  36109. } );
  36110. QUnit.test( "x", ( assert ) => {
  36111. assert.ok( false, "everything's gonna be alright" );
  36112. } );
  36113. QUnit.test( "y", ( assert ) => {
  36114. assert.ok( false, "everything's gonna be alright" );
  36115. } );
  36116. QUnit.test( "z", ( assert ) => {
  36117. assert.ok( false, "everything's gonna be alright" );
  36118. } );
  36119. QUnit.test( "w", ( assert ) => {
  36120. assert.ok( false, "everything's gonna be alright" );
  36121. } );
  36122. // PUBLIC STUFF
  36123. QUnit.test( "set", ( assert ) => {
  36124. var a = new Quaternion();
  36125. assert.ok( a.x == 0, "Passed!" );
  36126. assert.ok( a.y == 0, "Passed!" );
  36127. assert.ok( a.z == 0, "Passed!" );
  36128. assert.ok( a.w == 1, "Passed!" );
  36129. a.set( x, y, z, w );
  36130. assert.ok( a.x == x, "Passed!" );
  36131. assert.ok( a.y == y, "Passed!" );
  36132. assert.ok( a.z === z, "Passed!" );
  36133. assert.ok( a.w === w, "Passed!" );
  36134. } );
  36135. QUnit.test( "clone", ( assert ) => {
  36136. assert.ok( false, "everything's gonna be alright" );
  36137. } );
  36138. QUnit.test( "copy", ( assert ) => {
  36139. var a = new Quaternion( x, y, z, w );
  36140. var b = new Quaternion().copy( a );
  36141. assert.ok( b.x == x, "Passed!" );
  36142. assert.ok( b.y == y, "Passed!" );
  36143. assert.ok( b.z == z, "Passed!" );
  36144. assert.ok( b.w == w, "Passed!" );
  36145. // ensure that it is a true copy
  36146. a.x = 0;
  36147. a.y = - 1;
  36148. a.z = 0;
  36149. a.w = - 1;
  36150. assert.ok( b.x == x, "Passed!" );
  36151. assert.ok( b.y == y, "Passed!" );
  36152. } );
  36153. QUnit.test( "setFromEuler/setFromQuaternion", ( assert ) => {
  36154. var angles = [ new Vector3( 1, 0, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ) ];
  36155. // ensure euler conversion to/from Quaternion matches.
  36156. for ( var i = 0; i < orders.length; i ++ ) {
  36157. for ( var j = 0; j < angles.length; j ++ ) {
  36158. var eulers2 = new Euler().setFromQuaternion( new Quaternion().setFromEuler( new Euler( angles[ j ].x, angles[ j ].y, angles[ j ].z, orders[ i ] ) ), orders[ i ] );
  36159. var newAngle = new Vector3( eulers2.x, eulers2.y, eulers2.z );
  36160. assert.ok( newAngle.distanceTo( angles[ j ] ) < 0.001, "Passed!" );
  36161. }
  36162. }
  36163. } );
  36164. QUnit.test( "setFromAxisAngle", ( assert ) => {
  36165. // TODO: find cases to validate.
  36166. // assert.ok( true, "Passed!" );
  36167. var zero = new Quaternion();
  36168. var a = new Quaternion().setFromAxisAngle( new Vector3( 1, 0, 0 ), 0 );
  36169. assert.ok( a.equals( zero ), "Passed!" );
  36170. a = new Quaternion().setFromAxisAngle( new Vector3( 0, 1, 0 ), 0 );
  36171. assert.ok( a.equals( zero ), "Passed!" );
  36172. a = new Quaternion().setFromAxisAngle( new Vector3( 0, 0, 1 ), 0 );
  36173. assert.ok( a.equals( zero ), "Passed!" );
  36174. var b1 = new Quaternion().setFromAxisAngle( new Vector3( 1, 0, 0 ), Math.PI );
  36175. assert.ok( ! a.equals( b1 ), "Passed!" );
  36176. var b2 = new Quaternion().setFromAxisAngle( new Vector3( 1, 0, 0 ), - Math.PI );
  36177. assert.ok( ! a.equals( b2 ), "Passed!" );
  36178. b1.multiply( b2 );
  36179. assert.ok( a.equals( b1 ), "Passed!" );
  36180. } );
  36181. QUnit.test( "setFromEuler/setFromRotationMatrix", ( assert ) => {
  36182. // ensure euler conversion for Quaternion matches that of Matrix4
  36183. for ( var i = 0; i < orders.length; i ++ ) {
  36184. var q = new Quaternion().setFromEuler( eulerAngles, orders[ i ] );
  36185. var m = new Matrix4().makeRotationFromEuler( eulerAngles, orders[ i ] );
  36186. var q2 = new Quaternion().setFromRotationMatrix( m );
  36187. assert.ok( qSub( q, q2 ).length() < 0.001, "Passed!" );
  36188. }
  36189. } );
  36190. QUnit.test( "setFromRotationMatrix", ( assert ) => {
  36191. // contrived examples purely to please the god of code coverage...
  36192. // match conditions in various 'else [if]' blocks
  36193. var a = new Quaternion();
  36194. var q = new Quaternion( - 9, - 2, 3, - 4 ).normalize();
  36195. var m = new Matrix4().makeRotationFromQuaternion( q );
  36196. var expected = new Vector4( 0.8581163303210332, 0.19069251784911848, - 0.2860387767736777, 0.38138503569823695 );
  36197. a.setFromRotationMatrix( m );
  36198. assert.ok( Math.abs( a.x - expected.x ) <= eps, "m11 > m22 && m11 > m33: check x" );
  36199. assert.ok( Math.abs( a.y - expected.y ) <= eps, "m11 > m22 && m11 > m33: check y" );
  36200. assert.ok( Math.abs( a.z - expected.z ) <= eps, "m11 > m22 && m11 > m33: check z" );
  36201. assert.ok( Math.abs( a.w - expected.w ) <= eps, "m11 > m22 && m11 > m33: check w" );
  36202. var q = new Quaternion( - 1, - 2, 1, - 1 ).normalize();
  36203. m.makeRotationFromQuaternion( q );
  36204. var expected = new Vector4( 0.37796447300922714, 0.7559289460184544, - 0.37796447300922714, 0.37796447300922714 );
  36205. a.setFromRotationMatrix( m );
  36206. assert.ok( Math.abs( a.x - expected.x ) <= eps, "m22 > m33: check x" );
  36207. assert.ok( Math.abs( a.y - expected.y ) <= eps, "m22 > m33: check y" );
  36208. assert.ok( Math.abs( a.z - expected.z ) <= eps, "m22 > m33: check z" );
  36209. assert.ok( Math.abs( a.w - expected.w ) <= eps, "m22 > m33: check w" );
  36210. } );
  36211. QUnit.test( "setFromUnitVectors", ( assert ) => {
  36212. var a = new Quaternion();
  36213. var b = new Vector3( 1, 0, 0 );
  36214. var c = new Vector3( 0, 1, 0 );
  36215. var expected = new Quaternion( 0, 0, Math.sqrt( 2 ) / 2, Math.sqrt( 2 ) / 2 );
  36216. a.setFromUnitVectors( b, c );
  36217. assert.ok( Math.abs( a.x - expected.x ) <= eps, "Check x" );
  36218. assert.ok( Math.abs( a.y - expected.y ) <= eps, "Check y" );
  36219. assert.ok( Math.abs( a.z - expected.z ) <= eps, "Check z" );
  36220. assert.ok( Math.abs( a.w - expected.w ) <= eps, "Check w" );
  36221. } );
  36222. QUnit.test( "inverse/conjugate", ( assert ) => {
  36223. var a = new Quaternion( x, y, z, w );
  36224. // TODO: add better validation here.
  36225. var b = a.clone().conjugate();
  36226. assert.ok( a.x == - b.x, "Passed!" );
  36227. assert.ok( a.y == - b.y, "Passed!" );
  36228. assert.ok( a.z == - b.z, "Passed!" );
  36229. assert.ok( a.w == b.w, "Passed!" );
  36230. } );
  36231. QUnit.test( "inverse", ( assert ) => {
  36232. assert.expect( 6 );
  36233. var a = new Quaternion( x, y, z, w );
  36234. var inverted = new Quaternion( - 0.2721655269759087, - 0.408248290463863, - 0.5443310539518174, 0.6804138174397717 );
  36235. a.onChange( function () {
  36236. assert.ok( true, "onChange called" );
  36237. } );
  36238. a.inverse();
  36239. assert.ok( Math.abs( a.x - inverted.x ) <= eps, "Check x" );
  36240. assert.ok( Math.abs( a.y - inverted.y ) <= eps, "Check y" );
  36241. assert.ok( Math.abs( a.z - inverted.z ) <= eps, "Check z" );
  36242. assert.ok( Math.abs( a.w - inverted.w ) <= eps, "Check w" );
  36243. } );
  36244. QUnit.test( "dot", ( assert ) => {
  36245. assert.ok( false, "everything's gonna be alright" );
  36246. } );
  36247. QUnit.test( "normalize/length/lengthSq", ( assert ) => {
  36248. var a = new Quaternion( x, y, z, w );
  36249. var b = new Quaternion( - x, - y, - z, - w );
  36250. assert.ok( a.length() != 1, "Passed!" );
  36251. assert.ok( a.lengthSq() != 1, "Passed!" );
  36252. a.normalize();
  36253. assert.ok( a.length() == 1, "Passed!" );
  36254. assert.ok( a.lengthSq() == 1, "Passed!" );
  36255. a.set( 0, 0, 0, 0 );
  36256. assert.ok( a.lengthSq() == 0, "Passed!" );
  36257. assert.ok( a.length() == 0, "Passed!" );
  36258. a.normalize();
  36259. assert.ok( a.lengthSq() == 1, "Passed!" );
  36260. assert.ok( a.length() == 1, "Passed!" );
  36261. } );
  36262. QUnit.test( "multiplyQuaternions/multiply", ( assert ) => {
  36263. var angles = [ new Euler( 1, 0, 0 ), new Euler( 0, 1, 0 ), new Euler( 0, 0, 1 ) ];
  36264. var q1 = new Quaternion().setFromEuler( angles[ 0 ], "XYZ" );
  36265. var q2 = new Quaternion().setFromEuler( angles[ 1 ], "XYZ" );
  36266. var q3 = new Quaternion().setFromEuler( angles[ 2 ], "XYZ" );
  36267. var q = new Quaternion().multiplyQuaternions( q1, q2 ).multiply( q3 );
  36268. var m1 = new Matrix4().makeRotationFromEuler( angles[ 0 ], "XYZ" );
  36269. var m2 = new Matrix4().makeRotationFromEuler( angles[ 1 ], "XYZ" );
  36270. var m3 = new Matrix4().makeRotationFromEuler( angles[ 2 ], "XYZ" );
  36271. var m = new Matrix4().multiplyMatrices( m1, m2 ).multiply( m3 );
  36272. var qFromM = new Quaternion().setFromRotationMatrix( m );
  36273. assert.ok( qSub( q, qFromM ).length() < 0.001, "Passed!" );
  36274. } );
  36275. QUnit.test( "premultiply", ( assert ) => {
  36276. var a = new Quaternion( x, y, z, w );
  36277. var b = new Quaternion( 2 * x, - y, - 2 * z, w );
  36278. var expected = new Quaternion( 42, - 32, - 2, 58 );
  36279. a.premultiply( b );
  36280. assert.ok( Math.abs( a.x - expected.x ) <= eps, "Check x" );
  36281. assert.ok( Math.abs( a.y - expected.y ) <= eps, "Check y" );
  36282. assert.ok( Math.abs( a.z - expected.z ) <= eps, "Check z" );
  36283. assert.ok( Math.abs( a.w - expected.w ) <= eps, "Check w" );
  36284. } );
  36285. QUnit.test( "slerp", ( assert ) => {
  36286. assert.ok( false, "everything's gonna be alright" );
  36287. } );
  36288. QUnit.test( "equals", ( assert ) => {
  36289. var a = new Quaternion( x, y, z, w );
  36290. var b = new Quaternion( - x, - y, - z, - w );
  36291. assert.ok( a.x != b.x, "Passed!" );
  36292. assert.ok( a.y != b.y, "Passed!" );
  36293. assert.ok( ! a.equals( b ), "Passed!" );
  36294. assert.ok( ! b.equals( a ), "Passed!" );
  36295. a.copy( b );
  36296. assert.ok( a.x == b.x, "Passed!" );
  36297. assert.ok( a.y == b.y, "Passed!" );
  36298. assert.ok( a.equals( b ), "Passed!" );
  36299. assert.ok( b.equals( a ), "Passed!" );
  36300. } );
  36301. QUnit.test( "fromArray", ( assert ) => {
  36302. assert.ok( false, "everything's gonna be alright" );
  36303. } );
  36304. QUnit.test( "toArray", ( assert ) => {
  36305. var a = new Quaternion( x, y, z, w );
  36306. var array = a.toArray();
  36307. assert.strictEqual( array[ 0 ], x, "No array, no offset: check x" );
  36308. assert.strictEqual( array[ 1 ], y, "No array, no offset: check y" );
  36309. assert.strictEqual( array[ 2 ], z, "No array, no offset: check z" );
  36310. assert.strictEqual( array[ 3 ], w, "No array, no offset: check w" );
  36311. var array = [];
  36312. a.toArray( array );
  36313. assert.strictEqual( array[ 0 ], x, "With array, no offset: check x" );
  36314. assert.strictEqual( array[ 1 ], y, "With array, no offset: check y" );
  36315. assert.strictEqual( array[ 2 ], z, "With array, no offset: check z" );
  36316. assert.strictEqual( array[ 3 ], w, "With array, no offset: check w" );
  36317. var array = [];
  36318. a.toArray( array, 1 );
  36319. assert.strictEqual( array[ 0 ], undefined, "With array and offset: check [0]" );
  36320. assert.strictEqual( array[ 1 ], x, "With array and offset: check x" );
  36321. assert.strictEqual( array[ 2 ], y, "With array and offset: check y" );
  36322. assert.strictEqual( array[ 3 ], z, "With array and offset: check z" );
  36323. assert.strictEqual( array[ 4 ], w, "With array and offset: check w" );
  36324. } );
  36325. QUnit.test( "onChange", ( assert ) => {
  36326. assert.ok( false, "everything's gonna be alright" );
  36327. } );
  36328. QUnit.test( "onChangeCallback", ( assert ) => {
  36329. assert.ok( false, "everything's gonna be alright" );
  36330. } );
  36331. // OTHERS
  36332. QUnit.test( "multiplyVector3", ( assert ) => {
  36333. var angles = [ new Euler( 1, 0, 0 ), new Euler( 0, 1, 0 ), new Euler( 0, 0, 1 ) ];
  36334. // ensure euler conversion for Quaternion matches that of Matrix4
  36335. for ( var i = 0; i < orders.length; i ++ ) {
  36336. for ( var j = 0; j < angles.length; j ++ ) {
  36337. var q = new Quaternion().setFromEuler( angles[ j ], orders[ i ] );
  36338. var m = new Matrix4().makeRotationFromEuler( angles[ j ], orders[ i ] );
  36339. var v0 = new Vector3( 1, 0, 0 );
  36340. var qv = v0.clone().applyQuaternion( q );
  36341. var mv = v0.clone().applyMatrix4( m );
  36342. assert.ok( qv.distanceTo( mv ) < 0.001, "Passed!" );
  36343. }
  36344. }
  36345. } );
  36346. } );
  36347. } );
  36348. QUnit.module( "Quaternion" );
  36349. /**
  36350. * @author bhouston / http://exocortex.com
  36351. * @author TristanVALCKE / https://github.com/Itee
  36352. */
  36353. /* global QUnit */
  36354. QUnit.module( 'Maths', () => {
  36355. QUnit.module.todo( 'Ray', () => {
  36356. // INSTANCING
  36357. QUnit.test( "Instancing", ( assert ) => {
  36358. var a = new Ray();
  36359. assert.ok( a.origin.equals( zero3 ), "Passed!" );
  36360. assert.ok( a.direction.equals( zero3 ), "Passed!" );
  36361. var a = new Ray( two3.clone(), one3.clone() );
  36362. assert.ok( a.origin.equals( two3 ), "Passed!" );
  36363. assert.ok( a.direction.equals( one3 ), "Passed!" );
  36364. } );
  36365. // PUBLIC STUFF
  36366. QUnit.test( "isRay", ( assert ) => {
  36367. assert.ok( false, "everything's gonna be alright" );
  36368. } );
  36369. QUnit.test( "set", ( assert ) => {
  36370. var a = new Ray();
  36371. a.set( one3, one3 );
  36372. assert.ok( a.origin.equals( one3 ), "Passed!" );
  36373. assert.ok( a.direction.equals( one3 ), "Passed!" );
  36374. } );
  36375. QUnit.test( "recast/clone", ( assert ) => {
  36376. var a = new Ray( one3.clone(), new Vector3( 0, 0, 1 ) );
  36377. assert.ok( a.recast( 0 ).equals( a ), "Passed!" );
  36378. var b = a.clone();
  36379. assert.ok( b.recast( - 1 ).equals( new Ray( new Vector3( 1, 1, 0 ), new Vector3( 0, 0, 1 ) ) ), "Passed!" );
  36380. var c = a.clone();
  36381. assert.ok( c.recast( 1 ).equals( new Ray( new Vector3( 1, 1, 2 ), new Vector3( 0, 0, 1 ) ) ), "Passed!" );
  36382. var d = a.clone();
  36383. var e = d.clone().recast( 1 );
  36384. assert.ok( d.equals( a ), "Passed!" );
  36385. assert.ok( ! e.equals( d ), "Passed!" );
  36386. assert.ok( e.equals( c ), "Passed!" );
  36387. } );
  36388. QUnit.test( "copy/equals", ( assert ) => {
  36389. var a = new Ray( zero3.clone(), one3.clone() );
  36390. var b = new Ray().copy( a );
  36391. assert.ok( b.origin.equals( zero3 ), "Passed!" );
  36392. assert.ok( b.direction.equals( one3 ), "Passed!" );
  36393. // ensure that it is a true copy
  36394. a.origin = zero3;
  36395. a.direction = one3;
  36396. assert.ok( b.origin.equals( zero3 ), "Passed!" );
  36397. assert.ok( b.direction.equals( one3 ), "Passed!" );
  36398. } );
  36399. QUnit.test( "at", ( assert ) => {
  36400. var a = new Ray( one3.clone(), new Vector3( 0, 0, 1 ) );
  36401. assert.ok( a.at( 0 ).equals( one3 ), "Passed!" );
  36402. assert.ok( a.at( - 1 ).equals( new Vector3( 1, 1, 0 ) ), "Passed!" );
  36403. assert.ok( a.at( 1 ).equals( new Vector3( 1, 1, 2 ) ), "Passed!" );
  36404. } );
  36405. QUnit.test( "lookAt", ( assert ) => {
  36406. var a = new Ray( two3.clone(), one3.clone() );
  36407. var target = one3.clone();
  36408. var expected = target.sub( two3 ).normalize();
  36409. a.lookAt( target );
  36410. assert.ok( a.direction.equals( expected ), "Check if we're looking in the right direction" );
  36411. } );
  36412. QUnit.test( "closestPointToPoint", ( assert ) => {
  36413. var a = new Ray( one3.clone(), new Vector3( 0, 0, 1 ) );
  36414. // behind the ray
  36415. var b = a.closestPointToPoint( zero3 );
  36416. assert.ok( b.equals( one3 ), "Passed!" );
  36417. // front of the ray
  36418. var c = a.closestPointToPoint( new Vector3( 0, 0, 50 ) );
  36419. assert.ok( c.equals( new Vector3( 1, 1, 50 ) ), "Passed!" );
  36420. // exactly on the ray
  36421. var d = a.closestPointToPoint( one3 );
  36422. assert.ok( d.equals( one3 ), "Passed!" );
  36423. } );
  36424. QUnit.test( "distanceToPoint", ( assert ) => {
  36425. var a = new Ray( one3.clone(), new Vector3( 0, 0, 1 ) );
  36426. // behind the ray
  36427. var b = a.distanceToPoint( zero3 );
  36428. assert.ok( b === Math.sqrt( 3 ), "Passed!" );
  36429. // front of the ray
  36430. var c = a.distanceToPoint( new Vector3( 0, 0, 50 ) );
  36431. assert.ok( c === Math.sqrt( 2 ), "Passed!" );
  36432. // exactly on the ray
  36433. var d = a.distanceToPoint( one3 );
  36434. assert.ok( d === 0, "Passed!" );
  36435. } );
  36436. QUnit.test( "distanceSqToPoint", ( assert ) => {
  36437. var a = new Ray( one3.clone(), new Vector3( 0, 0, 1 ) );
  36438. // behind the ray
  36439. var b = a.distanceSqToPoint( zero3 );
  36440. assert.ok( b === 3, "Passed!" );
  36441. // front of the ray
  36442. var c = a.distanceSqToPoint( new Vector3( 0, 0, 50 ) );
  36443. assert.ok( c === 2, "Passed!" );
  36444. // exactly on the ray
  36445. var d = a.distanceSqToPoint( one3 );
  36446. assert.ok( d === 0, "Passed!" );
  36447. } );
  36448. QUnit.test( "distanceSqToSegment", ( assert ) => {
  36449. var a = new Ray( one3.clone(), new Vector3( 0, 0, 1 ) );
  36450. var ptOnLine = new Vector3();
  36451. var ptOnSegment = new Vector3();
  36452. //segment in front of the ray
  36453. var v0 = new Vector3( 3, 5, 50 );
  36454. var v1 = new Vector3( 50, 50, 50 ); // just a far away point
  36455. var distSqr = a.distanceSqToSegment( v0, v1, ptOnLine, ptOnSegment );
  36456. assert.ok( ptOnSegment.distanceTo( v0 ) < 0.0001, "Passed!" );
  36457. assert.ok( ptOnLine.distanceTo( new Vector3( 1, 1, 50 ) ) < 0.0001, "Passed!" );
  36458. // ((3-1) * (3-1) + (5-1) * (5-1) = 4 + 16 = 20
  36459. assert.ok( Math.abs( distSqr - 20 ) < 0.0001, "Passed!" );
  36460. //segment behind the ray
  36461. var v0 = new Vector3( - 50, - 50, - 50 ); // just a far away point
  36462. var v1 = new Vector3( - 3, - 5, - 4 );
  36463. var distSqr = a.distanceSqToSegment( v0, v1, ptOnLine, ptOnSegment );
  36464. assert.ok( ptOnSegment.distanceTo( v1 ) < 0.0001, "Passed!" );
  36465. assert.ok( ptOnLine.distanceTo( one3 ) < 0.0001, "Passed!" );
  36466. // ((-3-1) * (-3-1) + (-5-1) * (-5-1) + (-4-1) + (-4-1) = 16 + 36 + 25 = 77
  36467. assert.ok( Math.abs( distSqr - 77 ) < 0.0001, "Passed!" );
  36468. //exact intersection between the ray and the segment
  36469. var v0 = new Vector3( - 50, - 50, - 50 );
  36470. var v1 = new Vector3( 50, 50, 50 );
  36471. var distSqr = a.distanceSqToSegment( v0, v1, ptOnLine, ptOnSegment );
  36472. assert.ok( ptOnSegment.distanceTo( one3 ) < 0.0001, "Passed!" );
  36473. assert.ok( ptOnLine.distanceTo( one3 ) < 0.0001, "Passed!" );
  36474. assert.ok( distSqr < 0.0001, "Passed!" );
  36475. } );
  36476. QUnit.test( "intersectSphere", ( assert ) => {
  36477. var TOL = 0.0001;
  36478. // ray a0 origin located at ( 0, 0, 0 ) and points outward in negative-z direction
  36479. var a0 = new Ray( zero3.clone(), new Vector3( 0, 0, - 1 ) );
  36480. // ray a1 origin located at ( 1, 1, 1 ) and points left in negative-x direction
  36481. var a1 = new Ray( one3.clone(), new Vector3( - 1, 0, 0 ) );
  36482. // sphere (radius of 2) located behind ray a0, should result in null
  36483. var b = new Sphere( new Vector3( 0, 0, 3 ), 2 );
  36484. assert.ok( a0.intersectSphere( b ) === null, "Passed!" );
  36485. // sphere (radius of 2) located in front of, but too far right of ray a0, should result in null
  36486. var b = new Sphere( new Vector3( 3, 0, - 1 ), 2 );
  36487. assert.ok( a0.intersectSphere( b ) === null, "Passed!" );
  36488. // sphere (radius of 2) located below ray a1, should result in null
  36489. var b = new Sphere( new Vector3( 1, - 2, 1 ), 2 );
  36490. assert.ok( a1.intersectSphere( b ) === null, "Passed!" );
  36491. // sphere (radius of 1) located to the left of ray a1, should result in intersection at 0, 1, 1
  36492. var b = new Sphere( new Vector3( - 1, 1, 1 ), 1 );
  36493. assert.ok( a1.intersectSphere( b ).distanceTo( new Vector3( 0, 1, 1 ) ) < TOL, "Passed!" );
  36494. // sphere (radius of 1) located in front of ray a0, should result in intersection at 0, 0, -1
  36495. var b = new Sphere( new Vector3( 0, 0, - 2 ), 1 );
  36496. assert.ok( a0.intersectSphere( b ).distanceTo( new Vector3( 0, 0, - 1 ) ) < TOL, "Passed!" );
  36497. // sphere (radius of 2) located in front & right of ray a0, should result in intersection at 0, 0, -1, or left-most edge of sphere
  36498. var b = new Sphere( new Vector3( 2, 0, - 1 ), 2 );
  36499. assert.ok( a0.intersectSphere( b ).distanceTo( new Vector3( 0, 0, - 1 ) ) < TOL, "Passed!" );
  36500. // same situation as above, but move the sphere a fraction more to the right, and ray a0 should now just miss
  36501. var b = new Sphere( new Vector3( 2.01, 0, - 1 ), 2 );
  36502. assert.ok( a0.intersectSphere( b ) === null, "Passed!" );
  36503. // following QUnit.tests are for situations where the ray origin is inside the sphere
  36504. // sphere (radius of 1) center located at ray a0 origin / sphere surrounds the ray origin, so the first intersect point 0, 0, 1,
  36505. // is behind ray a0. Therefore, second exit point on back of sphere will be returned: 0, 0, -1
  36506. // thus keeping the intersection point always in front of the ray.
  36507. var b = new Sphere( zero3.clone(), 1 );
  36508. assert.ok( a0.intersectSphere( b ).distanceTo( new Vector3( 0, 0, - 1 ) ) < TOL, "Passed!" );
  36509. // sphere (radius of 4) center located behind ray a0 origin / sphere surrounds the ray origin, so the first intersect point 0, 0, 5,
  36510. // is behind ray a0. Therefore, second exit point on back of sphere will be returned: 0, 0, -3
  36511. // thus keeping the intersection point always in front of the ray.
  36512. var b = new Sphere( new Vector3( 0, 0, 1 ), 4 );
  36513. assert.ok( a0.intersectSphere( b ).distanceTo( new Vector3( 0, 0, - 3 ) ) < TOL, "Passed!" );
  36514. // sphere (radius of 4) center located in front of ray a0 origin / sphere surrounds the ray origin, so the first intersect point 0, 0, 3,
  36515. // is behind ray a0. Therefore, second exit point on back of sphere will be returned: 0, 0, -5
  36516. // thus keeping the intersection point always in front of the ray.
  36517. var b = new Sphere( new Vector3( 0, 0, - 1 ), 4 );
  36518. assert.ok( a0.intersectSphere( b ).distanceTo( new Vector3( 0, 0, - 5 ) ) < TOL, "Passed!" );
  36519. } );
  36520. QUnit.test( "intersectsSphere", ( assert ) => {
  36521. var a = new Ray( one3.clone(), new Vector3( 0, 0, 1 ) );
  36522. var b = new Sphere( zero3, 0.5 );
  36523. var c = new Sphere( zero3, 1.5 );
  36524. var d = new Sphere( one3, 0.1 );
  36525. var e = new Sphere( two3, 0.1 );
  36526. var f = new Sphere( two3, 1 );
  36527. assert.ok( ! a.intersectsSphere( b ), "Passed!" );
  36528. assert.ok( ! a.intersectsSphere( c ), "Passed!" );
  36529. assert.ok( a.intersectsSphere( d ), "Passed!" );
  36530. assert.ok( ! a.intersectsSphere( e ), "Passed!" );
  36531. assert.ok( ! a.intersectsSphere( f ), "Passed!" );
  36532. } );
  36533. QUnit.test( "distanceToPlane", ( assert ) => {
  36534. assert.ok( false, "everything's gonna be alright" );
  36535. } );
  36536. QUnit.test( "intersectPlane", ( assert ) => {
  36537. var a = new Ray( one3.clone(), new Vector3( 0, 0, 1 ) );
  36538. // parallel plane behind
  36539. var b = new Plane().setFromNormalAndCoplanarPoint( new Vector3( 0, 0, 1 ), new Vector3( 1, 1, - 1 ) );
  36540. assert.ok( a.intersectPlane( b ) === null, "Passed!" );
  36541. // parallel plane coincident with origin
  36542. var c = new Plane().setFromNormalAndCoplanarPoint( new Vector3( 0, 0, 1 ), new Vector3( 1, 1, 0 ) );
  36543. assert.ok( a.intersectPlane( c ) === null, "Passed!" );
  36544. // parallel plane infront
  36545. var d = new Plane().setFromNormalAndCoplanarPoint( new Vector3( 0, 0, 1 ), new Vector3( 1, 1, 1 ) );
  36546. assert.ok( a.intersectPlane( d ).equals( a.origin ), "Passed!" );
  36547. // perpendical ray that overlaps exactly
  36548. var e = new Plane().setFromNormalAndCoplanarPoint( new Vector3( 1, 0, 0 ), one3 );
  36549. assert.ok( a.intersectPlane( e ).equals( a.origin ), "Passed!" );
  36550. // perpendical ray that doesn't overlap
  36551. var f = new Plane().setFromNormalAndCoplanarPoint( new Vector3( 1, 0, 0 ), zero3 );
  36552. assert.ok( a.intersectPlane( f ) === null, "Passed!" );
  36553. } );
  36554. QUnit.test( "intersectsPlane", ( assert ) => {
  36555. var a = new Ray( one3.clone(), new Vector3( 0, 0, 1 ) );
  36556. // parallel plane in front of the ray
  36557. var b = new Plane().setFromNormalAndCoplanarPoint( new Vector3( 0, 0, 1 ), one3.clone().sub( new Vector3( 0, 0, - 1 ) ) );
  36558. assert.ok( a.intersectsPlane( b ), "Passed!" );
  36559. // parallel plane coincident with origin
  36560. var c = new Plane().setFromNormalAndCoplanarPoint( new Vector3( 0, 0, 1 ), one3.clone().sub( new Vector3( 0, 0, 0 ) ) );
  36561. assert.ok( a.intersectsPlane( c ), "Passed!" );
  36562. // parallel plane behind the ray
  36563. var d = new Plane().setFromNormalAndCoplanarPoint( new Vector3( 0, 0, 1 ), one3.clone().sub( new Vector3( 0, 0, 1 ) ) );
  36564. assert.ok( ! a.intersectsPlane( d ), "Passed!" );
  36565. // perpendical ray that overlaps exactly
  36566. var e = new Plane().setFromNormalAndCoplanarPoint( new Vector3( 1, 0, 0 ), one3 );
  36567. assert.ok( a.intersectsPlane( e ), "Passed!" );
  36568. // perpendical ray that doesn't overlap
  36569. var f = new Plane().setFromNormalAndCoplanarPoint( new Vector3( 1, 0, 0 ), zero3 );
  36570. assert.ok( ! a.intersectsPlane( f ), "Passed!" );
  36571. } );
  36572. QUnit.test( "intersectBox", ( assert ) => {
  36573. var TOL = 0.0001;
  36574. var box = new Box3( new Vector3( - 1, - 1, - 1 ), new Vector3( 1, 1, 1 ) );
  36575. var a = new Ray( new Vector3( - 2, 0, 0 ), new Vector3( 1, 0, 0 ) );
  36576. //ray should intersect box at -1,0,0
  36577. assert.ok( a.intersectsBox( box ) === true, "Passed!" );
  36578. assert.ok( a.intersectBox( box ).distanceTo( new Vector3( - 1, 0, 0 ) ) < TOL, "Passed!" );
  36579. var b = new Ray( new Vector3( - 2, 0, 0 ), new Vector3( - 1, 0, 0 ) );
  36580. //ray is point away from box, it should not intersect
  36581. assert.ok( b.intersectsBox( box ) === false, "Passed!" );
  36582. assert.ok( b.intersectBox( box ) === null, "Passed!" );
  36583. var c = new Ray( new Vector3( 0, 0, 0 ), new Vector3( 1, 0, 0 ) );
  36584. // ray is inside box, should return exit point
  36585. assert.ok( c.intersectsBox( box ) === true, "Passed!" );
  36586. assert.ok( c.intersectBox( box ).distanceTo( new Vector3( 1, 0, 0 ) ) < TOL, "Passed!" );
  36587. var d = new Ray( new Vector3( 0, 2, 1 ), new Vector3( 0, - 1, - 1 ).normalize() );
  36588. //tilted ray should intersect box at 0,1,0
  36589. assert.ok( d.intersectsBox( box ) === true, "Passed!" );
  36590. assert.ok( d.intersectBox( box ).distanceTo( new Vector3( 0, 1, 0 ) ) < TOL, "Passed!" );
  36591. var e = new Ray( new Vector3( 1, - 2, 1 ), new Vector3( 0, 1, 0 ).normalize() );
  36592. //handle case where ray is coplanar with one of the boxes side - box in front of ray
  36593. assert.ok( e.intersectsBox( box ) === true, "Passed!" );
  36594. assert.ok( e.intersectBox( box ).distanceTo( new Vector3( 1, - 1, 1 ) ) < TOL, "Passed!" );
  36595. var f = new Ray( new Vector3( 1, - 2, 0 ), new Vector3( 0, - 1, 0 ).normalize() );
  36596. //handle case where ray is coplanar with one of the boxes side - box behind ray
  36597. assert.ok( f.intersectsBox( box ) === false, "Passed!" );
  36598. assert.ok( f.intersectBox( box ) == null, "Passed!" );
  36599. } );
  36600. QUnit.test( "intersectsBox", ( assert ) => {
  36601. assert.ok( false, "everything's gonna be alright" );
  36602. } );
  36603. QUnit.test( "intersectTriangle", ( assert ) => {
  36604. var ray = new Ray();
  36605. var a = new Vector3( 1, 1, 0 );
  36606. var b = new Vector3( 0, 1, 1 );
  36607. var c = new Vector3( 1, 0, 1 );
  36608. var intersect;
  36609. // DdN == 0
  36610. ray.set( ray.origin, zero3.clone() );
  36611. intersect = ray.intersectTriangle( a, b, c, false );
  36612. assert.strictEqual( intersect, null, "No intersection if direction == zero" );
  36613. // DdN > 0, backfaceCulling = true
  36614. ray.set( ray.origin, one3.clone() );
  36615. intersect = ray.intersectTriangle( a, b, c, true );
  36616. assert.strictEqual( intersect, null, "No intersection with backside faces if backfaceCulling is true" );
  36617. // DdN > 0
  36618. ray.set( ray.origin, one3.clone() );
  36619. intersect = ray.intersectTriangle( a, b, c, false );
  36620. assert.ok( Math.abs( intersect.x - 2 / 3 ) <= eps, "Successful intersection: check x" );
  36621. assert.ok( Math.abs( intersect.y - 2 / 3 ) <= eps, "Successful intersection: check y" );
  36622. assert.ok( Math.abs( intersect.z - 2 / 3 ) <= eps, "Successful intersection: check z" );
  36623. // DdN > 0, DdQxE2 < 0
  36624. b.multiplyScalar( - 1 );
  36625. intersect = ray.intersectTriangle( a, b, c, false );
  36626. assert.strictEqual( intersect, null, "No intersection" );
  36627. // DdN > 0, DdE1xQ < 0
  36628. a.multiplyScalar( - 1 );
  36629. intersect = ray.intersectTriangle( a, b, c, false );
  36630. assert.strictEqual( intersect, null, "No intersection" );
  36631. // DdN > 0, DdQxE2 + DdE1xQ > DdN
  36632. b.multiplyScalar( - 1 );
  36633. intersect = ray.intersectTriangle( a, b, c, false );
  36634. assert.strictEqual( intersect, null, "No intersection" );
  36635. // DdN < 0, QdN < 0
  36636. a.multiplyScalar( - 1 );
  36637. b.multiplyScalar( - 1 );
  36638. ray.direction.multiplyScalar( - 1 );
  36639. intersect = ray.intersectTriangle( a, b, c, false );
  36640. assert.strictEqual( intersect, null, "No intersection when looking in the wrong direction" );
  36641. } );
  36642. QUnit.test( "applyMatrix4", ( assert ) => {
  36643. var a = new Ray( one3.clone(), new Vector3( 0, 0, 1 ) );
  36644. var m = new Matrix4();
  36645. assert.ok( a.clone().applyMatrix4( m ).equals( a ), "Passed!" );
  36646. var a = new Ray( zero3.clone(), new Vector3( 0, 0, 1 ) );
  36647. m.makeRotationZ( Math.PI );
  36648. assert.ok( a.clone().applyMatrix4( m ).equals( a ), "Passed!" );
  36649. m.makeRotationX( Math.PI );
  36650. var b = a.clone();
  36651. b.direction.negate();
  36652. var a2 = a.clone().applyMatrix4( m );
  36653. assert.ok( a2.origin.distanceTo( b.origin ) < 0.0001, "Passed!" );
  36654. assert.ok( a2.direction.distanceTo( b.direction ) < 0.0001, "Passed!" );
  36655. a.origin = new Vector3( 0, 0, 1 );
  36656. b.origin = new Vector3( 0, 0, - 1 );
  36657. var a2 = a.clone().applyMatrix4( m );
  36658. assert.ok( a2.origin.distanceTo( b.origin ) < 0.0001, "Passed!" );
  36659. assert.ok( a2.direction.distanceTo( b.direction ) < 0.0001, "Passed!" );
  36660. } );
  36661. QUnit.test( "equals", ( assert ) => {
  36662. assert.ok( false, "everything's gonna be alright" );
  36663. } );
  36664. } );
  36665. } );
  36666. /**
  36667. * @author bhouston / http://exocortex.com
  36668. * @author TristanVALCKE / https://github.com/Itee
  36669. */
  36670. /* global QUnit */
  36671. QUnit.module( 'Maths', () => {
  36672. QUnit.module.todo( 'Sphere', () => {
  36673. // INSTANCING
  36674. QUnit.test( "Instancing", ( assert ) => {
  36675. var a = new Sphere();
  36676. assert.ok( a.center.equals( zero3 ), "Passed!" );
  36677. assert.ok( a.radius == 0, "Passed!" );
  36678. var a = new Sphere( one3.clone(), 1 );
  36679. assert.ok( a.center.equals( one3 ), "Passed!" );
  36680. assert.ok( a.radius == 1, "Passed!" );
  36681. } );
  36682. // PUBLIC STUFF
  36683. QUnit.test( "isSphere", ( assert ) => {
  36684. assert.ok( false, "everything's gonna be alright" );
  36685. } );
  36686. QUnit.test( "set", ( assert ) => {
  36687. var a = new Sphere();
  36688. assert.ok( a.center.equals( zero3 ), "Passed!" );
  36689. assert.ok( a.radius == 0, "Passed!" );
  36690. a.set( one3, 1 );
  36691. assert.ok( a.center.equals( one3 ), "Passed!" );
  36692. assert.ok( a.radius == 1, "Passed!" );
  36693. } );
  36694. QUnit.test( "setFromPoints", ( assert ) => {
  36695. var a = new Sphere();
  36696. var expectedCenter = new Vector3( 0.9330126941204071, 0, 0 );
  36697. var expectedRadius = 1.3676668773461689;
  36698. var optionalCenter = new Vector3( 1, 1, 1 );
  36699. var points = [
  36700. new Vector3( 1, 1, 0 ), new Vector3( 1, 1, 0 ),
  36701. new Vector3( 1, 1, 0 ), new Vector3( 1, 1, 0 ),
  36702. new Vector3( 1, 1, 0 ), new Vector3( 0.8660253882408142, 0.5, 0 ),
  36703. new Vector3( - 0, 0.5, 0.8660253882408142 ), new Vector3( 1.8660253882408142, 0.5, 0 ),
  36704. new Vector3( 0, 0.5, - 0.8660253882408142 ), new Vector3( 0.8660253882408142, 0.5, - 0 ),
  36705. new Vector3( 0.8660253882408142, - 0.5, 0 ), new Vector3( - 0, - 0.5, 0.8660253882408142 ),
  36706. new Vector3( 1.8660253882408142, - 0.5, 0 ), new Vector3( 0, - 0.5, - 0.8660253882408142 ),
  36707. new Vector3( 0.8660253882408142, - 0.5, - 0 ), new Vector3( - 0, - 1, 0 ),
  36708. new Vector3( - 0, - 1, 0 ), new Vector3( 0, - 1, 0 ),
  36709. new Vector3( 0, - 1, - 0 ), new Vector3( - 0, - 1, - 0 ),
  36710. ];
  36711. a.setFromPoints( points );
  36712. assert.ok( Math.abs( a.center.x - expectedCenter.x ) <= eps, "Default center: check center.x" );
  36713. assert.ok( Math.abs( a.center.y - expectedCenter.y ) <= eps, "Default center: check center.y" );
  36714. assert.ok( Math.abs( a.center.z - expectedCenter.z ) <= eps, "Default center: check center.z" );
  36715. assert.ok( Math.abs( a.radius - expectedRadius ) <= eps, "Default center: check radius" );
  36716. var expectedRadius = 2.5946195770400102;
  36717. a.setFromPoints( points, optionalCenter );
  36718. assert.ok( Math.abs( a.center.x - optionalCenter.x ) <= eps, "Optional center: check center.x" );
  36719. assert.ok( Math.abs( a.center.y - optionalCenter.y ) <= eps, "Optional center: check center.y" );
  36720. assert.ok( Math.abs( a.center.z - optionalCenter.z ) <= eps, "Optional center: check center.z" );
  36721. assert.ok( Math.abs( a.radius - expectedRadius ) <= eps, "Optional center: check radius" );
  36722. } );
  36723. QUnit.test( "clone", ( assert ) => {
  36724. assert.ok( false, "everything's gonna be alright" );
  36725. } );
  36726. QUnit.test( "copy", ( assert ) => {
  36727. var a = new Sphere( one3.clone(), 1 );
  36728. var b = new Sphere().copy( a );
  36729. assert.ok( b.center.equals( one3 ), "Passed!" );
  36730. assert.ok( b.radius == 1, "Passed!" );
  36731. // ensure that it is a true copy
  36732. a.center = zero3;
  36733. a.radius = 0;
  36734. assert.ok( b.center.equals( one3 ), "Passed!" );
  36735. assert.ok( b.radius == 1, "Passed!" );
  36736. } );
  36737. QUnit.test( "empty", ( assert ) => {
  36738. var a = new Sphere();
  36739. assert.ok( a.empty(), "Passed!" );
  36740. a.set( one3, 1 );
  36741. assert.ok( ! a.empty(), "Passed!" );
  36742. } );
  36743. QUnit.test( "containsPoint", ( assert ) => {
  36744. var a = new Sphere( one3.clone(), 1 );
  36745. assert.ok( ! a.containsPoint( zero3 ), "Passed!" );
  36746. assert.ok( a.containsPoint( one3 ), "Passed!" );
  36747. } );
  36748. QUnit.test( "distanceToPoint", ( assert ) => {
  36749. var a = new Sphere( one3.clone(), 1 );
  36750. assert.ok( ( a.distanceToPoint( zero3 ) - 0.7320 ) < 0.001, "Passed!" );
  36751. assert.ok( a.distanceToPoint( one3 ) === - 1, "Passed!" );
  36752. } );
  36753. QUnit.test( "intersectsSphere", ( assert ) => {
  36754. var a = new Sphere( one3.clone(), 1 );
  36755. var b = new Sphere( zero3.clone(), 1 );
  36756. var c = new Sphere( zero3.clone(), 0.25 );
  36757. assert.ok( a.intersectsSphere( b ), "Passed!" );
  36758. assert.ok( ! a.intersectsSphere( c ), "Passed!" );
  36759. } );
  36760. QUnit.test( "intersectsBox", ( assert ) => {
  36761. var a = new Sphere();
  36762. var b = new Sphere( new Vector3( - 5, - 5, - 5 ) );
  36763. var box = new Box3( zero3, one3 );
  36764. assert.strictEqual( a.intersectsBox( box ), true, "Check default sphere" );
  36765. assert.strictEqual( b.intersectsBox( box ), false, "Check shifted sphere" );
  36766. } );
  36767. QUnit.test( "intersectsPlane", ( assert ) => {
  36768. var a = new Sphere( zero3.clone(), 1 );
  36769. var b = new Plane( new Vector3( 0, 1, 0 ), 1 );
  36770. var c = new Plane( new Vector3( 0, 1, 0 ), 1.25 );
  36771. var d = new Plane( new Vector3( 0, - 1, 0 ), 1.25 );
  36772. assert.ok( a.intersectsPlane( b ), "Passed!" );
  36773. assert.ok( ! a.intersectsPlane( c ), "Passed!" );
  36774. assert.ok( ! a.intersectsPlane( d ), "Passed!" );
  36775. } );
  36776. QUnit.test( "clampPoint", ( assert ) => {
  36777. var a = new Sphere( one3.clone(), 1 );
  36778. assert.ok( a.clampPoint( new Vector3( 1, 1, 3 ) ).equals( new Vector3( 1, 1, 2 ) ), "Passed!" );
  36779. assert.ok( a.clampPoint( new Vector3( 1, 1, - 3 ) ).equals( new Vector3( 1, 1, 0 ) ), "Passed!" );
  36780. } );
  36781. QUnit.test( "getBoundingBox", ( assert ) => {
  36782. var a = new Sphere( one3.clone(), 1 );
  36783. assert.ok( a.getBoundingBox().equals( new Box3( zero3, two3 ) ), "Passed!" );
  36784. a.set( zero3, 0 );
  36785. assert.ok( a.getBoundingBox().equals( new Box3( zero3, zero3 ) ), "Passed!" );
  36786. } );
  36787. QUnit.test( "applyMatrix4", ( assert ) => {
  36788. var a = new Sphere( one3.clone(), 1 );
  36789. var m = new Matrix4().makeTranslation( 1, - 2, 1 );
  36790. assert.ok( a.clone().applyMatrix4( m ).getBoundingBox().equals( a.getBoundingBox().applyMatrix4( m ) ), "Passed!" );
  36791. } );
  36792. QUnit.test( "translate", ( assert ) => {
  36793. var a = new Sphere( one3.clone(), 1 );
  36794. a.translate( one3.clone().negate() );
  36795. assert.ok( a.center.equals( zero3 ), "Passed!" );
  36796. } );
  36797. QUnit.test( "equals", ( assert ) => {
  36798. var a = new Sphere();
  36799. var b = new Sphere( new Vector3( 1, 0, 0 ) );
  36800. var c = new Sphere( new Vector3( 1, 0, 0 ), 1.0 );
  36801. assert.strictEqual( a.equals( b ), false, "a does not equal b" );
  36802. assert.strictEqual( a.equals( c ), false, "a does not equal c" );
  36803. assert.strictEqual( b.equals( c ), false, "b does not equal c" );
  36804. a.copy( b );
  36805. assert.strictEqual( a.equals( b ), true, "a equals b after copy()" );
  36806. } );
  36807. } );
  36808. } );
  36809. function Spherical( radius, phi, theta ) {
  36810. this.radius = ( radius !== undefined ) ? radius : 1.0;
  36811. this.phi = ( phi !== undefined ) ? phi : 0; // up / down towards top and bottom pole
  36812. this.theta = ( theta !== undefined ) ? theta : 0; // around the equator of the sphere
  36813. return this;
  36814. }
  36815. Object.assign( Spherical.prototype, {
  36816. set: function ( radius, phi, theta ) {
  36817. this.radius = radius;
  36818. this.phi = phi;
  36819. this.theta = theta;
  36820. return this;
  36821. },
  36822. clone: function () {
  36823. return new this.constructor().copy( this );
  36824. },
  36825. copy: function ( other ) {
  36826. this.radius = other.radius;
  36827. this.phi = other.phi;
  36828. this.theta = other.theta;
  36829. return this;
  36830. },
  36831. // restrict phi to be betwee EPS and PI-EPS
  36832. makeSafe: function () {
  36833. var EPS = 0.000001;
  36834. this.phi = Math.max( EPS, Math.min( Math.PI - EPS, this.phi ) );
  36835. return this;
  36836. },
  36837. setFromVector3: function ( vec3 ) {
  36838. this.radius = vec3.length();
  36839. if ( this.radius === 0 ) {
  36840. this.theta = 0;
  36841. this.phi = 0;
  36842. } else {
  36843. this.theta = Math.atan2( vec3.x, vec3.z ); // equator angle around y-up axis
  36844. this.phi = Math.acos( _Math.clamp( vec3.y / this.radius, - 1, 1 ) ); // polar angle
  36845. }
  36846. return this;
  36847. }
  36848. } );
  36849. /**
  36850. * @author moraxy / https://github.com/moraxy
  36851. * @author TristanVALCKE / https://github.com/Itee
  36852. */
  36853. /* global QUnit */
  36854. QUnit.module( 'Maths', () => {
  36855. QUnit.module.todo( 'Spherical', () => {
  36856. // INSTANCING
  36857. QUnit.test( "Instancing", ( assert ) => {
  36858. var a = new Spherical();
  36859. var radius = 10.0;
  36860. var phi = Math.acos( - 0.5 );
  36861. var theta = Math.sqrt( Math.PI ) * phi;
  36862. assert.strictEqual( a.radius, 1.0, "Default values: check radius" );
  36863. assert.strictEqual( a.phi, 0, "Default values: check phi" );
  36864. assert.strictEqual( a.theta, 0, "Default values: check theta" );
  36865. var a = new Spherical( radius, phi, theta );
  36866. assert.strictEqual( a.radius, radius, "Custom values: check radius" );
  36867. assert.strictEqual( a.phi, phi, "Custom values: check phi" );
  36868. assert.strictEqual( a.theta, theta, "Custom values: check theta" );
  36869. } );
  36870. // PUBLIC STUFF
  36871. QUnit.test( "isSpherical", ( assert ) => {
  36872. assert.ok( false, "everything's gonna be alright" );
  36873. } );
  36874. QUnit.test( "set", ( assert ) => {
  36875. var a = new Spherical();
  36876. var radius = 10.0;
  36877. var phi = Math.acos( - 0.5 );
  36878. var theta = Math.sqrt( Math.PI ) * phi;
  36879. a.set( radius, phi, theta );
  36880. assert.strictEqual( a.radius, radius, "Check radius" );
  36881. assert.strictEqual( a.phi, phi, "Check phi" );
  36882. assert.strictEqual( a.theta, theta, "Check theta" );
  36883. } );
  36884. QUnit.test( "clone", ( assert ) => {
  36885. var radius = 10.0;
  36886. var phi = Math.acos( - 0.5 );
  36887. var theta = Math.sqrt( Math.PI ) * phi;
  36888. var a = new Spherical( radius, phi, theta );
  36889. var b = a.clone();
  36890. assert.propEqual( a, b, "Check a and b are equal after clone()" );
  36891. a.radius = 2.0;
  36892. assert.notPropEqual( a, b, "Check a and b are not equal after modification" );
  36893. } );
  36894. QUnit.test( "copy", ( assert ) => {
  36895. var radius = 10.0;
  36896. var phi = Math.acos( - 0.5 );
  36897. var theta = Math.sqrt( Math.PI ) * phi;
  36898. var a = new Spherical( radius, phi, theta );
  36899. var b = new Spherical().copy( a );
  36900. assert.propEqual( a, b, "Check a and b are equal after copy()" );
  36901. a.radius = 2.0;
  36902. assert.notPropEqual( a, b, "Check a and b are not equal after modification" );
  36903. } );
  36904. QUnit.test( "makeSafe", ( assert ) => {
  36905. var EPS = 0.000001; // from source
  36906. var tooLow = 0.0;
  36907. var tooHigh = Math.PI;
  36908. var justRight = 1.5;
  36909. var a = new Spherical( 1, tooLow, 0 );
  36910. a.makeSafe();
  36911. assert.strictEqual( a.phi, EPS, "Check if small values are set to EPS" );
  36912. a.set( 1, tooHigh, 0 );
  36913. a.makeSafe();
  36914. assert.strictEqual( a.phi, Math.PI - EPS, "Check if high values are set to (Math.PI - EPS)" );
  36915. a.set( 1, justRight, 0 );
  36916. a.makeSafe();
  36917. assert.strictEqual( a.phi, justRight, "Check that valid values don't get changed" );
  36918. } );
  36919. QUnit.test( "setFromVector3", ( assert ) => {
  36920. var a = new Spherical( 1, 1, 1 );
  36921. var b = new Vector3( 0, 0, 0 );
  36922. var c = new Vector3( Math.PI, 1, - Math.PI );
  36923. var expected = new Spherical( 4.554032147688322, 1.3494066171539107, 2.356194490192345 );
  36924. a.setFromVector3( b );
  36925. assert.strictEqual( a.radius, 0, "Zero-length vector: check radius" );
  36926. assert.strictEqual( a.phi, 0, "Zero-length vector: check phi" );
  36927. assert.strictEqual( a.theta, 0, "Zero-length vector: check theta" );
  36928. a.setFromVector3( c );
  36929. assert.ok( Math.abs( a.radius - expected.radius ) <= eps, "Normal vector: check radius" );
  36930. assert.ok( Math.abs( a.phi - expected.phi ) <= eps, "Normal vector: check phi" );
  36931. assert.ok( Math.abs( a.theta - expected.theta ) <= eps, "Normal vector: check theta" );
  36932. } );
  36933. } );
  36934. } );
  36935. /**
  36936. * @author bhouston / http://exocortex.com
  36937. * @author TristanVALCKE / https://github.com/Itee
  36938. */
  36939. /* global QUnit */
  36940. QUnit.module( 'Maths', () => {
  36941. QUnit.module.todo( 'Triangle', () => {
  36942. // INSTANCING
  36943. QUnit.test( "Instancing", ( assert ) => {
  36944. var a = new Triangle();
  36945. assert.ok( a.a.equals( zero3 ), "Passed!" );
  36946. assert.ok( a.b.equals( zero3 ), "Passed!" );
  36947. assert.ok( a.c.equals( zero3 ), "Passed!" );
  36948. var a = new Triangle( one3.clone().negate(), one3.clone(), two3.clone() );
  36949. assert.ok( a.a.equals( one3.clone().negate() ), "Passed!" );
  36950. assert.ok( a.b.equals( one3 ), "Passed!" );
  36951. assert.ok( a.c.equals( two3 ), "Passed!" );
  36952. } );
  36953. // STATIC STUFF
  36954. QUnit.test( "normal", ( assert ) => {
  36955. assert.ok( false, "everything's gonna be alright" );
  36956. } );
  36957. QUnit.test( "barycoordFromPoint", ( assert ) => {
  36958. assert.ok( false, "everything's gonna be alright" );
  36959. } );
  36960. QUnit.test( "containsPoint", ( assert ) => {
  36961. assert.ok( false, "everything's gonna be alright" );
  36962. } );
  36963. // PUBLIC STUFF
  36964. QUnit.test( "set", ( assert ) => {
  36965. var a = new Triangle();
  36966. a.set( one3.clone().negate(), one3, two3 );
  36967. assert.ok( a.a.equals( one3.clone().negate() ), "Passed!" );
  36968. assert.ok( a.b.equals( one3 ), "Passed!" );
  36969. assert.ok( a.c.equals( two3 ), "Passed!" );
  36970. } );
  36971. QUnit.test( "setFromPointsAndIndices", ( assert ) => {
  36972. var a = new Triangle();
  36973. var points = [ one3, one3.clone().negate(), two3 ];
  36974. a.setFromPointsAndIndices( points, 1, 0, 2 );
  36975. assert.ok( a.a.equals( one3.clone().negate() ), "Passed!" );
  36976. assert.ok( a.b.equals( one3 ), "Passed!" );
  36977. assert.ok( a.c.equals( two3 ), "Passed!" );
  36978. } );
  36979. QUnit.test( "clone", ( assert ) => {
  36980. assert.ok( false, "everything's gonna be alright" );
  36981. } );
  36982. QUnit.test( "copy", ( assert ) => {
  36983. var a = new Triangle( one3.clone().negate(), one3.clone(), two3.clone() );
  36984. var b = new Triangle().copy( a );
  36985. assert.ok( b.a.equals( one3.clone().negate() ), "Passed!" );
  36986. assert.ok( b.b.equals( one3 ), "Passed!" );
  36987. assert.ok( b.c.equals( two3 ), "Passed!" );
  36988. // ensure that it is a true copy
  36989. a.a = one3;
  36990. a.b = zero3;
  36991. a.c = zero3;
  36992. assert.ok( b.a.equals( one3.clone().negate() ), "Passed!" );
  36993. assert.ok( b.b.equals( one3 ), "Passed!" );
  36994. assert.ok( b.c.equals( two3 ), "Passed!" );
  36995. } );
  36996. QUnit.test( "area", ( assert ) => {
  36997. var a = new Triangle();
  36998. assert.ok( a.area() == 0, "Passed!" );
  36999. var a = new Triangle( new Vector3( 0, 0, 0 ), new Vector3( 1, 0, 0 ), new Vector3( 0, 1, 0 ) );
  37000. assert.ok( a.area() == 0.5, "Passed!" );
  37001. var a = new Triangle( new Vector3( 2, 0, 0 ), new Vector3( 0, 0, 0 ), new Vector3( 0, 0, 2 ) );
  37002. assert.ok( a.area() == 2, "Passed!" );
  37003. // colinear triangle.
  37004. var a = new Triangle( new Vector3( 2, 0, 0 ), new Vector3( 0, 0, 0 ), new Vector3( 3, 0, 0 ) );
  37005. assert.ok( a.area() == 0, "Passed!" );
  37006. } );
  37007. QUnit.test( "midpoint", ( assert ) => {
  37008. var a = new Triangle();
  37009. assert.ok( a.midpoint().equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
  37010. var a = new Triangle( new Vector3( 0, 0, 0 ), new Vector3( 1, 0, 0 ), new Vector3( 0, 1, 0 ) );
  37011. assert.ok( a.midpoint().equals( new Vector3( 1 / 3, 1 / 3, 0 ) ), "Passed!" );
  37012. var a = new Triangle( new Vector3( 2, 0, 0 ), new Vector3( 0, 0, 0 ), new Vector3( 0, 0, 2 ) );
  37013. assert.ok( a.midpoint().equals( new Vector3( 2 / 3, 0, 2 / 3 ) ), "Passed!" );
  37014. } );
  37015. QUnit.test( "normal", ( assert ) => {
  37016. var a = new Triangle();
  37017. assert.ok( a.normal().equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
  37018. var a = new Triangle( new Vector3( 0, 0, 0 ), new Vector3( 1, 0, 0 ), new Vector3( 0, 1, 0 ) );
  37019. assert.ok( a.normal().equals( new Vector3( 0, 0, 1 ) ), "Passed!" );
  37020. var a = new Triangle( new Vector3( 2, 0, 0 ), new Vector3( 0, 0, 0 ), new Vector3( 0, 0, 2 ) );
  37021. assert.ok( a.normal().equals( new Vector3( 0, 1, 0 ) ), "Passed!" );
  37022. } );
  37023. QUnit.test( "plane", ( assert ) => {
  37024. var a = new Triangle();
  37025. assert.notOk( isNaN( a.plane().distanceToPoint( a.a ) ), "Passed!" );
  37026. assert.notOk( isNaN( a.plane().distanceToPoint( a.b ) ), "Passed!" );
  37027. assert.notOk( isNaN( a.plane().distanceToPoint( a.c ) ), "Passed!" );
  37028. assert.notPropEqual( a.plane().normal, {
  37029. x: NaN,
  37030. y: NaN,
  37031. z: NaN
  37032. }, "Passed!" );
  37033. var a = new Triangle( new Vector3( 0, 0, 0 ), new Vector3( 1, 0, 0 ), new Vector3( 0, 1, 0 ) );
  37034. assert.ok( a.plane().distanceToPoint( a.a ) == 0, "Passed!" );
  37035. assert.ok( a.plane().distanceToPoint( a.b ) == 0, "Passed!" );
  37036. assert.ok( a.plane().distanceToPoint( a.c ) == 0, "Passed!" );
  37037. assert.ok( a.plane().normal.equals( a.normal() ), "Passed!" );
  37038. var a = new Triangle( new Vector3( 2, 0, 0 ), new Vector3( 0, 0, 0 ), new Vector3( 0, 0, 2 ) );
  37039. assert.ok( a.plane().distanceToPoint( a.a ) == 0, "Passed!" );
  37040. assert.ok( a.plane().distanceToPoint( a.b ) == 0, "Passed!" );
  37041. assert.ok( a.plane().distanceToPoint( a.c ) == 0, "Passed!" );
  37042. assert.ok( a.plane().normal.clone().normalize().equals( a.normal() ), "Passed!" );
  37043. } );
  37044. QUnit.test( "barycoordFromPoint", ( assert ) => {
  37045. var a = new Triangle();
  37046. var bad = new Vector3( - 2, - 1, - 1 );
  37047. assert.ok( a.barycoordFromPoint( a.a ).equals( bad ), "Passed!" );
  37048. assert.ok( a.barycoordFromPoint( a.b ).equals( bad ), "Passed!" );
  37049. assert.ok( a.barycoordFromPoint( a.c ).equals( bad ), "Passed!" );
  37050. var a = new Triangle( new Vector3( 0, 0, 0 ), new Vector3( 1, 0, 0 ), new Vector3( 0, 1, 0 ) );
  37051. assert.ok( a.barycoordFromPoint( a.a ).equals( new Vector3( 1, 0, 0 ) ), "Passed!" );
  37052. assert.ok( a.barycoordFromPoint( a.b ).equals( new Vector3( 0, 1, 0 ) ), "Passed!" );
  37053. assert.ok( a.barycoordFromPoint( a.c ).equals( new Vector3( 0, 0, 1 ) ), "Passed!" );
  37054. assert.ok( a.barycoordFromPoint( a.midpoint() ).distanceTo( new Vector3( 1 / 3, 1 / 3, 1 / 3 ) ) < 0.0001, "Passed!" );
  37055. var a = new Triangle( new Vector3( 2, 0, 0 ), new Vector3( 0, 0, 0 ), new Vector3( 0, 0, 2 ) );
  37056. assert.ok( a.barycoordFromPoint( a.a ).equals( new Vector3( 1, 0, 0 ) ), "Passed!" );
  37057. assert.ok( a.barycoordFromPoint( a.b ).equals( new Vector3( 0, 1, 0 ) ), "Passed!" );
  37058. assert.ok( a.barycoordFromPoint( a.c ).equals( new Vector3( 0, 0, 1 ) ), "Passed!" );
  37059. assert.ok( a.barycoordFromPoint( a.midpoint() ).distanceTo( new Vector3( 1 / 3, 1 / 3, 1 / 3 ) ) < 0.0001, "Passed!" );
  37060. } );
  37061. QUnit.test( "containsPoint", ( assert ) => {
  37062. var a = new Triangle();
  37063. assert.ok( ! a.containsPoint( a.a ), "Passed!" );
  37064. assert.ok( ! a.containsPoint( a.b ), "Passed!" );
  37065. assert.ok( ! a.containsPoint( a.c ), "Passed!" );
  37066. var a = new Triangle( new Vector3( 0, 0, 0 ), new Vector3( 1, 0, 0 ), new Vector3( 0, 1, 0 ) );
  37067. assert.ok( a.containsPoint( a.a ), "Passed!" );
  37068. assert.ok( a.containsPoint( a.b ), "Passed!" );
  37069. assert.ok( a.containsPoint( a.c ), "Passed!" );
  37070. assert.ok( a.containsPoint( a.midpoint() ), "Passed!" );
  37071. assert.ok( ! a.containsPoint( new Vector3( - 1, - 1, - 1 ) ), "Passed!" );
  37072. var a = new Triangle( new Vector3( 2, 0, 0 ), new Vector3( 0, 0, 0 ), new Vector3( 0, 0, 2 ) );
  37073. assert.ok( a.containsPoint( a.a ), "Passed!" );
  37074. assert.ok( a.containsPoint( a.b ), "Passed!" );
  37075. assert.ok( a.containsPoint( a.c ), "Passed!" );
  37076. assert.ok( a.containsPoint( a.midpoint() ), "Passed!" );
  37077. assert.ok( ! a.containsPoint( new Vector3( - 1, - 1, - 1 ) ), "Passed!" );
  37078. } );
  37079. QUnit.test( "closestPointToPoint", ( assert ) => {
  37080. var a = new Triangle( new Vector3( - 1, 0, 0 ), new Vector3( 1, 0, 0 ), new Vector3( 0, 1, 0 ) );
  37081. // point lies inside the triangle
  37082. var b0 = a.closestPointToPoint( new Vector3( 0, 0.5, 0 ) );
  37083. assert.ok( b0.equals( new Vector3( 0, 0.5, 0 ) ), "Passed!" );
  37084. // point lies on a vertex
  37085. var b0 = a.closestPointToPoint( a.a );
  37086. assert.ok( b0.equals( a.a ), "Passed!" );
  37087. var b0 = a.closestPointToPoint( a.b );
  37088. assert.ok( b0.equals( a.b ), "Passed!" );
  37089. var b0 = a.closestPointToPoint( a.c );
  37090. assert.ok( b0.equals( a.c ), "Passed!" );
  37091. // point lies on an edge
  37092. var b0 = a.closestPointToPoint( zero3.clone() );
  37093. assert.ok( b0.equals( zero3.clone() ), "Passed!" );
  37094. // point lies outside the triangle
  37095. var b0 = a.closestPointToPoint( new Vector3( - 2, 0, 0 ) );
  37096. assert.ok( b0.equals( new Vector3( - 1, 0, 0 ) ), "Passed!" );
  37097. var b0 = a.closestPointToPoint( new Vector3( 2, 0, 0 ) );
  37098. assert.ok( b0.equals( new Vector3( 1, 0, 0 ) ), "Passed!" );
  37099. var b0 = a.closestPointToPoint( new Vector3( 0, 2, 0 ) );
  37100. assert.ok( b0.equals( new Vector3( 0, 1, 0 ) ), "Passed!" );
  37101. var b0 = a.closestPointToPoint( new Vector3( 0, - 2, 0 ) );
  37102. assert.ok( b0.equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
  37103. } );
  37104. QUnit.test( "equals", ( assert ) => {
  37105. var a = new Triangle(
  37106. new Vector3( 1, 0, 0 ),
  37107. new Vector3( 0, 1, 0 ),
  37108. new Vector3( 0, 0, 1 )
  37109. );
  37110. var b = new Triangle(
  37111. new Vector3( 0, 0, 1 ),
  37112. new Vector3( 0, 1, 0 ),
  37113. new Vector3( 1, 0, 0 )
  37114. );
  37115. var c = new Triangle(
  37116. new Vector3( - 1, 0, 0 ),
  37117. new Vector3( 0, 1, 0 ),
  37118. new Vector3( 0, 0, 1 )
  37119. );
  37120. assert.ok( a.equals( a ), "a equals a" );
  37121. assert.notOk( a.equals( b ), "a does not equal b" );
  37122. assert.notOk( a.equals( c ), "a does not equal c" );
  37123. assert.notOk( b.equals( c ), "b does not equal c" );
  37124. a.copy( b );
  37125. assert.ok( a.equals( a ), "a equals b after copy()" );
  37126. } );
  37127. } );
  37128. } );
  37129. /**
  37130. * @author bhouston / http://exocortex.com
  37131. * @author TristanVALCKE / https://github.com/Itee
  37132. */
  37133. /* global QUnit */
  37134. QUnit.module( 'Maths', () => {
  37135. QUnit.module.todo( 'Vector2', () => {
  37136. // INSTANCING
  37137. QUnit.test( "Instancing", ( assert ) => {
  37138. var a = new Vector2();
  37139. assert.ok( a.x == 0, "Passed!" );
  37140. assert.ok( a.y == 0, "Passed!" );
  37141. var a = new Vector2( x, y );
  37142. assert.ok( a.x === x, "Passed!" );
  37143. assert.ok( a.y === y, "Passed!" );
  37144. } );
  37145. // PROPERTIES // ( [Itee] WHAT ??? o_O )
  37146. QUnit.test( "properties", ( assert ) => {
  37147. var a = new Vector2( 0, 0 );
  37148. var width = 100;
  37149. var height = 200;
  37150. assert.ok( a.width = width, "Set width" );
  37151. assert.ok( a.height = height, "Set height" );
  37152. a.set( width, height );
  37153. assert.strictEqual( a.width, width, "Get width" );
  37154. assert.strictEqual( a.height, height, "Get height" );
  37155. } );
  37156. QUnit.test( "width", ( assert ) => {
  37157. assert.ok( false, "everything's gonna be alright" );
  37158. } );
  37159. QUnit.test( "height", ( assert ) => {
  37160. assert.ok( false, "everything's gonna be alright" );
  37161. } );
  37162. // PUBLIC STUFF
  37163. QUnit.test( "isVector2", ( assert ) => {
  37164. assert.ok( false, "everything's gonna be alright" );
  37165. } );
  37166. QUnit.test( "set", ( assert ) => {
  37167. var a = new Vector2();
  37168. assert.ok( a.x == 0, "Passed!" );
  37169. assert.ok( a.y == 0, "Passed!" );
  37170. a.set( x, y );
  37171. assert.ok( a.x == x, "Passed!" );
  37172. assert.ok( a.y == y, "Passed!" );
  37173. } );
  37174. QUnit.test( "setScalar", ( assert ) => {
  37175. assert.ok( false, "everything's gonna be alright" );
  37176. } );
  37177. QUnit.test( "setX", ( assert ) => {
  37178. assert.ok( false, "everything's gonna be alright" );
  37179. } );
  37180. QUnit.test( "setY", ( assert ) => {
  37181. assert.ok( false, "everything's gonna be alright" );
  37182. } );
  37183. QUnit.test( "setComponent", ( assert ) => {
  37184. assert.ok( false, "everything's gonna be alright" );
  37185. } );
  37186. QUnit.test( "getComponent", ( assert ) => {
  37187. assert.ok( false, "everything's gonna be alright" );
  37188. } );
  37189. QUnit.test( "clone", ( assert ) => {
  37190. assert.ok( false, "everything's gonna be alright" );
  37191. } );
  37192. QUnit.test( "copy", ( assert ) => {
  37193. var a = new Vector2( x, y );
  37194. var b = new Vector2().copy( a );
  37195. assert.ok( b.x == x, "Passed!" );
  37196. assert.ok( b.y == y, "Passed!" );
  37197. // ensure that it is a true copy
  37198. a.x = 0;
  37199. a.y = - 1;
  37200. assert.ok( b.x == x, "Passed!" );
  37201. assert.ok( b.y == y, "Passed!" );
  37202. } );
  37203. QUnit.test( "add", ( assert ) => {
  37204. var a = new Vector2( x, y );
  37205. var b = new Vector2( - x, - y );
  37206. a.add( b );
  37207. assert.ok( a.x == 0, "Passed!" );
  37208. assert.ok( a.y == 0, "Passed!" );
  37209. var c = new Vector2().addVectors( b, b );
  37210. assert.ok( c.x == - 2 * x, "Passed!" );
  37211. assert.ok( c.y == - 2 * y, "Passed!" );
  37212. } );
  37213. QUnit.test( "addScalar", ( assert ) => {
  37214. assert.ok( false, "everything's gonna be alright" );
  37215. } );
  37216. QUnit.test( "addVectors", ( assert ) => {
  37217. assert.ok( false, "everything's gonna be alright" );
  37218. } );
  37219. QUnit.test( "addScaledVector", ( assert ) => {
  37220. var a = new Vector2( x, y );
  37221. var b = new Vector2( 2, 3 );
  37222. var s = 3;
  37223. a.addScaledVector( b, s );
  37224. assert.strictEqual( a.x, x + b.x * s, "Check x" );
  37225. assert.strictEqual( a.y, y + b.y * s, "Check y" );
  37226. } );
  37227. QUnit.test( "sub", ( assert ) => {
  37228. var a = new Vector2( x, y );
  37229. var b = new Vector2( - x, - y );
  37230. a.sub( b );
  37231. assert.ok( a.x == 2 * x, "Passed!" );
  37232. assert.ok( a.y == 2 * y, "Passed!" );
  37233. var c = new Vector2().subVectors( a, a );
  37234. assert.ok( c.x == 0, "Passed!" );
  37235. assert.ok( c.y == 0, "Passed!" );
  37236. } );
  37237. QUnit.test( "subScalar", ( assert ) => {
  37238. assert.ok( false, "everything's gonna be alright" );
  37239. } );
  37240. QUnit.test( "subVectors", ( assert ) => {
  37241. assert.ok( false, "everything's gonna be alright" );
  37242. } );
  37243. QUnit.test( "multiply", ( assert ) => {
  37244. assert.ok( false, "everything's gonna be alright" );
  37245. } );
  37246. QUnit.test( "multiplyScalar", ( assert ) => {
  37247. assert.ok( false, "everything's gonna be alright" );
  37248. } );
  37249. QUnit.test( "divide", ( assert ) => {
  37250. assert.ok( false, "everything's gonna be alright" );
  37251. } );
  37252. QUnit.test( "divideScalar", ( assert ) => {
  37253. assert.ok( false, "everything's gonna be alright" );
  37254. } );
  37255. QUnit.test( "applyMatrix3", ( assert ) => {
  37256. var a = new Vector2( x, y );
  37257. var m = new Matrix3().set( 2, 3, 5, 7, 11, 13, 17, 19, 23 );
  37258. a.applyMatrix3( m );
  37259. assert.strictEqual( a.x, 18, "Check x" );
  37260. assert.strictEqual( a.y, 60, "Check y" );
  37261. } );
  37262. QUnit.test( "min", ( assert ) => {
  37263. assert.ok( false, "everything's gonna be alright" );
  37264. } );
  37265. QUnit.test( "max", ( assert ) => {
  37266. assert.ok( false, "everything's gonna be alright" );
  37267. } );
  37268. QUnit.test( "clamp", ( assert ) => {
  37269. assert.ok( false, "everything's gonna be alright" );
  37270. } );
  37271. QUnit.test( "clampScalar", ( assert ) => {
  37272. assert.ok( false, "everything's gonna be alright" );
  37273. } );
  37274. QUnit.test( "clampLength", ( assert ) => {
  37275. assert.ok( false, "everything's gonna be alright" );
  37276. } );
  37277. QUnit.test( "floor", ( assert ) => {
  37278. assert.ok( false, "everything's gonna be alright" );
  37279. } );
  37280. QUnit.test( "ceil", ( assert ) => {
  37281. assert.ok( false, "everything's gonna be alright" );
  37282. } );
  37283. QUnit.test( "round", ( assert ) => {
  37284. assert.ok( false, "everything's gonna be alright" );
  37285. } );
  37286. QUnit.test( "roundToZero", ( assert ) => {
  37287. assert.ok( false, "everything's gonna be alright" );
  37288. } );
  37289. QUnit.test( "negate", ( assert ) => {
  37290. var a = new Vector2( x, y );
  37291. a.negate();
  37292. assert.ok( a.x == - x, "Passed!" );
  37293. assert.ok( a.y == - y, "Passed!" );
  37294. } );
  37295. QUnit.test( "dot", ( assert ) => {
  37296. var a = new Vector2( x, y );
  37297. var b = new Vector2( - x, - y );
  37298. var c = new Vector2();
  37299. var result = a.dot( b );
  37300. assert.ok( result == ( - x * x - y * y ), "Passed!" );
  37301. var result = a.dot( c );
  37302. assert.ok( result == 0, "Passed!" );
  37303. } );
  37304. QUnit.test( "lengthSq", ( assert ) => {
  37305. assert.ok( false, "everything's gonna be alright" );
  37306. } );
  37307. QUnit.test( "length", ( assert ) => {
  37308. assert.ok( false, "everything's gonna be alright" );
  37309. } );
  37310. QUnit.test( "manhattanLength", ( assert ) => {
  37311. var a = new Vector2( x, 0 );
  37312. var b = new Vector2( 0, - y );
  37313. var c = new Vector2();
  37314. assert.strictEqual( a.manhattanLength(), x, "Positive component" );
  37315. assert.strictEqual( b.manhattanLength(), y, "Negative component" );
  37316. assert.strictEqual( c.manhattanLength(), 0, "Empty component" );
  37317. a.set( x, y );
  37318. assert.strictEqual( a.manhattanLength(), Math.abs( x ) + Math.abs( y ), "Two components" );
  37319. } );
  37320. QUnit.test( "normalize", ( assert ) => {
  37321. var a = new Vector2( x, 0 );
  37322. var b = new Vector2( 0, - y );
  37323. var c = new Vector2();
  37324. a.normalize();
  37325. assert.ok( a.length() == 1, "Passed!" );
  37326. assert.ok( a.x == 1, "Passed!" );
  37327. b.normalize();
  37328. assert.ok( b.length() == 1, "Passed!" );
  37329. assert.ok( b.y == - 1, "Passed!" );
  37330. } );
  37331. QUnit.test( "angle", ( assert ) => {
  37332. assert.ok( false, "everything's gonna be alright" );
  37333. } );
  37334. QUnit.test( "distanceTo", ( assert ) => {
  37335. assert.ok( false, "everything's gonna be alright" );
  37336. } );
  37337. QUnit.test( "distanceToSquared", ( assert ) => {
  37338. assert.ok( false, "everything's gonna be alright" );
  37339. } );
  37340. QUnit.test( "manhattanDistanceTo", ( assert ) => {
  37341. assert.ok( false, "everything's gonna be alright" );
  37342. } );
  37343. QUnit.test( "setLength", ( assert ) => {
  37344. var a = new Vector2( x, 0 );
  37345. assert.ok( a.length() == x, "Passed!" );
  37346. a.setLength( y );
  37347. assert.ok( a.length() == y, "Passed!" );
  37348. var a = new Vector2( 0, 0 );
  37349. assert.ok( a.length() == 0, "Passed!" );
  37350. a.setLength( y );
  37351. assert.ok( a.length() == 0, "Passed!" );
  37352. a.setLength();
  37353. assert.ok( isNaN( a.length() ), "Passed!" );
  37354. } );
  37355. QUnit.test( "lerp", ( assert ) => {
  37356. assert.ok( false, "everything's gonna be alright" );
  37357. } );
  37358. QUnit.test( "lerpVectors", ( assert ) => {
  37359. assert.ok( false, "everything's gonna be alright" );
  37360. } );
  37361. QUnit.test( "equals", ( assert ) => {
  37362. var a = new Vector2( x, 0 );
  37363. var b = new Vector2( 0, - y );
  37364. assert.ok( a.x != b.x, "Passed!" );
  37365. assert.ok( a.y != b.y, "Passed!" );
  37366. assert.ok( ! a.equals( b ), "Passed!" );
  37367. assert.ok( ! b.equals( a ), "Passed!" );
  37368. a.copy( b );
  37369. assert.ok( a.x == b.x, "Passed!" );
  37370. assert.ok( a.y == b.y, "Passed!" );
  37371. assert.ok( a.equals( b ), "Passed!" );
  37372. assert.ok( b.equals( a ), "Passed!" );
  37373. } );
  37374. QUnit.test( "fromArray", ( assert ) => {
  37375. var a = new Vector2();
  37376. var array = [ 1, 2, 3, 4 ];
  37377. a.fromArray( array );
  37378. assert.strictEqual( a.x, 1, "No offset: check x" );
  37379. assert.strictEqual( a.y, 2, "No offset: check y" );
  37380. a.fromArray( array, 2 );
  37381. assert.strictEqual( a.x, 3, "With offset: check x" );
  37382. assert.strictEqual( a.y, 4, "With offset: check y" );
  37383. } );
  37384. QUnit.test( "toArray", ( assert ) => {
  37385. var a = new Vector2( x, y );
  37386. var array = a.toArray();
  37387. assert.strictEqual( array[ 0 ], x, "No array, no offset: check x" );
  37388. assert.strictEqual( array[ 1 ], y, "No array, no offset: check y" );
  37389. var array = [];
  37390. a.toArray( array );
  37391. assert.strictEqual( array[ 0 ], x, "With array, no offset: check x" );
  37392. assert.strictEqual( array[ 1 ], y, "With array, no offset: check y" );
  37393. var array = [];
  37394. a.toArray( array, 1 );
  37395. assert.strictEqual( array[ 0 ], undefined, "With array and offset: check [0]" );
  37396. assert.strictEqual( array[ 1 ], x, "With array and offset: check x" );
  37397. assert.strictEqual( array[ 2 ], y, "With array and offset: check y" );
  37398. } );
  37399. QUnit.test( "fromBufferAttribute", ( assert ) => {
  37400. var a = new Vector2();
  37401. var attr = new BufferAttribute( new Float32Array( [ 1, 2, 3, 4 ] ), 2 );
  37402. a.fromBufferAttribute( attr, 0 );
  37403. assert.strictEqual( a.x, 1, "Offset 0: check x" );
  37404. assert.strictEqual( a.y, 2, "Offset 0: check y" );
  37405. a.fromBufferAttribute( attr, 1 );
  37406. assert.strictEqual( a.x, 3, "Offset 1: check x" );
  37407. assert.strictEqual( a.y, 4, "Offset 1: check y" );
  37408. } );
  37409. QUnit.test( "rotateAround", ( assert ) => {
  37410. assert.ok( false, "everything's gonna be alright" );
  37411. } );
  37412. // TODO (Itee) refactor/split
  37413. QUnit.test( "setX,setY", ( assert ) => {
  37414. var a = new Vector2();
  37415. assert.ok( a.x == 0, "Passed!" );
  37416. assert.ok( a.y == 0, "Passed!" );
  37417. a.setX( x );
  37418. a.setY( y );
  37419. assert.ok( a.x == x, "Passed!" );
  37420. assert.ok( a.y == y, "Passed!" );
  37421. } );
  37422. QUnit.test( "setComponent,getComponent", ( assert ) => {
  37423. var a = new Vector2();
  37424. assert.ok( a.x == 0, "Passed!" );
  37425. assert.ok( a.y == 0, "Passed!" );
  37426. a.setComponent( 0, 1 );
  37427. a.setComponent( 1, 2 );
  37428. assert.ok( a.getComponent( 0 ) == 1, "Passed!" );
  37429. assert.ok( a.getComponent( 1 ) == 2, "Passed!" );
  37430. } );
  37431. QUnit.test( "multiply/divide", ( assert ) => {
  37432. var a = new Vector2( x, y );
  37433. var b = new Vector2( - x, - y );
  37434. a.multiplyScalar( - 2 );
  37435. assert.ok( a.x == x * - 2, "Passed!" );
  37436. assert.ok( a.y == y * - 2, "Passed!" );
  37437. b.multiplyScalar( - 2 );
  37438. assert.ok( b.x == 2 * x, "Passed!" );
  37439. assert.ok( b.y == 2 * y, "Passed!" );
  37440. a.divideScalar( - 2 );
  37441. assert.ok( a.x == x, "Passed!" );
  37442. assert.ok( a.y == y, "Passed!" );
  37443. b.divideScalar( - 2 );
  37444. assert.ok( b.x == - x, "Passed!" );
  37445. assert.ok( b.y == - y, "Passed!" );
  37446. } );
  37447. QUnit.test( "min/max/clamp", ( assert ) => {
  37448. var a = new Vector2( x, y );
  37449. var b = new Vector2( - x, - y );
  37450. var c = new Vector2();
  37451. c.copy( a ).min( b );
  37452. assert.ok( c.x == - x, "Passed!" );
  37453. assert.ok( c.y == - y, "Passed!" );
  37454. c.copy( a ).max( b );
  37455. assert.ok( c.x == x, "Passed!" );
  37456. assert.ok( c.y == y, "Passed!" );
  37457. c.set( - 2 * x, 2 * y );
  37458. c.clamp( b, a );
  37459. assert.ok( c.x == - x, "Passed!" );
  37460. assert.ok( c.y == y, "Passed!" );
  37461. c.set( - 2 * x, 2 * x );
  37462. c.clampScalar( - x, x );
  37463. assert.equal( c.x, - x, "scalar clamp x" );
  37464. assert.equal( c.y, x, "scalar clamp y" );
  37465. } );
  37466. QUnit.test( "rounding", ( assert ) => {
  37467. assert.deepEqual( new Vector2( - 0.1, 0.1 ).floor(), new Vector2( - 1, 0 ), "floor .1" );
  37468. assert.deepEqual( new Vector2( - 0.5, 0.5 ).floor(), new Vector2( - 1, 0 ), "floor .5" );
  37469. assert.deepEqual( new Vector2( - 0.9, 0.9 ).floor(), new Vector2( - 1, 0 ), "floor .9" );
  37470. assert.deepEqual( new Vector2( - 0.1, 0.1 ).ceil(), new Vector2( 0, 1 ), "ceil .1" );
  37471. assert.deepEqual( new Vector2( - 0.5, 0.5 ).ceil(), new Vector2( 0, 1 ), "ceil .5" );
  37472. assert.deepEqual( new Vector2( - 0.9, 0.9 ).ceil(), new Vector2( 0, 1 ), "ceil .9" );
  37473. assert.deepEqual( new Vector2( - 0.1, 0.1 ).round(), new Vector2( 0, 0 ), "round .1" );
  37474. assert.deepEqual( new Vector2( - 0.5, 0.5 ).round(), new Vector2( 0, 1 ), "round .5" );
  37475. assert.deepEqual( new Vector2( - 0.9, 0.9 ).round(), new Vector2( - 1, 1 ), "round .9" );
  37476. assert.deepEqual( new Vector2( - 0.1, 0.1 ).roundToZero(), new Vector2( 0, 0 ), "roundToZero .1" );
  37477. assert.deepEqual( new Vector2( - 0.5, 0.5 ).roundToZero(), new Vector2( 0, 0 ), "roundToZero .5" );
  37478. assert.deepEqual( new Vector2( - 0.9, 0.9 ).roundToZero(), new Vector2( 0, 0 ), "roundToZero .9" );
  37479. assert.deepEqual( new Vector2( - 1.1, 1.1 ).roundToZero(), new Vector2( - 1, 1 ), "roundToZero 1.1" );
  37480. assert.deepEqual( new Vector2( - 1.5, 1.5 ).roundToZero(), new Vector2( - 1, 1 ), "roundToZero 1.5" );
  37481. assert.deepEqual( new Vector2( - 1.9, 1.9 ).roundToZero(), new Vector2( - 1, 1 ), "roundToZero 1.9" );
  37482. } );
  37483. QUnit.test( "length/lengthSq", ( assert ) => {
  37484. var a = new Vector2( x, 0 );
  37485. var b = new Vector2( 0, - y );
  37486. var c = new Vector2();
  37487. assert.ok( a.length() == x, "Passed!" );
  37488. assert.ok( a.lengthSq() == x * x, "Passed!" );
  37489. assert.ok( b.length() == y, "Passed!" );
  37490. assert.ok( b.lengthSq() == y * y, "Passed!" );
  37491. assert.ok( c.length() == 0, "Passed!" );
  37492. assert.ok( c.lengthSq() == 0, "Passed!" );
  37493. a.set( x, y );
  37494. assert.ok( a.length() == Math.sqrt( x * x + y * y ), "Passed!" );
  37495. assert.ok( a.lengthSq() == ( x * x + y * y ), "Passed!" );
  37496. } );
  37497. QUnit.test( "distanceTo/distanceToSquared", ( assert ) => {
  37498. var a = new Vector2( x, 0 );
  37499. var b = new Vector2( 0, - y );
  37500. var c = new Vector2();
  37501. assert.ok( a.distanceTo( c ) == x, "Passed!" );
  37502. assert.ok( a.distanceToSquared( c ) == x * x, "Passed!" );
  37503. assert.ok( b.distanceTo( c ) == y, "Passed!" );
  37504. assert.ok( b.distanceToSquared( c ) == y * y, "Passed!" );
  37505. } );
  37506. QUnit.test( "lerp/clone", ( assert ) => {
  37507. var a = new Vector2( x, 0 );
  37508. var b = new Vector2( 0, - y );
  37509. assert.ok( a.lerp( a, 0 ).equals( a.lerp( a, 0.5 ) ), "Passed!" );
  37510. assert.ok( a.lerp( a, 0 ).equals( a.lerp( a, 1 ) ), "Passed!" );
  37511. assert.ok( a.clone().lerp( b, 0 ).equals( a ), "Passed!" );
  37512. assert.ok( a.clone().lerp( b, 0.5 ).x == x * 0.5, "Passed!" );
  37513. assert.ok( a.clone().lerp( b, 0.5 ).y == - y * 0.5, "Passed!" );
  37514. assert.ok( a.clone().lerp( b, 1 ).equals( b ), "Passed!" );
  37515. } );
  37516. QUnit.test( "setComponent/getComponent exceptions", ( assert ) => {
  37517. var a = new Vector2( 0, 0 );
  37518. assert.throws(
  37519. function () {
  37520. a.setComponent( 2, 0 );
  37521. },
  37522. /index is out of range/,
  37523. "setComponent with an out of range index throws Error"
  37524. );
  37525. assert.throws(
  37526. function () {
  37527. a.getComponent( 2 );
  37528. },
  37529. /index is out of range/,
  37530. "getComponent with an out of range index throws Error"
  37531. );
  37532. } );
  37533. QUnit.test( "setScalar/addScalar/subScalar", ( assert ) => {
  37534. var a = new Vector2( 1, 1 );
  37535. var s = 3;
  37536. a.setScalar( s );
  37537. assert.strictEqual( a.x, s, "setScalar: check x" );
  37538. assert.strictEqual( a.y, s, "setScalar: check y" );
  37539. a.addScalar( s );
  37540. assert.strictEqual( a.x, 2 * s, "addScalar: check x" );
  37541. assert.strictEqual( a.y, 2 * s, "addScalar: check y" );
  37542. a.subScalar( 2 * s );
  37543. assert.strictEqual( a.x, 0, "subScalar: check x" );
  37544. assert.strictEqual( a.y, 0, "subScalar: check y" );
  37545. } );
  37546. QUnit.test( "multiply/divide", ( assert ) => {
  37547. var a = new Vector2( x, y );
  37548. var b = new Vector2( 2 * x, 2 * y );
  37549. var c = new Vector2( 4 * x, 4 * y );
  37550. a.multiply( b );
  37551. assert.strictEqual( a.x, x * b.x, "multiply: check x" );
  37552. assert.strictEqual( a.y, y * b.y, "multiply: check y" );
  37553. b.divide( c );
  37554. assert.strictEqual( b.x, 0.5, "divide: check x" );
  37555. assert.strictEqual( b.y, 0.5, "divide: check y" );
  37556. } );
  37557. } );
  37558. } );
  37559. /**
  37560. * @author bhouston / http://exocortex.com
  37561. * @author TristanVALCKE / https://github.com/Itee
  37562. */
  37563. /* global QUnit */
  37564. QUnit.module( 'Maths', () => {
  37565. QUnit.module.todo( 'Vector3', () => {
  37566. // INSTANCING
  37567. QUnit.test( "Instancing", ( assert ) => {
  37568. var a = new Vector3();
  37569. assert.ok( a.x == 0, "Passed!" );
  37570. assert.ok( a.y == 0, "Passed!" );
  37571. assert.ok( a.z == 0, "Passed!" );
  37572. var a = new Vector3( x, y, z );
  37573. assert.ok( a.x === x, "Passed!" );
  37574. assert.ok( a.y === y, "Passed!" );
  37575. assert.ok( a.z === z, "Passed!" );
  37576. } );
  37577. // PUBLIC STUFF
  37578. QUnit.test( "isVector3", ( assert ) => {
  37579. assert.ok( false, "everything's gonna be alright" );
  37580. } );
  37581. QUnit.test( "set", ( assert ) => {
  37582. var a = new Vector3();
  37583. assert.ok( a.x == 0, "Passed!" );
  37584. assert.ok( a.y == 0, "Passed!" );
  37585. assert.ok( a.z == 0, "Passed!" );
  37586. a.set( x, y, z );
  37587. assert.ok( a.x == x, "Passed!" );
  37588. assert.ok( a.y == y, "Passed!" );
  37589. assert.ok( a.z == z, "Passed!" );
  37590. } );
  37591. QUnit.test( "setScalar", ( assert ) => {
  37592. assert.ok( false, "everything's gonna be alright" );
  37593. } );
  37594. QUnit.test( "setX", ( assert ) => {
  37595. assert.ok( false, "everything's gonna be alright" );
  37596. } );
  37597. QUnit.test( "setY", ( assert ) => {
  37598. assert.ok( false, "everything's gonna be alright" );
  37599. } );
  37600. QUnit.test( "setZ", ( assert ) => {
  37601. assert.ok( false, "everything's gonna be alright" );
  37602. } );
  37603. QUnit.test( "setComponent", ( assert ) => {
  37604. assert.ok( false, "everything's gonna be alright" );
  37605. } );
  37606. QUnit.test( "getComponent", ( assert ) => {
  37607. assert.ok( false, "everything's gonna be alright" );
  37608. } );
  37609. QUnit.test( "clone", ( assert ) => {
  37610. assert.ok( false, "everything's gonna be alright" );
  37611. } );
  37612. QUnit.test( "copy", ( assert ) => {
  37613. var a = new Vector3( x, y, z );
  37614. var b = new Vector3().copy( a );
  37615. assert.ok( b.x == x, "Passed!" );
  37616. assert.ok( b.y == y, "Passed!" );
  37617. assert.ok( b.z == z, "Passed!" );
  37618. // ensure that it is a true copy
  37619. a.x = 0;
  37620. a.y = - 1;
  37621. a.z = - 2;
  37622. assert.ok( b.x == x, "Passed!" );
  37623. assert.ok( b.y == y, "Passed!" );
  37624. assert.ok( b.z == z, "Passed!" );
  37625. } );
  37626. QUnit.test( "add", ( assert ) => {
  37627. var a = new Vector3( x, y, z );
  37628. var b = new Vector3( - x, - y, - z );
  37629. a.add( b );
  37630. assert.ok( a.x == 0, "Passed!" );
  37631. assert.ok( a.y == 0, "Passed!" );
  37632. assert.ok( a.z == 0, "Passed!" );
  37633. var c = new Vector3().addVectors( b, b );
  37634. assert.ok( c.x == - 2 * x, "Passed!" );
  37635. assert.ok( c.y == - 2 * y, "Passed!" );
  37636. assert.ok( c.z == - 2 * z, "Passed!" );
  37637. } );
  37638. QUnit.test( "addScalar", ( assert ) => {
  37639. assert.ok( false, "everything's gonna be alright" );
  37640. } );
  37641. QUnit.test( "addVectors", ( assert ) => {
  37642. assert.ok( false, "everything's gonna be alright" );
  37643. } );
  37644. QUnit.test( "addScaledVector", ( assert ) => {
  37645. var a = new Vector3( x, y, z );
  37646. var b = new Vector3( 2, 3, 4 );
  37647. var s = 3;
  37648. a.addScaledVector( b, s );
  37649. assert.strictEqual( a.x, x + b.x * s, "Check x" );
  37650. assert.strictEqual( a.y, y + b.y * s, "Check y" );
  37651. assert.strictEqual( a.z, z + b.z * s, "Check z" );
  37652. } );
  37653. QUnit.test( "sub", ( assert ) => {
  37654. var a = new Vector3( x, y, z );
  37655. var b = new Vector3( - x, - y, - z );
  37656. a.sub( b );
  37657. assert.ok( a.x == 2 * x, "Passed!" );
  37658. assert.ok( a.y == 2 * y, "Passed!" );
  37659. assert.ok( a.z == 2 * z, "Passed!" );
  37660. var c = new Vector3().subVectors( a, a );
  37661. assert.ok( c.x == 0, "Passed!" );
  37662. assert.ok( c.y == 0, "Passed!" );
  37663. assert.ok( c.z == 0, "Passed!" );
  37664. } );
  37665. QUnit.test( "subScalar", ( assert ) => {
  37666. assert.ok( false, "everything's gonna be alright" );
  37667. } );
  37668. QUnit.test( "subVectors", ( assert ) => {
  37669. assert.ok( false, "everything's gonna be alright" );
  37670. } );
  37671. QUnit.test( "multiply", ( assert ) => {
  37672. assert.ok( false, "everything's gonna be alright" );
  37673. } );
  37674. QUnit.test( "multiplyScalar", ( assert ) => {
  37675. assert.ok( false, "everything's gonna be alright" );
  37676. } );
  37677. QUnit.test( "multiplyVectors", ( assert ) => {
  37678. var a = new Vector3( x, y, z );
  37679. var b = new Vector3( 2, 3, - 5 );
  37680. var c = new Vector3().multiplyVectors( a, b );
  37681. assert.strictEqual( c.x, x * 2, "Check x" );
  37682. assert.strictEqual( c.y, y * 3, "Check y" );
  37683. assert.strictEqual( c.z, z * - 5, "Check z" );
  37684. } );
  37685. QUnit.test( "applyEuler", ( assert ) => {
  37686. var a = new Vector3( x, y, z );
  37687. var euler = new Euler( 90, - 45, 0 );
  37688. var expected = new Vector3( - 2.352970120501014, - 4.7441750936226645, 0.9779234597246458 );
  37689. a.applyEuler( euler );
  37690. assert.ok( Math.abs( a.x - expected.x ) <= eps, "Check x" );
  37691. assert.ok( Math.abs( a.y - expected.y ) <= eps, "Check y" );
  37692. assert.ok( Math.abs( a.z - expected.z ) <= eps, "Check z" );
  37693. } );
  37694. QUnit.test( "applyAxisAngle", ( assert ) => {
  37695. var a = new Vector3( x, y, z );
  37696. var axis = new Vector3( 0, 1, 0 );
  37697. var angle = Math.PI / 4.0;
  37698. var expected = new Vector3( 3 * Math.sqrt( 2 ), 3, Math.sqrt( 2 ) );
  37699. a.applyAxisAngle( axis, angle );
  37700. assert.ok( Math.abs( a.x - expected.x ) <= eps, "Check x" );
  37701. assert.ok( Math.abs( a.y - expected.y ) <= eps, "Check y" );
  37702. assert.ok( Math.abs( a.z - expected.z ) <= eps, "Check z" );
  37703. } );
  37704. QUnit.test( "applyMatrix3", ( assert ) => {
  37705. var a = new Vector3( x, y, z );
  37706. var m = new Matrix3().set( 2, 3, 5, 7, 11, 13, 17, 19, 23 );
  37707. a.applyMatrix3( m );
  37708. assert.strictEqual( a.x, 33, "Check x" );
  37709. assert.strictEqual( a.y, 99, "Check y" );
  37710. assert.strictEqual( a.z, 183, "Check z" );
  37711. } );
  37712. QUnit.test( "applyMatrix4", ( assert ) => {
  37713. var a = new Vector3( x, y, z );
  37714. var b = new Vector4( x, y, z, 1 );
  37715. var m = new Matrix4().makeRotationX( Math.PI );
  37716. a.applyMatrix4( m );
  37717. b.applyMatrix4( m );
  37718. assert.ok( a.x == b.x / b.w, "Passed!" );
  37719. assert.ok( a.y == b.y / b.w, "Passed!" );
  37720. assert.ok( a.z == b.z / b.w, "Passed!" );
  37721. var m = new Matrix4().makeTranslation( 3, 2, 1 );
  37722. a.applyMatrix4( m );
  37723. b.applyMatrix4( m );
  37724. assert.ok( a.x == b.x / b.w, "Passed!" );
  37725. assert.ok( a.y == b.y / b.w, "Passed!" );
  37726. assert.ok( a.z == b.z / b.w, "Passed!" );
  37727. var m = new Matrix4().set(
  37728. 1, 0, 0, 0,
  37729. 0, 1, 0, 0,
  37730. 0, 0, 1, 0,
  37731. 0, 0, 1, 0
  37732. );
  37733. a.applyMatrix4( m );
  37734. b.applyMatrix4( m );
  37735. assert.ok( a.x == b.x / b.w, "Passed!" );
  37736. assert.ok( a.y == b.y / b.w, "Passed!" );
  37737. assert.ok( a.z == b.z / b.w, "Passed!" );
  37738. } );
  37739. QUnit.test( "applyQuaternion", ( assert ) => {
  37740. var a = new Vector3( x, y, z );
  37741. a.applyQuaternion( new Quaternion() );
  37742. assert.strictEqual( a.x, x, "Identity rotation: check x" );
  37743. assert.strictEqual( a.y, y, "Identity rotation: check y" );
  37744. assert.strictEqual( a.z, z, "Identity rotation: check z" );
  37745. a.applyQuaternion( new Quaternion( x, y, z, w ) );
  37746. assert.strictEqual( a.x, 108, "Normal rotation: check x" );
  37747. assert.strictEqual( a.y, 162, "Normal rotation: check y" );
  37748. assert.strictEqual( a.z, 216, "Normal rotation: check z" );
  37749. } );
  37750. QUnit.test( "project", ( assert ) => {
  37751. assert.ok( false, "everything's gonna be alright" );
  37752. } );
  37753. QUnit.test( "unproject", ( assert ) => {
  37754. assert.ok( false, "everything's gonna be alright" );
  37755. } );
  37756. QUnit.test( "transformDirection", ( assert ) => {
  37757. var a = new Vector3( x, y, z );
  37758. var m = new Matrix4();
  37759. var transformed = new Vector3( 0.3713906763541037, 0.5570860145311556, 0.7427813527082074 );
  37760. a.transformDirection( m );
  37761. assert.ok( Math.abs( a.x - transformed.x ) <= eps, "Check x" );
  37762. assert.ok( Math.abs( a.y - transformed.y ) <= eps, "Check y" );
  37763. assert.ok( Math.abs( a.z - transformed.z ) <= eps, "Check z" );
  37764. } );
  37765. QUnit.test( "divide", ( assert ) => {
  37766. assert.ok( false, "everything's gonna be alright" );
  37767. } );
  37768. QUnit.test( "divideScalar", ( assert ) => {
  37769. assert.ok( false, "everything's gonna be alright" );
  37770. } );
  37771. QUnit.test( "min", ( assert ) => {
  37772. assert.ok( false, "everything's gonna be alright" );
  37773. } );
  37774. QUnit.test( "max", ( assert ) => {
  37775. assert.ok( false, "everything's gonna be alright" );
  37776. } );
  37777. QUnit.test( "clamp", ( assert ) => {
  37778. assert.ok( false, "everything's gonna be alright" );
  37779. } );
  37780. QUnit.test( "clampScalar", ( assert ) => {
  37781. var a = new Vector3( - 0.01, 0.5, 1.5 );
  37782. var clamped = new Vector3( 0.1, 0.5, 1.0 );
  37783. a.clampScalar( 0.1, 1.0 );
  37784. assert.ok( Math.abs( a.x - clamped.x ) <= 0.001, "Check x" );
  37785. assert.ok( Math.abs( a.y - clamped.y ) <= 0.001, "Check y" );
  37786. assert.ok( Math.abs( a.z - clamped.z ) <= 0.001, "Check z" );
  37787. } );
  37788. QUnit.test( "clampLength", ( assert ) => {
  37789. assert.ok( false, "everything's gonna be alright" );
  37790. } );
  37791. QUnit.test( "floor", ( assert ) => {
  37792. assert.ok( false, "everything's gonna be alright" );
  37793. } );
  37794. QUnit.test( "ceil", ( assert ) => {
  37795. assert.ok( false, "everything's gonna be alright" );
  37796. } );
  37797. QUnit.test( "round", ( assert ) => {
  37798. assert.ok( false, "everything's gonna be alright" );
  37799. } );
  37800. QUnit.test( "roundToZero", ( assert ) => {
  37801. assert.ok( false, "everything's gonna be alright" );
  37802. } );
  37803. QUnit.test( "negate", ( assert ) => {
  37804. var a = new Vector3( x, y, z );
  37805. a.negate();
  37806. assert.ok( a.x == - x, "Passed!" );
  37807. assert.ok( a.y == - y, "Passed!" );
  37808. assert.ok( a.z == - z, "Passed!" );
  37809. } );
  37810. QUnit.test( "dot", ( assert ) => {
  37811. var a = new Vector3( x, y, z );
  37812. var b = new Vector3( - x, - y, - z );
  37813. var c = new Vector3();
  37814. var result = a.dot( b );
  37815. assert.ok( result == ( - x * x - y * y - z * z ), "Passed!" );
  37816. var result = a.dot( c );
  37817. assert.ok( result == 0, "Passed!" );
  37818. } );
  37819. QUnit.test( "lengthSq", ( assert ) => {
  37820. assert.ok( false, "everything's gonna be alright" );
  37821. } );
  37822. QUnit.test( "length", ( assert ) => {
  37823. assert.ok( false, "everything's gonna be alright" );
  37824. } );
  37825. QUnit.test( "manhattanLength", ( assert ) => {
  37826. var a = new Vector3( x, 0, 0 );
  37827. var b = new Vector3( 0, - y, 0 );
  37828. var c = new Vector3( 0, 0, z );
  37829. var d = new Vector3();
  37830. assert.ok( a.manhattanLength() == x, "Positive x" );
  37831. assert.ok( b.manhattanLength() == y, "Negative y" );
  37832. assert.ok( c.manhattanLength() == z, "Positive z" );
  37833. assert.ok( d.manhattanLength() == 0, "Empty initialization" );
  37834. a.set( x, y, z );
  37835. assert.ok( a.manhattanLength() == Math.abs( x ) + Math.abs( y ) + Math.abs( z ), "All components" );
  37836. } );
  37837. QUnit.test( "normalize", ( assert ) => {
  37838. var a = new Vector3( x, 0, 0 );
  37839. var b = new Vector3( 0, - y, 0 );
  37840. var c = new Vector3( 0, 0, z );
  37841. a.normalize();
  37842. assert.ok( a.length() == 1, "Passed!" );
  37843. assert.ok( a.x == 1, "Passed!" );
  37844. b.normalize();
  37845. assert.ok( b.length() == 1, "Passed!" );
  37846. assert.ok( b.y == - 1, "Passed!" );
  37847. c.normalize();
  37848. assert.ok( c.length() == 1, "Passed!" );
  37849. assert.ok( c.z == 1, "Passed!" );
  37850. } );
  37851. QUnit.test( "setLength", ( assert ) => {
  37852. var a = new Vector3( x, 0, 0 );
  37853. assert.ok( a.length() == x, "Passed!" );
  37854. a.setLength( y );
  37855. assert.ok( a.length() == y, "Passed!" );
  37856. var a = new Vector3( 0, 0, 0 );
  37857. assert.ok( a.length() == 0, "Passed!" );
  37858. a.setLength( y );
  37859. assert.ok( a.length() == 0, "Passed!" );
  37860. a.setLength();
  37861. assert.ok( isNaN( a.length() ), "Passed!" );
  37862. } );
  37863. QUnit.test( "lerp", ( assert ) => {
  37864. assert.ok( false, "everything's gonna be alright" );
  37865. } );
  37866. QUnit.test( "lerpVectors", ( assert ) => {
  37867. assert.ok( false, "everything's gonna be alright" );
  37868. } );
  37869. QUnit.test( "cross", ( assert ) => {
  37870. var a = new Vector3( x, y, z );
  37871. var b = new Vector3( 2 * x, - y, 0.5 * z );
  37872. var crossed = new Vector3( 18, 12, - 18 );
  37873. a.cross( b );
  37874. assert.ok( Math.abs( a.x - crossed.x ) <= eps, "Check x" );
  37875. assert.ok( Math.abs( a.y - crossed.y ) <= eps, "Check y" );
  37876. assert.ok( Math.abs( a.z - crossed.z ) <= eps, "Check z" );
  37877. } );
  37878. QUnit.test( "crossVectors", ( assert ) => {
  37879. var a = new Vector3( x, y, z );
  37880. var b = new Vector3( x, - y, z );
  37881. var c = new Vector3();
  37882. var crossed = new Vector3( 24, 0, - 12 );
  37883. c.crossVectors( a, b );
  37884. assert.ok( Math.abs( c.x - crossed.x ) <= eps, "Check x" );
  37885. assert.ok( Math.abs( c.y - crossed.y ) <= eps, "Check y" );
  37886. assert.ok( Math.abs( c.z - crossed.z ) <= eps, "Check z" );
  37887. } );
  37888. QUnit.test( "projectOnVector", ( assert ) => {
  37889. var a = new Vector3( 1, 0, 0 );
  37890. var b = new Vector3();
  37891. var normal = new Vector3( 10, 0, 0 );
  37892. assert.ok( b.copy( a ).projectOnVector( normal ).equals( new Vector3( 1, 0, 0 ) ), "Passed!" );
  37893. a.set( 0, 1, 0 );
  37894. assert.ok( b.copy( a ).projectOnVector( normal ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
  37895. a.set( 0, 0, - 1 );
  37896. assert.ok( b.copy( a ).projectOnVector( normal ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
  37897. a.set( - 1, 0, 0 );
  37898. assert.ok( b.copy( a ).projectOnVector( normal ).equals( new Vector3( - 1, 0, 0 ) ), "Passed!" );
  37899. } );
  37900. QUnit.test( "projectOnPlane", ( assert ) => {
  37901. var a = new Vector3( 1, 0, 0 );
  37902. var b = new Vector3();
  37903. var normal = new Vector3( 1, 0, 0 );
  37904. assert.ok( b.copy( a ).projectOnPlane( normal ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
  37905. a.set( 0, 1, 0 );
  37906. assert.ok( b.copy( a ).projectOnPlane( normal ).equals( new Vector3( 0, 1, 0 ) ), "Passed!" );
  37907. a.set( 0, 0, - 1 );
  37908. assert.ok( b.copy( a ).projectOnPlane( normal ).equals( new Vector3( 0, 0, - 1 ) ), "Passed!" );
  37909. a.set( - 1, 0, 0 );
  37910. assert.ok( b.copy( a ).projectOnPlane( normal ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
  37911. } );
  37912. QUnit.test( "reflect", ( assert ) => {
  37913. var a = new Vector3();
  37914. var normal = new Vector3( 0, 1, 0 );
  37915. var b = new Vector3();
  37916. a.set( 0, - 1, 0 );
  37917. assert.ok( b.copy( a ).reflect( normal ).equals( new Vector3( 0, 1, 0 ) ), "Passed!" );
  37918. a.set( 1, - 1, 0 );
  37919. assert.ok( b.copy( a ).reflect( normal ).equals( new Vector3( 1, 1, 0 ) ), "Passed!" );
  37920. a.set( 1, - 1, 0 );
  37921. normal.set( 0, - 1, 0 );
  37922. assert.ok( b.copy( a ).reflect( normal ).equals( new Vector3( 1, 1, 0 ) ), "Passed!" );
  37923. } );
  37924. QUnit.test( "angleTo", ( assert ) => {
  37925. var a = new Vector3( 0, - 0.18851655680720186, 0.9820700116639124 );
  37926. var b = new Vector3( 0, 0.18851655680720186, - 0.9820700116639124 );
  37927. assert.equal( a.angleTo( a ), 0 );
  37928. assert.equal( a.angleTo( b ), Math.PI );
  37929. var x$$1 = new Vector3( 1, 0, 0 );
  37930. var y$$1 = new Vector3( 0, 1, 0 );
  37931. var z$$1 = new Vector3( 0, 0, 1 );
  37932. assert.equal( x$$1.angleTo( y$$1 ), Math.PI / 2 );
  37933. assert.equal( x$$1.angleTo( z$$1 ), Math.PI / 2 );
  37934. assert.equal( z$$1.angleTo( x$$1 ), Math.PI / 2 );
  37935. assert.ok( Math.abs( x$$1.angleTo( new Vector3( 1, 1, 0 ) ) - ( Math.PI / 4 ) ) < 0.0000001 );
  37936. } );
  37937. QUnit.test( "distanceTo", ( assert ) => {
  37938. assert.ok( false, "everything's gonna be alright" );
  37939. } );
  37940. QUnit.test( "distanceToSquared", ( assert ) => {
  37941. assert.ok( false, "everything's gonna be alright" );
  37942. } );
  37943. QUnit.test( "manhattanDistanceTo", ( assert ) => {
  37944. assert.ok( false, "everything's gonna be alright" );
  37945. } );
  37946. QUnit.test( "setFromSpherical", ( assert ) => {
  37947. var a = new Vector3();
  37948. var phi = Math.acos( - 0.5 );
  37949. var theta = Math.sqrt( Math.PI ) * phi;
  37950. var sph = new Spherical( 10, phi, theta );
  37951. var expected = new Vector3( - 4.677914006701843, - 5, - 7.288149322420796 );
  37952. a.setFromSpherical( sph );
  37953. assert.ok( Math.abs( a.x - expected.x ) <= eps, "Check x" );
  37954. assert.ok( Math.abs( a.y - expected.y ) <= eps, "Check y" );
  37955. assert.ok( Math.abs( a.z - expected.z ) <= eps, "Check z" );
  37956. } );
  37957. QUnit.test( "setFromCylindrical", ( assert ) => {
  37958. var a = new Vector3();
  37959. var cyl = new Cylindrical( 10, Math.PI * 0.125, 20 );
  37960. var expected = new Vector3( 3.826834323650898, 20, 9.238795325112868 );
  37961. a.setFromCylindrical( cyl );
  37962. assert.ok( Math.abs( a.x - expected.x ) <= eps, "Check x" );
  37963. assert.ok( Math.abs( a.y - expected.y ) <= eps, "Check y" );
  37964. assert.ok( Math.abs( a.z - expected.z ) <= eps, "Check z" );
  37965. } );
  37966. QUnit.test( "setFromMatrixPosition", ( assert ) => {
  37967. var a = new Vector3();
  37968. var m = new Matrix4().set( 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53 );
  37969. a.setFromMatrixPosition( m );
  37970. assert.strictEqual( a.x, 7, "Check x" );
  37971. assert.strictEqual( a.y, 19, "Check y" );
  37972. assert.strictEqual( a.z, 37, "Check z" );
  37973. } );
  37974. QUnit.test( "setFromMatrixScale", ( assert ) => {
  37975. var a = new Vector3();
  37976. var m = new Matrix4().set( 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53 );
  37977. var expected = new Vector3( 25.573423705088842, 31.921779399024736, 35.70714214271425 );
  37978. a.setFromMatrixScale( m );
  37979. assert.ok( Math.abs( a.x - expected.x ) <= eps, "Check x" );
  37980. assert.ok( Math.abs( a.y - expected.y ) <= eps, "Check y" );
  37981. assert.ok( Math.abs( a.z - expected.z ) <= eps, "Check z" );
  37982. } );
  37983. QUnit.test( "setFromMatrixColumn", ( assert ) => {
  37984. var a = new Vector3();
  37985. var m = new Matrix4().set( 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53 );
  37986. a.setFromMatrixColumn( m, 0 );
  37987. assert.strictEqual( a.x, 2, "Index 0: check x" );
  37988. assert.strictEqual( a.y, 11, "Index 0: check y" );
  37989. assert.strictEqual( a.z, 23, "Index 0: check z" );
  37990. a.setFromMatrixColumn( m, 2 );
  37991. assert.strictEqual( a.x, 5, "Index 2: check x" );
  37992. assert.strictEqual( a.y, 17, "Index 2: check y" );
  37993. assert.strictEqual( a.z, 31, "Index 2: check z" );
  37994. } );
  37995. QUnit.test( "equals", ( assert ) => {
  37996. var a = new Vector3( x, 0, z );
  37997. var b = new Vector3( 0, - y, 0 );
  37998. assert.ok( a.x != b.x, "Passed!" );
  37999. assert.ok( a.y != b.y, "Passed!" );
  38000. assert.ok( a.z != b.z, "Passed!" );
  38001. assert.ok( ! a.equals( b ), "Passed!" );
  38002. assert.ok( ! b.equals( a ), "Passed!" );
  38003. a.copy( b );
  38004. assert.ok( a.x == b.x, "Passed!" );
  38005. assert.ok( a.y == b.y, "Passed!" );
  38006. assert.ok( a.z == b.z, "Passed!" );
  38007. assert.ok( a.equals( b ), "Passed!" );
  38008. assert.ok( b.equals( a ), "Passed!" );
  38009. } );
  38010. QUnit.test( "fromArray", ( assert ) => {
  38011. var a = new Vector3();
  38012. var array = [ 1, 2, 3, 4, 5, 6 ];
  38013. a.fromArray( array );
  38014. assert.strictEqual( a.x, 1, "No offset: check x" );
  38015. assert.strictEqual( a.y, 2, "No offset: check y" );
  38016. assert.strictEqual( a.z, 3, "No offset: check z" );
  38017. a.fromArray( array, 3 );
  38018. assert.strictEqual( a.x, 4, "With offset: check x" );
  38019. assert.strictEqual( a.y, 5, "With offset: check y" );
  38020. assert.strictEqual( a.z, 6, "With offset: check z" );
  38021. } );
  38022. QUnit.test( "toArray", ( assert ) => {
  38023. var a = new Vector3( x, y, z );
  38024. var array = a.toArray();
  38025. assert.strictEqual( array[ 0 ], x, "No array, no offset: check x" );
  38026. assert.strictEqual( array[ 1 ], y, "No array, no offset: check y" );
  38027. assert.strictEqual( array[ 2 ], z, "No array, no offset: check z" );
  38028. var array = [];
  38029. a.toArray( array );
  38030. assert.strictEqual( array[ 0 ], x, "With array, no offset: check x" );
  38031. assert.strictEqual( array[ 1 ], y, "With array, no offset: check y" );
  38032. assert.strictEqual( array[ 2 ], z, "With array, no offset: check z" );
  38033. var array = [];
  38034. a.toArray( array, 1 );
  38035. assert.strictEqual( array[ 0 ], undefined, "With array and offset: check [0]" );
  38036. assert.strictEqual( array[ 1 ], x, "With array and offset: check x" );
  38037. assert.strictEqual( array[ 2 ], y, "With array and offset: check y" );
  38038. assert.strictEqual( array[ 3 ], z, "With array and offset: check z" );
  38039. } );
  38040. QUnit.test( "fromBufferAttribute", ( assert ) => {
  38041. var a = new Vector3();
  38042. var attr = new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 5, 6 ] ), 3 );
  38043. a.fromBufferAttribute( attr, 0 );
  38044. assert.strictEqual( a.x, 1, "Offset 0: check x" );
  38045. assert.strictEqual( a.y, 2, "Offset 0: check y" );
  38046. assert.strictEqual( a.z, 3, "Offset 0: check z" );
  38047. a.fromBufferAttribute( attr, 1 );
  38048. assert.strictEqual( a.x, 4, "Offset 1: check x" );
  38049. assert.strictEqual( a.y, 5, "Offset 1: check y" );
  38050. assert.strictEqual( a.z, 6, "Offset 1: check z" );
  38051. } );
  38052. // TODO (Itee) refactor/split
  38053. QUnit.test( "setX,setY,setZ", ( assert ) => {
  38054. var a = new Vector3();
  38055. assert.ok( a.x == 0, "Passed!" );
  38056. assert.ok( a.y == 0, "Passed!" );
  38057. assert.ok( a.z == 0, "Passed!" );
  38058. a.setX( x );
  38059. a.setY( y );
  38060. a.setZ( z );
  38061. assert.ok( a.x == x, "Passed!" );
  38062. assert.ok( a.y == y, "Passed!" );
  38063. assert.ok( a.z == z, "Passed!" );
  38064. } );
  38065. QUnit.test( "setComponent,getComponent", ( assert ) => {
  38066. var a = new Vector3();
  38067. assert.ok( a.x == 0, "Passed!" );
  38068. assert.ok( a.y == 0, "Passed!" );
  38069. assert.ok( a.z == 0, "Passed!" );
  38070. a.setComponent( 0, 1 );
  38071. a.setComponent( 1, 2 );
  38072. a.setComponent( 2, 3 );
  38073. assert.ok( a.getComponent( 0 ) == 1, "Passed!" );
  38074. assert.ok( a.getComponent( 1 ) == 2, "Passed!" );
  38075. assert.ok( a.getComponent( 2 ) == 3, "Passed!" );
  38076. } );
  38077. QUnit.test( "setComponent/getComponent exceptions", ( assert ) => {
  38078. var a = new Vector3();
  38079. assert.throws(
  38080. function () {
  38081. a.setComponent( 3, 0 );
  38082. },
  38083. /index is out of range/,
  38084. "setComponent with an out of range index throws Error"
  38085. );
  38086. assert.throws(
  38087. function () {
  38088. a.getComponent( 3 );
  38089. },
  38090. /index is out of range/,
  38091. "getComponent with an out of range index throws Error"
  38092. );
  38093. } );
  38094. QUnit.test( "min/max/clamp", ( assert ) => {
  38095. var a = new Vector3( x, y, z );
  38096. var b = new Vector3( - x, - y, - z );
  38097. var c = new Vector3();
  38098. c.copy( a ).min( b );
  38099. assert.ok( c.x == - x, "Passed!" );
  38100. assert.ok( c.y == - y, "Passed!" );
  38101. assert.ok( c.z == - z, "Passed!" );
  38102. c.copy( a ).max( b );
  38103. assert.ok( c.x == x, "Passed!" );
  38104. assert.ok( c.y == y, "Passed!" );
  38105. assert.ok( c.z == z, "Passed!" );
  38106. c.set( - 2 * x, 2 * y, - 2 * z );
  38107. c.clamp( b, a );
  38108. assert.ok( c.x == - x, "Passed!" );
  38109. assert.ok( c.y == y, "Passed!" );
  38110. assert.ok( c.z == - z, "Passed!" );
  38111. } );
  38112. QUnit.test( "distanceTo/distanceToSquared", ( assert ) => {
  38113. var a = new Vector3( x, 0, 0 );
  38114. var b = new Vector3( 0, - y, 0 );
  38115. var c = new Vector3( 0, 0, z );
  38116. var d = new Vector3();
  38117. assert.ok( a.distanceTo( d ) == x, "Passed!" );
  38118. assert.ok( a.distanceToSquared( d ) == x * x, "Passed!" );
  38119. assert.ok( b.distanceTo( d ) == y, "Passed!" );
  38120. assert.ok( b.distanceToSquared( d ) == y * y, "Passed!" );
  38121. assert.ok( c.distanceTo( d ) == z, "Passed!" );
  38122. assert.ok( c.distanceToSquared( d ) == z * z, "Passed!" );
  38123. } );
  38124. QUnit.test( "setScalar/addScalar/subScalar", ( assert ) => {
  38125. var a = new Vector3();
  38126. var s = 3;
  38127. a.setScalar( s );
  38128. assert.strictEqual( a.x, s, "setScalar: check x" );
  38129. assert.strictEqual( a.y, s, "setScalar: check y" );
  38130. assert.strictEqual( a.z, s, "setScalar: check z" );
  38131. a.addScalar( s );
  38132. assert.strictEqual( a.x, 2 * s, "addScalar: check x" );
  38133. assert.strictEqual( a.y, 2 * s, "addScalar: check y" );
  38134. assert.strictEqual( a.z, 2 * s, "addScalar: check z" );
  38135. a.subScalar( 2 * s );
  38136. assert.strictEqual( a.x, 0, "subScalar: check x" );
  38137. assert.strictEqual( a.y, 0, "subScalar: check y" );
  38138. assert.strictEqual( a.z, 0, "subScalar: check z" );
  38139. } );
  38140. QUnit.test( "multiply/divide", ( assert ) => {
  38141. var a = new Vector3( x, y, z );
  38142. var b = new Vector3( 2 * x, 2 * y, 2 * z );
  38143. var c = new Vector3( 4 * x, 4 * y, 4 * z );
  38144. a.multiply( b );
  38145. assert.strictEqual( a.x, x * b.x, "multiply: check x" );
  38146. assert.strictEqual( a.y, y * b.y, "multiply: check y" );
  38147. assert.strictEqual( a.z, z * b.z, "multiply: check z" );
  38148. b.divide( c );
  38149. assert.ok( Math.abs( b.x - 0.5 ) <= eps, "divide: check z" );
  38150. assert.ok( Math.abs( b.y - 0.5 ) <= eps, "divide: check z" );
  38151. assert.ok( Math.abs( b.z - 0.5 ) <= eps, "divide: check z" );
  38152. } );
  38153. QUnit.test( "multiply/divide", ( assert ) => {
  38154. var a = new Vector3( x, y, z );
  38155. var b = new Vector3( - x, - y, - z );
  38156. a.multiplyScalar( - 2 );
  38157. assert.ok( a.x == x * - 2, "Passed!" );
  38158. assert.ok( a.y == y * - 2, "Passed!" );
  38159. assert.ok( a.z == z * - 2, "Passed!" );
  38160. b.multiplyScalar( - 2 );
  38161. assert.ok( b.x == 2 * x, "Passed!" );
  38162. assert.ok( b.y == 2 * y, "Passed!" );
  38163. assert.ok( b.z == 2 * z, "Passed!" );
  38164. a.divideScalar( - 2 );
  38165. assert.ok( a.x == x, "Passed!" );
  38166. assert.ok( a.y == y, "Passed!" );
  38167. assert.ok( a.z == z, "Passed!" );
  38168. b.divideScalar( - 2 );
  38169. assert.ok( b.x == - x, "Passed!" );
  38170. assert.ok( b.y == - y, "Passed!" );
  38171. assert.ok( b.z == - z, "Passed!" );
  38172. } );
  38173. QUnit.test( "project/unproject", ( assert ) => {
  38174. var a = new Vector3( x, y, z );
  38175. var camera = new PerspectiveCamera( 75, 16 / 9, 0.1, 300.0 );
  38176. var projected = new Vector3( - 0.36653213611158914, - 0.9774190296309043, 1.0506835611870624 );
  38177. a.project( camera );
  38178. assert.ok( Math.abs( a.x - projected.x ) <= eps, "project: check x" );
  38179. assert.ok( Math.abs( a.y - projected.y ) <= eps, "project: check y" );
  38180. assert.ok( Math.abs( a.z - projected.z ) <= eps, "project: check z" );
  38181. a.unproject( camera );
  38182. assert.ok( Math.abs( a.x - x ) <= eps, "unproject: check x" );
  38183. assert.ok( Math.abs( a.y - y ) <= eps, "unproject: check y" );
  38184. assert.ok( Math.abs( a.z - z ) <= eps, "unproject: check z" );
  38185. } );
  38186. QUnit.test( "length/lengthSq", ( assert ) => {
  38187. var a = new Vector3( x, 0, 0 );
  38188. var b = new Vector3( 0, - y, 0 );
  38189. var c = new Vector3( 0, 0, z );
  38190. var d = new Vector3();
  38191. assert.ok( a.length() == x, "Passed!" );
  38192. assert.ok( a.lengthSq() == x * x, "Passed!" );
  38193. assert.ok( b.length() == y, "Passed!" );
  38194. assert.ok( b.lengthSq() == y * y, "Passed!" );
  38195. assert.ok( c.length() == z, "Passed!" );
  38196. assert.ok( c.lengthSq() == z * z, "Passed!" );
  38197. assert.ok( d.length() == 0, "Passed!" );
  38198. assert.ok( d.lengthSq() == 0, "Passed!" );
  38199. a.set( x, y, z );
  38200. assert.ok( a.length() == Math.sqrt( x * x + y * y + z * z ), "Passed!" );
  38201. assert.ok( a.lengthSq() == ( x * x + y * y + z * z ), "Passed!" );
  38202. } );
  38203. QUnit.test( "lerp/clone", ( assert ) => {
  38204. var a = new Vector3( x, 0, z );
  38205. var b = new Vector3( 0, - y, 0 );
  38206. assert.ok( a.lerp( a, 0 ).equals( a.lerp( a, 0.5 ) ), "Passed!" );
  38207. assert.ok( a.lerp( a, 0 ).equals( a.lerp( a, 1 ) ), "Passed!" );
  38208. assert.ok( a.clone().lerp( b, 0 ).equals( a ), "Passed!" );
  38209. assert.ok( a.clone().lerp( b, 0.5 ).x == x * 0.5, "Passed!" );
  38210. assert.ok( a.clone().lerp( b, 0.5 ).y == - y * 0.5, "Passed!" );
  38211. assert.ok( a.clone().lerp( b, 0.5 ).z == z * 0.5, "Passed!" );
  38212. assert.ok( a.clone().lerp( b, 1 ).equals( b ), "Passed!" );
  38213. } );
  38214. } );
  38215. } );
  38216. /**
  38217. * @author bhouston / http://exocortex.com
  38218. * @author TristanVALCKE / https://github.com/Itee
  38219. */
  38220. /* global QUnit */
  38221. QUnit.module( 'Maths', () => {
  38222. QUnit.module.todo( 'Vector4', () => {
  38223. // INSTANCING
  38224. QUnit.test( "Instancing", ( assert ) => {
  38225. var a = new Vector4();
  38226. assert.ok( a.x == 0, "Passed!" );
  38227. assert.ok( a.y == 0, "Passed!" );
  38228. assert.ok( a.z == 0, "Passed!" );
  38229. assert.ok( a.w == 1, "Passed!" );
  38230. var a = new Vector4( x, y, z, w );
  38231. assert.ok( a.x === x, "Passed!" );
  38232. assert.ok( a.y === y, "Passed!" );
  38233. assert.ok( a.z === z, "Passed!" );
  38234. assert.ok( a.w === w, "Passed!" );
  38235. } );
  38236. // PUBLIC STUFF
  38237. QUnit.test( "isVector4", ( assert ) => {
  38238. assert.ok( false, "everything's gonna be alright" );
  38239. } );
  38240. QUnit.test( "set", ( assert ) => {
  38241. var a = new Vector4();
  38242. assert.ok( a.x == 0, "Passed!" );
  38243. assert.ok( a.y == 0, "Passed!" );
  38244. assert.ok( a.z == 0, "Passed!" );
  38245. assert.ok( a.w == 1, "Passed!" );
  38246. a.set( x, y, z, w );
  38247. assert.ok( a.x == x, "Passed!" );
  38248. assert.ok( a.y == y, "Passed!" );
  38249. assert.ok( a.z == z, "Passed!" );
  38250. assert.ok( a.w == w, "Passed!" );
  38251. } );
  38252. QUnit.test( "setScalar", ( assert ) => {
  38253. assert.ok( false, "everything's gonna be alright" );
  38254. } );
  38255. QUnit.test( "setX", ( assert ) => {
  38256. assert.ok( false, "everything's gonna be alright" );
  38257. } );
  38258. QUnit.test( "setY", ( assert ) => {
  38259. assert.ok( false, "everything's gonna be alright" );
  38260. } );
  38261. QUnit.test( "setZ", ( assert ) => {
  38262. assert.ok( false, "everything's gonna be alright" );
  38263. } );
  38264. QUnit.test( "setW", ( assert ) => {
  38265. assert.ok( false, "everything's gonna be alright" );
  38266. } );
  38267. QUnit.test( "setComponent", ( assert ) => {
  38268. assert.ok( false, "everything's gonna be alright" );
  38269. } );
  38270. QUnit.test( "getComponent", ( assert ) => {
  38271. assert.ok( false, "everything's gonna be alright" );
  38272. } );
  38273. QUnit.test( "clone", ( assert ) => {
  38274. assert.ok( false, "everything's gonna be alright" );
  38275. } );
  38276. QUnit.test( "copy", ( assert ) => {
  38277. var a = new Vector4( x, y, z, w );
  38278. var b = new Vector4().copy( a );
  38279. assert.ok( b.x == x, "Passed!" );
  38280. assert.ok( b.y == y, "Passed!" );
  38281. assert.ok( b.z == z, "Passed!" );
  38282. assert.ok( b.w == w, "Passed!" );
  38283. // ensure that it is a true copy
  38284. a.x = 0;
  38285. a.y = - 1;
  38286. a.z = - 2;
  38287. a.w = - 3;
  38288. assert.ok( b.x == x, "Passed!" );
  38289. assert.ok( b.y == y, "Passed!" );
  38290. assert.ok( b.z == z, "Passed!" );
  38291. assert.ok( b.w == w, "Passed!" );
  38292. } );
  38293. QUnit.test( "add", ( assert ) => {
  38294. var a = new Vector4( x, y, z, w );
  38295. var b = new Vector4( - x, - y, - z, - w );
  38296. a.add( b );
  38297. assert.ok( a.x == 0, "Passed!" );
  38298. assert.ok( a.y == 0, "Passed!" );
  38299. assert.ok( a.z == 0, "Passed!" );
  38300. assert.ok( a.w == 0, "Passed!" );
  38301. var c = new Vector4().addVectors( b, b );
  38302. assert.ok( c.x == - 2 * x, "Passed!" );
  38303. assert.ok( c.y == - 2 * y, "Passed!" );
  38304. assert.ok( c.z == - 2 * z, "Passed!" );
  38305. assert.ok( c.w == - 2 * w, "Passed!" );
  38306. } );
  38307. QUnit.test( "addScalar", ( assert ) => {
  38308. assert.ok( false, "everything's gonna be alright" );
  38309. } );
  38310. QUnit.test( "addVectors", ( assert ) => {
  38311. assert.ok( false, "everything's gonna be alright" );
  38312. } );
  38313. QUnit.test( "addScaledVector", ( assert ) => {
  38314. var a = new Vector4( x, y, z, w );
  38315. var b = new Vector4( 6, 7, 8, 9 );
  38316. var s = 3;
  38317. a.addScaledVector( b, s );
  38318. assert.strictEqual( a.x, x + b.x * s, "Check x" );
  38319. assert.strictEqual( a.y, y + b.y * s, "Check y" );
  38320. assert.strictEqual( a.z, z + b.z * s, "Check z" );
  38321. assert.strictEqual( a.w, w + b.w * s, "Check w" );
  38322. } );
  38323. QUnit.test( "sub", ( assert ) => {
  38324. var a = new Vector4( x, y, z, w );
  38325. var b = new Vector4( - x, - y, - z, - w );
  38326. a.sub( b );
  38327. assert.ok( a.x == 2 * x, "Passed!" );
  38328. assert.ok( a.y == 2 * y, "Passed!" );
  38329. assert.ok( a.z == 2 * z, "Passed!" );
  38330. assert.ok( a.w == 2 * w, "Passed!" );
  38331. var c = new Vector4().subVectors( a, a );
  38332. assert.ok( c.x == 0, "Passed!" );
  38333. assert.ok( c.y == 0, "Passed!" );
  38334. assert.ok( c.z == 0, "Passed!" );
  38335. assert.ok( c.w == 0, "Passed!" );
  38336. } );
  38337. QUnit.test( "subScalar", ( assert ) => {
  38338. assert.ok( false, "everything's gonna be alright" );
  38339. } );
  38340. QUnit.test( "subVectors", ( assert ) => {
  38341. assert.ok( false, "everything's gonna be alright" );
  38342. } );
  38343. QUnit.test( "multiplyScalar", ( assert ) => {
  38344. assert.ok( false, "everything's gonna be alright" );
  38345. } );
  38346. QUnit.test( "applyMatrix4", ( assert ) => {
  38347. var a = new Vector4( x, y, z, w );
  38348. var m = new Matrix4().makeRotationX( Math.PI );
  38349. var expected = new Vector4( 2, - 3, - 4, 5 );
  38350. a.applyMatrix4( m );
  38351. assert.ok( Math.abs( a.x - expected.x ) <= eps, "Rotation matrix: check x" );
  38352. assert.ok( Math.abs( a.y - expected.y ) <= eps, "Rotation matrix: check y" );
  38353. assert.ok( Math.abs( a.z - expected.z ) <= eps, "Rotation matrix: check z" );
  38354. assert.ok( Math.abs( a.w - expected.w ) <= eps, "Rotation matrix: check w" );
  38355. a.set( x, y, z, w );
  38356. m.makeTranslation( 5, 7, 11 );
  38357. expected.set( 27, 38, 59, 5 );
  38358. a.applyMatrix4( m );
  38359. assert.ok( Math.abs( a.x - expected.x ) <= eps, "Translation matrix: check x" );
  38360. assert.ok( Math.abs( a.y - expected.y ) <= eps, "Translation matrix: check y" );
  38361. assert.ok( Math.abs( a.z - expected.z ) <= eps, "Translation matrix: check z" );
  38362. assert.ok( Math.abs( a.w - expected.w ) <= eps, "Translation matrix: check w" );
  38363. a.set( x, y, z, w );
  38364. m.set( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0 );
  38365. expected.set( 2, 3, 4, 4 );
  38366. a.applyMatrix4( m );
  38367. assert.ok( Math.abs( a.x - expected.x ) <= eps, "Custom matrix: check x" );
  38368. assert.ok( Math.abs( a.y - expected.y ) <= eps, "Custom matrix: check y" );
  38369. assert.ok( Math.abs( a.z - expected.z ) <= eps, "Custom matrix: check z" );
  38370. assert.ok( Math.abs( a.w - expected.w ) <= eps, "Custom matrix: check w" );
  38371. a.set( x, y, z, w );
  38372. m.set( 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53 );
  38373. expected.set( 68, 224, 442, 664 );
  38374. a.applyMatrix4( m );
  38375. assert.ok( Math.abs( a.x - expected.x ) <= eps, "Bogus matrix: check x" );
  38376. assert.ok( Math.abs( a.y - expected.y ) <= eps, "Bogus matrix: check y" );
  38377. assert.ok( Math.abs( a.z - expected.z ) <= eps, "Bogus matrix: check z" );
  38378. assert.ok( Math.abs( a.w - expected.w ) <= eps, "Bogus matrix: check w" );
  38379. } );
  38380. QUnit.test( "divideScalar", ( assert ) => {
  38381. assert.ok( false, "everything's gonna be alright" );
  38382. } );
  38383. QUnit.test( "setAxisAngleFromQuaternion", ( assert ) => {
  38384. assert.ok( false, "everything's gonna be alright" );
  38385. } );
  38386. QUnit.test( "setAxisAngleFromRotationMatrix", ( assert ) => {
  38387. assert.ok( false, "everything's gonna be alright" );
  38388. } );
  38389. QUnit.test( "min", ( assert ) => {
  38390. assert.ok( false, "everything's gonna be alright" );
  38391. } );
  38392. QUnit.test( "max", ( assert ) => {
  38393. assert.ok( false, "everything's gonna be alright" );
  38394. } );
  38395. QUnit.test( "clamp", ( assert ) => {
  38396. assert.ok( false, "everything's gonna be alright" );
  38397. } );
  38398. QUnit.test( "clampScalar", ( assert ) => {
  38399. var a = new Vector4( - 0.1, 0.01, 0.5, 1.5 );
  38400. var clamped = new Vector4( 0.1, 0.1, 0.5, 1.0 );
  38401. a.clampScalar( 0.1, 1.0 );
  38402. assert.ok( Math.abs( a.x - clamped.x ) <= eps, "Check x" );
  38403. assert.ok( Math.abs( a.y - clamped.y ) <= eps, "Check y" );
  38404. assert.ok( Math.abs( a.z - clamped.z ) <= eps, "Check z" );
  38405. assert.ok( Math.abs( a.w - clamped.w ) <= eps, "Check w" );
  38406. } );
  38407. QUnit.test( "clampLength", ( assert ) => {
  38408. assert.ok( false, "everything's gonna be alright" );
  38409. } );
  38410. QUnit.test( "floor", ( assert ) => {
  38411. assert.ok( false, "everything's gonna be alright" );
  38412. } );
  38413. QUnit.test( "ceil", ( assert ) => {
  38414. assert.ok( false, "everything's gonna be alright" );
  38415. } );
  38416. QUnit.test( "round", ( assert ) => {
  38417. assert.ok( false, "everything's gonna be alright" );
  38418. } );
  38419. QUnit.test( "roundToZero", ( assert ) => {
  38420. assert.ok( false, "everything's gonna be alright" );
  38421. } );
  38422. QUnit.test( "negate", ( assert ) => {
  38423. var a = new Vector4( x, y, z, w );
  38424. a.negate();
  38425. assert.ok( a.x == - x, "Passed!" );
  38426. assert.ok( a.y == - y, "Passed!" );
  38427. assert.ok( a.z == - z, "Passed!" );
  38428. assert.ok( a.w == - w, "Passed!" );
  38429. } );
  38430. QUnit.test( "dot", ( assert ) => {
  38431. var a = new Vector4( x, y, z, w );
  38432. var b = new Vector4( - x, - y, - z, - w );
  38433. var c = new Vector4( 0, 0, 0, 0 );
  38434. var result = a.dot( b );
  38435. assert.ok( result == ( - x * x - y * y - z * z - w * w ), "Passed!" );
  38436. var result = a.dot( c );
  38437. assert.ok( result == 0, "Passed!" );
  38438. } );
  38439. QUnit.test( "lengthSq", ( assert ) => {
  38440. assert.ok( false, "everything's gonna be alright" );
  38441. } );
  38442. QUnit.test( "length", ( assert ) => {
  38443. assert.ok( false, "everything's gonna be alright" );
  38444. } );
  38445. QUnit.test( "manhattanLength", ( assert ) => {
  38446. var a = new Vector4( x, 0, 0, 0 );
  38447. var b = new Vector4( 0, - y, 0, 0 );
  38448. var c = new Vector4( 0, 0, z, 0 );
  38449. var d = new Vector4( 0, 0, 0, w );
  38450. var e = new Vector4( 0, 0, 0, 0 );
  38451. assert.ok( a.manhattanLength() == x, "Positive x" );
  38452. assert.ok( b.manhattanLength() == y, "Negative y" );
  38453. assert.ok( c.manhattanLength() == z, "Positive z" );
  38454. assert.ok( d.manhattanLength() == w, "Positive w" );
  38455. assert.ok( e.manhattanLength() == 0, "Empty initialization" );
  38456. a.set( x, y, z, w );
  38457. assert.ok(
  38458. a.manhattanLength() == Math.abs( x ) + Math.abs( y ) + Math.abs( z ) + Math.abs( w ),
  38459. "All components"
  38460. );
  38461. } );
  38462. QUnit.test( "normalize", ( assert ) => {
  38463. var a = new Vector4( x, 0, 0, 0 );
  38464. var b = new Vector4( 0, - y, 0, 0 );
  38465. var c = new Vector4( 0, 0, z, 0 );
  38466. var d = new Vector4( 0, 0, 0, - w );
  38467. a.normalize();
  38468. assert.ok( a.length() == 1, "Passed!" );
  38469. assert.ok( a.x == 1, "Passed!" );
  38470. b.normalize();
  38471. assert.ok( b.length() == 1, "Passed!" );
  38472. assert.ok( b.y == - 1, "Passed!" );
  38473. c.normalize();
  38474. assert.ok( c.length() == 1, "Passed!" );
  38475. assert.ok( c.z == 1, "Passed!" );
  38476. d.normalize();
  38477. assert.ok( d.length() == 1, "Passed!" );
  38478. assert.ok( d.w == - 1, "Passed!" );
  38479. } );
  38480. QUnit.test( "setLength", ( assert ) => {
  38481. var a = new Vector4( x, 0, 0, 0 );
  38482. assert.ok( a.length() == x, "Passed!" );
  38483. a.setLength( y );
  38484. assert.ok( a.length() == y, "Passed!" );
  38485. var a = new Vector4( 0, 0, 0, 0 );
  38486. assert.ok( a.length() == 0, "Passed!" );
  38487. a.setLength( y );
  38488. assert.ok( a.length() == 0, "Passed!" );
  38489. a.setLength();
  38490. assert.ok( isNaN( a.length() ), "Passed!" );
  38491. } );
  38492. QUnit.test( "lerp", ( assert ) => {
  38493. assert.ok( false, "everything's gonna be alright" );
  38494. } );
  38495. QUnit.test( "lerpVectors", ( assert ) => {
  38496. assert.ok( false, "everything's gonna be alright" );
  38497. } );
  38498. QUnit.test( "equals", ( assert ) => {
  38499. var a = new Vector4( x, 0, z, 0 );
  38500. var b = new Vector4( 0, - y, 0, - w );
  38501. assert.ok( a.x != b.x, "Passed!" );
  38502. assert.ok( a.y != b.y, "Passed!" );
  38503. assert.ok( a.z != b.z, "Passed!" );
  38504. assert.ok( a.w != b.w, "Passed!" );
  38505. assert.ok( ! a.equals( b ), "Passed!" );
  38506. assert.ok( ! b.equals( a ), "Passed!" );
  38507. a.copy( b );
  38508. assert.ok( a.x == b.x, "Passed!" );
  38509. assert.ok( a.y == b.y, "Passed!" );
  38510. assert.ok( a.z == b.z, "Passed!" );
  38511. assert.ok( a.w == b.w, "Passed!" );
  38512. assert.ok( a.equals( b ), "Passed!" );
  38513. assert.ok( b.equals( a ), "Passed!" );
  38514. } );
  38515. QUnit.test( "fromArray", ( assert ) => {
  38516. var a = new Vector4();
  38517. var array = [ 1, 2, 3, 4, 5, 6, 7, 8 ];
  38518. a.fromArray( array );
  38519. assert.strictEqual( a.x, 1, "No offset: check x" );
  38520. assert.strictEqual( a.y, 2, "No offset: check y" );
  38521. assert.strictEqual( a.z, 3, "No offset: check z" );
  38522. assert.strictEqual( a.w, 4, "No offset: check w" );
  38523. a.fromArray( array, 4 );
  38524. assert.strictEqual( a.x, 5, "With offset: check x" );
  38525. assert.strictEqual( a.y, 6, "With offset: check y" );
  38526. assert.strictEqual( a.z, 7, "With offset: check z" );
  38527. assert.strictEqual( a.w, 8, "With offset: check w" );
  38528. } );
  38529. QUnit.test( "toArray", ( assert ) => {
  38530. var a = new Vector4( x, y, z, w );
  38531. var array = a.toArray();
  38532. assert.strictEqual( array[ 0 ], x, "No array, no offset: check x" );
  38533. assert.strictEqual( array[ 1 ], y, "No array, no offset: check y" );
  38534. assert.strictEqual( array[ 2 ], z, "No array, no offset: check z" );
  38535. assert.strictEqual( array[ 3 ], w, "No array, no offset: check w" );
  38536. var array = [];
  38537. a.toArray( array );
  38538. assert.strictEqual( array[ 0 ], x, "With array, no offset: check x" );
  38539. assert.strictEqual( array[ 1 ], y, "With array, no offset: check y" );
  38540. assert.strictEqual( array[ 2 ], z, "With array, no offset: check z" );
  38541. assert.strictEqual( array[ 3 ], w, "With array, no offset: check w" );
  38542. var array = [];
  38543. a.toArray( array, 1 );
  38544. assert.strictEqual( array[ 0 ], undefined, "With array and offset: check [0]" );
  38545. assert.strictEqual( array[ 1 ], x, "With array and offset: check x" );
  38546. assert.strictEqual( array[ 2 ], y, "With array and offset: check y" );
  38547. assert.strictEqual( array[ 3 ], z, "With array and offset: check z" );
  38548. assert.strictEqual( array[ 4 ], w, "With array and offset: check w" );
  38549. } );
  38550. QUnit.test( "fromBufferAttribute", ( assert ) => {
  38551. var a = new Vector4();
  38552. var attr = new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ), 4 );
  38553. a.fromBufferAttribute( attr, 0 );
  38554. assert.strictEqual( a.x, 1, "Offset 0: check x" );
  38555. assert.strictEqual( a.y, 2, "Offset 0: check y" );
  38556. assert.strictEqual( a.z, 3, "Offset 0: check z" );
  38557. assert.strictEqual( a.w, 4, "Offset 0: check w" );
  38558. a.fromBufferAttribute( attr, 1 );
  38559. assert.strictEqual( a.x, 5, "Offset 1: check x" );
  38560. assert.strictEqual( a.y, 6, "Offset 1: check y" );
  38561. assert.strictEqual( a.z, 7, "Offset 1: check z" );
  38562. assert.strictEqual( a.w, 8, "Offset 1: check w" );
  38563. } );
  38564. // TODO (Itee) refactor/split
  38565. QUnit.test( "setX,setY,setZ,setW", ( assert ) => {
  38566. var a = new Vector4();
  38567. assert.ok( a.x == 0, "Passed!" );
  38568. assert.ok( a.y == 0, "Passed!" );
  38569. assert.ok( a.z == 0, "Passed!" );
  38570. assert.ok( a.w == 1, "Passed!" );
  38571. a.setX( x );
  38572. a.setY( y );
  38573. a.setZ( z );
  38574. a.setW( w );
  38575. assert.ok( a.x == x, "Passed!" );
  38576. assert.ok( a.y == y, "Passed!" );
  38577. assert.ok( a.z == z, "Passed!" );
  38578. assert.ok( a.w == w, "Passed!" );
  38579. } );
  38580. QUnit.test( "setComponent,getComponent", ( assert ) => {
  38581. var a = new Vector4();
  38582. assert.ok( a.x == 0, "Passed!" );
  38583. assert.ok( a.y == 0, "Passed!" );
  38584. assert.ok( a.z == 0, "Passed!" );
  38585. assert.ok( a.w == 1, "Passed!" );
  38586. a.setComponent( 0, 1 );
  38587. a.setComponent( 1, 2 );
  38588. a.setComponent( 2, 3 );
  38589. a.setComponent( 3, 4 );
  38590. assert.ok( a.getComponent( 0 ) == 1, "Passed!" );
  38591. assert.ok( a.getComponent( 1 ) == 2, "Passed!" );
  38592. assert.ok( a.getComponent( 2 ) == 3, "Passed!" );
  38593. assert.ok( a.getComponent( 3 ) == 4, "Passed!" );
  38594. } );
  38595. QUnit.test( "setComponent/getComponent exceptions", ( assert ) => {
  38596. var a = new Vector4();
  38597. assert.throws(
  38598. function () {
  38599. a.setComponent( 4, 0 );
  38600. },
  38601. /index is out of range/,
  38602. "setComponent with an out of range index throws Error"
  38603. );
  38604. assert.throws(
  38605. function () {
  38606. a.getComponent( 4 );
  38607. },
  38608. /index is out of range/,
  38609. "getComponent with an out of range index throws Error"
  38610. );
  38611. } );
  38612. QUnit.test( "setScalar/addScalar/subScalar", ( assert ) => {
  38613. var a = new Vector4();
  38614. var s = 3;
  38615. a.setScalar( s );
  38616. assert.strictEqual( a.x, s, "setScalar: check x" );
  38617. assert.strictEqual( a.y, s, "setScalar: check y" );
  38618. assert.strictEqual( a.z, s, "setScalar: check z" );
  38619. assert.strictEqual( a.w, s, "setScalar: check w" );
  38620. a.addScalar( s );
  38621. assert.strictEqual( a.x, 2 * s, "addScalar: check x" );
  38622. assert.strictEqual( a.y, 2 * s, "addScalar: check y" );
  38623. assert.strictEqual( a.z, 2 * s, "addScalar: check z" );
  38624. assert.strictEqual( a.w, 2 * s, "addScalar: check w" );
  38625. a.subScalar( 2 * s );
  38626. assert.strictEqual( a.x, 0, "subScalar: check x" );
  38627. assert.strictEqual( a.y, 0, "subScalar: check y" );
  38628. assert.strictEqual( a.z, 0, "subScalar: check z" );
  38629. assert.strictEqual( a.w, 0, "subScalar: check w" );
  38630. } );
  38631. QUnit.test( "multiply/divide", ( assert ) => {
  38632. var a = new Vector4( x, y, z, w );
  38633. var b = new Vector4( - x, - y, - z, - w );
  38634. a.multiplyScalar( - 2 );
  38635. assert.ok( a.x == x * - 2, "Passed!" );
  38636. assert.ok( a.y == y * - 2, "Passed!" );
  38637. assert.ok( a.z == z * - 2, "Passed!" );
  38638. assert.ok( a.w == w * - 2, "Passed!" );
  38639. b.multiplyScalar( - 2 );
  38640. assert.ok( b.x == 2 * x, "Passed!" );
  38641. assert.ok( b.y == 2 * y, "Passed!" );
  38642. assert.ok( b.z == 2 * z, "Passed!" );
  38643. assert.ok( b.w == 2 * w, "Passed!" );
  38644. a.divideScalar( - 2 );
  38645. assert.ok( a.x == x, "Passed!" );
  38646. assert.ok( a.y == y, "Passed!" );
  38647. assert.ok( a.z == z, "Passed!" );
  38648. assert.ok( a.w == w, "Passed!" );
  38649. b.divideScalar( - 2 );
  38650. assert.ok( b.x == - x, "Passed!" );
  38651. assert.ok( b.y == - y, "Passed!" );
  38652. assert.ok( b.z == - z, "Passed!" );
  38653. assert.ok( b.w == - w, "Passed!" );
  38654. } );
  38655. QUnit.test( "min/max/clamp", ( assert ) => {
  38656. var a = new Vector4( x, y, z, w );
  38657. var b = new Vector4( - x, - y, - z, - w );
  38658. var c = new Vector4();
  38659. c.copy( a ).min( b );
  38660. assert.ok( c.x == - x, "Passed!" );
  38661. assert.ok( c.y == - y, "Passed!" );
  38662. assert.ok( c.z == - z, "Passed!" );
  38663. assert.ok( c.w == - w, "Passed!" );
  38664. c.copy( a ).max( b );
  38665. assert.ok( c.x == x, "Passed!" );
  38666. assert.ok( c.y == y, "Passed!" );
  38667. assert.ok( c.z == z, "Passed!" );
  38668. assert.ok( c.w == w, "Passed!" );
  38669. c.set( - 2 * x, 2 * y, - 2 * z, 2 * w );
  38670. c.clamp( b, a );
  38671. assert.ok( c.x == - x, "Passed!" );
  38672. assert.ok( c.y == y, "Passed!" );
  38673. assert.ok( c.z == - z, "Passed!" );
  38674. assert.ok( c.w == w, "Passed!" );
  38675. } );
  38676. QUnit.test( "length/lengthSq", ( assert ) => {
  38677. var a = new Vector4( x, 0, 0, 0 );
  38678. var b = new Vector4( 0, - y, 0, 0 );
  38679. var c = new Vector4( 0, 0, z, 0 );
  38680. var d = new Vector4( 0, 0, 0, w );
  38681. var e = new Vector4( 0, 0, 0, 0 );
  38682. assert.ok( a.length() == x, "Passed!" );
  38683. assert.ok( a.lengthSq() == x * x, "Passed!" );
  38684. assert.ok( b.length() == y, "Passed!" );
  38685. assert.ok( b.lengthSq() == y * y, "Passed!" );
  38686. assert.ok( c.length() == z, "Passed!" );
  38687. assert.ok( c.lengthSq() == z * z, "Passed!" );
  38688. assert.ok( d.length() == w, "Passed!" );
  38689. assert.ok( d.lengthSq() == w * w, "Passed!" );
  38690. assert.ok( e.length() == 0, "Passed!" );
  38691. assert.ok( e.lengthSq() == 0, "Passed!" );
  38692. a.set( x, y, z, w );
  38693. assert.ok( a.length() == Math.sqrt( x * x + y * y + z * z + w * w ), "Passed!" );
  38694. assert.ok( a.lengthSq() == ( x * x + y * y + z * z + w * w ), "Passed!" );
  38695. } );
  38696. QUnit.test( "lerp/clone", ( assert ) => {
  38697. var a = new Vector4( x, 0, z, 0 );
  38698. var b = new Vector4( 0, - y, 0, - w );
  38699. assert.ok( a.lerp( a, 0 ).equals( a.lerp( a, 0.5 ) ), "Passed!" );
  38700. assert.ok( a.lerp( a, 0 ).equals( a.lerp( a, 1 ) ), "Passed!" );
  38701. assert.ok( a.clone().lerp( b, 0 ).equals( a ), "Passed!" );
  38702. assert.ok( a.clone().lerp( b, 0.5 ).x == x * 0.5, "Passed!" );
  38703. assert.ok( a.clone().lerp( b, 0.5 ).y == - y * 0.5, "Passed!" );
  38704. assert.ok( a.clone().lerp( b, 0.5 ).z == z * 0.5, "Passed!" );
  38705. assert.ok( a.clone().lerp( b, 0.5 ).w == - w * 0.5, "Passed!" );
  38706. assert.ok( a.clone().lerp( b, 1 ).equals( b ), "Passed!" );
  38707. } );
  38708. } );
  38709. } );
  38710. /**
  38711. * @author TristanVALCKE / https://github.com/Itee
  38712. */
  38713. /* global QUnit */
  38714. QUnit.module( 'Maths', () => {
  38715. QUnit.module( 'Interpolants', () => {
  38716. QUnit.module.todo( 'CubicInterpolant', () => {
  38717. // INHERITANCE
  38718. QUnit.test( "Extending", ( assert ) => {
  38719. assert.ok( false, "everything's gonna be alright" );
  38720. } );
  38721. // INSTANCING
  38722. QUnit.test( "Instancing", ( assert ) => {
  38723. assert.ok( false, "everything's gonna be alright" );
  38724. } );
  38725. // PRIVATE STUFF
  38726. QUnit.test( "DefaultSettings_", ( assert ) => {
  38727. assert.ok( false, "everything's gonna be alright" );
  38728. } );
  38729. QUnit.test( "intervalChanged_", ( assert ) => {
  38730. assert.ok( false, "everything's gonna be alright" );
  38731. } );
  38732. QUnit.test( "interpolate_", ( assert ) => {
  38733. assert.ok( false, "everything's gonna be alright" );
  38734. } );
  38735. } );
  38736. } );
  38737. } );
  38738. /**
  38739. * @author TristanVALCKE / https://github.com/Itee
  38740. */
  38741. /* global QUnit */
  38742. QUnit.module( 'Maths', () => {
  38743. QUnit.module( 'Interpolants', () => {
  38744. QUnit.module.todo( 'DiscreteInterpolant', () => {
  38745. // INHERITANCE
  38746. QUnit.test( "Extending", ( assert ) => {
  38747. assert.ok( false, "everything's gonna be alright" );
  38748. } );
  38749. // INSTANCING
  38750. QUnit.test( "Instancing", ( assert ) => {
  38751. assert.ok( false, "everything's gonna be alright" );
  38752. } );
  38753. // PRIVATE STUFF
  38754. QUnit.test( "interpolate_", ( assert ) => {
  38755. assert.ok( false, "everything's gonna be alright" );
  38756. } );
  38757. } );
  38758. } );
  38759. } );
  38760. /**
  38761. * @author TristanVALCKE / https://github.com/Itee
  38762. */
  38763. /* global QUnit */
  38764. QUnit.module( 'Maths', () => {
  38765. QUnit.module( 'Interpolants', () => {
  38766. QUnit.module.todo( 'LinearInterpolant', () => {
  38767. // INHERITANCE
  38768. QUnit.test( "Extending", ( assert ) => {
  38769. assert.ok( false, "everything's gonna be alright" );
  38770. } );
  38771. // INSTANCING
  38772. QUnit.test( "Instancing", ( assert ) => {
  38773. assert.ok( false, "everything's gonna be alright" );
  38774. } );
  38775. // PRIVATE STUFF
  38776. QUnit.test( "interpolate_", ( assert ) => {
  38777. assert.ok( false, "everything's gonna be alright" );
  38778. } );
  38779. } );
  38780. } );
  38781. } );
  38782. /**
  38783. * @author TristanVALCKE / https://github.com/Itee
  38784. */
  38785. /* global QUnit */
  38786. QUnit.module( 'Maths', () => {
  38787. QUnit.module( 'Interpolants', () => {
  38788. QUnit.module.todo( 'QuaternionLinearInterpolant', () => {
  38789. // INHERITANCE
  38790. QUnit.test( "Extending", ( assert ) => {
  38791. assert.ok( false, "everything's gonna be alright" );
  38792. } );
  38793. // INSTANCING
  38794. QUnit.test( "Instancing", ( assert ) => {
  38795. assert.ok( false, "everything's gonna be alright" );
  38796. } );
  38797. // PRIVATE STUFF
  38798. QUnit.test( "interpolate_", ( assert ) => {
  38799. assert.ok( false, "everything's gonna be alright" );
  38800. } );
  38801. } );
  38802. } );
  38803. } );
  38804. /**
  38805. * @author TristanVALCKE / https://github.com/Itee
  38806. */
  38807. /* global QUnit */
  38808. QUnit.module( 'Objects', () => {
  38809. QUnit.module.todo( 'Bone', () => {
  38810. // INHERITANCE
  38811. QUnit.test( "Extending", ( assert ) => {
  38812. assert.ok( false, "everything's gonna be alright" );
  38813. } );
  38814. // INSTANCING
  38815. QUnit.test( "Instancing", ( assert ) => {
  38816. assert.ok( false, "everything's gonna be alright" );
  38817. } );
  38818. // PUBLIC STUFF
  38819. QUnit.test( "isBone", ( assert ) => {
  38820. assert.ok( false, "everything's gonna be alright" );
  38821. } );
  38822. } );
  38823. } );
  38824. /**
  38825. * @author TristanVALCKE / https://github.com/Itee
  38826. */
  38827. /* global QUnit */
  38828. QUnit.module( 'Objects', () => {
  38829. QUnit.module.todo( 'Group', () => {
  38830. // INHERITANCE
  38831. QUnit.test( "Extending", ( assert ) => {
  38832. assert.ok( false, "everything's gonna be alright" );
  38833. } );
  38834. // INSTANCING
  38835. QUnit.test( "Instancing", ( assert ) => {
  38836. assert.ok( false, "everything's gonna be alright" );
  38837. } );
  38838. } );
  38839. } );
  38840. function LensFlare( texture, size, distance, blending, color ) {
  38841. Object3D.call( this );
  38842. this.lensFlares = [];
  38843. this.positionScreen = new Vector3();
  38844. this.customUpdateCallback = undefined;
  38845. if ( texture !== undefined ) {
  38846. this.add( texture, size, distance, blending, color );
  38847. }
  38848. }
  38849. LensFlare.prototype = Object.assign( Object.create( Object3D.prototype ), {
  38850. constructor: LensFlare,
  38851. isLensFlare: true,
  38852. copy: function ( source ) {
  38853. Object3D.prototype.copy.call( this, source );
  38854. this.positionScreen.copy( source.positionScreen );
  38855. this.customUpdateCallback = source.customUpdateCallback;
  38856. for ( var i = 0, l = source.lensFlares.length; i < l; i ++ ) {
  38857. this.lensFlares.push( source.lensFlares[ i ] );
  38858. }
  38859. return this;
  38860. },
  38861. add: function ( texture, size, distance, blending, color, opacity ) {
  38862. if ( size === undefined ) size = - 1;
  38863. if ( distance === undefined ) distance = 0;
  38864. if ( opacity === undefined ) opacity = 1;
  38865. if ( color === undefined ) color = new Color( 0xffffff );
  38866. if ( blending === undefined ) blending = NormalBlending;
  38867. distance = Math.min( distance, Math.max( 0, distance ) );
  38868. this.lensFlares.push( {
  38869. texture: texture, // THREE.Texture
  38870. size: size, // size in pixels (-1 = use texture.width)
  38871. distance: distance, // distance (0-1) from light source (0=at light source)
  38872. x: 0, y: 0, z: 0, // screen position (-1 => 1) z = 0 is in front z = 1 is back
  38873. scale: 1, // scale
  38874. rotation: 0, // rotation
  38875. opacity: opacity, // opacity
  38876. color: color, // color
  38877. blending: blending // blending
  38878. } );
  38879. },
  38880. /*
  38881. * Update lens flares update positions on all flares based on the screen position
  38882. * Set myLensFlare.customUpdateCallback to alter the flares in your project specific way.
  38883. */
  38884. updateLensFlares: function () {
  38885. var f, fl = this.lensFlares.length;
  38886. var flare;
  38887. var vecX = - this.positionScreen.x * 2;
  38888. var vecY = - this.positionScreen.y * 2;
  38889. for ( f = 0; f < fl; f ++ ) {
  38890. flare = this.lensFlares[ f ];
  38891. flare.x = this.positionScreen.x + vecX * flare.distance;
  38892. flare.y = this.positionScreen.y + vecY * flare.distance;
  38893. flare.wantedRotation = flare.x * Math.PI * 0.25;
  38894. flare.rotation += ( flare.wantedRotation - flare.rotation ) * 0.25;
  38895. }
  38896. }
  38897. } );
  38898. /**
  38899. * @author TristanVALCKE / https://github.com/Itee
  38900. */
  38901. /* global QUnit */
  38902. QUnit.module( 'Objects', () => {
  38903. QUnit.module.todo( 'LensFlare', () => {
  38904. // INHERITANCE
  38905. QUnit.test( "Extending", ( assert ) => {
  38906. assert.ok( false, "everything's gonna be alright" );
  38907. } );
  38908. // INSTANCING
  38909. QUnit.test( "Instancing", ( assert ) => {
  38910. assert.ok( false, "everything's gonna be alright" );
  38911. } );
  38912. // PUBLIC STUFF
  38913. QUnit.test( "isLensFlare", ( assert ) => {
  38914. assert.ok( false, "everything's gonna be alright" );
  38915. } );
  38916. QUnit.test( "copy", ( assert ) => {
  38917. assert.ok( false, "everything's gonna be alright" );
  38918. } );
  38919. QUnit.test( "add", ( assert ) => {
  38920. assert.ok( false, "everything's gonna be alright" );
  38921. } );
  38922. QUnit.test( "updateLensFlares", ( assert ) => {
  38923. assert.ok( false, "everything's gonna be alright" );
  38924. } );
  38925. } );
  38926. } );
  38927. /**
  38928. * @author TristanVALCKE / https://github.com/Itee
  38929. */
  38930. /* global QUnit */
  38931. QUnit.module( 'Objects', () => {
  38932. QUnit.module.todo( 'Line', () => {
  38933. // INHERITANCE
  38934. QUnit.test( "Extending", ( assert ) => {
  38935. assert.ok( false, "everything's gonna be alright" );
  38936. } );
  38937. // INSTANCING
  38938. QUnit.test( "Instancing", ( assert ) => {
  38939. assert.ok( false, "everything's gonna be alright" );
  38940. } );
  38941. // PUBLIC STUFF
  38942. QUnit.test( "isLine", ( assert ) => {
  38943. assert.ok( false, "everything's gonna be alright" );
  38944. } );
  38945. QUnit.test( "raycast", ( assert ) => {
  38946. assert.ok( false, "everything's gonna be alright" );
  38947. } );
  38948. QUnit.test( "clone", ( assert ) => {
  38949. assert.ok( false, "everything's gonna be alright" );
  38950. } );
  38951. } );
  38952. } );
  38953. /**
  38954. * @author TristanVALCKE / https://github.com/Itee
  38955. */
  38956. /* global QUnit */
  38957. QUnit.module( 'Objects', () => {
  38958. QUnit.module.todo( 'LineLoop', () => {
  38959. // INHERITANCE
  38960. QUnit.test( "Extending", ( assert ) => {
  38961. assert.ok( false, "everything's gonna be alright" );
  38962. } );
  38963. // INSTANCING
  38964. QUnit.test( "Instancing", ( assert ) => {
  38965. assert.ok( false, "everything's gonna be alright" );
  38966. } );
  38967. // PUBLIC STUFF
  38968. QUnit.test( "isLineLoop", ( assert ) => {
  38969. assert.ok( false, "everything's gonna be alright" );
  38970. } );
  38971. } );
  38972. } );
  38973. /**
  38974. * @author TristanVALCKE / https://github.com/Itee
  38975. */
  38976. /* global QUnit */
  38977. QUnit.module( 'Objects', () => {
  38978. QUnit.module.todo( 'LineSegments', () => {
  38979. // INHERITANCE
  38980. QUnit.test( "Extending", ( assert ) => {
  38981. assert.ok( false, "everything's gonna be alright" );
  38982. } );
  38983. // INSTANCING
  38984. QUnit.test( "Instancing", ( assert ) => {
  38985. assert.ok( false, "everything's gonna be alright" );
  38986. } );
  38987. // PUBLIC STUFF
  38988. QUnit.test( "isLineSegments", ( assert ) => {
  38989. assert.ok( false, "everything's gonna be alright" );
  38990. } );
  38991. } );
  38992. } );
  38993. /**
  38994. * @author TristanVALCKE / https://github.com/Itee
  38995. */
  38996. /* global QUnit */
  38997. QUnit.module( 'Objects', () => {
  38998. QUnit.module.todo( 'LOD', () => {
  38999. // INHERITANCE
  39000. QUnit.test( "Extending", ( assert ) => {
  39001. assert.ok( false, "everything's gonna be alright" );
  39002. } );
  39003. // INSTANCING
  39004. QUnit.test( "Instancing", ( assert ) => {
  39005. assert.ok( false, "everything's gonna be alright" );
  39006. } );
  39007. // PROPERTIES
  39008. QUnit.test( "levels", ( assert ) => {
  39009. assert.ok( false, "everything's gonna be alright" );
  39010. } );
  39011. // PUBLIC STUFF
  39012. QUnit.test( "isLOD", ( assert ) => {
  39013. assert.ok( false, "everything's gonna be alright" );
  39014. } );
  39015. QUnit.test( "copy", ( assert ) => {
  39016. assert.ok( false, "everything's gonna be alright" );
  39017. } );
  39018. QUnit.test( "addLevel", ( assert ) => {
  39019. assert.ok( false, "everything's gonna be alright" );
  39020. } );
  39021. QUnit.test( "getObjectForDistance", ( assert ) => {
  39022. assert.ok( false, "everything's gonna be alright" );
  39023. } );
  39024. QUnit.test( "raycast", ( assert ) => {
  39025. assert.ok( false, "everything's gonna be alright" );
  39026. } );
  39027. QUnit.test( "update", ( assert ) => {
  39028. assert.ok( false, "everything's gonna be alright" );
  39029. } );
  39030. QUnit.test( "toJSON", ( assert ) => {
  39031. assert.ok( false, "everything's gonna be alright" );
  39032. } );
  39033. } );
  39034. } );
  39035. /**
  39036. * @author TristanVALCKE / https://github.com/Itee
  39037. */
  39038. /* global QUnit */
  39039. QUnit.module( 'Objects', () => {
  39040. QUnit.module.todo( 'Mesh', () => {
  39041. // INHERITANCE
  39042. QUnit.test( "Extending", ( assert ) => {
  39043. assert.ok( false, "everything's gonna be alright" );
  39044. } );
  39045. // INSTANCING
  39046. QUnit.test( "Instancing", ( assert ) => {
  39047. assert.ok( false, "everything's gonna be alright" );
  39048. } );
  39049. // PUBLIC STUFF
  39050. QUnit.test( "isMesh", ( assert ) => {
  39051. assert.ok( false, "everything's gonna be alright" );
  39052. } );
  39053. QUnit.test( "setDrawMode", ( assert ) => {
  39054. assert.ok( false, "everything's gonna be alright" );
  39055. } );
  39056. QUnit.test( "copy", ( assert ) => {
  39057. assert.ok( false, "everything's gonna be alright" );
  39058. } );
  39059. QUnit.test( "updateMorphTargets", ( assert ) => {
  39060. assert.ok( false, "everything's gonna be alright" );
  39061. } );
  39062. QUnit.test( "raycast", ( assert ) => {
  39063. assert.ok( false, "everything's gonna be alright" );
  39064. } );
  39065. QUnit.test( "clone", ( assert ) => {
  39066. assert.ok( false, "everything's gonna be alright" );
  39067. } );
  39068. } );
  39069. } );
  39070. /**
  39071. * @author TristanVALCKE / https://github.com/Itee
  39072. */
  39073. /* global QUnit */
  39074. QUnit.module( 'Objects', () => {
  39075. QUnit.module.todo( 'Points', () => {
  39076. // INHERITANCE
  39077. QUnit.test( "isPoints", ( assert ) => {
  39078. assert.ok( false, "everything's gonna be alright" );
  39079. } );
  39080. // INSTANCING
  39081. QUnit.test( "raycast", ( assert ) => {
  39082. assert.ok( false, "everything's gonna be alright" );
  39083. } );
  39084. // PUBLIC STUFF
  39085. QUnit.test( "clone", ( assert ) => {
  39086. assert.ok( false, "everything's gonna be alright" );
  39087. } );
  39088. } );
  39089. } );
  39090. /**
  39091. * @author TristanVALCKE / https://github.com/Itee
  39092. */
  39093. /* global QUnit */
  39094. QUnit.module( 'Objects', () => {
  39095. QUnit.module.todo( 'Skeleton', () => {
  39096. // INSTANCING
  39097. QUnit.test( "Instancing", ( assert ) => {
  39098. assert.ok( false, "everything's gonna be alright" );
  39099. } );
  39100. // PUBLIC STUFF
  39101. QUnit.test( "calculateInverses", ( assert ) => {
  39102. assert.ok( false, "everything's gonna be alright" );
  39103. } );
  39104. QUnit.test( "pose", ( assert ) => {
  39105. assert.ok( false, "everything's gonna be alright" );
  39106. } );
  39107. QUnit.test( "update", ( assert ) => {
  39108. assert.ok( false, "everything's gonna be alright" );
  39109. } );
  39110. QUnit.test( "clone", ( assert ) => {
  39111. assert.ok( false, "everything's gonna be alright" );
  39112. } );
  39113. } );
  39114. } );
  39115. /**
  39116. * @author TristanVALCKE / https://github.com/Itee
  39117. */
  39118. /* global QUnit */
  39119. QUnit.module( 'Objects', () => {
  39120. QUnit.module.todo( 'SkinnedMesh', () => {
  39121. // INHERITANCE
  39122. QUnit.test( "Extending", ( assert ) => {
  39123. assert.ok( false, "everything's gonna be alright" );
  39124. } );
  39125. // INSTANCING
  39126. QUnit.test( "Instancing", ( assert ) => {
  39127. assert.ok( false, "everything's gonna be alright" );
  39128. } );
  39129. // PUBLIC STUFF
  39130. QUnit.test( "isSkinnedMesh", ( assert ) => {
  39131. assert.ok( false, "everything's gonna be alright" );
  39132. } );
  39133. QUnit.test( "initBones", ( assert ) => {
  39134. assert.ok( false, "everything's gonna be alright" );
  39135. } );
  39136. QUnit.test( "bind", ( assert ) => {
  39137. assert.ok( false, "everything's gonna be alright" );
  39138. } );
  39139. QUnit.test( "pose", ( assert ) => {
  39140. assert.ok( false, "everything's gonna be alright" );
  39141. } );
  39142. QUnit.test( "normalizeSkinWeights", ( assert ) => {
  39143. assert.ok( false, "everything's gonna be alright" );
  39144. } );
  39145. QUnit.test( "updateMatrixWorld", ( assert ) => {
  39146. assert.ok( false, "everything's gonna be alright" );
  39147. } );
  39148. QUnit.test( "clone", ( assert ) => {
  39149. assert.ok( false, "everything's gonna be alright" );
  39150. } );
  39151. } );
  39152. } );
  39153. /**
  39154. * @author TristanVALCKE / https://github.com/Itee
  39155. */
  39156. /* global QUnit */
  39157. QUnit.module( 'Objects', () => {
  39158. QUnit.module.todo( 'Sprite', () => {
  39159. // INHERITANCE
  39160. QUnit.test( "Extending", ( assert ) => {
  39161. assert.ok( false, "everything's gonna be alright" );
  39162. } );
  39163. // INSTANCING
  39164. QUnit.test( "Instancing", ( assert ) => {
  39165. assert.ok( false, "everything's gonna be alright" );
  39166. } );
  39167. // PUBLIC STUFF
  39168. QUnit.test( "isSprite", ( assert ) => {
  39169. assert.ok( false, "everything's gonna be alright" );
  39170. } );
  39171. QUnit.test( "raycast", ( assert ) => {
  39172. assert.ok( false, "everything's gonna be alright" );
  39173. } );
  39174. QUnit.test( "clone", ( assert ) => {
  39175. assert.ok( false, "everything's gonna be alright" );
  39176. } );
  39177. } );
  39178. } );
  39179. /**
  39180. * @author mrdoob / http://mrdoob.com/
  39181. */
  39182. /**
  39183. * @author TristanVALCKE / https://github.com/Itee
  39184. */
  39185. /* global QUnit */
  39186. QUnit.module( 'Renderers', () => {
  39187. QUnit.module.todo( 'WebGL2Renderer', () => {
  39188. // INSTANCING
  39189. QUnit.test( "Instancing", ( assert ) => {
  39190. assert.ok( false, "everything's gonna be alright" );
  39191. } );
  39192. // PUBLIC STUFF
  39193. QUnit.test( "domElement", ( assert ) => {
  39194. assert.ok( false, "everything's gonna be alright" );
  39195. } );
  39196. QUnit.test( "clear", ( assert ) => {
  39197. assert.ok( false, "everything's gonna be alright" );
  39198. } );
  39199. QUnit.test( "setPixelRatio", ( assert ) => {
  39200. assert.ok( false, "everything's gonna be alright" );
  39201. } );
  39202. QUnit.test( "setSize", ( assert ) => {
  39203. assert.ok( false, "everything's gonna be alright" );
  39204. } );
  39205. QUnit.test( "render", ( assert ) => {
  39206. assert.ok( false, "everything's gonna be alright" );
  39207. } );
  39208. } );
  39209. } );
  39210. /**
  39211. * @author TristanVALCKE / https://github.com/Itee
  39212. */
  39213. /* global QUnit */
  39214. QUnit.module( 'Renderers', () => {
  39215. QUnit.module.todo( 'WebGLRenderer', () => {
  39216. // INSTANCING
  39217. QUnit.test( "Instancing", ( assert ) => {
  39218. assert.ok( false, "everything's gonna be alright" );
  39219. } );
  39220. // PUBLIC STUFF
  39221. QUnit.test( "PrayForUs", ( assert ) => {
  39222. assert.ok( false, "everything's gonna be alright" );
  39223. } );
  39224. } );
  39225. } );
  39226. /**
  39227. * @author TristanVALCKE / https://github.com/Itee
  39228. */
  39229. /* global QUnit */
  39230. QUnit.module( 'Renderers', () => {
  39231. QUnit.module.todo( 'WebGLRenderTarget', () => {
  39232. // INHERITANCE
  39233. QUnit.test( "Extending", ( assert ) => {
  39234. assert.ok( false, "everything's gonna be alright" );
  39235. } );
  39236. // INSTANCING
  39237. QUnit.test( "Instancing", ( assert ) => {
  39238. assert.ok( false, "everything's gonna be alright" );
  39239. } );
  39240. // PUBLIC STUFF
  39241. QUnit.test( "isWebGLRenderTarget", ( assert ) => {
  39242. assert.ok( false, "everything's gonna be alright" );
  39243. } );
  39244. QUnit.test( "setSize", ( assert ) => {
  39245. assert.ok( false, "everything's gonna be alright" );
  39246. } );
  39247. QUnit.test( "clone", ( assert ) => {
  39248. assert.ok( false, "everything's gonna be alright" );
  39249. } );
  39250. QUnit.test( "copy", ( assert ) => {
  39251. assert.ok( false, "everything's gonna be alright" );
  39252. } );
  39253. QUnit.test( "dispose", ( assert ) => {
  39254. assert.ok( false, "everything's gonna be alright" );
  39255. } );
  39256. } );
  39257. } );
  39258. /**
  39259. * @author TristanVALCKE / https://github.com/Itee
  39260. */
  39261. /* global QUnit */
  39262. QUnit.module( 'Renderers', () => {
  39263. QUnit.module.todo( 'WebGLRenderTargetCube', () => {
  39264. // INSTANCING
  39265. QUnit.test( "Instancing", ( assert ) => {
  39266. assert.ok( false, "everything's gonna be alright" );
  39267. } );
  39268. // PUBLIC STUFF
  39269. QUnit.test( "isWebGLRenderTargetCube", ( assert ) => {
  39270. assert.ok( false, "everything's gonna be alright" );
  39271. } );
  39272. } );
  39273. } );
  39274. /**
  39275. * @author TristanVALCKE / https://github.com/Itee
  39276. */
  39277. /* global QUnit */
  39278. QUnit.module( 'Renderers', () => {
  39279. QUnit.module( 'Shaders', () => {
  39280. QUnit.module.todo( 'ShaderChunk', () => {
  39281. QUnit.test( 'write me !', ( assert ) => {
  39282. assert.ok( false, "everything's gonna be alright" );
  39283. } );
  39284. } );
  39285. } );
  39286. } );
  39287. /**
  39288. * @author TristanVALCKE / https://github.com/Itee
  39289. */
  39290. /* global QUnit */
  39291. QUnit.module( 'Renderers', () => {
  39292. QUnit.module( 'Shaders', () => {
  39293. QUnit.module.todo( 'ShaderLib', () => {
  39294. QUnit.test( 'write me !', ( assert ) => {
  39295. assert.ok( false, "everything's gonna be alright" );
  39296. } );
  39297. } );
  39298. } );
  39299. } );
  39300. /**
  39301. * @author TristanVALCKE / https://github.com/Itee
  39302. */
  39303. /* global QUnit */
  39304. QUnit.module( 'Renderers', () => {
  39305. QUnit.module( 'Shaders', () => {
  39306. QUnit.module.todo( 'UniformsLib', () => {
  39307. // PUBLIC STUFF
  39308. QUnit.test( "merge", ( assert ) => {
  39309. assert.ok( false, "everything's gonna be alright" );
  39310. } );
  39311. QUnit.test( "clone", ( assert ) => {
  39312. assert.ok( false, "everything's gonna be alright" );
  39313. } );
  39314. } );
  39315. } );
  39316. } );
  39317. /**
  39318. * @author TristanVALCKE / https://github.com/Itee
  39319. */
  39320. /* global QUnit */
  39321. QUnit.module( 'Renderers', () => {
  39322. QUnit.module( 'Shaders', () => {
  39323. QUnit.module.todo( 'UniformsUtils', () => {
  39324. QUnit.test( 'write me !', ( assert ) => {
  39325. assert.ok( false, "everything's gonna be alright" );
  39326. } );
  39327. } );
  39328. } );
  39329. } );
  39330. /**
  39331. * @author TristanVALCKE / https://github.com/Itee
  39332. */
  39333. /* global QUnit */
  39334. QUnit.module( 'Renderers', () => {
  39335. QUnit.module( 'WebGL', () => {
  39336. QUnit.module.todo( 'WebGLAttributes', () => {
  39337. // INSTANCING
  39338. QUnit.test( "Instancing", ( assert ) => {
  39339. assert.ok( false, "everything's gonna be alright" );
  39340. } );
  39341. // PUBLIC STUFF
  39342. QUnit.test( "get", ( assert ) => {
  39343. assert.ok( false, "everything's gonna be alright" );
  39344. } );
  39345. QUnit.test( "remove", ( assert ) => {
  39346. assert.ok( false, "everything's gonna be alright" );
  39347. } );
  39348. QUnit.test( "update", ( assert ) => {
  39349. assert.ok( false, "everything's gonna be alright" );
  39350. } );
  39351. } );
  39352. } );
  39353. } );
  39354. /**
  39355. * @author TristanVALCKE / https://github.com/Itee
  39356. */
  39357. /* global QUnit */
  39358. QUnit.module( 'Renderers', () => {
  39359. QUnit.module( 'WebGL', () => {
  39360. QUnit.module.todo( 'WebGLBackground', () => {
  39361. // INSTANCING
  39362. QUnit.test( "Instancing", ( assert ) => {
  39363. assert.ok( false, "everything's gonna be alright" );
  39364. } );
  39365. // PUBLIC STUFF
  39366. QUnit.test( "getClearColor", ( assert ) => {
  39367. assert.ok( false, "everything's gonna be alright" );
  39368. } );
  39369. QUnit.test( "setClearColor", ( assert ) => {
  39370. assert.ok( false, "everything's gonna be alright" );
  39371. } );
  39372. QUnit.test( "getClearAlpha", ( assert ) => {
  39373. assert.ok( false, "everything's gonna be alright" );
  39374. } );
  39375. QUnit.test( "setClearAlpha", ( assert ) => {
  39376. assert.ok( false, "everything's gonna be alright" );
  39377. } );
  39378. QUnit.test( "render", ( assert ) => {
  39379. assert.ok( false, "everything's gonna be alright" );
  39380. } );
  39381. } );
  39382. } );
  39383. } );
  39384. /**
  39385. * @author TristanVALCKE / https://github.com/Itee
  39386. */
  39387. /* global QUnit */
  39388. QUnit.module( 'Renderers', () => {
  39389. QUnit.module( 'WebGL', () => {
  39390. QUnit.module.todo( 'WebGLBufferRenderer', () => {
  39391. // INSTANCING
  39392. QUnit.test( "Instancing", ( assert ) => {
  39393. assert.ok( false, "everything's gonna be alright" );
  39394. } );
  39395. // PUBLIC STUFF
  39396. QUnit.test( "setMode", ( assert ) => {
  39397. assert.ok( false, "everything's gonna be alright" );
  39398. } );
  39399. QUnit.test( "render", ( assert ) => {
  39400. assert.ok( false, "everything's gonna be alright" );
  39401. } );
  39402. QUnit.test( "renderInstances", ( assert ) => {
  39403. assert.ok( false, "everything's gonna be alright" );
  39404. } );
  39405. } );
  39406. } );
  39407. } );
  39408. /**
  39409. * @author TristanVALCKE / https://github.com/Itee
  39410. */
  39411. /* global QUnit */
  39412. QUnit.module( 'Renderers', () => {
  39413. QUnit.module( 'WebGL', () => {
  39414. QUnit.module.todo( 'WebGLCapabilities', () => {
  39415. // INSTANCING
  39416. QUnit.test( "Instancing", ( assert ) => {
  39417. assert.ok( false, "everything's gonna be alright" );
  39418. } );
  39419. // PUBLIC STUFF
  39420. QUnit.test( "getMaxAnisotropy", ( assert ) => {
  39421. assert.ok( false, "everything's gonna be alright" );
  39422. } );
  39423. QUnit.test( "getMaxPrecision", ( assert ) => {
  39424. assert.ok( false, "everything's gonna be alright" );
  39425. } );
  39426. QUnit.test( "precision", ( assert ) => {
  39427. assert.ok( false, "everything's gonna be alright" );
  39428. } );
  39429. QUnit.test( "logarithmicDepthBuffer", ( assert ) => {
  39430. assert.ok( false, "everything's gonna be alright" );
  39431. } );
  39432. QUnit.test( "maxTextures", ( assert ) => {
  39433. assert.ok( false, "everything's gonna be alright" );
  39434. } );
  39435. QUnit.test( "maxVertexTextures", ( assert ) => {
  39436. assert.ok( false, "everything's gonna be alright" );
  39437. } );
  39438. QUnit.test( "maxTextureSize", ( assert ) => {
  39439. assert.ok( false, "everything's gonna be alright" );
  39440. } );
  39441. QUnit.test( "maxCubemapSize", ( assert ) => {
  39442. assert.ok( false, "everything's gonna be alright" );
  39443. } );
  39444. QUnit.test( "maxAttributes", ( assert ) => {
  39445. assert.ok( false, "everything's gonna be alright" );
  39446. } );
  39447. QUnit.test( "maxVertexUniforms", ( assert ) => {
  39448. assert.ok( false, "everything's gonna be alright" );
  39449. } );
  39450. QUnit.test( "maxVaryings", ( assert ) => {
  39451. assert.ok( false, "everything's gonna be alright" );
  39452. } );
  39453. QUnit.test( "maxFragmentUniforms", ( assert ) => {
  39454. assert.ok( false, "everything's gonna be alright" );
  39455. } );
  39456. QUnit.test( "vertexTextures", ( assert ) => {
  39457. assert.ok( false, "everything's gonna be alright" );
  39458. } );
  39459. QUnit.test( "floatFragmentTextures", ( assert ) => {
  39460. assert.ok( false, "everything's gonna be alright" );
  39461. } );
  39462. QUnit.test( "floatVertexTextures", ( assert ) => {
  39463. assert.ok( false, "everything's gonna be alright" );
  39464. } );
  39465. } );
  39466. } );
  39467. } );
  39468. /**
  39469. * @author TristanVALCKE / https://github.com/Itee
  39470. */
  39471. /* global QUnit */
  39472. QUnit.module( 'Renderers', () => {
  39473. QUnit.module( 'WebGL', () => {
  39474. QUnit.module.todo( 'WebGLClipping', () => {
  39475. // INSTANCING
  39476. QUnit.test( "Instancing", ( assert ) => {
  39477. assert.ok( false, "everything's gonna be alright" );
  39478. } );
  39479. // PUBLIC STUFF
  39480. QUnit.test( "init", ( assert ) => {
  39481. assert.ok( false, "everything's gonna be alright" );
  39482. } );
  39483. QUnit.test( "beginShadows", ( assert ) => {
  39484. assert.ok( false, "everything's gonna be alright" );
  39485. } );
  39486. QUnit.test( "endShadows", ( assert ) => {
  39487. assert.ok( false, "everything's gonna be alright" );
  39488. } );
  39489. QUnit.test( "setState", ( assert ) => {
  39490. assert.ok( false, "everything's gonna be alright" );
  39491. } );
  39492. } );
  39493. } );
  39494. } );
  39495. /**
  39496. * @author TristanVALCKE / https://github.com/Itee
  39497. */
  39498. /* global QUnit */
  39499. QUnit.module( 'Renderers', () => {
  39500. QUnit.module( 'WebGL', () => {
  39501. QUnit.module.todo( 'WebGLExtensions', () => {
  39502. // INSTANCING
  39503. QUnit.test( "Instancing", ( assert ) => {
  39504. assert.ok( false, "everything's gonna be alright" );
  39505. } );
  39506. // PUBLIC STUFF
  39507. QUnit.test( "get", ( assert ) => {
  39508. assert.ok( false, "everything's gonna be alright" );
  39509. } );
  39510. } );
  39511. } );
  39512. } );
  39513. /**
  39514. * @author TristanVALCKE / https://github.com/Itee
  39515. */
  39516. /* global QUnit */
  39517. QUnit.module( 'Renderers', () => {
  39518. QUnit.module( 'WebGL', () => {
  39519. QUnit.module.todo( 'WebGLFlareRenderer', () => {
  39520. // INSTANCING
  39521. QUnit.test( "Instancing", ( assert ) => {
  39522. assert.ok( false, "everything's gonna be alright" );
  39523. } );
  39524. // PUBLIC STUFF
  39525. QUnit.test( "render", ( assert ) => {
  39526. assert.ok( false, "everything's gonna be alright" );
  39527. } );
  39528. } );
  39529. } );
  39530. } );
  39531. /**
  39532. * @author TristanVALCKE / https://github.com/Itee
  39533. */
  39534. /* global QUnit */
  39535. QUnit.module( 'Renderers', () => {
  39536. QUnit.module( 'WebGL', () => {
  39537. QUnit.module.todo( 'WebGLGeometries', () => {
  39538. // INSTANCING
  39539. QUnit.test( "Instancing", ( assert ) => {
  39540. assert.ok( false, "everything's gonna be alright" );
  39541. } );
  39542. // PUBLIC STUFF
  39543. QUnit.test( "get", ( assert ) => {
  39544. assert.ok( false, "everything's gonna be alright" );
  39545. } );
  39546. QUnit.test( "update", ( assert ) => {
  39547. assert.ok( false, "everything's gonna be alright" );
  39548. } );
  39549. QUnit.test( "getWireframeAttribute", ( assert ) => {
  39550. assert.ok( false, "everything's gonna be alright" );
  39551. } );
  39552. } );
  39553. } );
  39554. } );
  39555. /**
  39556. * @author TristanVALCKE / https://github.com/Itee
  39557. */
  39558. /* global QUnit */
  39559. QUnit.module( 'Renderers', () => {
  39560. QUnit.module( 'WebGL', () => {
  39561. QUnit.module.todo( 'WebGLIndexedBufferRenderer', () => {
  39562. // INSTANCING
  39563. QUnit.test( "Instancing", ( assert ) => {
  39564. assert.ok( false, "everything's gonna be alright" );
  39565. } );
  39566. // PUBLIC STUFF
  39567. QUnit.test( "setMode", ( assert ) => {
  39568. assert.ok( false, "everything's gonna be alright" );
  39569. } );
  39570. QUnit.test( "setIndex", ( assert ) => {
  39571. assert.ok( false, "everything's gonna be alright" );
  39572. } );
  39573. QUnit.test( "render", ( assert ) => {
  39574. assert.ok( false, "everything's gonna be alright" );
  39575. } );
  39576. QUnit.test( "renderInstances", ( assert ) => {
  39577. assert.ok( false, "everything's gonna be alright" );
  39578. } );
  39579. } );
  39580. } );
  39581. } );
  39582. /**
  39583. * @author TristanVALCKE / https://github.com/Itee
  39584. */
  39585. /* global QUnit */
  39586. QUnit.module( 'Renderers', () => {
  39587. QUnit.module( 'WebGL', () => {
  39588. QUnit.module.todo( 'WebGLLights', () => {
  39589. // INSTANCING
  39590. QUnit.test( "Instancing", ( assert ) => {
  39591. assert.ok( false, "everything's gonna be alright" );
  39592. } );
  39593. // PUBLIC STUFF
  39594. QUnit.test( "setup", ( assert ) => {
  39595. assert.ok( false, "everything's gonna be alright" );
  39596. } );
  39597. QUnit.test( "state", ( assert ) => {
  39598. assert.ok( false, "everything's gonna be alright" );
  39599. } );
  39600. } );
  39601. } );
  39602. } );
  39603. /**
  39604. * @author TristanVALCKE / https://github.com/Itee
  39605. */
  39606. /* global QUnit */
  39607. QUnit.module( 'Renderers', () => {
  39608. QUnit.module( 'WebGL', () => {
  39609. QUnit.module.todo( 'WebGLMorphtargets', () => {
  39610. // INSTANCING
  39611. QUnit.test( "Instancing", ( assert ) => {
  39612. assert.ok( false, "everything's gonna be alright" );
  39613. } );
  39614. // PUBLIC STUFF
  39615. QUnit.test( "update", ( assert ) => {
  39616. assert.ok( false, "everything's gonna be alright" );
  39617. } );
  39618. } );
  39619. } );
  39620. } );
  39621. /**
  39622. * @author TristanVALCKE / https://github.com/Itee
  39623. */
  39624. /* global QUnit */
  39625. QUnit.module( 'Renderers', () => {
  39626. QUnit.module( 'WebGL', () => {
  39627. QUnit.module.todo( 'WebGLObjects', () => {
  39628. // INSTANCING
  39629. QUnit.test( "Instancing", ( assert ) => {
  39630. assert.ok( false, "everything's gonna be alright" );
  39631. } );
  39632. // PUBLIC STUFF
  39633. QUnit.test( "update", ( assert ) => {
  39634. assert.ok( false, "everything's gonna be alright" );
  39635. } );
  39636. QUnit.test( "clear", ( assert ) => {
  39637. assert.ok( false, "everything's gonna be alright" );
  39638. } );
  39639. } );
  39640. } );
  39641. } );
  39642. /**
  39643. * @author TristanVALCKE / https://github.com/Itee
  39644. */
  39645. /* global QUnit */
  39646. QUnit.module( 'Renderers', () => {
  39647. QUnit.module( 'WebGL', () => {
  39648. QUnit.module.todo( 'WebGLProgram', () => {
  39649. // INSTANCING
  39650. QUnit.test( "Instancing", ( assert ) => {
  39651. assert.ok( false, "everything's gonna be alright" );
  39652. } );
  39653. // PROPERTIES
  39654. QUnit.test( "uniforms", ( assert ) => {
  39655. assert.ok( false, "everything's gonna be alright" );
  39656. } );
  39657. QUnit.test( "attributes", ( assert ) => {
  39658. assert.ok( false, "everything's gonna be alright" );
  39659. } );
  39660. // PUBLIC STUFF
  39661. QUnit.test( "getUniforms", ( assert ) => {
  39662. assert.ok( false, "everything's gonna be alright" );
  39663. } );
  39664. QUnit.test( "getAttributes", ( assert ) => {
  39665. assert.ok( false, "everything's gonna be alright" );
  39666. } );
  39667. QUnit.test( "destroy", ( assert ) => {
  39668. assert.ok( false, "everything's gonna be alright" );
  39669. } );
  39670. } );
  39671. } );
  39672. } );
  39673. /**
  39674. * @author TristanVALCKE / https://github.com/Itee
  39675. */
  39676. /* global QUnit */
  39677. QUnit.module( 'Renderers', () => {
  39678. QUnit.module( 'WebGL', () => {
  39679. QUnit.module.todo( 'WebGLPrograms', () => {
  39680. // INSTANCING
  39681. QUnit.test( "Instancing", ( assert ) => {
  39682. assert.ok( false, "everything's gonna be alright" );
  39683. } );
  39684. // PUBLIC STUFF
  39685. QUnit.test( "getParameters", ( assert ) => {
  39686. assert.ok( false, "everything's gonna be alright" );
  39687. } );
  39688. QUnit.test( "getProgramCode", ( assert ) => {
  39689. assert.ok( false, "everything's gonna be alright" );
  39690. } );
  39691. QUnit.test( "acquireProgram", ( assert ) => {
  39692. assert.ok( false, "everything's gonna be alright" );
  39693. } );
  39694. QUnit.test( "releaseProgram", ( assert ) => {
  39695. assert.ok( false, "everything's gonna be alright" );
  39696. } );
  39697. QUnit.test( "programs", ( assert ) => {
  39698. assert.ok( false, "everything's gonna be alright" );
  39699. } );
  39700. } );
  39701. } );
  39702. } );
  39703. /**
  39704. * @author TristanVALCKE / https://github.com/Itee
  39705. */
  39706. /* global QUnit */
  39707. QUnit.module( 'Renderers', () => {
  39708. QUnit.module( 'WebGL', () => {
  39709. QUnit.module.todo( 'WebGLProperties', () => {
  39710. // INSTANCING
  39711. QUnit.test( "Instancing", ( assert ) => {
  39712. assert.ok( false, "everything's gonna be alright" );
  39713. } );
  39714. // PUBLIC STUFF
  39715. QUnit.test( "get", ( assert ) => {
  39716. assert.ok( false, "everything's gonna be alright" );
  39717. } );
  39718. QUnit.test( "remove", ( assert ) => {
  39719. assert.ok( false, "everything's gonna be alright" );
  39720. } );
  39721. QUnit.test( "clear", ( assert ) => {
  39722. assert.ok( false, "everything's gonna be alright" );
  39723. } );
  39724. } );
  39725. } );
  39726. } );
  39727. /**
  39728. * @author TristanVALCKE / https://github.com/Itee
  39729. */
  39730. /* global QUnit */
  39731. QUnit.module( 'Renderers', () => {
  39732. QUnit.module( 'WebGL', () => {
  39733. QUnit.module.todo( 'WebGLRenderLists', () => {
  39734. // INSTANCING
  39735. QUnit.test( "Instancing", ( assert ) => {
  39736. assert.ok( false, "everything's gonna be alright" );
  39737. } );
  39738. // PUBLIC STUFF
  39739. QUnit.test( "get", ( assert ) => {
  39740. assert.ok( false, "everything's gonna be alright" );
  39741. } );
  39742. QUnit.test( "dispose", ( assert ) => {
  39743. assert.ok( false, "everything's gonna be alright" );
  39744. } );
  39745. } );
  39746. } );
  39747. } );
  39748. /**
  39749. * @author TristanVALCKE / https://github.com/Itee
  39750. */
  39751. /* global QUnit */
  39752. QUnit.module( 'Renderers', () => {
  39753. QUnit.module( 'WebGL', () => {
  39754. QUnit.module.todo( 'WebGLShader', () => {
  39755. // INSTANCING
  39756. QUnit.test( "Instancing", ( assert ) => {
  39757. assert.ok( false, "everything's gonna be alright" );
  39758. } );
  39759. } );
  39760. } );
  39761. } );
  39762. /**
  39763. * @author TristanVALCKE / https://github.com/Itee
  39764. */
  39765. /* global QUnit */
  39766. QUnit.module( 'Renderers', () => {
  39767. QUnit.module( 'WebGL', () => {
  39768. QUnit.module.todo( 'WebGLShadowMap', () => {
  39769. // INSTANCING
  39770. QUnit.test( "Instancing", ( assert ) => {
  39771. assert.ok( false, "everything's gonna be alright" );
  39772. } );
  39773. // PUBLIC STUFF
  39774. QUnit.test( "render", ( assert ) => {
  39775. assert.ok( false, "everything's gonna be alright" );
  39776. } );
  39777. } );
  39778. } );
  39779. } );
  39780. /**
  39781. * @author TristanVALCKE / https://github.com/Itee
  39782. */
  39783. /* global QUnit */
  39784. QUnit.module( 'Renderers', () => {
  39785. QUnit.module( 'WebGL', () => {
  39786. QUnit.module.todo( 'WebGLSpriteRenderer', () => {
  39787. // INSTANCING
  39788. QUnit.test( "Instancing", ( assert ) => {
  39789. assert.ok( false, "everything's gonna be alright" );
  39790. } );
  39791. // PUBLIC STUFF
  39792. QUnit.test( "render", ( assert ) => {
  39793. assert.ok( false, "everything's gonna be alright" );
  39794. } );
  39795. } );
  39796. } );
  39797. } );
  39798. /**
  39799. * @author TristanVALCKE / https://github.com/Itee
  39800. */
  39801. /* global QUnit */
  39802. QUnit.module( 'Renderers', () => {
  39803. QUnit.module( 'WebGL', () => {
  39804. QUnit.module.todo( 'WebGLState', () => {
  39805. // INSTANCING
  39806. QUnit.test( "Instancing", ( assert ) => {
  39807. assert.ok( false, "everything's gonna be alright" );
  39808. } );
  39809. // PUBLIC STUFF
  39810. QUnit.test( "buffers", ( assert ) => {
  39811. assert.ok( false, "everything's gonna be alright" );
  39812. } );
  39813. QUnit.test( "initAttributes", ( assert ) => {
  39814. assert.ok( false, "everything's gonna be alright" );
  39815. } );
  39816. QUnit.test( "enableAttribute", ( assert ) => {
  39817. assert.ok( false, "everything's gonna be alright" );
  39818. } );
  39819. QUnit.test( "enableAttributeAndDivisor", ( assert ) => {
  39820. assert.ok( false, "everything's gonna be alright" );
  39821. } );
  39822. QUnit.test( "disableUnusedAttributes", ( assert ) => {
  39823. assert.ok( false, "everything's gonna be alright" );
  39824. } );
  39825. QUnit.test( "enable", ( assert ) => {
  39826. assert.ok( false, "everything's gonna be alright" );
  39827. } );
  39828. QUnit.test( "disable", ( assert ) => {
  39829. assert.ok( false, "everything's gonna be alright" );
  39830. } );
  39831. QUnit.test( "getCompressedTextureFormats", ( assert ) => {
  39832. assert.ok( false, "everything's gonna be alright" );
  39833. } );
  39834. QUnit.test( "useProgram", ( assert ) => {
  39835. assert.ok( false, "everything's gonna be alright" );
  39836. } );
  39837. QUnit.test( "setBlending", ( assert ) => {
  39838. assert.ok( false, "everything's gonna be alright" );
  39839. } );
  39840. QUnit.test( "setMaterial", ( assert ) => {
  39841. assert.ok( false, "everything's gonna be alright" );
  39842. } );
  39843. QUnit.test( "setFlipSided", ( assert ) => {
  39844. assert.ok( false, "everything's gonna be alright" );
  39845. } );
  39846. QUnit.test( "setCullFace", ( assert ) => {
  39847. assert.ok( false, "everything's gonna be alright" );
  39848. } );
  39849. QUnit.test( "setLineWidth", ( assert ) => {
  39850. assert.ok( false, "everything's gonna be alright" );
  39851. } );
  39852. QUnit.test( "setPolygonOffset", ( assert ) => {
  39853. assert.ok( false, "everything's gonna be alright" );
  39854. } );
  39855. QUnit.test( "setScissorTest", ( assert ) => {
  39856. assert.ok( false, "everything's gonna be alright" );
  39857. } );
  39858. QUnit.test( "activeTexture", ( assert ) => {
  39859. assert.ok( false, "everything's gonna be alright" );
  39860. } );
  39861. QUnit.test( "bindTexture", ( assert ) => {
  39862. assert.ok( false, "everything's gonna be alright" );
  39863. } );
  39864. QUnit.test( "compressedTexImage2D", ( assert ) => {
  39865. assert.ok( false, "everything's gonna be alright" );
  39866. } );
  39867. QUnit.test( "texImage2D", ( assert ) => {
  39868. assert.ok( false, "everything's gonna be alright" );
  39869. } );
  39870. QUnit.test( "scissor", ( assert ) => {
  39871. assert.ok( false, "everything's gonna be alright" );
  39872. } );
  39873. QUnit.test( "viewport", ( assert ) => {
  39874. assert.ok( false, "everything's gonna be alright" );
  39875. } );
  39876. QUnit.test( "reset", ( assert ) => {
  39877. assert.ok( false, "everything's gonna be alright" );
  39878. } );
  39879. } );
  39880. } );
  39881. } );
  39882. /**
  39883. * @author TristanVALCKE / https://github.com/Itee
  39884. */
  39885. /* global QUnit */
  39886. QUnit.module( 'Renderers', () => {
  39887. QUnit.module( 'WebGL', () => {
  39888. QUnit.module.todo( 'WebGLTextures', () => {
  39889. // INSTANCING
  39890. QUnit.test( "Instancing", ( assert ) => {
  39891. assert.ok( false, "everything's gonna be alright" );
  39892. } );
  39893. // PUBLIC STUFF
  39894. QUnit.test( "setTexture2D", ( assert ) => {
  39895. assert.ok( false, "everything's gonna be alright" );
  39896. } );
  39897. QUnit.test( "setTextureCube", ( assert ) => {
  39898. assert.ok( false, "everything's gonna be alright" );
  39899. } );
  39900. QUnit.test( "setTextureCubeDynamic", ( assert ) => {
  39901. assert.ok( false, "everything's gonna be alright" );
  39902. } );
  39903. QUnit.test( "setupRenderTarget", ( assert ) => {
  39904. assert.ok( false, "everything's gonna be alright" );
  39905. } );
  39906. QUnit.test( "updateRenderTargetMipmap", ( assert ) => {
  39907. assert.ok( false, "everything's gonna be alright" );
  39908. } );
  39909. } );
  39910. } );
  39911. } );
  39912. /**
  39913. * @author TristanVALCKE / https://github.com/Itee
  39914. */
  39915. /* global QUnit */
  39916. QUnit.module( 'Renderers', () => {
  39917. QUnit.module( 'WebGL', () => {
  39918. QUnit.module.todo( 'WebGLUniforms', () => {
  39919. // INSTANCING
  39920. QUnit.test( "Instancing", ( assert ) => {
  39921. assert.ok( false, "everything's gonna be alright" );
  39922. } );
  39923. // PUBLIC STUFF
  39924. QUnit.test( "setValue", ( assert ) => {
  39925. assert.ok( false, "everything's gonna be alright" );
  39926. } );
  39927. QUnit.test( "setOptional", ( assert ) => {
  39928. assert.ok( false, "everything's gonna be alright" );
  39929. } );
  39930. QUnit.test( "upload", ( assert ) => {
  39931. assert.ok( false, "everything's gonna be alright" );
  39932. } );
  39933. QUnit.test( "seqWithValue", ( assert ) => {
  39934. assert.ok( false, "everything's gonna be alright" );
  39935. } );
  39936. } );
  39937. } );
  39938. } );
  39939. /**
  39940. * @author TristanVALCKE / https://github.com/Itee
  39941. */
  39942. /* global QUnit */
  39943. QUnit.module( 'Renderers', () => {
  39944. QUnit.module( 'WebGL', () => {
  39945. QUnit.module.todo( 'WebGLUtils', () => {
  39946. // INSTANCING
  39947. QUnit.test( "Instancing", ( assert ) => {
  39948. assert.ok( false, "everything's gonna be alright" );
  39949. } );
  39950. // PUBLIC STUFF
  39951. QUnit.test( "convert", ( assert ) => {
  39952. assert.ok( false, "everything's gonna be alright" );
  39953. } );
  39954. } );
  39955. } );
  39956. } );
  39957. /**
  39958. * @author TristanVALCKE / https://github.com/Itee
  39959. */
  39960. /* global QUnit */
  39961. QUnit.module( 'Renderers', () => {
  39962. QUnit.module( 'WebGL', () => {
  39963. QUnit.module.todo( 'WebVRManager', () => {
  39964. // INSTANCING
  39965. QUnit.test( "Instancing", ( assert ) => {
  39966. assert.ok( false, "everything's gonna be alright" );
  39967. } );
  39968. // PUBLIC STUFF
  39969. QUnit.test( "getDevice", ( assert ) => {
  39970. assert.ok( false, "everything's gonna be alright" );
  39971. } );
  39972. QUnit.test( "setDevice", ( assert ) => {
  39973. assert.ok( false, "everything's gonna be alright" );
  39974. } );
  39975. QUnit.test( "getCamera", ( assert ) => {
  39976. assert.ok( false, "everything's gonna be alright" );
  39977. } );
  39978. QUnit.test( "getStandingMatrix", ( assert ) => {
  39979. assert.ok( false, "everything's gonna be alright" );
  39980. } );
  39981. QUnit.test( "submitFrame", ( assert ) => {
  39982. assert.ok( false, "everything's gonna be alright" );
  39983. } );
  39984. QUnit.test( "dispose", ( assert ) => {
  39985. assert.ok( false, "everything's gonna be alright" );
  39986. } );
  39987. } );
  39988. } );
  39989. } );
  39990. /**
  39991. * @author TristanVALCKE / https://github.com/Itee
  39992. */
  39993. /* global QUnit */
  39994. QUnit.module( 'Fog', () => {
  39995. QUnit.module.todo( 'Scene', () => {
  39996. // INHERITANCE
  39997. QUnit.test( "Extending", ( assert ) => {
  39998. assert.ok( false, "everything's gonna be alright" );
  39999. } );
  40000. // INSTANCING
  40001. QUnit.test( "Instancing", ( assert ) => {
  40002. assert.ok( false, "everything's gonna be alright" );
  40003. } );
  40004. // PUBLIC STUFF
  40005. QUnit.test( "isFog", ( assert ) => {
  40006. assert.ok( false, "everything's gonna be alright" );
  40007. } );
  40008. QUnit.test( "clone", ( assert ) => {
  40009. assert.ok( false, "everything's gonna be alright" );
  40010. } );
  40011. QUnit.test( "toJSON", ( assert ) => {
  40012. assert.ok( false, "everything's gonna be alright" );
  40013. } );
  40014. } );
  40015. } );
  40016. /**
  40017. * @author TristanVALCKE / https://github.com/Itee
  40018. */
  40019. /* global QUnit */
  40020. QUnit.module( 'FoxExp2', () => {
  40021. QUnit.module.todo( 'Scene', () => {
  40022. // INHERITANCE
  40023. QUnit.test( "Extending", ( assert ) => {
  40024. assert.ok( false, "everything's gonna be alright" );
  40025. } );
  40026. // INSTANCING
  40027. QUnit.test( "Instancing", ( assert ) => {
  40028. assert.ok( false, "everything's gonna be alright" );
  40029. } );
  40030. // PUBLIC STUFF
  40031. QUnit.test( "isFogExp2", ( assert ) => {
  40032. assert.ok( false, "everything's gonna be alright" );
  40033. } );
  40034. QUnit.test( "clone", ( assert ) => {
  40035. assert.ok( false, "everything's gonna be alright" );
  40036. } );
  40037. QUnit.test( "toJSON", ( assert ) => {
  40038. assert.ok( false, "everything's gonna be alright" );
  40039. } );
  40040. } );
  40041. } );
  40042. /**
  40043. * @author TristanVALCKE / https://github.com/Itee
  40044. */
  40045. /* global QUnit */
  40046. QUnit.module( 'Scenes', () => {
  40047. QUnit.module.todo( 'Scene', () => {
  40048. // INHERITANCE
  40049. QUnit.test( "Extending", ( assert ) => {
  40050. assert.ok( false, "everything's gonna be alright" );
  40051. } );
  40052. // INSTANCING
  40053. QUnit.test( "Instancing", ( assert ) => {
  40054. assert.ok( false, "everything's gonna be alright" );
  40055. } );
  40056. // PUBLIC STUFF
  40057. QUnit.test( "isScene", ( assert ) => {
  40058. assert.ok( false, "everything's gonna be alright" );
  40059. } );
  40060. QUnit.test( "copy", ( assert ) => {
  40061. assert.ok( false, "everything's gonna be alright" );
  40062. } );
  40063. QUnit.test( "toJSON", ( assert ) => {
  40064. assert.ok( false, "everything's gonna be alright" );
  40065. } );
  40066. } );
  40067. } );
  40068. /**
  40069. * @author TristanVALCKE / https://github.com/Itee
  40070. */
  40071. /* global QUnit */
  40072. QUnit.module( 'Textures', () => {
  40073. QUnit.module.todo( 'CanvasTexture', () => {
  40074. // INHERITANCE
  40075. QUnit.test( "Extending", ( assert ) => {
  40076. assert.ok( false, "everything's gonna be alright" );
  40077. } );
  40078. // INSTANCING
  40079. QUnit.test( "Instancing", ( assert ) => {
  40080. assert.ok( false, "everything's gonna be alright" );
  40081. } );
  40082. // PUBLIC STUFF
  40083. QUnit.test( "isCanvasTexture", ( assert ) => {
  40084. assert.ok( false, "everything's gonna be alright" );
  40085. } );
  40086. } );
  40087. } );
  40088. /**
  40089. * @author TristanVALCKE / https://github.com/Itee
  40090. */
  40091. /* global QUnit */
  40092. QUnit.module( 'Textures', () => {
  40093. QUnit.module.todo( 'CompressedTexture', () => {
  40094. // INHERITANCE
  40095. QUnit.test( "Extending", ( assert ) => {
  40096. assert.ok( false, "everything's gonna be alright" );
  40097. } );
  40098. // INSTANCING
  40099. QUnit.test( "Instancing", ( assert ) => {
  40100. assert.ok( false, "everything's gonna be alright" );
  40101. } );
  40102. // PUBLIC STUFF
  40103. QUnit.test( "isCompressedTexture", ( assert ) => {
  40104. assert.ok( false, "everything's gonna be alright" );
  40105. } );
  40106. } );
  40107. } );
  40108. /**
  40109. * @author TristanVALCKE / https://github.com/Itee
  40110. */
  40111. /* global QUnit */
  40112. QUnit.module( 'Textures', () => {
  40113. QUnit.module.todo( 'CubeTexture', () => {
  40114. // INHERITANCE
  40115. QUnit.test( "Extending", ( assert ) => {
  40116. assert.ok( false, "everything's gonna be alright" );
  40117. } );
  40118. // INSTANCING
  40119. QUnit.test( "Instancing", ( assert ) => {
  40120. assert.ok( false, "everything's gonna be alright" );
  40121. } );
  40122. // PROPERTIES
  40123. QUnit.test( "images", ( assert ) => {
  40124. assert.ok( false, "everything's gonna be alright" );
  40125. } );
  40126. // PUBLIC STUFF
  40127. QUnit.test( "isCubeTexture", ( assert ) => {
  40128. assert.ok( false, "everything's gonna be alright" );
  40129. } );
  40130. } );
  40131. } );
  40132. /**
  40133. * @author TristanVALCKE / https://github.com/Itee
  40134. */
  40135. /* global QUnit */
  40136. QUnit.module( 'Textures', () => {
  40137. QUnit.module.todo( 'DataTexture', () => {
  40138. // INHERITANCE
  40139. QUnit.test( "Extending", ( assert ) => {
  40140. assert.ok( false, "everything's gonna be alright" );
  40141. } );
  40142. // INSTANCING
  40143. QUnit.test( "Instancing", ( assert ) => {
  40144. assert.ok( false, "everything's gonna be alright" );
  40145. } );
  40146. // PUBLIC STUFF
  40147. QUnit.test( "isDataTexture", ( assert ) => {
  40148. assert.ok( false, "everything's gonna be alright" );
  40149. } );
  40150. } );
  40151. } );
  40152. /**
  40153. * @author Matt DesLauriers / @mattdesl
  40154. * @author atix / arthursilber.de
  40155. */
  40156. /**
  40157. * @author TristanVALCKE / https://github.com/Itee
  40158. */
  40159. /* global QUnit */
  40160. QUnit.module( 'Textures', () => {
  40161. QUnit.module.todo( 'DepthTexture', () => {
  40162. // INHERITANCE
  40163. QUnit.test( "Extending", ( assert ) => {
  40164. assert.ok( false, "everything's gonna be alright" );
  40165. } );
  40166. // INSTANCING
  40167. QUnit.test( "Instancing", ( assert ) => {
  40168. assert.ok( false, "everything's gonna be alright" );
  40169. } );
  40170. // PUBLIC STUFF
  40171. QUnit.test( "isDepthTexture", ( assert ) => {
  40172. assert.ok( false, "everything's gonna be alright" );
  40173. } );
  40174. } );
  40175. } );
  40176. /**
  40177. * @author TristanVALCKE / https://github.com/Itee
  40178. */
  40179. /* global QUnit */
  40180. QUnit.module( 'Textures', () => {
  40181. QUnit.module.todo( 'Texture', () => {
  40182. // INSTANCING
  40183. QUnit.test( "Instancing", ( assert ) => {
  40184. assert.ok( false, "everything's gonna be alright" );
  40185. } );
  40186. // PROPERTIES
  40187. QUnit.test( "needsUpdate", ( assert ) => {
  40188. assert.ok( false, "everything's gonna be alright" );
  40189. } );
  40190. // PUBLIC STUFF
  40191. QUnit.test( "isTexture", ( assert ) => {
  40192. assert.ok( false, "everything's gonna be alright" );
  40193. } );
  40194. QUnit.test( "clone", ( assert ) => {
  40195. assert.ok( false, "everything's gonna be alright" );
  40196. } );
  40197. QUnit.test( "copy", ( assert ) => {
  40198. assert.ok( false, "everything's gonna be alright" );
  40199. } );
  40200. QUnit.test( "toJSON", ( assert ) => {
  40201. assert.ok( false, "everything's gonna be alright" );
  40202. } );
  40203. QUnit.test( "dispose", ( assert ) => {
  40204. assert.ok( false, "everything's gonna be alright" );
  40205. } );
  40206. QUnit.test( "transformUv", ( assert ) => {
  40207. assert.ok( false, "everything's gonna be alright" );
  40208. } );
  40209. } );
  40210. } );
  40211. /**
  40212. * @author mrdoob / http://mrdoob.com/
  40213. */
  40214. /**
  40215. * @author TristanVALCKE / https://github.com/Itee
  40216. */
  40217. /* global QUnit */
  40218. QUnit.module( 'Textures', () => {
  40219. QUnit.module.todo( 'VideoTexture', () => {
  40220. // INHERITANCE
  40221. QUnit.test( "Extending", ( assert ) => {
  40222. assert.ok( false, "everything's gonna be alright" );
  40223. } );
  40224. // INSTANCING
  40225. QUnit.test( "Instancing", ( assert ) => {
  40226. assert.ok( false, "everything's gonna be alright" );
  40227. } );
  40228. // PUBLIC STUFF
  40229. QUnit.test( "isVideoTexture", ( assert ) => {
  40230. assert.ok( false, "everything's gonna be alright" );
  40231. } );
  40232. } );
  40233. } );
  40234. /**
  40235. * @author TristanVALCKE / https://github.com/Itee
  40236. */
  40237. //src
  40238. } );
  40239. })));