three.source.unit.js 1.5 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681486824868348684486854868648687486884868948690486914869248693486944869548696486974869848699487004870148702487034870448705487064870748708487094871048711487124871348714487154871648717487184871948720487214872248723487244872548726487274872848729487304873148732487334873448735487364873748738487394874048741487424874348744487454874648747487484874948750487514875248753487544875548756487574875848759487604876148762487634876448765487664876748768487694877048771487724877348774487754877648777487784877948780487814878248783487844878548786487874878848789487904879148792487934879448795487964879748798487994880048801488024880348804488054880648807488084880948810488114881248813488144881548816488174881848819488204882148822488234882448825488264882748828488294883048831488324883348834488354883648837488384883948840488414884248843488444884548846488474884848849488504885148852488534885448855488564885748858488594886048861488624886348864488654886648867488684886948870488714887248873488744887548876488774887848879488804888148882488834888448885488864888748888488894889048891488924889348894488954889648897488984889948900489014890248903489044890548906489074890848909489104891148912489134891448915489164891748918489194892048921489224892348924489254892648927489284892948930489314893248933489344893548936489374893848939489404894148942489434894448945489464894748948489494895048951489524895348954489554895648957489584895948960489614896248963489644896548966489674896848969489704897148972489734897448975489764897748978489794898048981489824898348984489854898648987489884898948990489914899248993489944899548996489974899848999490004900149002490034900449005490064900749008490094901049011490124901349014490154901649017490184901949020490214902249023490244902549026490274902849029490304903149032490334903449035490364903749038490394904049041490424904349044490454904649047490484904949050490514905249053490544905549056490574905849059490604906149062490634906449065490664906749068490694907049071490724907349074490754907649077490784907949080490814908249083490844908549086490874908849089490904909149092490934909449095490964909749098490994910049101491024910349104491054910649107491084910949110491114911249113491144911549116491174911849119491204912149122491234912449125491264912749128491294913049131491324913349134491354913649137491384913949140491414914249143491444914549146491474914849149491504915149152491534915449155491564915749158491594916049161491624916349164491654916649167491684916949170491714917249173491744917549176491774917849179491804918149182491834918449185491864918749188491894919049191491924919349194491954919649197491984919949200492014920249203492044920549206492074920849209492104921149212492134921449215492164921749218492194922049221492224922349224492254922649227492284922949230492314923249233492344923549236492374923849239492404924149242492434924449245492464924749248492494925049251492524925349254492554925649257492584925949260492614926249263492644926549266492674926849269492704927149272492734927449275492764927749278492794928049281492824928349284492854928649287492884928949290492914929249293492944929549296492974929849299493004930149302493034930449305493064930749308493094931049311493124931349314493154931649317493184931949320493214932249323493244932549326493274932849329493304933149332493334933449335493364933749338493394934049341493424934349344493454934649347493484934949350493514935249353493544935549356493574935849359493604936149362493634936449365493664936749368493694937049371493724937349374493754937649377493784937949380493814938249383493844938549386493874938849389493904939149392493934939449395493964939749398493994940049401494024940349404494054940649407494084940949410494114941249413494144941549416494174941849419494204942149422494234942449425494264942749428494294943049431494324943349434494354943649437494384943949440494414944249443494444944549446494474944849449494504945149452494534945449455494564945749458494594946049461494624946349464494654946649467494684946949470494714947249473494744947549476494774947849479494804948149482494834948449485494864948749488494894949049491494924949349494494954949649497494984949949500495014950249503495044950549506495074950849509495104951149512495134951449515495164951749518495194952049521495224952349524495254952649527495284952949530495314953249533495344953549536495374953849539495404954149542495434954449545495464954749548495494955049551495524955349554495554955649557495584955949560495614956249563495644956549566495674956849569495704957149572495734957449575495764957749578495794958049581495824958349584495854958649587495884958949590495914959249593495944959549596495974959849599496004960149602496034960449605496064960749608496094961049611496124961349614496154961649617496184961949620496214962249623496244962549626496274962849629496304963149632496334963449635496364963749638496394964049641496424964349644496454964649647496484964949650496514965249653496544965549656496574965849659496604966149662496634966449665496664966749668496694967049671496724967349674496754967649677496784967949680496814968249683496844968549686496874968849689496904969149692496934969449695496964969749698496994970049701497024970349704497054970649707497084970949710497114971249713497144971549716497174971849719497204972149722497234972449725497264972749728497294973049731497324973349734497354973649737497384973949740497414974249743497444974549746497474974849749497504975149752497534975449755497564975749758497594976049761497624976349764497654976649767497684976949770497714977249773497744977549776497774977849779497804978149782497834978449785497864978749788497894979049791497924979349794497954979649797497984979949800498014980249803498044980549806498074980849809498104981149812498134981449815498164981749818498194982049821498224982349824498254982649827498284982949830498314983249833498344983549836498374983849839498404984149842498434984449845498464984749848498494985049851498524985349854498554985649857498584985949860498614986249863498644986549866498674986849869498704987149872498734987449875498764987749878498794988049881498824988349884498854988649887498884988949890498914989249893498944989549896498974989849899499004990149902499034990449905499064990749908499094991049911499124991349914499154991649917499184991949920499214992249923499244992549926499274992849929499304993149932499334993449935499364993749938499394994049941499424994349944499454994649947499484994949950499514995249953499544995549956499574995849959499604996149962499634996449965499664996749968499694997049971499724997349974499754997649977499784997949980499814998249983499844998549986499874998849989499904999149992499934999449995499964999749998499995000050001500025000350004500055000650007500085000950010500115001250013500145001550016500175001850019500205002150022500235002450025500265002750028500295003050031500325003350034500355003650037500385003950040500415004250043500445004550046500475004850049500505005150052500535005450055500565005750058500595006050061500625006350064500655006650067500685006950070500715007250073500745007550076500775007850079500805008150082500835008450085500865008750088500895009050091500925009350094500955009650097500985009950100501015010250103501045010550106501075010850109501105011150112501135011450115501165011750118501195012050121501225012350124501255012650127501285012950130501315013250133501345013550136501375013850139501405014150142501435014450145501465014750148501495015050151501525015350154501555015650157501585015950160501615016250163501645016550166501675016850169501705017150172501735017450175501765017750178501795018050181501825018350184501855018650187501885018950190501915019250193501945019550196501975019850199502005020150202502035020450205502065020750208502095021050211502125021350214502155021650217502185021950220502215022250223502245022550226502275022850229502305023150232502335023450235502365023750238502395024050241502425024350244502455024650247502485024950250502515025250253502545025550256502575025850259502605026150262502635026450265502665026750268502695027050271502725027350274502755027650277502785027950280502815028250283502845028550286502875028850289502905029150292502935029450295502965029750298502995030050301503025030350304503055030650307503085030950310503115031250313503145031550316503175031850319503205032150322503235032450325503265032750328503295033050331503325033350334503355033650337503385033950340503415034250343503445034550346503475034850349503505035150352503535035450355503565035750358503595036050361503625036350364503655036650367503685036950370503715037250373503745037550376503775037850379503805038150382503835038450385503865038750388503895039050391503925039350394503955039650397503985039950400504015040250403504045040550406504075040850409504105041150412504135041450415504165041750418504195042050421504225042350424504255042650427504285042950430504315043250433504345043550436504375043850439504405044150442504435044450445504465044750448504495045050451504525045350454504555045650457504585045950460504615046250463504645046550466504675046850469504705047150472504735047450475504765047750478504795048050481504825048350484504855048650487504885048950490504915049250493504945049550496504975049850499505005050150502505035050450505505065050750508505095051050511505125051350514505155051650517505185051950520505215052250523505245052550526505275052850529505305053150532505335053450535505365053750538505395054050541505425054350544505455054650547505485054950550505515055250553505545055550556505575055850559505605056150562505635056450565505665056750568505695057050571505725057350574505755057650577505785057950580505815058250583505845058550586505875058850589505905059150592505935059450595505965059750598505995060050601506025060350604506055060650607506085060950610506115061250613506145061550616506175061850619506205062150622506235062450625506265062750628506295063050631506325063350634506355063650637506385063950640506415064250643506445064550646506475064850649506505065150652506535065450655506565065750658506595066050661506625066350664506655066650667506685066950670506715067250673506745067550676506775067850679506805068150682506835068450685506865068750688506895069050691506925069350694506955069650697506985069950700507015070250703507045070550706507075070850709507105071150712507135071450715507165071750718507195072050721507225072350724507255072650727507285072950730507315073250733507345073550736507375073850739507405074150742507435074450745507465074750748507495075050751507525075350754507555075650757507585075950760507615076250763507645076550766507675076850769507705077150772507735077450775507765077750778507795078050781507825078350784507855078650787507885078950790507915079250793507945079550796507975079850799508005080150802508035080450805508065080750808508095081050811508125081350814508155081650817508185081950820508215082250823508245082550826508275082850829508305083150832508335083450835508365083750838508395084050841508425084350844508455084650847508485084950850508515085250853508545085550856508575085850859508605086150862508635086450865508665086750868508695087050871508725087350874508755087650877508785087950880508815088250883508845088550886508875088850889508905089150892508935089450895508965089750898508995090050901509025090350904509055090650907509085090950910509115091250913509145091550916509175091850919509205092150922509235092450925509265092750928509295093050931509325093350934509355093650937509385093950940509415094250943509445094550946509475094850949509505095150952509535095450955509565095750958509595096050961509625096350964509655096650967509685096950970509715097250973509745097550976509775097850979509805098150982509835098450985509865098750988509895099050991509925099350994509955099650997509985099951000510015100251003510045100551006510075100851009510105101151012510135101451015510165101751018510195102051021510225102351024510255102651027510285102951030510315103251033510345103551036510375103851039510405104151042510435104451045510465104751048510495105051051510525105351054510555105651057510585105951060510615106251063510645106551066510675106851069510705107151072510735107451075510765107751078510795108051081510825108351084510855108651087510885108951090510915109251093510945109551096510975109851099511005110151102511035110451105511065110751108511095111051111511125111351114511155111651117511185111951120511215112251123511245112551126511275112851129511305113151132511335113451135511365113751138511395114051141511425114351144511455114651147511485114951150511515115251153511545115551156511575115851159511605116151162511635116451165511665116751168511695117051171511725117351174511755117651177511785117951180511815118251183511845118551186511875118851189511905119151192511935119451195511965119751198511995120051201512025120351204512055120651207512085120951210512115121251213512145121551216512175121851219512205122151222512235122451225512265122751228512295123051231512325123351234512355123651237512385123951240512415124251243512445124551246512475124851249512505125151252512535125451255512565125751258512595126051261512625126351264512655126651267512685126951270512715127251273512745127551276512775127851279512805128151282512835128451285512865128751288512895129051291512925129351294512955129651297512985129951300513015130251303513045130551306513075130851309513105131151312513135131451315513165131751318513195132051321513225132351324513255132651327513285132951330513315133251333513345133551336513375133851339513405134151342513435134451345513465134751348513495135051351513525135351354513555135651357513585135951360513615136251363513645136551366513675136851369513705137151372513735137451375513765137751378513795138051381513825138351384513855138651387513885138951390513915139251393513945139551396513975139851399514005140151402514035140451405514065140751408514095141051411514125141351414514155141651417514185141951420514215142251423514245142551426514275142851429514305143151432514335143451435514365143751438514395144051441514425144351444514455144651447514485144951450514515145251453514545145551456514575145851459514605146151462514635146451465514665146751468514695147051471514725147351474514755147651477514785147951480514815148251483514845148551486514875148851489514905149151492514935149451495514965149751498514995150051501515025150351504515055150651507515085150951510515115151251513515145151551516515175151851519515205152151522515235152451525515265152751528515295153051531515325153351534515355153651537515385153951540515415154251543515445154551546515475154851549515505155151552515535155451555515565155751558515595156051561515625156351564515655156651567515685156951570515715157251573515745157551576515775157851579515805158151582515835158451585515865158751588515895159051591515925159351594515955159651597515985159951600516015160251603516045160551606516075160851609516105161151612516135161451615516165161751618516195162051621516225162351624516255162651627516285162951630516315163251633516345163551636516375163851639516405164151642516435164451645516465164751648516495165051651516525165351654516555165651657516585165951660516615166251663516645166551666516675166851669516705167151672516735167451675516765167751678516795168051681516825168351684516855168651687516885168951690516915169251693516945169551696516975169851699517005170151702517035170451705517065170751708517095171051711517125171351714517155171651717517185171951720517215172251723517245172551726517275172851729517305173151732517335173451735517365173751738517395174051741517425174351744517455174651747517485174951750517515175251753517545175551756517575175851759517605176151762517635176451765517665176751768517695177051771517725177351774517755177651777517785177951780517815178251783517845178551786517875178851789517905179151792517935179451795517965179751798517995180051801518025180351804518055180651807518085180951810518115181251813518145181551816518175181851819518205182151822518235182451825518265182751828518295183051831518325183351834518355183651837518385183951840518415184251843518445184551846518475184851849518505185151852518535185451855518565185751858518595186051861518625186351864518655186651867518685186951870518715187251873518745187551876518775187851879518805188151882518835188451885518865188751888518895189051891518925189351894518955189651897518985189951900519015190251903519045190551906519075190851909519105191151912519135191451915519165191751918519195192051921519225192351924519255192651927519285192951930519315193251933519345193551936519375193851939519405194151942519435194451945519465194751948519495195051951519525195351954519555195651957519585195951960519615196251963519645196551966519675196851969519705197151972519735197451975519765197751978519795198051981519825198351984519855198651987519885198951990519915199251993519945199551996519975199851999520005200152002520035200452005520065200752008520095201052011520125201352014520155201652017520185201952020520215202252023520245202552026520275202852029520305203152032520335203452035520365203752038520395204052041520425204352044520455204652047520485204952050520515205252053520545205552056520575205852059520605206152062520635206452065520665206752068520695207052071520725207352074520755207652077520785207952080520815208252083520845208552086520875208852089520905209152092520935209452095520965209752098520995210052101521025210352104521055210652107521085210952110521115211252113521145211552116521175211852119521205212152122521235212452125521265212752128521295213052131521325213352134521355213652137521385213952140521415214252143521445214552146521475214852149521505215152152521535215452155521565215752158521595216052161521625216352164521655216652167521685216952170521715217252173521745217552176521775217852179521805218152182521835218452185521865218752188521895219052191521925219352194521955219652197521985219952200522015220252203522045220552206522075220852209522105221152212522135221452215522165221752218522195222052221522225222352224522255222652227522285222952230522315223252233522345223552236522375223852239522405224152242522435224452245522465224752248522495225052251522525225352254522555225652257522585225952260522615226252263522645226552266522675226852269522705227152272522735227452275522765227752278522795228052281522825228352284522855228652287522885228952290522915229252293522945229552296522975229852299523005230152302523035230452305523065230752308523095231052311523125231352314523155231652317523185231952320523215232252323523245232552326523275232852329523305233152332523335233452335523365233752338523395234052341523425234352344523455234652347523485234952350523515235252353523545235552356523575235852359523605236152362523635236452365523665236752368523695237052371523725237352374523755237652377523785237952380523815238252383523845238552386523875238852389523905239152392523935239452395523965239752398523995240052401524025240352404524055240652407524085240952410524115241252413524145241552416524175241852419524205242152422524235242452425524265242752428524295243052431524325243352434524355243652437524385243952440524415244252443524445244552446524475244852449524505245152452524535245452455524565245752458524595246052461524625246352464524655246652467524685246952470524715247252473524745247552476524775247852479524805248152482524835248452485524865248752488524895249052491524925249352494524955249652497524985249952500525015250252503525045250552506525075250852509525105251152512525135251452515525165251752518525195252052521525225252352524525255252652527525285252952530525315253252533525345253552536525375253852539525405254152542525435254452545525465254752548525495255052551525525255352554525555255652557525585255952560525615256252563525645256552566525675256852569525705257152572525735257452575525765257752578525795258052581525825258352584525855258652587525885258952590525915259252593525945259552596525975259852599526005260152602526035260452605526065260752608526095261052611526125261352614526155261652617526185261952620526215262252623526245262552626526275262852629526305263152632526335263452635526365263752638526395264052641526425264352644526455264652647526485264952650526515265252653526545265552656526575265852659526605266152662526635266452665526665266752668526695267052671526725267352674526755267652677526785267952680526815268252683526845268552686526875268852689526905269152692526935269452695526965269752698526995270052701527025270352704527055270652707527085270952710527115271252713527145271552716527175271852719527205272152722527235272452725527265272752728527295273052731527325273352734527355273652737527385273952740527415274252743527445274552746527475274852749527505275152752527535275452755527565275752758527595276052761527625276352764527655276652767527685276952770527715277252773527745277552776527775277852779527805278152782527835278452785527865278752788527895279052791527925279352794527955279652797527985279952800528015280252803528045280552806528075280852809528105281152812528135281452815528165281752818528195282052821528225282352824528255282652827528285282952830528315283252833528345283552836528375283852839528405284152842528435284452845528465284752848528495285052851528525285352854528555285652857528585285952860528615286252863528645286552866528675286852869528705287152872528735287452875528765287752878528795288052881528825288352884528855288652887528885288952890528915289252893528945289552896528975289852899529005290152902529035290452905529065290752908529095291052911529125291352914529155291652917529185291952920529215292252923529245292552926529275292852929529305293152932529335293452935529365293752938529395294052941529425294352944529455294652947529485294952950529515295252953529545295552956529575295852959529605296152962529635296452965529665296752968529695297052971529725297352974529755297652977529785297952980529815298252983529845298552986529875298852989529905299152992529935299452995529965299752998529995300053001530025300353004530055300653007530085300953010530115301253013530145301553016530175301853019530205302153022530235302453025530265302753028530295303053031530325303353034530355303653037530385303953040530415304253043530445304553046530475304853049530505305153052530535305453055530565305753058530595306053061530625306353064530655306653067530685306953070530715307253073530745307553076530775307853079530805308153082530835308453085530865308753088530895309053091530925309353094530955309653097530985309953100531015310253103531045310553106531075310853109531105311153112531135311453115531165311753118531195312053121531225312353124531255312653127531285312953130531315313253133531345313553136531375313853139531405314153142531435314453145531465314753148531495315053151531525315353154531555315653157531585315953160531615316253163531645316553166531675316853169531705317153172531735317453175531765317753178531795318053181531825318353184531855318653187531885318953190531915319253193531945319553196531975319853199532005320153202532035320453205532065320753208532095321053211532125321353214532155321653217532185321953220532215322253223532245322553226532275322853229532305323153232532335323453235532365323753238532395324053241532425324353244532455324653247532485324953250532515325253253532545325553256532575325853259532605326153262532635326453265532665326753268532695327053271532725327353274532755327653277532785327953280532815328253283532845328553286532875328853289532905329153292532935329453295532965329753298532995330053301533025330353304533055330653307533085330953310533115331253313533145331553316533175331853319533205332153322533235332453325533265332753328533295333053331533325333353334533355333653337533385333953340533415334253343533445334553346533475334853349533505335153352533535335453355533565335753358533595336053361533625336353364533655336653367533685336953370533715337253373533745337553376533775337853379533805338153382533835338453385533865338753388533895339053391533925339353394533955339653397533985339953400534015340253403534045340553406534075340853409534105341153412534135341453415534165341753418534195342053421534225342353424534255342653427534285342953430534315343253433534345343553436534375343853439534405344153442534435344453445534465344753448534495345053451534525345353454534555345653457534585345953460534615346253463534645346553466534675346853469534705347153472534735347453475534765347753478534795348053481534825348353484534855348653487534885348953490534915349253493534945349553496534975349853499535005350153502535035350453505535065350753508535095351053511535125351353514535155351653517535185351953520535215352253523535245352553526535275352853529535305353153532535335353453535535365353753538535395354053541535425354353544535455354653547535485354953550535515355253553535545355553556535575355853559535605356153562535635356453565535665356753568535695357053571535725357353574535755357653577535785357953580535815358253583535845358553586535875358853589535905359153592535935359453595535965359753598535995360053601536025360353604536055360653607536085360953610536115361253613536145361553616536175361853619536205362153622536235362453625536265362753628536295363053631536325363353634536355363653637536385363953640536415364253643536445364553646536475364853649536505365153652536535365453655536565365753658536595366053661536625366353664536655366653667536685366953670536715367253673536745367553676536775367853679536805368153682536835368453685536865368753688536895369053691536925369353694536955369653697536985369953700537015370253703537045370553706537075370853709537105371153712537135371453715537165371753718537195372053721537225372353724537255372653727537285372953730537315373253733537345373553736537375373853739537405374153742537435374453745537465374753748537495375053751537525375353754537555375653757537585375953760537615376253763537645376553766537675376853769537705377153772537735377453775537765377753778537795378053781537825378353784537855378653787537885378953790537915379253793537945379553796537975379853799538005380153802538035380453805538065380753808538095381053811538125381353814538155381653817538185381953820538215382253823538245382553826538275382853829538305383153832538335383453835538365383753838538395384053841538425384353844538455384653847538485384953850538515385253853538545385553856538575385853859538605386153862538635386453865538665386753868538695387053871538725387353874538755387653877538785387953880538815388253883538845388553886538875388853889538905389153892538935389453895538965389753898538995390053901539025390353904539055390653907539085390953910539115391253913539145391553916539175391853919539205392153922539235392453925539265392753928539295393053931539325393353934539355393653937539385393953940539415394253943539445394553946539475394853949539505395153952539535395453955539565395753958539595396053961539625396353964539655396653967539685396953970539715397253973539745397553976539775397853979539805398153982539835398453985539865398753988539895399053991539925399353994539955399653997539985399954000540015400254003540045400554006540075400854009540105401154012540135401454015540165401754018540195402054021540225402354024540255402654027540285402954030540315403254033540345403554036540375403854039540405404154042540435404454045540465404754048540495405054051540525405354054540555405654057540585405954060540615406254063540645406554066540675406854069540705407154072540735407454075540765407754078540795408054081540825408354084540855408654087540885408954090540915409254093540945409554096540975409854099541005410154102541035410454105541065410754108541095411054111541125411354114541155411654117541185411954120541215412254123541245412554126541275412854129541305413154132541335413454135541365413754138541395414054141541425414354144541455414654147541485414954150541515415254153541545415554156541575415854159541605416154162541635416454165541665416754168541695417054171541725417354174541755417654177541785417954180541815418254183541845418554186541875418854189541905419154192541935419454195541965419754198541995420054201542025420354204542055420654207542085420954210542115421254213542145421554216542175421854219542205422154222542235422454225542265422754228542295423054231542325423354234542355423654237542385423954240542415424254243542445424554246542475424854249542505425154252542535425454255542565425754258542595426054261542625426354264542655426654267542685426954270542715427254273542745427554276542775427854279542805428154282542835428454285542865428754288542895429054291542925429354294542955429654297542985429954300543015430254303543045430554306543075430854309543105431154312543135431454315543165431754318543195432054321543225432354324543255432654327543285432954330543315433254333543345433554336543375433854339543405434154342543435434454345543465434754348543495435054351543525435354354543555435654357543585435954360543615436254363543645436554366543675436854369543705437154372543735437454375543765437754378543795438054381543825438354384543855438654387543885438954390543915439254393543945439554396543975439854399544005440154402544035440454405544065440754408544095441054411544125441354414544155441654417544185441954420544215442254423544245442554426544275442854429544305443154432544335443454435544365443754438544395444054441544425444354444544455444654447544485444954450544515445254453544545445554456544575445854459544605446154462544635446454465544665446754468544695447054471544725447354474544755447654477544785447954480544815448254483544845448554486544875448854489544905449154492544935449454495544965449754498544995450054501545025450354504545055450654507545085450954510545115451254513545145451554516545175451854519545205452154522545235452454525545265452754528545295453054531545325453354534545355453654537545385453954540545415454254543545445454554546545475454854549545505455154552545535455454555545565455754558545595456054561545625456354564545655456654567545685456954570545715457254573545745457554576545775457854579545805458154582545835458454585545865458754588545895459054591545925459354594545955459654597545985459954600546015460254603546045460554606546075460854609546105461154612546135461454615546165461754618546195462054621546225462354624546255462654627546285462954630546315463254633546345463554636546375463854639546405464154642546435464454645546465464754648546495465054651546525465354654546555465654657546585465954660546615466254663546645466554666546675466854669546705467154672546735467454675546765467754678546795468054681546825468354684546855468654687546885468954690546915469254693546945469554696546975469854699547005470154702547035470454705547065470754708547095471054711547125471354714547155471654717547185471954720547215472254723547245472554726547275472854729547305473154732547335473454735547365473754738547395474054741547425474354744547455474654747547485474954750547515475254753547545475554756547575475854759547605476154762547635476454765547665476754768547695477054771547725477354774547755477654777547785477954780547815478254783547845478554786547875478854789547905479154792547935479454795547965479754798547995480054801548025480354804548055480654807548085480954810548115481254813548145481554816548175481854819548205482154822548235482454825548265482754828548295483054831548325483354834548355483654837548385483954840548415484254843548445484554846548475484854849548505485154852548535485454855548565485754858548595486054861548625486354864548655486654867548685486954870548715487254873548745487554876548775487854879548805488154882548835488454885548865488754888548895489054891548925489354894548955489654897548985489954900549015490254903549045490554906549075490854909549105491154912549135491454915549165491754918549195492054921549225492354924549255492654927549285492954930549315493254933549345493554936549375493854939549405494154942549435494454945549465494754948549495495054951549525495354954549555495654957549585495954960549615496254963549645496554966549675496854969549705497154972549735497454975549765497754978549795498054981549825498354984549855498654987549885498954990549915499254993549945499554996549975499854999550005500155002550035500455005550065500755008550095501055011550125501355014550155501655017550185501955020550215502255023550245502555026550275502855029550305503155032550335503455035550365503755038550395504055041550425504355044550455504655047550485504955050550515505255053550545505555056550575505855059550605506155062550635506455065550665506755068550695507055071550725507355074550755507655077550785507955080550815508255083550845508555086550875508855089550905509155092550935509455095550965509755098550995510055101551025510355104551055510655107551085510955110551115511255113551145511555116551175511855119551205512155122551235512455125551265512755128551295513055131551325513355134551355513655137551385513955140551415514255143551445514555146551475514855149551505515155152551535515455155551565515755158551595516055161551625516355164551655516655167551685516955170551715517255173551745517555176551775517855179551805518155182551835518455185551865518755188551895519055191551925519355194551955519655197551985519955200552015520255203552045520555206552075520855209552105521155212552135521455215552165521755218552195522055221552225522355224552255522655227552285522955230552315523255233552345523555236552375523855239552405524155242552435524455245552465524755248552495525055251552525525355254552555525655257552585525955260552615526255263552645526555266552675526855269552705527155272552735527455275552765527755278552795528055281552825528355284552855528655287552885528955290552915529255293552945529555296552975529855299553005530155302553035530455305553065530755308553095531055311553125531355314553155531655317553185531955320553215532255323553245532555326553275532855329553305533155332553335533455335553365533755338553395534055341553425534355344553455534655347553485534955350553515535255353553545535555356553575535855359553605536155362553635536455365553665536755368553695537055371553725537355374553755537655377553785537955380553815538255383553845538555386553875538855389553905539155392553935539455395553965539755398553995540055401554025540355404554055540655407554085540955410554115541255413554145541555416554175541855419554205542155422554235542455425554265542755428554295543055431554325543355434554355543655437554385543955440554415544255443554445544555446554475544855449554505545155452554535545455455554565545755458554595546055461554625546355464554655546655467554685546955470554715547255473554745547555476554775547855479554805548155482554835548455485554865548755488554895549055491554925549355494554955549655497554985549955500555015550255503555045550555506555075550855509555105551155512555135551455515555165551755518555195552055521555225552355524555255552655527555285552955530555315553255533555345553555536555375553855539555405554155542555435554455545555465554755548555495555055551555525555355554555555555655557555585555955560555615556255563555645556555566555675556855569555705557155572555735557455575555765557755578555795558055581555825558355584555855558655587555885558955590555915559255593555945559555596555975559855599556005560155602556035560455605556065560755608556095561055611556125561355614556155561655617556185561955620556215562255623556245562555626556275562855629556305563155632556335563455635556365563755638556395564055641556425564355644556455564655647556485564955650556515565255653556545565555656556575565855659556605566155662556635566455665556665566755668556695567055671556725567355674556755567655677556785567955680556815568255683556845568555686556875568855689556905569155692556935569455695556965569755698556995570055701557025570355704557055570655707557085570955710557115571255713557145571555716557175571855719557205572155722557235572455725557265572755728557295573055731557325573355734557355573655737557385573955740557415574255743557445574555746557475574855749557505575155752557535575455755557565575755758557595576055761557625576355764557655576655767557685576955770557715577255773557745577555776557775577855779557805578155782557835578455785557865578755788557895579055791557925579355794557955579655797557985579955800558015580255803558045580555806558075580855809558105581155812558135581455815558165581755818558195582055821558225582355824558255582655827558285582955830558315583255833558345583555836558375583855839558405584155842558435584455845558465584755848558495585055851558525585355854558555585655857558585585955860558615586255863558645586555866558675586855869558705587155872558735587455875558765587755878558795588055881558825588355884558855588655887558885588955890558915589255893558945589555896558975589855899559005590155902559035590455905559065590755908559095591055911559125591355914559155591655917559185591955920559215592255923559245592555926559275592855929559305593155932559335593455935559365593755938559395594055941559425594355944559455594655947559485594955950559515595255953559545595555956559575595855959559605596155962559635596455965559665596755968559695597055971559725597355974559755597655977559785597955980559815598255983559845598555986559875598855989559905599155992559935599455995559965599755998559995600056001560025600356004560055600656007560085600956010560115601256013560145601556016560175601856019560205602156022560235602456025560265602756028560295603056031560325603356034560355603656037560385603956040560415604256043560445604556046560475604856049560505605156052560535605456055560565605756058560595606056061560625606356064560655606656067560685606956070560715607256073560745607556076560775607856079560805608156082560835608456085560865608756088560895609056091560925609356094560955609656097560985609956100561015610256103561045610556106561075610856109561105611156112561135611456115561165611756118561195612056121561225612356124561255612656127561285612956130561315613256133561345613556136561375613856139561405614156142561435614456145561465614756148561495615056151561525615356154561555615656157561585615956160561615616256163561645616556166561675616856169561705617156172561735617456175561765617756178561795618056181561825618356184561855618656187561885618956190561915619256193561945619556196561975619856199562005620156202562035620456205562065620756208562095621056211562125621356214562155621656217562185621956220562215622256223562245622556226562275622856229562305623156232562335623456235562365623756238562395624056241562425624356244562455624656247562485624956250562515625256253562545625556256562575625856259562605626156262562635626456265562665626756268562695627056271562725627356274562755627656277562785627956280562815628256283562845628556286562875628856289562905629156292562935629456295562965629756298562995630056301563025630356304563055630656307563085630956310563115631256313563145631556316563175631856319563205632156322563235632456325563265632756328563295633056331563325633356334563355633656337563385633956340563415634256343563445634556346563475634856349563505635156352563535635456355563565635756358563595636056361563625636356364563655636656367563685636956370563715637256373563745637556376563775637856379563805638156382563835638456385563865638756388563895639056391563925639356394563955639656397563985639956400564015640256403564045640556406564075640856409564105641156412564135641456415564165641756418564195642056421564225642356424564255642656427564285642956430564315643256433564345643556436564375643856439564405644156442564435644456445564465644756448564495645056451564525645356454564555645656457564585645956460564615646256463564645646556466564675646856469564705647156472564735647456475564765647756478564795648056481564825648356484564855648656487564885648956490564915649256493564945649556496564975649856499565005650156502565035650456505565065650756508565095651056511565125651356514565155651656517565185651956520565215652256523565245652556526565275652856529565305653156532565335653456535565365653756538565395654056541565425654356544565455654656547565485654956550565515655256553565545655556556565575655856559565605656156562565635656456565565665656756568565695657056571565725657356574565755657656577565785657956580565815658256583565845658556586565875658856589565905659156592565935659456595565965659756598565995660056601566025660356604566055660656607566085660956610566115661256613566145661556616566175661856619566205662156622566235662456625566265662756628566295663056631566325663356634566355663656637566385663956640566415664256643566445664556646566475664856649566505665156652566535665456655566565665756658566595666056661566625666356664566655666656667566685666956670566715667256673566745667556676566775667856679566805668156682566835668456685566865668756688566895669056691566925669356694566955669656697566985669956700567015670256703567045670556706567075670856709567105671156712567135671456715567165671756718567195672056721567225672356724567255672656727567285672956730567315673256733567345673556736567375673856739567405674156742567435674456745567465674756748567495675056751567525675356754567555675656757567585675956760567615676256763567645676556766567675676856769567705677156772567735677456775567765677756778567795678056781567825678356784567855678656787567885678956790567915679256793567945679556796567975679856799568005680156802568035680456805568065680756808568095681056811568125681356814568155681656817568185681956820568215682256823568245682556826568275682856829568305683156832568335683456835568365683756838568395684056841568425684356844568455684656847568485684956850568515685256853568545685556856568575685856859568605686156862568635686456865568665686756868568695687056871568725687356874568755687656877568785687956880568815688256883568845688556886568875688856889568905689156892568935689456895568965689756898568995690056901569025690356904569055690656907569085690956910569115691256913569145691556916569175691856919569205692156922569235692456925569265692756928569295693056931569325693356934569355693656937569385693956940569415694256943569445694556946569475694856949569505695156952569535695456955569565695756958569595696056961569625696356964569655696656967569685696956970569715697256973569745697556976569775697856979569805698156982569835698456985569865698756988569895699056991569925699356994569955699656997569985699957000570015700257003570045700557006570075700857009570105701157012570135701457015570165701757018570195702057021570225702357024570255702657027570285702957030570315703257033570345703557036570375703857039570405704157042570435704457045570465704757048570495705057051570525705357054570555705657057570585705957060570615706257063570645706557066570675706857069570705707157072570735707457075570765707757078570795708057081570825708357084570855708657087570885708957090570915709257093570945709557096570975709857099571005710157102571035710457105571065710757108571095711057111571125711357114571155711657117571185711957120571215712257123571245712557126571275712857129571305713157132571335713457135571365713757138571395714057141571425714357144571455714657147571485714957150571515715257153571545715557156571575715857159571605716157162571635716457165571665716757168571695717057171571725717357174571755717657177571785717957180571815718257183571845718557186571875718857189571905719157192571935719457195571965719757198571995720057201572025720357204572055720657207572085720957210572115721257213572145721557216572175721857219572205722157222572235722457225572265722757228572295723057231572325723357234572355723657237572385723957240572415724257243572445724557246572475724857249572505725157252572535725457255572565725757258572595726057261572625726357264572655726657267572685726957270572715727257273572745727557276572775727857279572805728157282572835728457285572865728757288572895729057291572925729357294572955729657297572985729957300573015730257303573045730557306573075730857309573105731157312573135731457315573165731757318573195732057321573225732357324573255732657327573285732957330573315733257333573345733557336573375733857339573405734157342573435734457345573465734757348573495735057351573525735357354573555735657357573585735957360573615736257363573645736557366573675736857369573705737157372573735737457375573765737757378573795738057381573825738357384573855738657387573885738957390573915739257393573945739557396573975739857399574005740157402574035740457405574065740757408574095741057411574125741357414574155741657417574185741957420574215742257423574245742557426574275742857429574305743157432574335743457435574365743757438574395744057441574425744357444574455744657447574485744957450574515745257453574545745557456574575745857459574605746157462574635746457465574665746757468574695747057471574725747357474574755747657477574785747957480574815748257483574845748557486574875748857489574905749157492574935749457495574965749757498574995750057501575025750357504575055750657507575085750957510575115751257513575145751557516575175751857519575205752157522575235752457525575265752757528575295753057531575325753357534575355753657537575385753957540575415754257543575445754557546575475754857549575505755157552575535755457555575565755757558575595756057561575625756357564575655756657567575685756957570575715757257573575745757557576575775757857579575805758157582575835758457585575865758757588575895759057591575925759357594575955759657597575985759957600576015760257603576045760557606576075760857609576105761157612576135761457615576165761757618576195762057621576225762357624576255762657627576285762957630576315763257633576345763557636576375763857639576405764157642576435764457645576465764757648576495765057651576525765357654576555765657657576585765957660576615766257663576645766557666576675766857669576705767157672576735767457675576765767757678576795768057681576825768357684576855768657687576885768957690576915769257693576945769557696576975769857699577005770157702577035770457705577065770757708577095771057711577125771357714577155771657717577185771957720577215772257723577245772557726577275772857729577305773157732577335773457735577365773757738577395774057741577425774357744577455774657747577485774957750577515775257753577545775557756577575775857759577605776157762577635776457765577665776757768577695777057771577725777357774577755777657777577785777957780577815778257783577845778557786577875778857789577905779157792577935779457795577965779757798577995780057801578025780357804578055780657807578085780957810578115781257813578145781557816578175781857819578205782157822578235782457825578265782757828578295783057831578325783357834578355783657837578385783957840578415784257843578445784557846578475784857849578505785157852578535785457855578565785757858578595786057861578625786357864578655786657867578685786957870578715787257873578745787557876578775787857879578805788157882578835788457885578865788757888578895789057891578925789357894578955789657897578985789957900579015790257903579045790557906579075790857909579105791157912579135791457915579165791757918579195792057921579225792357924579255792657927579285792957930579315793257933579345793557936579375793857939579405794157942579435794457945579465794757948579495795057951579525795357954579555795657957579585795957960579615796257963579645796557966579675796857969579705797157972579735797457975579765797757978579795798057981579825798357984579855798657987579885798957990579915799257993579945799557996579975799857999580005800158002580035800458005580065800758008580095801058011580125801358014580155801658017580185801958020580215802258023580245802558026580275802858029580305803158032580335803458035580365803758038580395804058041580425804358044580455804658047580485804958050580515805258053580545805558056580575805858059580605806158062580635806458065580665806758068580695807058071580725807358074580755807658077580785807958080580815808258083580845808558086580875808858089580905809158092580935809458095580965809758098580995810058101581025810358104581055810658107581085810958110581115811258113581145811558116581175811858119581205812158122581235812458125581265812758128581295813058131581325813358134581355813658137581385813958140581415814258143581445814558146581475814858149581505815158152581535815458155581565815758158581595816058161581625816358164581655816658167581685816958170581715817258173581745817558176581775817858179581805818158182581835818458185581865818758188581895819058191581925819358194581955819658197581985819958200582015820258203582045820558206582075820858209582105821158212582135821458215582165821758218582195822058221582225822358224582255822658227582285822958230582315823258233582345823558236582375823858239582405824158242582435824458245582465824758248582495825058251582525825358254582555825658257582585825958260582615826258263582645826558266582675826858269582705827158272582735827458275582765827758278582795828058281582825828358284582855828658287582885828958290582915829258293582945829558296582975829858299583005830158302583035830458305583065830758308583095831058311583125831358314583155831658317583185831958320583215832258323583245832558326583275832858329583305833158332583335833458335583365833758338583395834058341583425834358344583455834658347583485834958350583515835258353583545835558356583575835858359583605836158362583635836458365583665836758368583695837058371583725837358374583755837658377583785837958380583815838258383583845838558386583875838858389583905839158392583935839458395583965839758398583995840058401584025840358404584055840658407584085840958410584115841258413584145841558416584175841858419584205842158422584235842458425584265842758428584295843058431584325843358434584355843658437584385843958440584415844258443584445844558446584475844858449584505845158452584535845458455584565845758458584595846058461584625846358464584655846658467584685846958470584715847258473584745847558476584775847858479584805848158482584835848458485584865848758488584895849058491584925849358494584955849658497584985849958500585015850258503585045850558506585075850858509585105851158512585135851458515585165851758518585195852058521585225852358524585255852658527585285852958530585315853258533585345853558536585375853858539585405854158542585435854458545585465854758548585495855058551585525855358554585555855658557585585855958560585615856258563585645856558566585675856858569585705857158572585735857458575585765857758578585795858058581585825858358584585855858658587585885858958590585915859258593585945859558596585975859858599586005860158602586035860458605586065860758608586095861058611586125861358614586155861658617586185861958620586215862258623586245862558626586275862858629586305863158632586335863458635586365863758638586395864058641586425864358644586455864658647586485864958650586515865258653586545865558656586575865858659586605866158662586635866458665586665866758668586695867058671586725867358674586755867658677586785867958680586815868258683586845868558686586875868858689586905869158692586935869458695586965869758698586995870058701587025870358704587055870658707587085870958710587115871258713587145871558716587175871858719587205872158722587235872458725587265872758728587295873058731587325873358734587355873658737587385873958740587415874258743587445874558746587475874858749587505875158752587535875458755587565875758758587595876058761587625876358764587655876658767587685876958770587715877258773587745877558776587775877858779587805878158782587835878458785587865878758788587895879058791587925879358794587955879658797587985879958800588015880258803588045880558806588075880858809588105881158812588135881458815588165881758818588195882058821588225882358824588255882658827588285882958830588315883258833588345883558836588375883858839588405884158842588435884458845588465884758848588495885058851588525885358854588555885658857588585885958860588615886258863588645886558866588675886858869588705887158872588735887458875588765887758878588795888058881588825888358884588855888658887588885888958890588915889258893588945889558896588975889858899589005890158902589035890458905589065890758908589095891058911589125891358914589155891658917589185891958920589215892258923589245892558926589275892858929589305893158932589335893458935589365893758938589395894058941589425894358944589455894658947589485894958950589515895258953589545895558956589575895858959589605896158962589635896458965589665896758968589695897058971589725897358974589755897658977589785897958980589815898258983589845898558986589875898858989589905899158992589935899458995589965899758998589995900059001590025900359004590055900659007590085900959010590115901259013590145901559016590175901859019590205902159022590235902459025590265902759028590295903059031590325903359034590355903659037590385903959040590415904259043590445904559046590475904859049590505905159052590535905459055590565905759058590595906059061590625906359064590655906659067590685906959070590715907259073590745907559076590775907859079590805908159082590835908459085590865908759088590895909059091590925909359094590955909659097590985909959100591015910259103591045910559106591075910859109591105911159112591135911459115591165911759118591195912059121591225912359124591255912659127591285912959130591315913259133591345913559136591375913859139591405914159142591435914459145591465914759148591495915059151591525915359154591555915659157591585915959160591615916259163591645916559166591675916859169591705917159172591735917459175591765917759178591795918059181591825918359184591855918659187591885918959190591915919259193591945919559196591975919859199592005920159202592035920459205592065920759208592095921059211592125921359214592155921659217592185921959220592215922259223592245922559226592275922859229592305923159232592335923459235592365923759238592395924059241592425924359244592455924659247592485924959250592515925259253592545925559256592575925859259592605926159262592635926459265592665926759268592695927059271592725927359274592755927659277592785927959280592815928259283592845928559286592875928859289592905929159292592935929459295592965929759298592995930059301593025930359304593055930659307593085930959310593115931259313593145931559316593175931859319593205932159322593235932459325593265932759328593295933059331593325933359334593355933659337593385933959340593415934259343593445934559346593475934859349593505935159352593535935459355593565935759358593595936059361593625936359364593655936659367593685936959370593715937259373593745937559376593775937859379593805938159382593835938459385593865938759388593895939059391593925939359394593955939659397593985939959400594015940259403594045940559406594075940859409594105941159412594135941459415594165941759418594195942059421594225942359424594255942659427594285942959430594315943259433594345943559436594375943859439594405944159442594435944459445594465944759448594495945059451594525945359454594555945659457594585945959460594615946259463594645946559466594675946859469594705947159472594735947459475594765947759478594795948059481594825948359484594855948659487594885948959490594915949259493594945949559496594975949859499595005950159502595035950459505595065950759508595095951059511595125951359514595155951659517595185951959520595215952259523595245952559526595275952859529595305953159532595335953459535595365953759538595395954059541595425954359544595455954659547595485954959550595515955259553595545955559556595575955859559595605956159562595635956459565595665956759568595695957059571595725957359574595755957659577595785957959580595815958259583595845958559586595875958859589595905959159592595935959459595595965959759598595995960059601596025960359604596055960659607596085960959610596115961259613596145961559616596175961859619596205962159622596235962459625596265962759628596295963059631596325963359634596355963659637596385963959640596415964259643596445964559646596475964859649596505965159652596535965459655596565965759658596595966059661596625966359664596655966659667596685966959670596715967259673596745967559676596775967859679596805968159682596835968459685596865968759688596895969059691596925969359694596955969659697596985969959700597015970259703597045970559706597075970859709597105971159712597135971459715597165971759718597195972059721597225972359724597255972659727597285972959730597315973259733597345973559736597375973859739597405974159742597435974459745597465974759748597495975059751597525975359754597555975659757597585975959760597615976259763597645976559766597675976859769597705977159772597735977459775597765977759778597795978059781597825978359784597855978659787597885978959790597915979259793597945979559796597975979859799598005980159802598035980459805598065980759808598095981059811598125981359814598155981659817598185981959820598215982259823598245982559826598275982859829598305983159832598335983459835598365983759838598395984059841598425984359844598455984659847598485984959850598515985259853598545985559856598575985859859598605986159862598635986459865598665986759868598695987059871598725987359874598755987659877598785987959880598815988259883598845988559886598875988859889598905989159892598935989459895598965989759898598995990059901599025990359904599055990659907599085990959910599115991259913599145991559916599175991859919599205992159922599235992459925599265992759928599295993059931599325993359934599355993659937599385993959940599415994259943599445994559946599475994859949599505995159952599535995459955599565995759958599595996059961599625996359964599655996659967599685996959970599715997259973599745997559976599775997859979599805998159982599835998459985599865998759988599895999059991599925999359994599955999659997599985999960000600016000260003600046000560006600076000860009600106001160012600136001460015600166001760018600196002060021600226002360024600256002660027600286002960030600316003260033600346003560036600376003860039600406004160042600436004460045600466004760048600496005060051600526005360054600556005660057600586005960060600616006260063600646006560066600676006860069600706007160072600736007460075600766007760078600796008060081600826008360084600856008660087600886008960090600916009260093600946009560096600976009860099601006010160102601036010460105601066010760108601096011060111601126011360114601156011660117601186011960120601216012260123601246012560126601276012860129601306013160132601336013460135601366013760138601396014060141601426014360144601456014660147601486014960150601516015260153601546015560156601576015860159601606016160162601636016460165601666016760168601696017060171601726017360174601756017660177601786017960180601816018260183601846018560186601876018860189601906019160192601936019460195601966019760198601996020060201602026020360204602056020660207602086020960210602116021260213602146021560216602176021860219602206022160222602236022460225602266022760228602296023060231602326023360234602356023660237602386023960240602416024260243602446024560246602476024860249602506025160252602536025460255602566025760258602596026060261602626026360264602656026660267602686026960270602716027260273602746027560276602776027860279602806028160282602836028460285602866028760288602896029060291602926029360294602956029660297602986029960300603016030260303603046030560306603076030860309603106031160312603136031460315603166031760318603196032060321603226032360324603256032660327603286032960330603316033260333603346033560336603376033860339603406034160342603436034460345603466034760348603496035060351603526035360354603556035660357603586035960360603616036260363603646036560366603676036860369603706037160372603736037460375603766037760378603796038060381603826038360384603856038660387603886038960390603916039260393603946039560396603976039860399604006040160402604036040460405604066040760408604096041060411604126041360414604156041660417604186041960420604216042260423604246042560426604276042860429604306043160432604336043460435604366043760438604396044060441604426044360444604456044660447604486044960450604516045260453604546045560456604576045860459604606046160462604636046460465604666046760468604696047060471604726047360474604756047660477604786047960480604816048260483604846048560486604876048860489604906049160492604936049460495604966049760498604996050060501605026050360504605056050660507605086050960510605116051260513605146051560516605176051860519605206052160522605236052460525605266052760528605296053060531605326053360534605356053660537605386053960540605416054260543605446054560546605476054860549605506055160552605536055460555605566055760558605596056060561605626056360564605656056660567605686056960570605716057260573605746057560576605776057860579605806058160582605836058460585605866058760588605896059060591605926059360594605956059660597605986059960600606016060260603606046060560606606076060860609606106061160612606136061460615606166061760618606196062060621606226062360624606256062660627606286062960630606316063260633606346063560636606376063860639606406064160642606436064460645606466064760648606496065060651606526065360654606556065660657606586065960660606616066260663606646066560666606676066860669606706067160672606736067460675606766067760678606796068060681606826068360684606856068660687606886068960690606916069260693606946069560696606976069860699607006070160702607036070460705607066070760708607096071060711607126071360714607156071660717607186071960720607216072260723607246072560726607276072860729607306073160732607336073460735607366073760738607396074060741607426074360744607456074660747607486074960750607516075260753607546075560756607576075860759607606076160762607636076460765607666076760768607696077060771607726077360774607756077660777607786077960780607816078260783607846078560786607876078860789607906079160792607936079460795607966079760798607996080060801608026080360804608056080660807608086080960810608116081260813608146081560816608176081860819608206082160822608236082460825608266082760828608296083060831608326083360834608356083660837608386083960840608416084260843608446084560846608476084860849608506085160852608536085460855608566085760858608596086060861608626086360864608656086660867608686086960870608716087260873608746087560876608776087860879608806088160882608836088460885608866088760888608896089060891608926089360894608956089660897608986089960900609016090260903609046090560906609076090860909609106091160912609136091460915609166091760918609196092060921609226092360924609256092660927609286092960930609316093260933609346093560936609376093860939609406094160942609436094460945609466094760948609496095060951609526095360954609556095660957609586095960960609616096260963609646096560966609676096860969609706097160972609736097460975609766097760978609796098060981609826098360984609856098660987609886098960990609916099260993609946099560996609976099860999610006100161002610036100461005610066100761008610096101061011610126101361014610156101661017610186101961020610216102261023610246102561026610276102861029610306103161032610336103461035610366103761038610396104061041610426104361044610456104661047610486104961050610516105261053610546105561056610576105861059610606106161062610636106461065610666106761068610696107061071610726107361074610756107661077610786107961080610816108261083610846108561086610876108861089610906109161092610936109461095610966109761098610996110061101611026110361104611056110661107611086110961110611116111261113611146111561116611176111861119611206112161122611236112461125611266112761128611296113061131611326113361134611356113661137611386113961140611416114261143611446114561146611476114861149611506115161152611536115461155611566115761158611596116061161611626116361164611656116661167611686116961170611716117261173611746117561176611776117861179611806118161182611836118461185611866118761188611896119061191611926119361194611956119661197611986119961200612016120261203612046120561206612076120861209612106121161212612136121461215612166121761218612196122061221612226122361224612256122661227612286122961230612316123261233612346123561236612376123861239612406124161242612436124461245612466124761248612496125061251612526125361254612556125661257612586125961260612616126261263612646126561266612676126861269612706127161272612736127461275612766127761278612796128061281612826128361284612856128661287612886128961290612916129261293612946129561296612976129861299613006130161302613036130461305613066130761308613096131061311613126131361314613156131661317613186131961320613216132261323613246132561326613276132861329613306133161332613336133461335613366133761338613396134061341613426134361344613456134661347613486134961350613516135261353613546135561356613576135861359613606136161362613636136461365613666136761368613696137061371613726137361374613756137661377613786137961380613816138261383613846138561386613876138861389613906139161392613936139461395613966139761398613996140061401614026140361404614056140661407614086140961410614116141261413614146141561416614176141861419614206142161422614236142461425614266142761428614296143061431614326143361434614356143661437614386143961440614416144261443614446144561446614476144861449614506145161452614536145461455614566145761458614596146061461614626146361464614656146661467614686146961470614716147261473614746147561476614776147861479614806148161482614836148461485614866148761488614896149061491614926149361494614956149661497614986149961500615016150261503615046150561506615076150861509615106151161512615136151461515615166151761518615196152061521615226152361524615256152661527615286152961530615316153261533615346153561536615376153861539615406154161542615436154461545615466154761548615496155061551615526155361554615556155661557615586155961560615616156261563615646156561566615676156861569615706157161572615736157461575615766157761578615796158061581615826158361584615856158661587615886158961590615916159261593615946159561596615976159861599616006160161602616036160461605616066160761608616096161061611616126161361614616156161661617616186161961620616216162261623616246162561626616276162861629616306163161632616336163461635616366163761638616396164061641616426164361644616456164661647616486164961650616516165261653616546165561656616576165861659616606166161662616636166461665616666166761668616696167061671616726167361674616756167661677616786167961680616816168261683616846168561686616876168861689616906169161692616936169461695616966169761698616996170061701617026170361704617056170661707617086170961710617116171261713617146171561716617176171861719617206172161722617236172461725617266172761728617296173061731617326173361734617356173661737617386173961740617416174261743617446174561746617476174861749617506175161752617536175461755617566175761758617596176061761617626176361764617656176661767617686176961770617716177261773617746177561776617776177861779617806178161782617836178461785617866178761788617896179061791617926179361794617956179661797617986179961800618016180261803618046180561806618076180861809618106181161812618136181461815618166181761818618196182061821618226182361824618256182661827618286182961830618316183261833618346183561836618376183861839618406184161842618436184461845618466184761848618496185061851618526185361854618556185661857618586185961860618616186261863618646186561866618676186861869618706187161872618736187461875618766187761878618796188061881618826188361884618856188661887618886188961890618916189261893618946189561896618976189861899619006190161902619036190461905619066190761908619096191061911619126191361914619156191661917619186191961920619216192261923619246192561926619276192861929619306193161932619336193461935619366193761938619396194061941619426194361944619456194661947619486194961950619516195261953619546195561956619576195861959619606196161962619636196461965619666196761968619696197061971619726197361974619756197661977619786197961980619816198261983619846198561986619876198861989619906199161992619936199461995619966199761998619996200062001620026200362004620056200662007620086200962010620116201262013620146201562016620176201862019620206202162022620236202462025620266202762028620296203062031620326203362034620356203662037620386203962040620416204262043620446204562046620476204862049620506205162052620536205462055620566205762058620596206062061620626206362064620656206662067620686206962070620716207262073620746207562076620776207862079620806208162082620836208462085620866208762088620896209062091620926209362094620956209662097620986209962100621016210262103621046210562106621076210862109621106211162112621136211462115621166211762118621196212062121621226212362124621256212662127621286212962130621316213262133621346213562136621376213862139621406214162142621436214462145621466214762148621496215062151621526215362154621556215662157621586215962160621616216262163621646216562166621676216862169621706217162172621736217462175621766217762178621796218062181621826218362184621856218662187621886218962190621916219262193621946219562196621976219862199622006220162202622036220462205622066220762208622096221062211622126221362214622156221662217622186221962220622216222262223622246222562226622276222862229622306223162232622336223462235622366223762238622396224062241622426224362244622456224662247622486224962250622516225262253622546225562256622576225862259622606226162262622636226462265622666226762268622696227062271622726227362274622756227662277622786227962280622816228262283622846228562286622876228862289622906229162292622936229462295622966229762298622996230062301623026230362304623056230662307623086230962310623116231262313623146231562316623176231862319623206232162322623236232462325623266232762328623296233062331623326233362334623356233662337623386233962340623416234262343623446234562346623476234862349623506235162352623536235462355623566235762358623596236062361623626236362364623656236662367623686236962370623716237262373623746237562376623776237862379623806238162382623836238462385623866238762388623896239062391623926239362394623956239662397623986239962400624016240262403624046240562406624076240862409624106241162412624136241462415624166241762418624196242062421624226242362424624256242662427624286242962430624316243262433624346243562436624376243862439624406244162442624436244462445624466244762448624496245062451624526245362454624556245662457624586245962460624616246262463624646246562466624676246862469624706247162472624736247462475624766247762478624796248062481624826248362484624856248662487624886248962490624916249262493624946249562496624976249862499625006250162502625036250462505625066250762508625096251062511625126251362514625156251662517625186251962520625216252262523625246252562526625276252862529625306253162532625336253462535625366253762538625396254062541625426254362544625456254662547625486254962550625516255262553625546255562556625576255862559625606256162562625636256462565625666256762568625696257062571625726257362574625756257662577625786257962580625816258262583625846258562586625876258862589625906259162592625936259462595625966259762598625996260062601626026260362604626056260662607626086260962610626116261262613626146261562616626176261862619626206262162622626236262462625626266262762628626296263062631626326263362634626356263662637626386263962640626416264262643626446264562646626476264862649626506265162652626536265462655626566265762658626596266062661626626266362664626656266662667626686266962670626716267262673626746267562676626776267862679626806268162682626836268462685626866268762688626896269062691626926269362694626956269662697626986269962700627016270262703627046270562706627076270862709627106271162712627136271462715627166271762718627196272062721627226272362724627256272662727627286272962730627316273262733627346273562736627376273862739627406274162742627436274462745627466274762748627496275062751627526275362754627556275662757627586275962760627616276262763627646276562766627676276862769627706277162772627736277462775627766277762778627796278062781627826278362784627856278662787627886278962790627916279262793627946279562796627976279862799628006280162802628036280462805628066280762808628096281062811628126281362814628156281662817628186281962820628216282262823628246282562826628276282862829628306283162832628336283462835628366283762838628396284062841628426284362844628456284662847628486284962850628516285262853628546285562856628576285862859628606286162862628636286462865628666286762868628696287062871628726287362874628756287662877628786287962880628816288262883628846288562886628876288862889628906289162892628936289462895628966289762898628996290062901629026290362904629056290662907629086290962910629116291262913629146291562916629176291862919629206292162922629236292462925629266292762928629296293062931629326293362934629356293662937629386293962940629416294262943629446294562946629476294862949629506295162952629536295462955629566295762958629596296062961629626296362964629656296662967629686296962970629716297262973629746297562976629776297862979629806298162982629836298462985629866298762988629896299062991629926299362994629956299662997629986299963000630016300263003630046300563006630076300863009630106301163012630136301463015630166301763018630196302063021630226302363024630256302663027630286302963030630316303263033630346303563036630376303863039630406304163042630436304463045630466304763048630496305063051630526305363054630556305663057630586305963060630616306263063630646306563066630676306863069630706307163072630736307463075630766307763078630796308063081630826308363084630856308663087630886308963090630916309263093630946309563096630976309863099631006310163102631036310463105631066310763108631096311063111631126311363114631156311663117631186311963120631216312263123631246312563126631276312863129631306313163132631336313463135631366313763138631396314063141631426314363144631456314663147631486314963150631516315263153631546315563156631576315863159631606316163162631636316463165631666316763168631696317063171631726317363174631756317663177631786317963180631816318263183631846318563186631876318863189631906319163192631936319463195631966319763198631996320063201632026320363204632056320663207632086320963210632116321263213632146321563216632176321863219632206322163222632236322463225632266322763228632296323063231632326323363234632356323663237632386323963240632416324263243632446324563246632476324863249632506325163252632536325463255632566325763258632596326063261632626326363264632656326663267632686326963270632716327263273632746327563276632776327863279632806328163282632836328463285632866328763288632896329063291632926329363294632956329663297632986329963300633016330263303633046330563306633076330863309633106331163312633136331463315633166331763318633196332063321633226332363324633256332663327633286332963330633316333263333633346333563336633376333863339633406334163342633436334463345633466334763348633496335063351633526335363354633556335663357633586335963360633616336263363633646336563366633676336863369633706337163372633736337463375633766337763378633796338063381633826338363384633856338663387633886338963390633916339263393633946339563396633976339863399634006340163402634036340463405634066340763408634096341063411634126341363414634156341663417634186341963420634216342263423634246342563426634276342863429634306343163432634336343463435634366343763438634396344063441634426344363444634456344663447634486344963450634516345263453634546345563456634576345863459634606346163462634636346463465634666346763468634696347063471634726347363474634756347663477634786347963480634816348263483634846348563486634876348863489634906349163492634936349463495634966349763498634996350063501635026350363504635056350663507635086350963510635116351263513635146351563516635176351863519635206352163522635236352463525635266352763528635296353063531635326353363534635356353663537635386353963540635416354263543635446354563546635476354863549635506355163552635536355463555635566355763558635596356063561635626356363564635656356663567635686356963570635716357263573635746357563576635776357863579635806358163582635836358463585635866358763588635896359063591635926359363594635956359663597635986359963600636016360263603636046360563606636076360863609636106361163612636136361463615636166361763618636196362063621636226362363624636256362663627636286362963630636316363263633636346363563636636376363863639636406364163642636436364463645636466364763648636496365063651636526365363654636556365663657636586365963660636616366263663636646366563666636676366863669636706367163672636736367463675636766367763678636796368063681636826368363684636856368663687636886368963690636916369263693636946369563696636976369863699637006370163702637036370463705637066370763708637096371063711637126371363714637156371663717637186371963720637216372263723637246372563726637276372863729637306373163732637336373463735637366373763738637396374063741637426374363744637456374663747637486374963750637516375263753637546375563756637576375863759637606376163762637636376463765637666376763768637696377063771637726377363774637756377663777637786377963780637816378263783637846378563786637876378863789637906379163792637936379463795637966379763798637996380063801638026380363804638056380663807638086380963810638116381263813638146381563816638176381863819638206382163822638236382463825638266382763828638296383063831638326383363834638356383663837638386383963840638416384263843638446384563846638476384863849638506385163852638536385463855638566385763858638596386063861638626386363864638656386663867638686386963870638716387263873638746387563876638776387863879638806388163882638836388463885638866388763888638896389063891638926389363894638956389663897638986389963900639016390263903639046390563906639076390863909639106391163912639136391463915639166391763918639196392063921639226392363924639256392663927639286392963930639316393263933639346393563936639376393863939639406394163942639436394463945639466394763948639496395063951639526395363954639556395663957639586395963960639616396263963639646396563966639676396863969639706397163972639736397463975639766397763978639796398063981639826398363984639856398663987639886398963990639916399263993639946399563996639976399863999640006400164002640036400464005640066400764008640096401064011640126401364014640156401664017640186401964020640216402264023640246402564026640276402864029640306403164032640336403464035640366403764038640396404064041640426404364044640456404664047640486404964050640516405264053640546405564056640576405864059640606406164062640636406464065640666406764068640696407064071640726407364074640756407664077640786407964080640816408264083640846408564086640876408864089640906409164092640936409464095640966409764098640996410064101641026410364104641056410664107641086410964110641116411264113641146411564116641176411864119641206412164122641236412464125641266412764128641296413064131641326413364134641356413664137641386413964140641416414264143641446414564146641476414864149641506415164152641536415464155641566415764158641596416064161641626416364164641656416664167641686416964170641716417264173641746417564176641776417864179641806418164182641836418464185641866418764188641896419064191641926419364194641956419664197641986419964200642016420264203642046420564206642076420864209642106421164212642136421464215642166421764218642196422064221642226422364224642256422664227642286422964230642316423264233642346423564236642376423864239642406424164242642436424464245642466424764248642496425064251642526425364254642556425664257642586425964260642616426264263642646426564266642676426864269642706427164272642736427464275642766427764278642796428064281642826428364284642856428664287642886428964290642916429264293642946429564296642976429864299643006430164302643036430464305643066430764308643096431064311643126431364314643156431664317643186431964320643216432264323643246432564326643276432864329643306433164332643336433464335643366433764338643396434064341643426434364344643456434664347643486434964350643516435264353643546435564356643576435864359643606436164362643636436464365643666436764368643696437064371643726437364374643756437664377643786437964380643816438264383643846438564386643876438864389643906439164392643936439464395643966439764398643996440064401644026440364404644056440664407644086440964410644116441264413644146441564416644176441864419644206442164422644236442464425644266442764428644296443064431644326443364434644356443664437644386443964440644416444264443644446444564446644476444864449644506445164452644536445464455644566445764458644596446064461644626446364464644656446664467644686446964470644716447264473644746447564476644776447864479644806448164482644836448464485644866448764488644896449064491644926449364494644956449664497644986449964500645016450264503645046450564506645076450864509645106451164512645136451464515645166451764518645196452064521645226452364524645256452664527645286452964530645316453264533645346453564536645376453864539645406454164542645436454464545645466454764548645496455064551645526455364554645556455664557645586455964560645616456264563645646456564566645676456864569645706457164572645736457464575645766457764578645796458064581645826458364584645856458664587645886458964590645916459264593645946459564596645976459864599646006460164602646036460464605646066460764608646096461064611646126461364614646156461664617646186461964620646216462264623646246462564626646276462864629646306463164632646336463464635646366463764638646396464064641646426464364644646456464664647646486464964650646516465264653646546465564656646576465864659646606466164662646636466464665646666466764668646696467064671646726467364674646756467664677646786467964680646816468264683646846468564686646876468864689646906469164692646936469464695646966469764698646996470064701647026470364704647056470664707647086470964710647116471264713647146471564716647176471864719647206472164722647236472464725647266472764728647296473064731647326473364734647356473664737647386473964740647416474264743647446474564746647476474864749647506475164752647536475464755647566475764758647596476064761647626476364764647656476664767647686476964770647716477264773647746477564776647776477864779647806478164782647836478464785647866478764788647896479064791647926479364794647956479664797647986479964800648016480264803648046480564806648076480864809648106481164812648136481464815648166481764818648196482064821648226482364824648256482664827648286482964830648316483264833648346483564836648376483864839648406484164842648436484464845648466484764848648496485064851648526485364854648556485664857648586485964860648616486264863648646486564866648676486864869648706487164872648736487464875648766487764878648796488064881648826488364884648856488664887648886488964890648916489264893648946489564896648976489864899649006490164902649036490464905649066490764908649096491064911649126491364914649156491664917649186491964920649216492264923649246492564926649276492864929649306493164932649336493464935649366493764938649396494064941649426494364944649456494664947649486494964950649516495264953649546495564956649576495864959649606496164962649636496464965649666496764968649696497064971649726497364974649756497664977649786497964980649816498264983649846498564986649876498864989649906499164992649936499464995649966499764998649996500065001650026500365004650056500665007650086500965010650116501265013650146501565016650176501865019650206502165022650236502465025650266502765028650296503065031650326503365034650356503665037650386503965040650416504265043650446504565046650476504865049650506505165052650536505465055650566505765058650596506065061650626506365064650656506665067650686506965070650716507265073650746507565076650776507865079650806508165082650836508465085650866508765088650896509065091650926509365094650956509665097650986509965100651016510265103651046510565106651076510865109651106511165112651136511465115651166511765118651196512065121651226512365124651256512665127651286512965130651316513265133651346513565136651376513865139651406514165142651436514465145651466514765148651496515065151651526515365154651556515665157651586515965160651616516265163651646516565166651676516865169651706517165172651736517465175651766517765178651796518065181651826518365184651856518665187651886518965190651916519265193651946519565196651976519865199652006520165202652036520465205652066520765208652096521065211652126521365214652156521665217652186521965220652216522265223652246522565226652276522865229652306523165232652336523465235652366523765238652396524065241652426524365244652456524665247652486524965250652516525265253652546525565256652576525865259652606526165262652636526465265652666526765268652696527065271652726527365274652756527665277652786527965280652816528265283652846528565286652876528865289652906529165292652936529465295652966529765298652996530065301653026530365304653056530665307653086530965310653116531265313653146531565316653176531865319653206532165322653236532465325653266532765328653296533065331653326533365334653356533665337653386533965340653416534265343653446534565346653476534865349653506535165352653536535465355653566535765358653596536065361653626536365364653656536665367653686536965370653716537265373653746537565376653776537865379653806538165382653836538465385653866538765388653896539065391653926539365394653956539665397653986539965400654016540265403654046540565406654076540865409654106541165412654136541465415654166541765418654196542065421654226542365424654256542665427654286542965430654316543265433654346543565436654376543865439654406544165442654436544465445654466544765448654496545065451654526545365454654556545665457654586545965460654616546265463654646546565466654676546865469654706547165472654736547465475654766547765478654796548065481654826548365484654856548665487654886548965490654916549265493654946549565496654976549865499655006550165502655036550465505655066550765508655096551065511655126551365514655156551665517655186551965520655216552265523655246552565526655276552865529655306553165532655336553465535655366553765538655396554065541655426554365544655456554665547655486554965550655516555265553655546555565556655576555865559655606556165562655636556465565655666556765568655696557065571655726557365574655756557665577655786557965580655816558265583655846558565586655876558865589655906559165592655936559465595655966559765598655996560065601656026560365604656056560665607656086560965610656116561265613656146561565616656176561865619656206562165622656236562465625656266562765628656296563065631656326563365634656356563665637656386563965640656416564265643656446564565646656476564865649656506565165652656536565465655656566565765658656596566065661656626566365664656656566665667656686566965670656716567265673656746567565676656776567865679656806568165682656836568465685656866568765688656896569065691656926569365694656956569665697656986569965700657016570265703657046570565706657076570865709657106571165712657136571465715657166571765718657196572065721657226572365724657256572665727657286572965730657316573265733657346573565736657376573865739657406574165742657436574465745657466574765748657496575065751657526575365754657556575665757657586575965760657616576265763657646576565766657676576865769657706577165772657736577465775657766577765778657796578065781657826578365784657856578665787657886578965790657916579265793657946579565796657976579865799658006580165802658036580465805658066580765808658096581065811658126581365814658156581665817658186581965820658216582265823658246582565826658276582865829658306583165832658336583465835658366583765838658396584065841658426584365844658456584665847658486584965850658516585265853658546585565856658576585865859658606586165862658636586465865658666586765868658696587065871658726587365874658756587665877658786587965880658816588265883658846588565886658876588865889658906589165892658936589465895658966589765898658996590065901659026590365904659056590665907659086590965910659116591265913659146591565916659176591865919659206592165922659236592465925659266592765928659296593065931659326593365934659356593665937659386593965940659416594265943659446594565946659476594865949659506595165952659536595465955659566595765958659596596065961659626596365964659656596665967659686596965970659716597265973659746597565976659776597865979659806598165982659836598465985659866598765988659896599065991659926599365994659956599665997659986599966000660016600266003660046600566006660076600866009660106601166012660136601466015660166601766018660196602066021660226602366024660256602666027660286602966030660316603266033660346603566036660376603866039660406604166042660436604466045660466604766048660496605066051660526605366054660556605666057660586605966060660616606266063660646606566066660676606866069660706607166072660736607466075660766607766078660796608066081660826608366084660856608666087660886608966090660916609266093660946609566096660976609866099661006610166102661036610466105661066610766108661096611066111661126611366114661156611666117661186611966120661216612266123661246612566126661276612866129661306613166132661336613466135661366613766138661396614066141661426614366144661456614666147661486614966150661516615266153661546615566156661576615866159661606616166162661636616466165661666616766168661696617066171661726617366174661756617666177661786617966180661816618266183661846618566186661876618866189661906619166192661936619466195661966619766198661996620066201662026620366204662056620666207662086620966210662116621266213662146621566216662176621866219662206622166222662236622466225662266622766228662296623066231662326623366234662356623666237662386623966240662416624266243662446624566246662476624866249662506625166252662536625466255662566625766258662596626066261662626626366264662656626666267662686626966270662716627266273662746627566276662776627866279662806628166282662836628466285662866628766288662896629066291662926629366294662956629666297662986629966300663016630266303663046630566306663076630866309663106631166312663136631466315663166631766318663196632066321663226632366324663256632666327663286632966330663316633266333663346633566336663376633866339663406634166342663436634466345663466634766348663496635066351663526635366354663556635666357663586635966360663616636266363663646636566366663676636866369663706637166372663736637466375663766637766378663796638066381663826638366384663856638666387663886638966390663916639266393663946639566396663976639866399664006640166402664036640466405664066640766408664096641066411664126641366414664156641666417664186641966420664216642266423664246642566426664276642866429664306643166432664336643466435664366643766438664396644066441664426644366444664456644666447664486644966450664516645266453664546645566456664576645866459664606646166462664636646466465664666646766468664696647066471664726647366474664756647666477664786647966480664816648266483664846648566486664876648866489664906649166492664936649466495664966649766498664996650066501665026650366504665056650666507665086650966510665116651266513665146651566516665176651866519665206652166522665236652466525665266652766528665296653066531665326653366534665356653666537665386653966540665416654266543665446654566546665476654866549665506655166552665536655466555665566655766558665596656066561665626656366564665656656666567665686656966570665716657266573665746657566576665776657866579665806658166582665836658466585665866658766588665896659066591665926659366594665956659666597665986659966600666016660266603666046660566606666076660866609666106661166612666136661466615666166661766618666196662066621666226662366624666256662666627666286662966630666316663266633666346663566636666376663866639666406664166642666436664466645666466664766648666496665066651666526665366654666556665666657666586665966660666616666266663666646666566666666676666866669666706667166672666736667466675666766667766678666796668066681666826668366684666856668666687666886668966690666916669266693666946669566696666976669866699667006670166702667036670466705667066670766708667096671066711667126671366714667156671666717667186671966720667216672266723667246672566726667276672866729667306673166732667336673466735667366673766738667396674066741667426674366744667456674666747667486674966750667516675266753667546675566756667576675866759667606676166762667636676466765667666676766768667696677066771667726677366774667756677666777667786677966780667816678266783667846678566786667876678866789667906679166792667936679466795667966679766798667996680066801668026680366804668056680666807
  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. console.log("TADA");
  7. QUnit.module( "Source", () => {
  8. var REVISION = '88dev';
  9. var MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2 };
  10. var CullFaceNone = 0;
  11. var CullFaceBack = 1;
  12. var CullFaceFront = 2;
  13. var CullFaceFrontBack = 3;
  14. var FrontFaceDirectionCW = 0;
  15. var FrontFaceDirectionCCW = 1;
  16. var BasicShadowMap = 0;
  17. var PCFShadowMap = 1;
  18. var PCFSoftShadowMap = 2;
  19. var FrontSide = 0;
  20. var BackSide = 1;
  21. var DoubleSide = 2;
  22. var FlatShading = 1;
  23. var SmoothShading = 2;
  24. var NoColors = 0;
  25. var FaceColors = 1;
  26. var VertexColors = 2;
  27. var NoBlending = 0;
  28. var NormalBlending = 1;
  29. var AdditiveBlending = 2;
  30. var SubtractiveBlending = 3;
  31. var MultiplyBlending = 4;
  32. var CustomBlending = 5;
  33. var AddEquation = 100;
  34. var SubtractEquation = 101;
  35. var ReverseSubtractEquation = 102;
  36. var MinEquation = 103;
  37. var MaxEquation = 104;
  38. var ZeroFactor = 200;
  39. var OneFactor = 201;
  40. var SrcColorFactor = 202;
  41. var OneMinusSrcColorFactor = 203;
  42. var SrcAlphaFactor = 204;
  43. var OneMinusSrcAlphaFactor = 205;
  44. var DstAlphaFactor = 206;
  45. var OneMinusDstAlphaFactor = 207;
  46. var DstColorFactor = 208;
  47. var OneMinusDstColorFactor = 209;
  48. var SrcAlphaSaturateFactor = 210;
  49. var NeverDepth = 0;
  50. var AlwaysDepth = 1;
  51. var LessDepth = 2;
  52. var LessEqualDepth = 3;
  53. var EqualDepth = 4;
  54. var GreaterEqualDepth = 5;
  55. var GreaterDepth = 6;
  56. var NotEqualDepth = 7;
  57. var MultiplyOperation = 0;
  58. var MixOperation = 1;
  59. var AddOperation = 2;
  60. var NoToneMapping = 0;
  61. var LinearToneMapping = 1;
  62. var ReinhardToneMapping = 2;
  63. var Uncharted2ToneMapping = 3;
  64. var CineonToneMapping = 4;
  65. var UVMapping = 300;
  66. var CubeReflectionMapping = 301;
  67. var CubeRefractionMapping = 302;
  68. var EquirectangularReflectionMapping = 303;
  69. var EquirectangularRefractionMapping = 304;
  70. var SphericalReflectionMapping = 305;
  71. var CubeUVReflectionMapping = 306;
  72. var CubeUVRefractionMapping = 307;
  73. var RepeatWrapping = 1000;
  74. var ClampToEdgeWrapping = 1001;
  75. var MirroredRepeatWrapping = 1002;
  76. var NearestFilter = 1003;
  77. var NearestMipMapNearestFilter = 1004;
  78. var NearestMipMapLinearFilter = 1005;
  79. var LinearFilter = 1006;
  80. var LinearMipMapNearestFilter = 1007;
  81. var LinearMipMapLinearFilter = 1008;
  82. var UnsignedByteType = 1009;
  83. var ByteType = 1010;
  84. var ShortType = 1011;
  85. var UnsignedShortType = 1012;
  86. var IntType = 1013;
  87. var UnsignedIntType = 1014;
  88. var FloatType = 1015;
  89. var HalfFloatType = 1016;
  90. var UnsignedShort4444Type = 1017;
  91. var UnsignedShort5551Type = 1018;
  92. var UnsignedShort565Type = 1019;
  93. var UnsignedInt248Type = 1020;
  94. var AlphaFormat = 1021;
  95. var RGBFormat = 1022;
  96. var RGBAFormat = 1023;
  97. var LuminanceFormat = 1024;
  98. var LuminanceAlphaFormat = 1025;
  99. var RGBEFormat = RGBAFormat;
  100. var DepthFormat = 1026;
  101. var DepthStencilFormat = 1027;
  102. var RGB_S3TC_DXT1_Format = 2001;
  103. var RGBA_S3TC_DXT1_Format = 2002;
  104. var RGBA_S3TC_DXT3_Format = 2003;
  105. var RGBA_S3TC_DXT5_Format = 2004;
  106. var RGB_PVRTC_4BPPV1_Format = 2100;
  107. var RGB_PVRTC_2BPPV1_Format = 2101;
  108. var RGBA_PVRTC_4BPPV1_Format = 2102;
  109. var RGBA_PVRTC_2BPPV1_Format = 2103;
  110. var RGB_ETC1_Format = 2151;
  111. var LoopOnce = 2200;
  112. var LoopRepeat = 2201;
  113. var LoopPingPong = 2202;
  114. var InterpolateDiscrete = 2300;
  115. var InterpolateLinear = 2301;
  116. var InterpolateSmooth = 2302;
  117. var ZeroCurvatureEnding = 2400;
  118. var ZeroSlopeEnding = 2401;
  119. var WrapAroundEnding = 2402;
  120. var TrianglesDrawMode = 0;
  121. var TriangleStripDrawMode = 1;
  122. var TriangleFanDrawMode = 2;
  123. var LinearEncoding = 3000;
  124. var sRGBEncoding = 3001;
  125. var GammaEncoding = 3007;
  126. var RGBEEncoding = 3002;
  127. var LogLuvEncoding = 3003;
  128. var RGBM7Encoding = 3004;
  129. var RGBM16Encoding = 3005;
  130. var RGBDEncoding = 3006;
  131. var BasicDepthPacking = 3200;
  132. var RGBADepthPacking = 3201;
  133. /**
  134. * @author TristanVALCKE / https://github.com/Itee
  135. */
  136. /* global QUnit */
  137. QUnit.module( 'Constants', () => {
  138. QUnit.test( "default values", ( assert ) => {
  139. assert.propEqual( MOUSE, { LEFT: 0, MIDDLE: 1, RIGHT: 2 }, 'MOUSE equal { LEFT: 0, MIDDLE: 1, RIGHT: 2 }' );
  140. assert.equal( CullFaceNone, 0, 'CullFaceNone equal 0' );
  141. assert.equal( CullFaceBack, 1, 'CullFaceBack equal 1' );
  142. assert.equal( CullFaceFront, 2, 'CullFaceFront is equal to 2' );
  143. assert.equal( CullFaceFrontBack, 3, 'CullFaceFrontBack is equal to 3' );
  144. assert.equal( FrontFaceDirectionCW, 0, 'FrontFaceDirectionCW is equal to 0' );
  145. assert.equal( FrontFaceDirectionCCW, 1, 'FrontFaceDirectionCCW is equal to 1' );
  146. assert.equal( BasicShadowMap, 0, 'BasicShadowMap is equal to 0' );
  147. assert.equal( PCFShadowMap, 1, 'PCFShadowMap is equal to 1' );
  148. assert.equal( PCFSoftShadowMap, 2, 'PCFSoftShadowMap is equal to 2' );
  149. assert.equal( FrontSide, 0, 'FrontSide is equal to 0' );
  150. assert.equal( BackSide, 1, 'BackSide is equal to 1' );
  151. assert.equal( DoubleSide, 2, 'DoubleSide is equal to 2' );
  152. assert.equal( FlatShading, 1, 'FlatShading is equal to 1' );
  153. assert.equal( SmoothShading, 2, 'SmoothShading is equal to 2' );
  154. assert.equal( NoColors, 0, 'NoColors is equal to 0' );
  155. assert.equal( FaceColors, 1, 'FaceColors is equal to 1' );
  156. assert.equal( VertexColors, 2, 'VertexColors is equal to 2' );
  157. assert.equal( NoBlending, 0, 'NoBlending is equal to 0' );
  158. assert.equal( NormalBlending, 1, 'NormalBlending is equal to 1' );
  159. assert.equal( AdditiveBlending, 2, 'AdditiveBlending is equal to 2' );
  160. assert.equal( SubtractiveBlending, 3, 'SubtractiveBlending is equal to 3' );
  161. assert.equal( MultiplyBlending, 4, 'MultiplyBlending is equal to 4' );
  162. assert.equal( CustomBlending, 5, 'CustomBlending is equal to 5' );
  163. assert.equal( AddEquation, 100, 'AddEquation is equal to 100' );
  164. assert.equal( SubtractEquation, 101, 'SubtractEquation is equal to 101' );
  165. assert.equal( ReverseSubtractEquation, 102, 'ReverseSubtractEquation is equal to 102' );
  166. assert.equal( MinEquation, 103, 'MinEquation is equal to 103' );
  167. assert.equal( MaxEquation, 104, 'MaxEquation is equal to 104' );
  168. assert.equal( ZeroFactor, 200, 'ZeroFactor is equal to 200' );
  169. assert.equal( OneFactor, 201, 'OneFactor is equal to 201' );
  170. assert.equal( SrcColorFactor, 202, 'SrcColorFactor is equal to 202' );
  171. assert.equal( OneMinusSrcColorFactor, 203, 'OneMinusSrcColorFactor is equal to 203' );
  172. assert.equal( SrcAlphaFactor, 204, 'SrcAlphaFactor is equal to 204' );
  173. assert.equal( OneMinusSrcAlphaFactor, 205, 'OneMinusSrcAlphaFactor is equal to 205' );
  174. assert.equal( DstAlphaFactor, 206, 'DstAlphaFactor is equal to 206' );
  175. assert.equal( OneMinusDstAlphaFactor, 207, 'OneMinusDstAlphaFactor is equal to 207' );
  176. assert.equal( DstColorFactor, 208, 'DstColorFactor is equal to 208' );
  177. assert.equal( OneMinusDstColorFactor, 209, 'OneMinusDstColorFactor is equal to 209' );
  178. assert.equal( SrcAlphaSaturateFactor, 210, 'SrcAlphaSaturateFactor is equal to 210' );
  179. assert.equal( NeverDepth, 0, 'NeverDepth is equal to 0' );
  180. assert.equal( AlwaysDepth, 1, 'AlwaysDepth is equal to 1' );
  181. assert.equal( LessDepth, 2, 'LessDepth is equal to 2' );
  182. assert.equal( LessEqualDepth, 3, 'LessEqualDepth is equal to 3' );
  183. assert.equal( EqualDepth, 4, 'EqualDepth is equal to 4' );
  184. assert.equal( GreaterEqualDepth, 5, 'GreaterEqualDepth is equal to 5' );
  185. assert.equal( GreaterDepth, 6, 'GreaterDepth is equal to 6' );
  186. assert.equal( NotEqualDepth, 7, 'NotEqualDepth is equal to 7' );
  187. assert.equal( MultiplyOperation, 0, 'MultiplyOperation is equal to 0' );
  188. assert.equal( MixOperation, 1, 'MixOperation is equal to 1' );
  189. assert.equal( AddOperation, 2, 'AddOperation is equal to 2' );
  190. assert.equal( NoToneMapping, 0, 'NoToneMapping is equal to 0' );
  191. assert.equal( LinearToneMapping, 1, 'LinearToneMapping is equal to 1' );
  192. assert.equal( ReinhardToneMapping, 2, 'ReinhardToneMapping is equal to 2' );
  193. assert.equal( Uncharted2ToneMapping, 3, 'Uncharted2ToneMapping is equal to 3' );
  194. assert.equal( CineonToneMapping, 4, 'CineonToneMapping is equal to 4' );
  195. assert.equal( UVMapping, 300, 'UVMapping is equal to 300' );
  196. assert.equal( CubeReflectionMapping, 301, 'CubeReflectionMapping is equal to 301' );
  197. assert.equal( CubeRefractionMapping, 302, 'CubeRefractionMapping is equal to 302' );
  198. assert.equal( EquirectangularReflectionMapping, 303, 'EquirectangularReflectionMapping is equal to 303' );
  199. assert.equal( EquirectangularRefractionMapping, 304, 'EquirectangularRefractionMapping is equal to 304' );
  200. assert.equal( SphericalReflectionMapping, 305, 'SphericalReflectionMapping is equal to 305' );
  201. assert.equal( CubeUVReflectionMapping, 306, 'CubeUVReflectionMapping is equal to 306' );
  202. assert.equal( CubeUVRefractionMapping, 307, 'CubeUVRefractionMapping is equal to 307' );
  203. assert.equal( RepeatWrapping, 1000, 'RepeatWrapping is equal to 1000' );
  204. assert.equal( ClampToEdgeWrapping, 1001, 'ClampToEdgeWrapping is equal to 1001' );
  205. assert.equal( MirroredRepeatWrapping, 1002, 'MirroredRepeatWrapping is equal to 1002' );
  206. assert.equal( NearestFilter, 1003, 'NearestFilter is equal to 1003' );
  207. assert.equal( NearestMipMapNearestFilter, 1004, 'NearestMipMapNearestFilter is equal to 1004' );
  208. assert.equal( NearestMipMapLinearFilter, 1005, 'NearestMipMapLinearFilter is equal to 1005' );
  209. assert.equal( LinearFilter, 1006, 'LinearFilter is equal to 1006' );
  210. assert.equal( LinearMipMapNearestFilter, 1007, 'LinearMipMapNearestFilter is equal to 1007' );
  211. assert.equal( LinearMipMapLinearFilter, 1008, 'LinearMipMapLinearFilter is equal to 1008' );
  212. assert.equal( UnsignedByteType, 1009, 'UnsignedByteType is equal to 1009' );
  213. assert.equal( ByteType, 1010, 'ByteType is equal to 1010' );
  214. assert.equal( ShortType, 1011, 'ShortType is equal to 1011' );
  215. assert.equal( UnsignedShortType, 1012, 'UnsignedShortType is equal to 1012' );
  216. assert.equal( IntType, 1013, 'IntType is equal to 1013' );
  217. assert.equal( UnsignedIntType, 1014, 'UnsignedIntType is equal to 1014' );
  218. assert.equal( FloatType, 1015, 'FloatType is equal to 1015' );
  219. assert.equal( HalfFloatType, 1016, 'HalfFloatType is equal to 1016' );
  220. assert.equal( UnsignedShort4444Type, 1017, 'UnsignedShort4444Type is equal to 1017' );
  221. assert.equal( UnsignedShort5551Type, 1018, 'UnsignedShort5551Type is equal to 1018' );
  222. assert.equal( UnsignedShort565Type, 1019, 'UnsignedShort565Type is equal to 1019' );
  223. assert.equal( UnsignedInt248Type, 1020, 'UnsignedInt248Type is equal to 1020' );
  224. assert.equal( AlphaFormat, 1021, 'AlphaFormat is equal to 1021' );
  225. assert.equal( RGBFormat, 1022, 'RGBFormat is equal to 1022' );
  226. assert.equal( RGBAFormat, 1023, 'RGBAFormat is equal to 1023' );
  227. assert.equal( LuminanceFormat, 1024, 'LuminanceFormat is equal to 1024' );
  228. assert.equal( LuminanceAlphaFormat, 1025, 'LuminanceAlphaFormat is equal to 1025' );
  229. assert.equal( RGBEFormat, RGBAFormat, 'RGBEFormat is equal to RGBAFormat' );
  230. assert.equal( DepthFormat, 1026, 'DepthFormat is equal to 1026' );
  231. assert.equal( DepthStencilFormat, 1027, 'DepthStencilFormat is equal to 1027' );
  232. assert.equal( RGB_S3TC_DXT1_Format, 2001, 'RGB_S3TC_DXT1_Format is equal to 2001' );
  233. assert.equal( RGBA_S3TC_DXT1_Format, 2002, 'RGBA_S3TC_DXT1_Format is equal to 2002' );
  234. assert.equal( RGBA_S3TC_DXT3_Format, 2003, 'RGBA_S3TC_DXT3_Format is equal to 2003' );
  235. assert.equal( RGBA_S3TC_DXT5_Format, 2004, 'RGBA_S3TC_DXT5_Format is equal to 2004' );
  236. assert.equal( RGB_PVRTC_4BPPV1_Format, 2100, 'RGB_PVRTC_4BPPV1_Format is equal to 2100' );
  237. assert.equal( RGB_PVRTC_2BPPV1_Format, 2101, 'RGB_PVRTC_2BPPV1_Format is equal to 2101' );
  238. assert.equal( RGBA_PVRTC_4BPPV1_Format, 2102, 'RGBA_PVRTC_4BPPV1_Format is equal to 2102' );
  239. assert.equal( RGBA_PVRTC_2BPPV1_Format, 2103, 'RGBA_PVRTC_2BPPV1_Format is equal to 2103' );
  240. assert.equal( RGB_ETC1_Format, 2151, 'RGB_ETC1_Format is equal to 2151' );
  241. assert.equal( LoopOnce, 2200, 'LoopOnce is equal to 2200' );
  242. assert.equal( LoopRepeat, 2201, 'LoopRepeat is equal to 2201' );
  243. assert.equal( LoopPingPong, 2202, 'LoopPingPong is equal to 2202' );
  244. assert.equal( InterpolateDiscrete, 2300, 'InterpolateDiscrete is equal to 2300' );
  245. assert.equal( InterpolateLinear, 2301, 'InterpolateLinear is equal to 2301' );
  246. assert.equal( InterpolateSmooth, 2302, 'InterpolateSmooth is equal to 2302' );
  247. assert.equal( ZeroCurvatureEnding, 2400, 'ZeroCurvatureEnding is equal to 2400' );
  248. assert.equal( ZeroSlopeEnding, 2401, 'ZeroSlopeEnding is equal to 2401' );
  249. assert.equal( WrapAroundEnding, 2402, 'WrapAroundEnding is equal to 2402' );
  250. assert.equal( TrianglesDrawMode, 0, 'TrianglesDrawMode is equal to 0' );
  251. assert.equal( TriangleStripDrawMode, 1, 'TriangleStripDrawMode is equal to 1' );
  252. assert.equal( TriangleFanDrawMode, 2, 'TriangleFanDrawMode is equal to 2' );
  253. assert.equal( LinearEncoding, 3000, 'LinearEncoding is equal to 3000' );
  254. assert.equal( sRGBEncoding, 3001, 'sRGBEncoding is equal to 3001' );
  255. assert.equal( GammaEncoding, 3007, 'GammaEncoding is equal to 3007' );
  256. assert.equal( RGBEEncoding, 3002, 'RGBEEncoding is equal to 3002' );
  257. assert.equal( LogLuvEncoding, 3003, 'LogLuvEncoding is equal to 3003' );
  258. assert.equal( RGBM7Encoding, 3004, 'RGBM7Encoding is equal to 3004' );
  259. assert.equal( RGBM16Encoding, 3005, 'RGBM16Encoding is equal to 3005' );
  260. assert.equal( RGBDEncoding, 3006, 'RGBDEncoding is equal to 3006' );
  261. assert.equal( BasicDepthPacking, 3200, 'BasicDepthPacking is equal to 3200' );
  262. assert.equal( RGBADepthPacking, 3201, 'RGBADepthPacking is equal to 3201' );
  263. } );
  264. } );
  265. // Polyfills
  266. if ( Number.EPSILON === undefined ) {
  267. Number.EPSILON = Math.pow( 2, - 52 );
  268. }
  269. if ( Number.isInteger === undefined ) {
  270. // Missing in IE
  271. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger
  272. Number.isInteger = function ( value ) {
  273. return typeof value === 'number' && isFinite( value ) && Math.floor( value ) === value;
  274. };
  275. }
  276. //
  277. if ( Math.sign === undefined ) {
  278. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  279. Math.sign = function ( x ) {
  280. return ( x < 0 ) ? - 1 : ( x > 0 ) ? 1 : + x;
  281. };
  282. }
  283. if ( 'name' in Function.prototype === false ) {
  284. // Missing in IE
  285. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
  286. Object.defineProperty( Function.prototype, 'name', {
  287. get: function () {
  288. return this.toString().match( /^\s*function\s*([^\(\s]*)/ )[ 1 ];
  289. }
  290. } );
  291. }
  292. if ( Object.assign === undefined ) {
  293. // Missing in IE
  294. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
  295. ( function () {
  296. Object.assign = function ( target ) {
  297. 'use strict';
  298. if ( target === undefined || target === null ) {
  299. throw new TypeError( 'Cannot convert undefined or null to object' );
  300. }
  301. var output = Object( target );
  302. for ( var index = 1; index < arguments.length; index ++ ) {
  303. var source = arguments[ index ];
  304. if ( source !== undefined && source !== null ) {
  305. for ( var nextKey in source ) {
  306. if ( Object.prototype.hasOwnProperty.call( source, nextKey ) ) {
  307. output[ nextKey ] = source[ nextKey ];
  308. }
  309. }
  310. }
  311. }
  312. return output;
  313. };
  314. } )();
  315. }
  316. /**
  317. * @author alteredq / http://alteredqualia.com/
  318. * @author mrdoob / http://mrdoob.com/
  319. */
  320. var _Math = {
  321. DEG2RAD: Math.PI / 180,
  322. RAD2DEG: 180 / Math.PI,
  323. generateUUID: function () {
  324. // http://www.broofa.com/Tools/Math.uuid.htm
  325. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split( '' );
  326. var uuid = new Array( 36 );
  327. var rnd = 0, r;
  328. return function generateUUID() {
  329. for ( var i = 0; i < 36; i ++ ) {
  330. if ( i === 8 || i === 13 || i === 18 || i === 23 ) {
  331. uuid[ i ] = '-';
  332. } else if ( i === 14 ) {
  333. uuid[ i ] = '4';
  334. } else {
  335. if ( rnd <= 0x02 ) rnd = 0x2000000 + ( Math.random() * 0x1000000 ) | 0;
  336. r = rnd & 0xf;
  337. rnd = rnd >> 4;
  338. uuid[ i ] = chars[ ( i === 19 ) ? ( r & 0x3 ) | 0x8 : r ];
  339. }
  340. }
  341. return uuid.join( '' );
  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. /**
  402. * @author mrdoob / http://mrdoob.com/
  403. * @author supereggbert / http://www.paulbrunt.co.uk/
  404. * @author philogb / http://blog.thejit.org/
  405. * @author jordi_ros / http://plattsoft.com
  406. * @author D1plo1d / http://github.com/D1plo1d
  407. * @author alteredq / http://alteredqualia.com/
  408. * @author mikael emtinger / http://gomo.se/
  409. * @author timknip / http://www.floorplanner.com/
  410. * @author bhouston / http://clara.io
  411. * @author WestLangley / http://github.com/WestLangley
  412. */
  413. function Matrix4() {
  414. this.elements = [
  415. 1, 0, 0, 0,
  416. 0, 1, 0, 0,
  417. 0, 0, 1, 0,
  418. 0, 0, 0, 1
  419. ];
  420. if ( arguments.length > 0 ) {
  421. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  422. }
  423. }
  424. Object.assign( Matrix4.prototype, {
  425. isMatrix4: true,
  426. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  427. var te = this.elements;
  428. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  429. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  430. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  431. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  432. return this;
  433. },
  434. identity: function () {
  435. this.set(
  436. 1, 0, 0, 0,
  437. 0, 1, 0, 0,
  438. 0, 0, 1, 0,
  439. 0, 0, 0, 1
  440. );
  441. return this;
  442. },
  443. clone: function () {
  444. return new Matrix4().fromArray( this.elements );
  445. },
  446. copy: function ( m ) {
  447. var te = this.elements;
  448. var me = m.elements;
  449. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ]; te[ 3 ] = me[ 3 ];
  450. te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ]; te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ];
  451. te[ 8 ] = me[ 8 ]; te[ 9 ] = me[ 9 ]; te[ 10 ] = me[ 10 ]; te[ 11 ] = me[ 11 ];
  452. te[ 12 ] = me[ 12 ]; te[ 13 ] = me[ 13 ]; te[ 14 ] = me[ 14 ]; te[ 15 ] = me[ 15 ];
  453. return this;
  454. },
  455. copyPosition: function ( m ) {
  456. var te = this.elements, me = m.elements;
  457. te[ 12 ] = me[ 12 ];
  458. te[ 13 ] = me[ 13 ];
  459. te[ 14 ] = me[ 14 ];
  460. return this;
  461. },
  462. extractBasis: function ( xAxis, yAxis, zAxis ) {
  463. xAxis.setFromMatrixColumn( this, 0 );
  464. yAxis.setFromMatrixColumn( this, 1 );
  465. zAxis.setFromMatrixColumn( this, 2 );
  466. return this;
  467. },
  468. makeBasis: function ( xAxis, yAxis, zAxis ) {
  469. this.set(
  470. xAxis.x, yAxis.x, zAxis.x, 0,
  471. xAxis.y, yAxis.y, zAxis.y, 0,
  472. xAxis.z, yAxis.z, zAxis.z, 0,
  473. 0, 0, 0, 1
  474. );
  475. return this;
  476. },
  477. extractRotation: function () {
  478. var v1 = new Vector3();
  479. return function extractRotation( m ) {
  480. var te = this.elements;
  481. var me = m.elements;
  482. var scaleX = 1 / v1.setFromMatrixColumn( m, 0 ).length();
  483. var scaleY = 1 / v1.setFromMatrixColumn( m, 1 ).length();
  484. var scaleZ = 1 / v1.setFromMatrixColumn( m, 2 ).length();
  485. te[ 0 ] = me[ 0 ] * scaleX;
  486. te[ 1 ] = me[ 1 ] * scaleX;
  487. te[ 2 ] = me[ 2 ] * scaleX;
  488. te[ 4 ] = me[ 4 ] * scaleY;
  489. te[ 5 ] = me[ 5 ] * scaleY;
  490. te[ 6 ] = me[ 6 ] * scaleY;
  491. te[ 8 ] = me[ 8 ] * scaleZ;
  492. te[ 9 ] = me[ 9 ] * scaleZ;
  493. te[ 10 ] = me[ 10 ] * scaleZ;
  494. return this;
  495. };
  496. }(),
  497. makeRotationFromEuler: function ( euler ) {
  498. if ( ! ( euler && euler.isEuler ) ) {
  499. console.error( 'THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  500. }
  501. var te = this.elements;
  502. var x = euler.x, y = euler.y, z = euler.z;
  503. var a = Math.cos( x ), b = Math.sin( x );
  504. var c = Math.cos( y ), d = Math.sin( y );
  505. var e = Math.cos( z ), f = Math.sin( z );
  506. if ( euler.order === 'XYZ' ) {
  507. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  508. te[ 0 ] = c * e;
  509. te[ 4 ] = - c * f;
  510. te[ 8 ] = d;
  511. te[ 1 ] = af + be * d;
  512. te[ 5 ] = ae - bf * d;
  513. te[ 9 ] = - b * c;
  514. te[ 2 ] = bf - ae * d;
  515. te[ 6 ] = be + af * d;
  516. te[ 10 ] = a * c;
  517. } else if ( euler.order === 'YXZ' ) {
  518. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  519. te[ 0 ] = ce + df * b;
  520. te[ 4 ] = de * b - cf;
  521. te[ 8 ] = a * d;
  522. te[ 1 ] = a * f;
  523. te[ 5 ] = a * e;
  524. te[ 9 ] = - b;
  525. te[ 2 ] = cf * b - de;
  526. te[ 6 ] = df + ce * b;
  527. te[ 10 ] = a * c;
  528. } else if ( euler.order === 'ZXY' ) {
  529. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  530. te[ 0 ] = ce - df * b;
  531. te[ 4 ] = - a * f;
  532. te[ 8 ] = de + cf * b;
  533. te[ 1 ] = cf + de * b;
  534. te[ 5 ] = a * e;
  535. te[ 9 ] = df - ce * b;
  536. te[ 2 ] = - a * d;
  537. te[ 6 ] = b;
  538. te[ 10 ] = a * c;
  539. } else if ( euler.order === 'ZYX' ) {
  540. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  541. te[ 0 ] = c * e;
  542. te[ 4 ] = be * d - af;
  543. te[ 8 ] = ae * d + bf;
  544. te[ 1 ] = c * f;
  545. te[ 5 ] = bf * d + ae;
  546. te[ 9 ] = af * d - be;
  547. te[ 2 ] = - d;
  548. te[ 6 ] = b * c;
  549. te[ 10 ] = a * c;
  550. } else if ( euler.order === 'YZX' ) {
  551. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  552. te[ 0 ] = c * e;
  553. te[ 4 ] = bd - ac * f;
  554. te[ 8 ] = bc * f + ad;
  555. te[ 1 ] = f;
  556. te[ 5 ] = a * e;
  557. te[ 9 ] = - b * e;
  558. te[ 2 ] = - d * e;
  559. te[ 6 ] = ad * f + bc;
  560. te[ 10 ] = ac - bd * f;
  561. } else if ( euler.order === 'XZY' ) {
  562. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  563. te[ 0 ] = c * e;
  564. te[ 4 ] = - f;
  565. te[ 8 ] = d * e;
  566. te[ 1 ] = ac * f + bd;
  567. te[ 5 ] = a * e;
  568. te[ 9 ] = ad * f - bc;
  569. te[ 2 ] = bc * f - ad;
  570. te[ 6 ] = b * e;
  571. te[ 10 ] = bd * f + ac;
  572. }
  573. // last column
  574. te[ 3 ] = 0;
  575. te[ 7 ] = 0;
  576. te[ 11 ] = 0;
  577. // bottom row
  578. te[ 12 ] = 0;
  579. te[ 13 ] = 0;
  580. te[ 14 ] = 0;
  581. te[ 15 ] = 1;
  582. return this;
  583. },
  584. makeRotationFromQuaternion: function ( q ) {
  585. var te = this.elements;
  586. var x = q._x, y = q._y, z = q._z, w = q._w;
  587. var x2 = x + x, y2 = y + y, z2 = z + z;
  588. var xx = x * x2, xy = x * y2, xz = x * z2;
  589. var yy = y * y2, yz = y * z2, zz = z * z2;
  590. var wx = w * x2, wy = w * y2, wz = w * z2;
  591. te[ 0 ] = 1 - ( yy + zz );
  592. te[ 4 ] = xy - wz;
  593. te[ 8 ] = xz + wy;
  594. te[ 1 ] = xy + wz;
  595. te[ 5 ] = 1 - ( xx + zz );
  596. te[ 9 ] = yz - wx;
  597. te[ 2 ] = xz - wy;
  598. te[ 6 ] = yz + wx;
  599. te[ 10 ] = 1 - ( xx + yy );
  600. // last column
  601. te[ 3 ] = 0;
  602. te[ 7 ] = 0;
  603. te[ 11 ] = 0;
  604. // bottom row
  605. te[ 12 ] = 0;
  606. te[ 13 ] = 0;
  607. te[ 14 ] = 0;
  608. te[ 15 ] = 1;
  609. return this;
  610. },
  611. lookAt: function () {
  612. var x = new Vector3();
  613. var y = new Vector3();
  614. var z = new Vector3();
  615. return function lookAt( eye, target, up ) {
  616. var te = this.elements;
  617. z.subVectors( eye, target );
  618. if ( z.lengthSq() === 0 ) {
  619. // eye and target are in the same position
  620. z.z = 1;
  621. }
  622. z.normalize();
  623. x.crossVectors( up, z );
  624. if ( x.lengthSq() === 0 ) {
  625. // up and z are parallel
  626. if ( Math.abs( up.z ) === 1 ) {
  627. z.x += 0.0001;
  628. } else {
  629. z.z += 0.0001;
  630. }
  631. z.normalize();
  632. x.crossVectors( up, z );
  633. }
  634. x.normalize();
  635. y.crossVectors( z, x );
  636. te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
  637. te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
  638. te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
  639. return this;
  640. };
  641. }(),
  642. multiply: function ( m, n ) {
  643. if ( n !== undefined ) {
  644. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  645. return this.multiplyMatrices( m, n );
  646. }
  647. return this.multiplyMatrices( this, m );
  648. },
  649. premultiply: function ( m ) {
  650. return this.multiplyMatrices( m, this );
  651. },
  652. multiplyMatrices: function ( a, b ) {
  653. var ae = a.elements;
  654. var be = b.elements;
  655. var te = this.elements;
  656. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  657. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  658. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  659. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  660. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  661. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  662. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  663. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  664. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  665. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  666. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  667. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  668. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  669. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  670. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  671. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  672. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  673. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  674. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  675. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  676. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  677. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  678. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  679. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  680. return this;
  681. },
  682. multiplyScalar: function ( s ) {
  683. var te = this.elements;
  684. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  685. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  686. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  687. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  688. return this;
  689. },
  690. applyToBufferAttribute: function () {
  691. var v1 = new Vector3();
  692. return function applyToBufferAttribute( attribute ) {
  693. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  694. v1.x = attribute.getX( i );
  695. v1.y = attribute.getY( i );
  696. v1.z = attribute.getZ( i );
  697. v1.applyMatrix4( this );
  698. attribute.setXYZ( i, v1.x, v1.y, v1.z );
  699. }
  700. return attribute;
  701. };
  702. }(),
  703. determinant: function () {
  704. var te = this.elements;
  705. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  706. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  707. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  708. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  709. //TODO: make this more efficient
  710. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  711. return (
  712. n41 * (
  713. + n14 * n23 * n32
  714. - n13 * n24 * n32
  715. - n14 * n22 * n33
  716. + n12 * n24 * n33
  717. + n13 * n22 * n34
  718. - n12 * n23 * n34
  719. ) +
  720. n42 * (
  721. + n11 * n23 * n34
  722. - n11 * n24 * n33
  723. + n14 * n21 * n33
  724. - n13 * n21 * n34
  725. + n13 * n24 * n31
  726. - n14 * n23 * n31
  727. ) +
  728. n43 * (
  729. + n11 * n24 * n32
  730. - n11 * n22 * n34
  731. - n14 * n21 * n32
  732. + n12 * n21 * n34
  733. + n14 * n22 * n31
  734. - n12 * n24 * n31
  735. ) +
  736. n44 * (
  737. - n13 * n22 * n31
  738. - n11 * n23 * n32
  739. + n11 * n22 * n33
  740. + n13 * n21 * n32
  741. - n12 * n21 * n33
  742. + n12 * n23 * n31
  743. )
  744. );
  745. },
  746. transpose: function () {
  747. var te = this.elements;
  748. var tmp;
  749. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  750. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  751. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  752. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  753. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  754. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  755. return this;
  756. },
  757. setPosition: function ( v ) {
  758. var te = this.elements;
  759. te[ 12 ] = v.x;
  760. te[ 13 ] = v.y;
  761. te[ 14 ] = v.z;
  762. return this;
  763. },
  764. getInverse: function ( m, throwOnDegenerate ) {
  765. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  766. var te = this.elements,
  767. me = m.elements,
  768. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ], n41 = me[ 3 ],
  769. n12 = me[ 4 ], n22 = me[ 5 ], n32 = me[ 6 ], n42 = me[ 7 ],
  770. n13 = me[ 8 ], n23 = me[ 9 ], n33 = me[ 10 ], n43 = me[ 11 ],
  771. n14 = me[ 12 ], n24 = me[ 13 ], n34 = me[ 14 ], n44 = me[ 15 ],
  772. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  773. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  774. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  775. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  776. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  777. if ( det === 0 ) {
  778. var msg = "THREE.Matrix4: .getInverse() can't invert matrix, determinant is 0";
  779. if ( throwOnDegenerate === true ) {
  780. throw new Error( msg );
  781. } else {
  782. console.warn( msg );
  783. }
  784. return this.identity();
  785. }
  786. var detInv = 1 / det;
  787. te[ 0 ] = t11 * detInv;
  788. te[ 1 ] = ( n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44 ) * detInv;
  789. te[ 2 ] = ( n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44 ) * detInv;
  790. te[ 3 ] = ( n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43 ) * detInv;
  791. te[ 4 ] = t12 * detInv;
  792. te[ 5 ] = ( n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44 ) * detInv;
  793. te[ 6 ] = ( n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44 ) * detInv;
  794. te[ 7 ] = ( n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43 ) * detInv;
  795. te[ 8 ] = t13 * detInv;
  796. te[ 9 ] = ( n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44 ) * detInv;
  797. te[ 10 ] = ( n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44 ) * detInv;
  798. te[ 11 ] = ( n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43 ) * detInv;
  799. te[ 12 ] = t14 * detInv;
  800. te[ 13 ] = ( n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34 ) * detInv;
  801. te[ 14 ] = ( n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34 ) * detInv;
  802. te[ 15 ] = ( n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33 ) * detInv;
  803. return this;
  804. },
  805. scale: function ( v ) {
  806. var te = this.elements;
  807. var x = v.x, y = v.y, z = v.z;
  808. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  809. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  810. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  811. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  812. return this;
  813. },
  814. getMaxScaleOnAxis: function () {
  815. var te = this.elements;
  816. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  817. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  818. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  819. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  820. },
  821. makeTranslation: function ( x, y, z ) {
  822. this.set(
  823. 1, 0, 0, x,
  824. 0, 1, 0, y,
  825. 0, 0, 1, z,
  826. 0, 0, 0, 1
  827. );
  828. return this;
  829. },
  830. makeRotationX: function ( theta ) {
  831. var c = Math.cos( theta ), s = Math.sin( theta );
  832. this.set(
  833. 1, 0, 0, 0,
  834. 0, c, - s, 0,
  835. 0, s, c, 0,
  836. 0, 0, 0, 1
  837. );
  838. return this;
  839. },
  840. makeRotationY: function ( theta ) {
  841. var c = Math.cos( theta ), s = Math.sin( theta );
  842. this.set(
  843. c, 0, s, 0,
  844. 0, 1, 0, 0,
  845. - s, 0, c, 0,
  846. 0, 0, 0, 1
  847. );
  848. return this;
  849. },
  850. makeRotationZ: function ( theta ) {
  851. var c = Math.cos( theta ), s = Math.sin( theta );
  852. this.set(
  853. c, - s, 0, 0,
  854. s, c, 0, 0,
  855. 0, 0, 1, 0,
  856. 0, 0, 0, 1
  857. );
  858. return this;
  859. },
  860. makeRotationAxis: function ( axis, angle ) {
  861. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  862. var c = Math.cos( angle );
  863. var s = Math.sin( angle );
  864. var t = 1 - c;
  865. var x = axis.x, y = axis.y, z = axis.z;
  866. var tx = t * x, ty = t * y;
  867. this.set(
  868. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  869. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  870. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  871. 0, 0, 0, 1
  872. );
  873. return this;
  874. },
  875. makeScale: function ( x, y, z ) {
  876. this.set(
  877. x, 0, 0, 0,
  878. 0, y, 0, 0,
  879. 0, 0, z, 0,
  880. 0, 0, 0, 1
  881. );
  882. return this;
  883. },
  884. makeShear: function ( x, y, z ) {
  885. this.set(
  886. 1, y, z, 0,
  887. x, 1, z, 0,
  888. x, y, 1, 0,
  889. 0, 0, 0, 1
  890. );
  891. return this;
  892. },
  893. compose: function ( position, quaternion, scale ) {
  894. this.makeRotationFromQuaternion( quaternion );
  895. this.scale( scale );
  896. this.setPosition( position );
  897. return this;
  898. },
  899. decompose: function () {
  900. var vector = new Vector3();
  901. var matrix = new Matrix4();
  902. return function decompose( position, quaternion, scale ) {
  903. var te = this.elements;
  904. var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  905. var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  906. var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  907. // if determine is negative, we need to invert one scale
  908. var det = this.determinant();
  909. if ( det < 0 ) sx = - sx;
  910. position.x = te[ 12 ];
  911. position.y = te[ 13 ];
  912. position.z = te[ 14 ];
  913. // scale the rotation part
  914. matrix.copy( this );
  915. var invSX = 1 / sx;
  916. var invSY = 1 / sy;
  917. var invSZ = 1 / sz;
  918. matrix.elements[ 0 ] *= invSX;
  919. matrix.elements[ 1 ] *= invSX;
  920. matrix.elements[ 2 ] *= invSX;
  921. matrix.elements[ 4 ] *= invSY;
  922. matrix.elements[ 5 ] *= invSY;
  923. matrix.elements[ 6 ] *= invSY;
  924. matrix.elements[ 8 ] *= invSZ;
  925. matrix.elements[ 9 ] *= invSZ;
  926. matrix.elements[ 10 ] *= invSZ;
  927. quaternion.setFromRotationMatrix( matrix );
  928. scale.x = sx;
  929. scale.y = sy;
  930. scale.z = sz;
  931. return this;
  932. };
  933. }(),
  934. makePerspective: function ( left, right, top, bottom, near, far ) {
  935. if ( far === undefined ) {
  936. console.warn( 'THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.' );
  937. }
  938. var te = this.elements;
  939. var x = 2 * near / ( right - left );
  940. var y = 2 * near / ( top - bottom );
  941. var a = ( right + left ) / ( right - left );
  942. var b = ( top + bottom ) / ( top - bottom );
  943. var c = - ( far + near ) / ( far - near );
  944. var d = - 2 * far * near / ( far - near );
  945. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  946. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  947. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  948. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  949. return this;
  950. },
  951. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  952. var te = this.elements;
  953. var w = 1.0 / ( right - left );
  954. var h = 1.0 / ( top - bottom );
  955. var p = 1.0 / ( far - near );
  956. var x = ( right + left ) * w;
  957. var y = ( top + bottom ) * h;
  958. var z = ( far + near ) * p;
  959. te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  960. te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y;
  961. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 * p; te[ 14 ] = - z;
  962. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  963. return this;
  964. },
  965. equals: function ( matrix ) {
  966. var te = this.elements;
  967. var me = matrix.elements;
  968. for ( var i = 0; i < 16; i ++ ) {
  969. if ( te[ i ] !== me[ i ] ) return false;
  970. }
  971. return true;
  972. },
  973. fromArray: function ( array, offset ) {
  974. if ( offset === undefined ) offset = 0;
  975. for ( var i = 0; i < 16; i ++ ) {
  976. this.elements[ i ] = array[ i + offset ];
  977. }
  978. return this;
  979. },
  980. toArray: function ( array, offset ) {
  981. if ( array === undefined ) array = [];
  982. if ( offset === undefined ) offset = 0;
  983. var te = this.elements;
  984. array[ offset ] = te[ 0 ];
  985. array[ offset + 1 ] = te[ 1 ];
  986. array[ offset + 2 ] = te[ 2 ];
  987. array[ offset + 3 ] = te[ 3 ];
  988. array[ offset + 4 ] = te[ 4 ];
  989. array[ offset + 5 ] = te[ 5 ];
  990. array[ offset + 6 ] = te[ 6 ];
  991. array[ offset + 7 ] = te[ 7 ];
  992. array[ offset + 8 ] = te[ 8 ];
  993. array[ offset + 9 ] = te[ 9 ];
  994. array[ offset + 10 ] = te[ 10 ];
  995. array[ offset + 11 ] = te[ 11 ];
  996. array[ offset + 12 ] = te[ 12 ];
  997. array[ offset + 13 ] = te[ 13 ];
  998. array[ offset + 14 ] = te[ 14 ];
  999. array[ offset + 15 ] = te[ 15 ];
  1000. return array;
  1001. }
  1002. } );
  1003. /**
  1004. * @author mikael emtinger / http://gomo.se/
  1005. * @author alteredq / http://alteredqualia.com/
  1006. * @author WestLangley / http://github.com/WestLangley
  1007. * @author bhouston / http://clara.io
  1008. */
  1009. function Quaternion( x, y, z, w ) {
  1010. this._x = x || 0;
  1011. this._y = y || 0;
  1012. this._z = z || 0;
  1013. this._w = ( w !== undefined ) ? w : 1;
  1014. }
  1015. Object.assign( Quaternion, {
  1016. slerp: function ( qa, qb, qm, t ) {
  1017. return qm.copy( qa ).slerp( qb, t );
  1018. },
  1019. slerpFlat: function ( dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {
  1020. // fuzz-free, array-based Quaternion SLERP operation
  1021. var x0 = src0[ srcOffset0 + 0 ],
  1022. y0 = src0[ srcOffset0 + 1 ],
  1023. z0 = src0[ srcOffset0 + 2 ],
  1024. w0 = src0[ srcOffset0 + 3 ],
  1025. x1 = src1[ srcOffset1 + 0 ],
  1026. y1 = src1[ srcOffset1 + 1 ],
  1027. z1 = src1[ srcOffset1 + 2 ],
  1028. w1 = src1[ srcOffset1 + 3 ];
  1029. if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {
  1030. var s = 1 - t,
  1031. cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  1032. dir = ( cos >= 0 ? 1 : - 1 ),
  1033. sqrSin = 1 - cos * cos;
  1034. // Skip the Slerp for tiny steps to avoid numeric problems:
  1035. if ( sqrSin > Number.EPSILON ) {
  1036. var sin = Math.sqrt( sqrSin ),
  1037. len = Math.atan2( sin, cos * dir );
  1038. s = Math.sin( s * len ) / sin;
  1039. t = Math.sin( t * len ) / sin;
  1040. }
  1041. var tDir = t * dir;
  1042. x0 = x0 * s + x1 * tDir;
  1043. y0 = y0 * s + y1 * tDir;
  1044. z0 = z0 * s + z1 * tDir;
  1045. w0 = w0 * s + w1 * tDir;
  1046. // Normalize in case we just did a lerp:
  1047. if ( s === 1 - t ) {
  1048. var f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 );
  1049. x0 *= f;
  1050. y0 *= f;
  1051. z0 *= f;
  1052. w0 *= f;
  1053. }
  1054. }
  1055. dst[ dstOffset ] = x0;
  1056. dst[ dstOffset + 1 ] = y0;
  1057. dst[ dstOffset + 2 ] = z0;
  1058. dst[ dstOffset + 3 ] = w0;
  1059. }
  1060. } );
  1061. Object.defineProperties( Quaternion.prototype, {
  1062. x: {
  1063. get: function () {
  1064. return this._x;
  1065. },
  1066. set: function ( value ) {
  1067. this._x = value;
  1068. this.onChangeCallback();
  1069. }
  1070. },
  1071. y: {
  1072. get: function () {
  1073. return this._y;
  1074. },
  1075. set: function ( value ) {
  1076. this._y = value;
  1077. this.onChangeCallback();
  1078. }
  1079. },
  1080. z: {
  1081. get: function () {
  1082. return this._z;
  1083. },
  1084. set: function ( value ) {
  1085. this._z = value;
  1086. this.onChangeCallback();
  1087. }
  1088. },
  1089. w: {
  1090. get: function () {
  1091. return this._w;
  1092. },
  1093. set: function ( value ) {
  1094. this._w = value;
  1095. this.onChangeCallback();
  1096. }
  1097. }
  1098. } );
  1099. Object.assign( Quaternion.prototype, {
  1100. set: function ( x, y, z, w ) {
  1101. this._x = x;
  1102. this._y = y;
  1103. this._z = z;
  1104. this._w = w;
  1105. this.onChangeCallback();
  1106. return this;
  1107. },
  1108. clone: function () {
  1109. return new this.constructor( this._x, this._y, this._z, this._w );
  1110. },
  1111. copy: function ( quaternion ) {
  1112. this._x = quaternion.x;
  1113. this._y = quaternion.y;
  1114. this._z = quaternion.z;
  1115. this._w = quaternion.w;
  1116. this.onChangeCallback();
  1117. return this;
  1118. },
  1119. setFromEuler: function ( euler, update ) {
  1120. if ( ! ( euler && euler.isEuler ) ) {
  1121. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1122. }
  1123. var x = euler._x, y = euler._y, z = euler._z, order = euler.order;
  1124. // http://www.mathworks.com/matlabcentral/fileexchange/
  1125. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  1126. // content/SpinCalc.m
  1127. var cos = Math.cos;
  1128. var sin = Math.sin;
  1129. var c1 = cos( x / 2 );
  1130. var c2 = cos( y / 2 );
  1131. var c3 = cos( z / 2 );
  1132. var s1 = sin( x / 2 );
  1133. var s2 = sin( y / 2 );
  1134. var s3 = sin( z / 2 );
  1135. if ( order === 'XYZ' ) {
  1136. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1137. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1138. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1139. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1140. } else if ( order === 'YXZ' ) {
  1141. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1142. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1143. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1144. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1145. } else if ( order === 'ZXY' ) {
  1146. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1147. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1148. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1149. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1150. } else if ( order === 'ZYX' ) {
  1151. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1152. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1153. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1154. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1155. } else if ( order === 'YZX' ) {
  1156. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1157. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1158. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1159. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1160. } else if ( order === 'XZY' ) {
  1161. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1162. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1163. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1164. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1165. }
  1166. if ( update !== false ) this.onChangeCallback();
  1167. return this;
  1168. },
  1169. setFromAxisAngle: function ( axis, angle ) {
  1170. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  1171. // assumes axis is normalized
  1172. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  1173. this._x = axis.x * s;
  1174. this._y = axis.y * s;
  1175. this._z = axis.z * s;
  1176. this._w = Math.cos( halfAngle );
  1177. this.onChangeCallback();
  1178. return this;
  1179. },
  1180. setFromRotationMatrix: function ( m ) {
  1181. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  1182. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1183. var te = m.elements,
  1184. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1185. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1186. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  1187. trace = m11 + m22 + m33,
  1188. s;
  1189. if ( trace > 0 ) {
  1190. s = 0.5 / Math.sqrt( trace + 1.0 );
  1191. this._w = 0.25 / s;
  1192. this._x = ( m32 - m23 ) * s;
  1193. this._y = ( m13 - m31 ) * s;
  1194. this._z = ( m21 - m12 ) * s;
  1195. } else if ( m11 > m22 && m11 > m33 ) {
  1196. s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  1197. this._w = ( m32 - m23 ) / s;
  1198. this._x = 0.25 * s;
  1199. this._y = ( m12 + m21 ) / s;
  1200. this._z = ( m13 + m31 ) / s;
  1201. } else if ( m22 > m33 ) {
  1202. s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  1203. this._w = ( m13 - m31 ) / s;
  1204. this._x = ( m12 + m21 ) / s;
  1205. this._y = 0.25 * s;
  1206. this._z = ( m23 + m32 ) / s;
  1207. } else {
  1208. s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  1209. this._w = ( m21 - m12 ) / s;
  1210. this._x = ( m13 + m31 ) / s;
  1211. this._y = ( m23 + m32 ) / s;
  1212. this._z = 0.25 * s;
  1213. }
  1214. this.onChangeCallback();
  1215. return this;
  1216. },
  1217. setFromUnitVectors: function () {
  1218. // assumes direction vectors vFrom and vTo are normalized
  1219. var v1 = new Vector3();
  1220. var r;
  1221. var EPS = 0.000001;
  1222. return function setFromUnitVectors( vFrom, vTo ) {
  1223. if ( v1 === undefined ) v1 = new Vector3();
  1224. r = vFrom.dot( vTo ) + 1;
  1225. if ( r < EPS ) {
  1226. r = 0;
  1227. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  1228. v1.set( - vFrom.y, vFrom.x, 0 );
  1229. } else {
  1230. v1.set( 0, - vFrom.z, vFrom.y );
  1231. }
  1232. } else {
  1233. v1.crossVectors( vFrom, vTo );
  1234. }
  1235. this._x = v1.x;
  1236. this._y = v1.y;
  1237. this._z = v1.z;
  1238. this._w = r;
  1239. return this.normalize();
  1240. };
  1241. }(),
  1242. inverse: function () {
  1243. return this.conjugate().normalize();
  1244. },
  1245. conjugate: function () {
  1246. this._x *= - 1;
  1247. this._y *= - 1;
  1248. this._z *= - 1;
  1249. this.onChangeCallback();
  1250. return this;
  1251. },
  1252. dot: function ( v ) {
  1253. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  1254. },
  1255. lengthSq: function () {
  1256. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  1257. },
  1258. length: function () {
  1259. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  1260. },
  1261. normalize: function () {
  1262. var l = this.length();
  1263. if ( l === 0 ) {
  1264. this._x = 0;
  1265. this._y = 0;
  1266. this._z = 0;
  1267. this._w = 1;
  1268. } else {
  1269. l = 1 / l;
  1270. this._x = this._x * l;
  1271. this._y = this._y * l;
  1272. this._z = this._z * l;
  1273. this._w = this._w * l;
  1274. }
  1275. this.onChangeCallback();
  1276. return this;
  1277. },
  1278. multiply: function ( q, p ) {
  1279. if ( p !== undefined ) {
  1280. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  1281. return this.multiplyQuaternions( q, p );
  1282. }
  1283. return this.multiplyQuaternions( this, q );
  1284. },
  1285. premultiply: function ( q ) {
  1286. return this.multiplyQuaternions( q, this );
  1287. },
  1288. multiplyQuaternions: function ( a, b ) {
  1289. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  1290. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  1291. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  1292. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  1293. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  1294. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  1295. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  1296. this.onChangeCallback();
  1297. return this;
  1298. },
  1299. slerp: function ( qb, t ) {
  1300. if ( t === 0 ) return this;
  1301. if ( t === 1 ) return this.copy( qb );
  1302. var x = this._x, y = this._y, z = this._z, w = this._w;
  1303. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  1304. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  1305. if ( cosHalfTheta < 0 ) {
  1306. this._w = - qb._w;
  1307. this._x = - qb._x;
  1308. this._y = - qb._y;
  1309. this._z = - qb._z;
  1310. cosHalfTheta = - cosHalfTheta;
  1311. } else {
  1312. this.copy( qb );
  1313. }
  1314. if ( cosHalfTheta >= 1.0 ) {
  1315. this._w = w;
  1316. this._x = x;
  1317. this._y = y;
  1318. this._z = z;
  1319. return this;
  1320. }
  1321. var sinHalfTheta = Math.sqrt( 1.0 - cosHalfTheta * cosHalfTheta );
  1322. if ( Math.abs( sinHalfTheta ) < 0.001 ) {
  1323. this._w = 0.5 * ( w + this._w );
  1324. this._x = 0.5 * ( x + this._x );
  1325. this._y = 0.5 * ( y + this._y );
  1326. this._z = 0.5 * ( z + this._z );
  1327. return this;
  1328. }
  1329. var halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );
  1330. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  1331. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  1332. this._w = ( w * ratioA + this._w * ratioB );
  1333. this._x = ( x * ratioA + this._x * ratioB );
  1334. this._y = ( y * ratioA + this._y * ratioB );
  1335. this._z = ( z * ratioA + this._z * ratioB );
  1336. this.onChangeCallback();
  1337. return this;
  1338. },
  1339. equals: function ( quaternion ) {
  1340. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  1341. },
  1342. fromArray: function ( array, offset ) {
  1343. if ( offset === undefined ) offset = 0;
  1344. this._x = array[ offset ];
  1345. this._y = array[ offset + 1 ];
  1346. this._z = array[ offset + 2 ];
  1347. this._w = array[ offset + 3 ];
  1348. this.onChangeCallback();
  1349. return this;
  1350. },
  1351. toArray: function ( array, offset ) {
  1352. if ( array === undefined ) array = [];
  1353. if ( offset === undefined ) offset = 0;
  1354. array[ offset ] = this._x;
  1355. array[ offset + 1 ] = this._y;
  1356. array[ offset + 2 ] = this._z;
  1357. array[ offset + 3 ] = this._w;
  1358. return array;
  1359. },
  1360. onChange: function ( callback ) {
  1361. this.onChangeCallback = callback;
  1362. return this;
  1363. },
  1364. onChangeCallback: function () {}
  1365. } );
  1366. /**
  1367. * @author mrdoob / http://mrdoob.com/
  1368. * @author kile / http://kile.stravaganza.org/
  1369. * @author philogb / http://blog.thejit.org/
  1370. * @author mikael emtinger / http://gomo.se/
  1371. * @author egraether / http://egraether.com/
  1372. * @author WestLangley / http://github.com/WestLangley
  1373. */
  1374. function Vector3( x, y, z ) {
  1375. this.x = x || 0;
  1376. this.y = y || 0;
  1377. this.z = z || 0;
  1378. }
  1379. Object.assign( Vector3.prototype, {
  1380. isVector3: true,
  1381. set: function ( x, y, z ) {
  1382. this.x = x;
  1383. this.y = y;
  1384. this.z = z;
  1385. return this;
  1386. },
  1387. setScalar: function ( scalar ) {
  1388. this.x = scalar;
  1389. this.y = scalar;
  1390. this.z = scalar;
  1391. return this;
  1392. },
  1393. setX: function ( x ) {
  1394. this.x = x;
  1395. return this;
  1396. },
  1397. setY: function ( y ) {
  1398. this.y = y;
  1399. return this;
  1400. },
  1401. setZ: function ( z ) {
  1402. this.z = z;
  1403. return this;
  1404. },
  1405. setComponent: function ( index, value ) {
  1406. switch ( index ) {
  1407. case 0: this.x = value; break;
  1408. case 1: this.y = value; break;
  1409. case 2: this.z = value; break;
  1410. default: throw new Error( 'index is out of range: ' + index );
  1411. }
  1412. return this;
  1413. },
  1414. getComponent: function ( index ) {
  1415. switch ( index ) {
  1416. case 0: return this.x;
  1417. case 1: return this.y;
  1418. case 2: return this.z;
  1419. default: throw new Error( 'index is out of range: ' + index );
  1420. }
  1421. },
  1422. clone: function () {
  1423. return new this.constructor( this.x, this.y, this.z );
  1424. },
  1425. copy: function ( v ) {
  1426. this.x = v.x;
  1427. this.y = v.y;
  1428. this.z = v.z;
  1429. return this;
  1430. },
  1431. add: function ( v, w ) {
  1432. if ( w !== undefined ) {
  1433. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1434. return this.addVectors( v, w );
  1435. }
  1436. this.x += v.x;
  1437. this.y += v.y;
  1438. this.z += v.z;
  1439. return this;
  1440. },
  1441. addScalar: function ( s ) {
  1442. this.x += s;
  1443. this.y += s;
  1444. this.z += s;
  1445. return this;
  1446. },
  1447. addVectors: function ( a, b ) {
  1448. this.x = a.x + b.x;
  1449. this.y = a.y + b.y;
  1450. this.z = a.z + b.z;
  1451. return this;
  1452. },
  1453. addScaledVector: function ( v, s ) {
  1454. this.x += v.x * s;
  1455. this.y += v.y * s;
  1456. this.z += v.z * s;
  1457. return this;
  1458. },
  1459. sub: function ( v, w ) {
  1460. if ( w !== undefined ) {
  1461. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1462. return this.subVectors( v, w );
  1463. }
  1464. this.x -= v.x;
  1465. this.y -= v.y;
  1466. this.z -= v.z;
  1467. return this;
  1468. },
  1469. subScalar: function ( s ) {
  1470. this.x -= s;
  1471. this.y -= s;
  1472. this.z -= s;
  1473. return this;
  1474. },
  1475. subVectors: function ( a, b ) {
  1476. this.x = a.x - b.x;
  1477. this.y = a.y - b.y;
  1478. this.z = a.z - b.z;
  1479. return this;
  1480. },
  1481. multiply: function ( v, w ) {
  1482. if ( w !== undefined ) {
  1483. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  1484. return this.multiplyVectors( v, w );
  1485. }
  1486. this.x *= v.x;
  1487. this.y *= v.y;
  1488. this.z *= v.z;
  1489. return this;
  1490. },
  1491. multiplyScalar: function ( scalar ) {
  1492. this.x *= scalar;
  1493. this.y *= scalar;
  1494. this.z *= scalar;
  1495. return this;
  1496. },
  1497. multiplyVectors: function ( a, b ) {
  1498. this.x = a.x * b.x;
  1499. this.y = a.y * b.y;
  1500. this.z = a.z * b.z;
  1501. return this;
  1502. },
  1503. applyEuler: function () {
  1504. var quaternion = new Quaternion();
  1505. return function applyEuler( euler ) {
  1506. if ( ! ( euler && euler.isEuler ) ) {
  1507. console.error( 'THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1508. }
  1509. return this.applyQuaternion( quaternion.setFromEuler( euler ) );
  1510. };
  1511. }(),
  1512. applyAxisAngle: function () {
  1513. var quaternion = new Quaternion();
  1514. return function applyAxisAngle( axis, angle ) {
  1515. return this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
  1516. };
  1517. }(),
  1518. applyMatrix3: function ( m ) {
  1519. var x = this.x, y = this.y, z = this.z;
  1520. var e = m.elements;
  1521. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1522. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1523. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1524. return this;
  1525. },
  1526. applyMatrix4: function ( m ) {
  1527. var x = this.x, y = this.y, z = this.z;
  1528. var e = m.elements;
  1529. var w = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] );
  1530. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * w;
  1531. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * w;
  1532. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * w;
  1533. return this;
  1534. },
  1535. applyQuaternion: function ( q ) {
  1536. var x = this.x, y = this.y, z = this.z;
  1537. var qx = q.x, qy = q.y, qz = q.z, qw = q.w;
  1538. // calculate quat * vector
  1539. var ix = qw * x + qy * z - qz * y;
  1540. var iy = qw * y + qz * x - qx * z;
  1541. var iz = qw * z + qx * y - qy * x;
  1542. var iw = - qx * x - qy * y - qz * z;
  1543. // calculate result * inverse quat
  1544. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1545. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1546. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1547. return this;
  1548. },
  1549. project: function () {
  1550. var matrix = new Matrix4();
  1551. return function project( camera ) {
  1552. matrix.multiplyMatrices( camera.projectionMatrix, matrix.getInverse( camera.matrixWorld ) );
  1553. return this.applyMatrix4( matrix );
  1554. };
  1555. }(),
  1556. unproject: function () {
  1557. var matrix = new Matrix4();
  1558. return function unproject( camera ) {
  1559. matrix.multiplyMatrices( camera.matrixWorld, matrix.getInverse( camera.projectionMatrix ) );
  1560. return this.applyMatrix4( matrix );
  1561. };
  1562. }(),
  1563. transformDirection: function ( m ) {
  1564. // input: THREE.Matrix4 affine matrix
  1565. // vector interpreted as a direction
  1566. var x = this.x, y = this.y, z = this.z;
  1567. var e = m.elements;
  1568. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1569. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1570. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1571. return this.normalize();
  1572. },
  1573. divide: function ( v ) {
  1574. this.x /= v.x;
  1575. this.y /= v.y;
  1576. this.z /= v.z;
  1577. return this;
  1578. },
  1579. divideScalar: function ( scalar ) {
  1580. return this.multiplyScalar( 1 / scalar );
  1581. },
  1582. min: function ( v ) {
  1583. this.x = Math.min( this.x, v.x );
  1584. this.y = Math.min( this.y, v.y );
  1585. this.z = Math.min( this.z, v.z );
  1586. return this;
  1587. },
  1588. max: function ( v ) {
  1589. this.x = Math.max( this.x, v.x );
  1590. this.y = Math.max( this.y, v.y );
  1591. this.z = Math.max( this.z, v.z );
  1592. return this;
  1593. },
  1594. clamp: function ( min, max ) {
  1595. // assumes min < max, componentwise
  1596. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1597. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1598. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1599. return this;
  1600. },
  1601. clampScalar: function () {
  1602. var min = new Vector3();
  1603. var max = new Vector3();
  1604. return function clampScalar( minVal, maxVal ) {
  1605. min.set( minVal, minVal, minVal );
  1606. max.set( maxVal, maxVal, maxVal );
  1607. return this.clamp( min, max );
  1608. };
  1609. }(),
  1610. clampLength: function ( min, max ) {
  1611. var length = this.length();
  1612. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  1613. },
  1614. floor: function () {
  1615. this.x = Math.floor( this.x );
  1616. this.y = Math.floor( this.y );
  1617. this.z = Math.floor( this.z );
  1618. return this;
  1619. },
  1620. ceil: function () {
  1621. this.x = Math.ceil( this.x );
  1622. this.y = Math.ceil( this.y );
  1623. this.z = Math.ceil( this.z );
  1624. return this;
  1625. },
  1626. round: function () {
  1627. this.x = Math.round( this.x );
  1628. this.y = Math.round( this.y );
  1629. this.z = Math.round( this.z );
  1630. return this;
  1631. },
  1632. roundToZero: function () {
  1633. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1634. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1635. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1636. return this;
  1637. },
  1638. negate: function () {
  1639. this.x = - this.x;
  1640. this.y = - this.y;
  1641. this.z = - this.z;
  1642. return this;
  1643. },
  1644. dot: function ( v ) {
  1645. return this.x * v.x + this.y * v.y + this.z * v.z;
  1646. },
  1647. // TODO lengthSquared?
  1648. lengthSq: function () {
  1649. return this.x * this.x + this.y * this.y + this.z * this.z;
  1650. },
  1651. length: function () {
  1652. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1653. },
  1654. manhattanLength: function () {
  1655. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1656. },
  1657. normalize: function () {
  1658. return this.divideScalar( this.length() || 1 );
  1659. },
  1660. setLength: function ( length ) {
  1661. return this.normalize().multiplyScalar( length );
  1662. },
  1663. lerp: function ( v, alpha ) {
  1664. this.x += ( v.x - this.x ) * alpha;
  1665. this.y += ( v.y - this.y ) * alpha;
  1666. this.z += ( v.z - this.z ) * alpha;
  1667. return this;
  1668. },
  1669. lerpVectors: function ( v1, v2, alpha ) {
  1670. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1671. },
  1672. cross: function ( v, w ) {
  1673. if ( w !== undefined ) {
  1674. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  1675. return this.crossVectors( v, w );
  1676. }
  1677. var x = this.x, y = this.y, z = this.z;
  1678. this.x = y * v.z - z * v.y;
  1679. this.y = z * v.x - x * v.z;
  1680. this.z = x * v.y - y * v.x;
  1681. return this;
  1682. },
  1683. crossVectors: function ( a, b ) {
  1684. var ax = a.x, ay = a.y, az = a.z;
  1685. var bx = b.x, by = b.y, bz = b.z;
  1686. this.x = ay * bz - az * by;
  1687. this.y = az * bx - ax * bz;
  1688. this.z = ax * by - ay * bx;
  1689. return this;
  1690. },
  1691. projectOnVector: function ( vector ) {
  1692. var scalar = vector.dot( this ) / vector.lengthSq();
  1693. return this.copy( vector ).multiplyScalar( scalar );
  1694. },
  1695. projectOnPlane: function () {
  1696. var v1 = new Vector3();
  1697. return function projectOnPlane( planeNormal ) {
  1698. v1.copy( this ).projectOnVector( planeNormal );
  1699. return this.sub( v1 );
  1700. };
  1701. }(),
  1702. reflect: function () {
  1703. // reflect incident vector off plane orthogonal to normal
  1704. // normal is assumed to have unit length
  1705. var v1 = new Vector3();
  1706. return function reflect( normal ) {
  1707. return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1708. };
  1709. }(),
  1710. angleTo: function ( v ) {
  1711. var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) );
  1712. // clamp, to handle numerical problems
  1713. return Math.acos( _Math.clamp( theta, - 1, 1 ) );
  1714. },
  1715. distanceTo: function ( v ) {
  1716. return Math.sqrt( this.distanceToSquared( v ) );
  1717. },
  1718. distanceToSquared: function ( v ) {
  1719. var dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
  1720. return dx * dx + dy * dy + dz * dz;
  1721. },
  1722. manhattanDistanceTo: function ( v ) {
  1723. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y ) + Math.abs( this.z - v.z );
  1724. },
  1725. setFromSpherical: function ( s ) {
  1726. var sinPhiRadius = Math.sin( s.phi ) * s.radius;
  1727. this.x = sinPhiRadius * Math.sin( s.theta );
  1728. this.y = Math.cos( s.phi ) * s.radius;
  1729. this.z = sinPhiRadius * Math.cos( s.theta );
  1730. return this;
  1731. },
  1732. setFromCylindrical: function ( c ) {
  1733. this.x = c.radius * Math.sin( c.theta );
  1734. this.y = c.y;
  1735. this.z = c.radius * Math.cos( c.theta );
  1736. return this;
  1737. },
  1738. setFromMatrixPosition: function ( m ) {
  1739. var e = m.elements;
  1740. this.x = e[ 12 ];
  1741. this.y = e[ 13 ];
  1742. this.z = e[ 14 ];
  1743. return this;
  1744. },
  1745. setFromMatrixScale: function ( m ) {
  1746. var sx = this.setFromMatrixColumn( m, 0 ).length();
  1747. var sy = this.setFromMatrixColumn( m, 1 ).length();
  1748. var sz = this.setFromMatrixColumn( m, 2 ).length();
  1749. this.x = sx;
  1750. this.y = sy;
  1751. this.z = sz;
  1752. return this;
  1753. },
  1754. setFromMatrixColumn: function ( m, index ) {
  1755. return this.fromArray( m.elements, index * 4 );
  1756. },
  1757. equals: function ( v ) {
  1758. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1759. },
  1760. fromArray: function ( array, offset ) {
  1761. if ( offset === undefined ) offset = 0;
  1762. this.x = array[ offset ];
  1763. this.y = array[ offset + 1 ];
  1764. this.z = array[ offset + 2 ];
  1765. return this;
  1766. },
  1767. toArray: function ( array, offset ) {
  1768. if ( array === undefined ) array = [];
  1769. if ( offset === undefined ) offset = 0;
  1770. array[ offset ] = this.x;
  1771. array[ offset + 1 ] = this.y;
  1772. array[ offset + 2 ] = this.z;
  1773. return array;
  1774. },
  1775. fromBufferAttribute: function ( attribute, index, offset ) {
  1776. if ( offset !== undefined ) {
  1777. console.warn( 'THREE.Vector3: offset has been removed from .fromBufferAttribute().' );
  1778. }
  1779. this.x = attribute.getX( index );
  1780. this.y = attribute.getY( index );
  1781. this.z = attribute.getZ( index );
  1782. return this;
  1783. }
  1784. } );
  1785. /**
  1786. * @author TristanVALCKE / https://github.com/Itee
  1787. */
  1788. /* global QUnit */
  1789. QUnit.module.todo( 'Polyfills', () => {
  1790. // PUBLIC STUFF
  1791. QUnit.test( "Number.EPSILON", ( assert ) => {
  1792. assert.ok( false, "everything's gonna be alright" );
  1793. } );
  1794. QUnit.test( "Number.isInteger", ( assert ) => {
  1795. assert.ok( false, "everything's gonna be alright" );
  1796. } );
  1797. //https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  1798. //http://people.mozilla.org/~jorendorff/es6-draft.html#sec-math.sign
  1799. /*
  1800. 20.2.2.29 Math.sign(x)
  1801. Returns the sign of the x, indicating whether x is positive, negative or zero.
  1802. If x is NaN, the result is NaN.
  1803. If x is -0, the result is -0.
  1804. If x is +0, the result is +0.
  1805. If x is negative and not -0, the result is -1.
  1806. If x is positive and not +0, the result is +1.
  1807. */
  1808. QUnit.test( "Math.sign", ( assert ) => {
  1809. assert.ok( isNaN( Math.sign( NaN ) ), "If x is NaN<NaN>, the result is NaN." );
  1810. assert.ok( isNaN( Math.sign( new Vector3() ) ), "If x is NaN<object>, the result is NaN." );
  1811. assert.ok( isNaN( Math.sign() ), "If x is NaN<undefined>, the result is NaN." );
  1812. assert.ok( isNaN( Math.sign( '--3' ) ), "If x is NaN<'--3'>, the result is NaN." );
  1813. assert.ok( isNegativeZero( Math.sign( - 0 ) ), "If x is -0, the result is -0." );
  1814. assert.ok( Math.sign( + 0 ) === + 0, "If x is +0, the result is +0." );
  1815. assert.ok( Math.sign( - Infinity ) === - 1, "If x is negative<-Infinity> and not -0, the result is -1." );
  1816. assert.ok( Math.sign( '-3' ) === - 1, "If x is negative<'-3'> and not -0, the result is -1." );
  1817. assert.ok( Math.sign( '-1e-10' ) === - 1, "If x is negative<'-1e-10'> and not -0, the result is -1." );
  1818. assert.ok( Math.sign( + Infinity ) === + 1, "If x is positive<+Infinity> and not +0, the result is +1." );
  1819. assert.ok( Math.sign( '+3' ) === + 1, "If x is positive<'+3'> and not +0, the result is +1." );
  1820. // Comparing with -0 is tricky because 0 === -0. But
  1821. // luckily 1 / -0 === -Infinity so we can use that.
  1822. function isNegativeZero( value ) {
  1823. return value === 0 && 1 / value < 0;
  1824. }
  1825. } );
  1826. QUnit.test( "'name' in Function.prototype", ( assert ) => {
  1827. assert.ok( false, "everything's gonna be alright" );
  1828. } );
  1829. QUnit.test( "Object.assign", ( assert ) => {
  1830. assert.ok( false, "everything's gonna be alright" );
  1831. } );
  1832. } );
  1833. /**
  1834. * @author mrdoob / http://mrdoob.com/
  1835. */
  1836. function arrayMin( array ) {
  1837. if ( array.length === 0 ) return Infinity;
  1838. var min = array[ 0 ];
  1839. for ( var i = 1, l = array.length; i < l; ++ i ) {
  1840. if ( array[ i ] < min ) min = array[ i ];
  1841. }
  1842. return min;
  1843. }
  1844. function arrayMax( array ) {
  1845. if ( array.length === 0 ) return - Infinity;
  1846. var max = array[ 0 ];
  1847. for ( var i = 1, l = array.length; i < l; ++ i ) {
  1848. if ( array[ i ] > max ) max = array[ i ];
  1849. }
  1850. return max;
  1851. }
  1852. /**
  1853. * @author alemures / https://github.com/alemures
  1854. * @author TristanVALCKE / https://github.com/Itee
  1855. */
  1856. /* global QUnit */
  1857. QUnit.module( 'utils', () => {
  1858. QUnit.test( 'arrayMin', ( assert ) => {
  1859. assert.equal( arrayMin( [] ), Infinity, 'Empty array return positive infinit' );
  1860. assert.equal( arrayMin( [ 5 ] ), 5, 'Single valued array should return the unique value as minimum' );
  1861. assert.equal( arrayMin( [ 1, 5, 10 ] ), 1, 'The array [ 1, 5, 10 ] return 1' );
  1862. assert.equal( arrayMin( [ 5, 1, 10 ] ), 1, 'The array [ 5, 1, 10 ] return 1' );
  1863. assert.equal( arrayMin( [ 10, 5, 1 ] ), 1, 'The array [ 10, 5, 1 ] return 1' );
  1864. assert.equal( arrayMax( [ - 0, 0 ] ), - 0, 'The array [ - 0, 0 ] return -0' );
  1865. assert.equal( arrayMin( [ - Infinity, 0, Infinity ] ), - Infinity, 'The array [ - Infinity, 0, Infinity ] return -Infinity' );
  1866. } );
  1867. QUnit.test( 'arrayMax', ( assert ) => {
  1868. assert.equal( arrayMax( [] ), - Infinity, 'Empty array return negative infinit' );
  1869. assert.equal( arrayMax( [ 5 ] ), 5, 'Single valued array should return the unique value as maximum' );
  1870. assert.equal( arrayMax( [ 10, 5, 1 ] ), 10, 'The array [ 10, 5, 1 ] return 10' );
  1871. assert.equal( arrayMax( [ 1, 10, 5 ] ), 10, 'The array [ 1, 10, 5 ] return 10' );
  1872. assert.equal( arrayMax( [ 1, 5, 10 ] ), 10, 'The array [ 1, 5, 10 ] return 10' );
  1873. assert.equal( arrayMax( [ - 0, 0 ] ), 0, 'The array [ - 0, 0 ] return 0' );
  1874. assert.equal( arrayMax( [ - Infinity, 0, Infinity ] ), Infinity, 'The array [ - Infinity, 0, Infinity ] return Infinity' );
  1875. } );
  1876. } );
  1877. /**
  1878. *
  1879. * Action provided by AnimationMixer for scheduling clip playback on specific
  1880. * objects.
  1881. *
  1882. * @author Ben Houston / http://clara.io/
  1883. * @author David Sarno / http://lighthaus.us/
  1884. * @author tschw
  1885. *
  1886. */
  1887. function AnimationAction( mixer, clip, localRoot ) {
  1888. this._mixer = mixer;
  1889. this._clip = clip;
  1890. this._localRoot = localRoot || null;
  1891. var tracks = clip.tracks,
  1892. nTracks = tracks.length,
  1893. interpolants = new Array( nTracks );
  1894. var interpolantSettings = {
  1895. endingStart: ZeroCurvatureEnding,
  1896. endingEnd: ZeroCurvatureEnding
  1897. };
  1898. for ( var i = 0; i !== nTracks; ++ i ) {
  1899. var interpolant = tracks[ i ].createInterpolant( null );
  1900. interpolants[ i ] = interpolant;
  1901. interpolant.settings = interpolantSettings;
  1902. }
  1903. this._interpolantSettings = interpolantSettings;
  1904. this._interpolants = interpolants; // bound by the mixer
  1905. // inside: PropertyMixer (managed by the mixer)
  1906. this._propertyBindings = new Array( nTracks );
  1907. this._cacheIndex = null; // for the memory manager
  1908. this._byClipCacheIndex = null; // for the memory manager
  1909. this._timeScaleInterpolant = null;
  1910. this._weightInterpolant = null;
  1911. this.loop = LoopRepeat;
  1912. this._loopCount = - 1;
  1913. // global mixer time when the action is to be started
  1914. // it's set back to 'null' upon start of the action
  1915. this._startTime = null;
  1916. // scaled local time of the action
  1917. // gets clamped or wrapped to 0..clip.duration according to loop
  1918. this.time = 0;
  1919. this.timeScale = 1;
  1920. this._effectiveTimeScale = 1;
  1921. this.weight = 1;
  1922. this._effectiveWeight = 1;
  1923. this.repetitions = Infinity; // no. of repetitions when looping
  1924. this.paused = false; // true -> zero effective time scale
  1925. this.enabled = true; // false -> zero effective weight
  1926. this.clampWhenFinished = false; // keep feeding the last frame?
  1927. this.zeroSlopeAtStart = true; // for smooth interpolation w/o separate
  1928. this.zeroSlopeAtEnd = true; // clips for start, loop and end
  1929. }
  1930. Object.assign( AnimationAction.prototype, {
  1931. // State & Scheduling
  1932. play: function () {
  1933. this._mixer._activateAction( this );
  1934. return this;
  1935. },
  1936. stop: function () {
  1937. this._mixer._deactivateAction( this );
  1938. return this.reset();
  1939. },
  1940. reset: function () {
  1941. this.paused = false;
  1942. this.enabled = true;
  1943. this.time = 0; // restart clip
  1944. this._loopCount = - 1; // forget previous loops
  1945. this._startTime = null; // forget scheduling
  1946. return this.stopFading().stopWarping();
  1947. },
  1948. isRunning: function () {
  1949. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  1950. this._startTime === null && this._mixer._isActiveAction( this );
  1951. },
  1952. // return true when play has been called
  1953. isScheduled: function () {
  1954. return this._mixer._isActiveAction( this );
  1955. },
  1956. startAt: function ( time ) {
  1957. this._startTime = time;
  1958. return this;
  1959. },
  1960. setLoop: function ( mode, repetitions ) {
  1961. this.loop = mode;
  1962. this.repetitions = repetitions;
  1963. return this;
  1964. },
  1965. // Weight
  1966. // set the weight stopping any scheduled fading
  1967. // although .enabled = false yields an effective weight of zero, this
  1968. // method does *not* change .enabled, because it would be confusing
  1969. setEffectiveWeight: function ( weight ) {
  1970. this.weight = weight;
  1971. // note: same logic as when updated at runtime
  1972. this._effectiveWeight = this.enabled ? weight : 0;
  1973. return this.stopFading();
  1974. },
  1975. // return the weight considering fading and .enabled
  1976. getEffectiveWeight: function () {
  1977. return this._effectiveWeight;
  1978. },
  1979. fadeIn: function ( duration ) {
  1980. return this._scheduleFading( duration, 0, 1 );
  1981. },
  1982. fadeOut: function ( duration ) {
  1983. return this._scheduleFading( duration, 1, 0 );
  1984. },
  1985. crossFadeFrom: function ( fadeOutAction, duration, warp ) {
  1986. fadeOutAction.fadeOut( duration );
  1987. this.fadeIn( duration );
  1988. if ( warp ) {
  1989. var fadeInDuration = this._clip.duration,
  1990. fadeOutDuration = fadeOutAction._clip.duration,
  1991. startEndRatio = fadeOutDuration / fadeInDuration,
  1992. endStartRatio = fadeInDuration / fadeOutDuration;
  1993. fadeOutAction.warp( 1.0, startEndRatio, duration );
  1994. this.warp( endStartRatio, 1.0, duration );
  1995. }
  1996. return this;
  1997. },
  1998. crossFadeTo: function ( fadeInAction, duration, warp ) {
  1999. return fadeInAction.crossFadeFrom( this, duration, warp );
  2000. },
  2001. stopFading: function () {
  2002. var weightInterpolant = this._weightInterpolant;
  2003. if ( weightInterpolant !== null ) {
  2004. this._weightInterpolant = null;
  2005. this._mixer._takeBackControlInterpolant( weightInterpolant );
  2006. }
  2007. return this;
  2008. },
  2009. // Time Scale Control
  2010. // set the time scale stopping any scheduled warping
  2011. // although .paused = true yields an effective time scale of zero, this
  2012. // method does *not* change .paused, because it would be confusing
  2013. setEffectiveTimeScale: function ( timeScale ) {
  2014. this.timeScale = timeScale;
  2015. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  2016. return this.stopWarping();
  2017. },
  2018. // return the time scale considering warping and .paused
  2019. getEffectiveTimeScale: function () {
  2020. return this._effectiveTimeScale;
  2021. },
  2022. setDuration: function ( duration ) {
  2023. this.timeScale = this._clip.duration / duration;
  2024. return this.stopWarping();
  2025. },
  2026. syncWith: function ( action ) {
  2027. this.time = action.time;
  2028. this.timeScale = action.timeScale;
  2029. return this.stopWarping();
  2030. },
  2031. halt: function ( duration ) {
  2032. return this.warp( this._effectiveTimeScale, 0, duration );
  2033. },
  2034. warp: function ( startTimeScale, endTimeScale, duration ) {
  2035. var mixer = this._mixer, now = mixer.time,
  2036. interpolant = this._timeScaleInterpolant,
  2037. timeScale = this.timeScale;
  2038. if ( interpolant === null ) {
  2039. interpolant = mixer._lendControlInterpolant();
  2040. this._timeScaleInterpolant = interpolant;
  2041. }
  2042. var times = interpolant.parameterPositions,
  2043. values = interpolant.sampleValues;
  2044. times[ 0 ] = now;
  2045. times[ 1 ] = now + duration;
  2046. values[ 0 ] = startTimeScale / timeScale;
  2047. values[ 1 ] = endTimeScale / timeScale;
  2048. return this;
  2049. },
  2050. stopWarping: function () {
  2051. var timeScaleInterpolant = this._timeScaleInterpolant;
  2052. if ( timeScaleInterpolant !== null ) {
  2053. this._timeScaleInterpolant = null;
  2054. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  2055. }
  2056. return this;
  2057. },
  2058. // Object Accessors
  2059. getMixer: function () {
  2060. return this._mixer;
  2061. },
  2062. getClip: function () {
  2063. return this._clip;
  2064. },
  2065. getRoot: function () {
  2066. return this._localRoot || this._mixer._root;
  2067. },
  2068. // Interna
  2069. _update: function ( time, deltaTime, timeDirection, accuIndex ) {
  2070. // called by the mixer
  2071. if ( ! this.enabled ) {
  2072. // call ._updateWeight() to update ._effectiveWeight
  2073. this._updateWeight( time );
  2074. return;
  2075. }
  2076. var startTime = this._startTime;
  2077. if ( startTime !== null ) {
  2078. // check for scheduled start of action
  2079. var timeRunning = ( time - startTime ) * timeDirection;
  2080. if ( timeRunning < 0 || timeDirection === 0 ) {
  2081. return; // yet to come / don't decide when delta = 0
  2082. }
  2083. // start
  2084. this._startTime = null; // unschedule
  2085. deltaTime = timeDirection * timeRunning;
  2086. }
  2087. // apply time scale and advance time
  2088. deltaTime *= this._updateTimeScale( time );
  2089. var clipTime = this._updateTime( deltaTime );
  2090. // note: _updateTime may disable the action resulting in
  2091. // an effective weight of 0
  2092. var weight = this._updateWeight( time );
  2093. if ( weight > 0 ) {
  2094. var interpolants = this._interpolants;
  2095. var propertyMixers = this._propertyBindings;
  2096. for ( var j = 0, m = interpolants.length; j !== m; ++ j ) {
  2097. interpolants[ j ].evaluate( clipTime );
  2098. propertyMixers[ j ].accumulate( accuIndex, weight );
  2099. }
  2100. }
  2101. },
  2102. _updateWeight: function ( time ) {
  2103. var weight = 0;
  2104. if ( this.enabled ) {
  2105. weight = this.weight;
  2106. var interpolant = this._weightInterpolant;
  2107. if ( interpolant !== null ) {
  2108. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  2109. weight *= interpolantValue;
  2110. if ( time > interpolant.parameterPositions[ 1 ] ) {
  2111. this.stopFading();
  2112. if ( interpolantValue === 0 ) {
  2113. // faded out, disable
  2114. this.enabled = false;
  2115. }
  2116. }
  2117. }
  2118. }
  2119. this._effectiveWeight = weight;
  2120. return weight;
  2121. },
  2122. _updateTimeScale: function ( time ) {
  2123. var timeScale = 0;
  2124. if ( ! this.paused ) {
  2125. timeScale = this.timeScale;
  2126. var interpolant = this._timeScaleInterpolant;
  2127. if ( interpolant !== null ) {
  2128. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  2129. timeScale *= interpolantValue;
  2130. if ( time > interpolant.parameterPositions[ 1 ] ) {
  2131. this.stopWarping();
  2132. if ( timeScale === 0 ) {
  2133. // motion has halted, pause
  2134. this.paused = true;
  2135. } else {
  2136. // warp done - apply final time scale
  2137. this.timeScale = timeScale;
  2138. }
  2139. }
  2140. }
  2141. }
  2142. this._effectiveTimeScale = timeScale;
  2143. return timeScale;
  2144. },
  2145. _updateTime: function ( deltaTime ) {
  2146. var time = this.time + deltaTime;
  2147. if ( deltaTime === 0 ) return time;
  2148. var duration = this._clip.duration,
  2149. loop = this.loop,
  2150. loopCount = this._loopCount;
  2151. if ( loop === LoopOnce ) {
  2152. if ( loopCount === - 1 ) {
  2153. // just started
  2154. this._loopCount = 0;
  2155. this._setEndings( true, true, false );
  2156. }
  2157. handle_stop: {
  2158. if ( time >= duration ) {
  2159. time = duration;
  2160. } else if ( time < 0 ) {
  2161. time = 0;
  2162. } else break handle_stop;
  2163. if ( this.clampWhenFinished ) this.paused = true;
  2164. else this.enabled = false;
  2165. this._mixer.dispatchEvent( {
  2166. type: 'finished', action: this,
  2167. direction: deltaTime < 0 ? - 1 : 1
  2168. } );
  2169. }
  2170. } else { // repetitive Repeat or PingPong
  2171. var pingPong = ( loop === LoopPingPong );
  2172. if ( loopCount === - 1 ) {
  2173. // just started
  2174. if ( deltaTime >= 0 ) {
  2175. loopCount = 0;
  2176. this._setEndings( true, this.repetitions === 0, pingPong );
  2177. } else {
  2178. // when looping in reverse direction, the initial
  2179. // transition through zero counts as a repetition,
  2180. // so leave loopCount at -1
  2181. this._setEndings( this.repetitions === 0, true, pingPong );
  2182. }
  2183. }
  2184. if ( time >= duration || time < 0 ) {
  2185. // wrap around
  2186. var loopDelta = Math.floor( time / duration ); // signed
  2187. time -= duration * loopDelta;
  2188. loopCount += Math.abs( loopDelta );
  2189. var pending = this.repetitions - loopCount;
  2190. if ( pending < 0 ) {
  2191. // have to stop (switch state, clamp time, fire event)
  2192. if ( this.clampWhenFinished ) this.paused = true;
  2193. else this.enabled = false;
  2194. time = deltaTime > 0 ? duration : 0;
  2195. this._mixer.dispatchEvent( {
  2196. type: 'finished', action: this,
  2197. direction: deltaTime > 0 ? 1 : - 1
  2198. } );
  2199. } else {
  2200. // keep running
  2201. if ( pending === 0 ) {
  2202. // entering the last round
  2203. var atStart = deltaTime < 0;
  2204. this._setEndings( atStart, ! atStart, pingPong );
  2205. } else {
  2206. this._setEndings( false, false, pingPong );
  2207. }
  2208. this._loopCount = loopCount;
  2209. this._mixer.dispatchEvent( {
  2210. type: 'loop', action: this, loopDelta: loopDelta
  2211. } );
  2212. }
  2213. }
  2214. if ( pingPong && ( loopCount & 1 ) === 1 ) {
  2215. // invert time for the "pong round"
  2216. this.time = time;
  2217. return duration - time;
  2218. }
  2219. }
  2220. this.time = time;
  2221. return time;
  2222. },
  2223. _setEndings: function ( atStart, atEnd, pingPong ) {
  2224. var settings = this._interpolantSettings;
  2225. if ( pingPong ) {
  2226. settings.endingStart = ZeroSlopeEnding;
  2227. settings.endingEnd = ZeroSlopeEnding;
  2228. } else {
  2229. // assuming for LoopOnce atStart == atEnd == true
  2230. if ( atStart ) {
  2231. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  2232. } else {
  2233. settings.endingStart = WrapAroundEnding;
  2234. }
  2235. if ( atEnd ) {
  2236. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  2237. } else {
  2238. settings.endingEnd = WrapAroundEnding;
  2239. }
  2240. }
  2241. },
  2242. _scheduleFading: function ( duration, weightNow, weightThen ) {
  2243. var mixer = this._mixer, now = mixer.time,
  2244. interpolant = this._weightInterpolant;
  2245. if ( interpolant === null ) {
  2246. interpolant = mixer._lendControlInterpolant();
  2247. this._weightInterpolant = interpolant;
  2248. }
  2249. var times = interpolant.parameterPositions,
  2250. values = interpolant.sampleValues;
  2251. times[ 0 ] = now; values[ 0 ] = weightNow;
  2252. times[ 1 ] = now + duration; values[ 1 ] = weightThen;
  2253. return this;
  2254. }
  2255. } );
  2256. /**
  2257. * https://github.com/mrdoob/eventdispatcher.js/
  2258. */
  2259. function EventDispatcher() {}
  2260. Object.assign( EventDispatcher.prototype, {
  2261. addEventListener: function ( type, listener ) {
  2262. if ( this._listeners === undefined ) this._listeners = {};
  2263. var listeners = this._listeners;
  2264. if ( listeners[ type ] === undefined ) {
  2265. listeners[ type ] = [];
  2266. }
  2267. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  2268. listeners[ type ].push( listener );
  2269. }
  2270. },
  2271. hasEventListener: function ( type, listener ) {
  2272. if ( this._listeners === undefined ) return false;
  2273. var listeners = this._listeners;
  2274. return listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1;
  2275. },
  2276. removeEventListener: function ( type, listener ) {
  2277. if ( this._listeners === undefined ) return;
  2278. var listeners = this._listeners;
  2279. var listenerArray = listeners[ type ];
  2280. if ( listenerArray !== undefined ) {
  2281. var index = listenerArray.indexOf( listener );
  2282. if ( index !== - 1 ) {
  2283. listenerArray.splice( index, 1 );
  2284. }
  2285. }
  2286. },
  2287. dispatchEvent: function ( event ) {
  2288. if ( this._listeners === undefined ) return;
  2289. var listeners = this._listeners;
  2290. var listenerArray = listeners[ event.type ];
  2291. if ( listenerArray !== undefined ) {
  2292. event.target = this;
  2293. var array = listenerArray.slice( 0 );
  2294. for ( var i = 0, l = array.length; i < l; i ++ ) {
  2295. array[ i ].call( this, event );
  2296. }
  2297. }
  2298. }
  2299. } );
  2300. /**
  2301. * Abstract base class of interpolants over parametric samples.
  2302. *
  2303. * The parameter domain is one dimensional, typically the time or a path
  2304. * along a curve defined by the data.
  2305. *
  2306. * The sample values can have any dimensionality and derived classes may
  2307. * apply special interpretations to the data.
  2308. *
  2309. * This class provides the interval seek in a Template Method, deferring
  2310. * the actual interpolation to derived classes.
  2311. *
  2312. * Time complexity is O(1) for linear access crossing at most two points
  2313. * and O(log N) for random access, where N is the number of positions.
  2314. *
  2315. * References:
  2316. *
  2317. * http://www.oodesign.com/template-method-pattern.html
  2318. *
  2319. * @author tschw
  2320. */
  2321. function Interpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  2322. this.parameterPositions = parameterPositions;
  2323. this._cachedIndex = 0;
  2324. this.resultBuffer = resultBuffer !== undefined ?
  2325. resultBuffer : new sampleValues.constructor( sampleSize );
  2326. this.sampleValues = sampleValues;
  2327. this.valueSize = sampleSize;
  2328. }
  2329. Object.assign( Interpolant.prototype, {
  2330. evaluate: function ( t ) {
  2331. var pp = this.parameterPositions,
  2332. i1 = this._cachedIndex,
  2333. t1 = pp[ i1 ],
  2334. t0 = pp[ i1 - 1 ];
  2335. validate_interval: {
  2336. seek: {
  2337. var right;
  2338. linear_scan: {
  2339. //- See http://jsperf.com/comparison-to-undefined/3
  2340. //- slower code:
  2341. //-
  2342. //- if ( t >= t1 || t1 === undefined ) {
  2343. forward_scan: if ( ! ( t < t1 ) ) {
  2344. for ( var giveUpAt = i1 + 2; ; ) {
  2345. if ( t1 === undefined ) {
  2346. if ( t < t0 ) break forward_scan;
  2347. // after end
  2348. i1 = pp.length;
  2349. this._cachedIndex = i1;
  2350. return this.afterEnd_( i1 - 1, t, t0 );
  2351. }
  2352. if ( i1 === giveUpAt ) break; // this loop
  2353. t0 = t1;
  2354. t1 = pp[ ++ i1 ];
  2355. if ( t < t1 ) {
  2356. // we have arrived at the sought interval
  2357. break seek;
  2358. }
  2359. }
  2360. // prepare binary search on the right side of the index
  2361. right = pp.length;
  2362. break linear_scan;
  2363. }
  2364. //- slower code:
  2365. //- if ( t < t0 || t0 === undefined ) {
  2366. if ( ! ( t >= t0 ) ) {
  2367. // looping?
  2368. var t1global = pp[ 1 ];
  2369. if ( t < t1global ) {
  2370. i1 = 2; // + 1, using the scan for the details
  2371. t0 = t1global;
  2372. }
  2373. // linear reverse scan
  2374. for ( var giveUpAt = i1 - 2; ; ) {
  2375. if ( t0 === undefined ) {
  2376. // before start
  2377. this._cachedIndex = 0;
  2378. return this.beforeStart_( 0, t, t1 );
  2379. }
  2380. if ( i1 === giveUpAt ) break; // this loop
  2381. t1 = t0;
  2382. t0 = pp[ -- i1 - 1 ];
  2383. if ( t >= t0 ) {
  2384. // we have arrived at the sought interval
  2385. break seek;
  2386. }
  2387. }
  2388. // prepare binary search on the left side of the index
  2389. right = i1;
  2390. i1 = 0;
  2391. break linear_scan;
  2392. }
  2393. // the interval is valid
  2394. break validate_interval;
  2395. } // linear scan
  2396. // binary search
  2397. while ( i1 < right ) {
  2398. var mid = ( i1 + right ) >>> 1;
  2399. if ( t < pp[ mid ] ) {
  2400. right = mid;
  2401. } else {
  2402. i1 = mid + 1;
  2403. }
  2404. }
  2405. t1 = pp[ i1 ];
  2406. t0 = pp[ i1 - 1 ];
  2407. // check boundary cases, again
  2408. if ( t0 === undefined ) {
  2409. this._cachedIndex = 0;
  2410. return this.beforeStart_( 0, t, t1 );
  2411. }
  2412. if ( t1 === undefined ) {
  2413. i1 = pp.length;
  2414. this._cachedIndex = i1;
  2415. return this.afterEnd_( i1 - 1, t0, t );
  2416. }
  2417. } // seek
  2418. this._cachedIndex = i1;
  2419. this.intervalChanged_( i1, t0, t1 );
  2420. } // validate_interval
  2421. return this.interpolate_( i1, t0, t, t1 );
  2422. },
  2423. settings: null, // optional, subclass-specific settings structure
  2424. // Note: The indirection allows central control of many interpolants.
  2425. // --- Protected interface
  2426. DefaultSettings_: {},
  2427. getSettings_: function () {
  2428. return this.settings || this.DefaultSettings_;
  2429. },
  2430. copySampleValue_: function ( index ) {
  2431. // copies a sample value to the result buffer
  2432. var result = this.resultBuffer,
  2433. values = this.sampleValues,
  2434. stride = this.valueSize,
  2435. offset = index * stride;
  2436. for ( var i = 0; i !== stride; ++ i ) {
  2437. result[ i ] = values[ offset + i ];
  2438. }
  2439. return result;
  2440. },
  2441. // Template methods for derived classes:
  2442. interpolate_: function ( /* i1, t0, t, t1 */ ) {
  2443. throw new Error( 'call to abstract method' );
  2444. // implementations shall return this.resultBuffer
  2445. },
  2446. intervalChanged_: function ( /* i1, t0, t1 */ ) {
  2447. // empty
  2448. }
  2449. } );
  2450. //!\ DECLARE ALIAS AFTER assign prototype !
  2451. Object.assign( Interpolant.prototype, {
  2452. //( 0, t, t0 ), returns this.resultBuffer
  2453. beforeStart_: Interpolant.prototype.copySampleValue_,
  2454. //( N-1, tN-1, t ), returns this.resultBuffer
  2455. afterEnd_: Interpolant.prototype.copySampleValue_,
  2456. } );
  2457. /**
  2458. * @author tschw
  2459. */
  2460. function LinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  2461. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  2462. }
  2463. LinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  2464. constructor: LinearInterpolant,
  2465. interpolate_: function ( i1, t0, t, t1 ) {
  2466. var result = this.resultBuffer,
  2467. values = this.sampleValues,
  2468. stride = this.valueSize,
  2469. offset1 = i1 * stride,
  2470. offset0 = offset1 - stride,
  2471. weight1 = ( t - t0 ) / ( t1 - t0 ),
  2472. weight0 = 1 - weight1;
  2473. for ( var i = 0; i !== stride; ++ i ) {
  2474. result[ i ] =
  2475. values[ offset0 + i ] * weight0 +
  2476. values[ offset1 + i ] * weight1;
  2477. }
  2478. return result;
  2479. }
  2480. } );
  2481. /**
  2482. *
  2483. * A reference to a real property in the scene graph.
  2484. *
  2485. *
  2486. * @author Ben Houston / http://clara.io/
  2487. * @author David Sarno / http://lighthaus.us/
  2488. * @author tschw
  2489. */
  2490. function Composite( targetGroup, path, optionalParsedPath ) {
  2491. var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName( path );
  2492. this._targetGroup = targetGroup;
  2493. this._bindings = targetGroup.subscribe_( path, parsedPath );
  2494. }
  2495. Object.assign( Composite.prototype, {
  2496. getValue: function ( array, offset ) {
  2497. this.bind(); // bind all binding
  2498. var firstValidIndex = this._targetGroup.nCachedObjects_,
  2499. binding = this._bindings[ firstValidIndex ];
  2500. // and only call .getValue on the first
  2501. if ( binding !== undefined ) binding.getValue( array, offset );
  2502. },
  2503. setValue: function ( array, offset ) {
  2504. var bindings = this._bindings;
  2505. for ( var i = this._targetGroup.nCachedObjects_,
  2506. n = bindings.length; i !== n; ++ i ) {
  2507. bindings[ i ].setValue( array, offset );
  2508. }
  2509. },
  2510. bind: function () {
  2511. var bindings = this._bindings;
  2512. for ( var i = this._targetGroup.nCachedObjects_,
  2513. n = bindings.length; i !== n; ++ i ) {
  2514. bindings[ i ].bind();
  2515. }
  2516. },
  2517. unbind: function () {
  2518. var bindings = this._bindings;
  2519. for ( var i = this._targetGroup.nCachedObjects_,
  2520. n = bindings.length; i !== n; ++ i ) {
  2521. bindings[ i ].unbind();
  2522. }
  2523. }
  2524. } );
  2525. function PropertyBinding( rootNode, path, parsedPath ) {
  2526. this.path = path;
  2527. this.parsedPath = parsedPath || PropertyBinding.parseTrackName( path );
  2528. this.node = PropertyBinding.findNode( rootNode, this.parsedPath.nodeName ) || rootNode;
  2529. this.rootNode = rootNode;
  2530. }
  2531. Object.assign( PropertyBinding, {
  2532. Composite: Composite,
  2533. create: function ( root, path, parsedPath ) {
  2534. if ( ! ( root && root.isAnimationObjectGroup ) ) {
  2535. return new PropertyBinding( root, path, parsedPath );
  2536. } else {
  2537. return new PropertyBinding.Composite( root, path, parsedPath );
  2538. }
  2539. },
  2540. /**
  2541. * Replaces spaces with underscores and removes unsupported characters from
  2542. * node names, to ensure compatibility with parseTrackName().
  2543. *
  2544. * @param {string} name Node name to be sanitized.
  2545. * @return {string}
  2546. */
  2547. sanitizeNodeName: function ( name ) {
  2548. return name.replace( /\s/g, '_' ).replace( /[^\w-]/g, '' );
  2549. },
  2550. parseTrackName: function () {
  2551. // Parent directories, delimited by '/' or ':'. Currently unused, but must
  2552. // be matched to parse the rest of the track name.
  2553. var directoryRe = /((?:[\w-]+[\/:])*)/;
  2554. // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  2555. var nodeRe = /([\w-\.]+)?/;
  2556. // Object on target node, and accessor. Name may contain only word
  2557. // characters. Accessor may contain any character except closing bracket.
  2558. var objectRe = /(?:\.([\w-]+)(?:\[(.+)\])?)?/;
  2559. // Property and accessor. May contain only word characters. Accessor may
  2560. // contain any non-bracket characters.
  2561. var propertyRe = /\.([\w-]+)(?:\[(.+)\])?/;
  2562. var trackRe = new RegExp( ''
  2563. + '^'
  2564. + directoryRe.source
  2565. + nodeRe.source
  2566. + objectRe.source
  2567. + propertyRe.source
  2568. + '$'
  2569. );
  2570. var supportedObjectNames = [ 'material', 'materials', 'bones' ];
  2571. return function ( trackName ) {
  2572. var matches = trackRe.exec( trackName );
  2573. if ( ! matches ) {
  2574. throw new Error( 'PropertyBinding: Cannot parse trackName: ' + trackName );
  2575. }
  2576. var results = {
  2577. // directoryName: matches[ 1 ], // (tschw) currently unused
  2578. nodeName: matches[ 2 ],
  2579. objectName: matches[ 3 ],
  2580. objectIndex: matches[ 4 ],
  2581. propertyName: matches[ 5 ], // required
  2582. propertyIndex: matches[ 6 ]
  2583. };
  2584. var lastDot = results.nodeName && results.nodeName.lastIndexOf( '.' );
  2585. if ( lastDot !== undefined && lastDot !== - 1 ) {
  2586. var objectName = results.nodeName.substring( lastDot + 1 );
  2587. // Object names must be checked against a whitelist. Otherwise, there
  2588. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  2589. // 'bar' could be the objectName, or part of a nodeName (which can
  2590. // include '.' characters).
  2591. if ( supportedObjectNames.indexOf( objectName ) !== - 1 ) {
  2592. results.nodeName = results.nodeName.substring( 0, lastDot );
  2593. results.objectName = objectName;
  2594. }
  2595. }
  2596. if ( results.propertyName === null || results.propertyName.length === 0 ) {
  2597. throw new Error( 'PropertyBinding: can not parse propertyName from trackName: ' + trackName );
  2598. }
  2599. return results;
  2600. };
  2601. }(),
  2602. findNode: function ( root, nodeName ) {
  2603. if ( ! nodeName || nodeName === "" || nodeName === "root" || nodeName === "." || nodeName === - 1 || nodeName === root.name || nodeName === root.uuid ) {
  2604. return root;
  2605. }
  2606. // search into skeleton bones.
  2607. if ( root.skeleton ) {
  2608. var searchSkeleton = function ( skeleton ) {
  2609. for ( var i = 0; i < skeleton.bones.length; i ++ ) {
  2610. var bone = skeleton.bones[ i ];
  2611. if ( bone.name === nodeName ) {
  2612. return bone;
  2613. }
  2614. }
  2615. return null;
  2616. };
  2617. var bone = searchSkeleton( root.skeleton );
  2618. if ( bone ) {
  2619. return bone;
  2620. }
  2621. }
  2622. // search into node subtree.
  2623. if ( root.children ) {
  2624. var searchNodeSubtree = function ( children ) {
  2625. for ( var i = 0; i < children.length; i ++ ) {
  2626. var childNode = children[ i ];
  2627. if ( childNode.name === nodeName || childNode.uuid === nodeName ) {
  2628. return childNode;
  2629. }
  2630. var result = searchNodeSubtree( childNode.children );
  2631. if ( result ) return result;
  2632. }
  2633. return null;
  2634. };
  2635. var subTreeNode = searchNodeSubtree( root.children );
  2636. if ( subTreeNode ) {
  2637. return subTreeNode;
  2638. }
  2639. }
  2640. return null;
  2641. }
  2642. } );
  2643. Object.assign( PropertyBinding.prototype, { // prototype, continued
  2644. // these are used to "bind" a nonexistent property
  2645. _getValue_unavailable: function () {},
  2646. _setValue_unavailable: function () {},
  2647. BindingType: {
  2648. Direct: 0,
  2649. EntireArray: 1,
  2650. ArrayElement: 2,
  2651. HasFromToArray: 3
  2652. },
  2653. Versioning: {
  2654. None: 0,
  2655. NeedsUpdate: 1,
  2656. MatrixWorldNeedsUpdate: 2
  2657. },
  2658. GetterByBindingType: [
  2659. function getValue_direct( buffer, offset ) {
  2660. buffer[ offset ] = this.node[ this.propertyName ];
  2661. },
  2662. function getValue_array( buffer, offset ) {
  2663. var source = this.resolvedProperty;
  2664. for ( var i = 0, n = source.length; i !== n; ++ i ) {
  2665. buffer[ offset ++ ] = source[ i ];
  2666. }
  2667. },
  2668. function getValue_arrayElement( buffer, offset ) {
  2669. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  2670. },
  2671. function getValue_toArray( buffer, offset ) {
  2672. this.resolvedProperty.toArray( buffer, offset );
  2673. }
  2674. ],
  2675. SetterByBindingTypeAndVersioning: [
  2676. [
  2677. // Direct
  2678. function setValue_direct( buffer, offset ) {
  2679. this.targetObject[ this.propertyName ] = buffer[ offset ];
  2680. },
  2681. function setValue_direct_setNeedsUpdate( buffer, offset ) {
  2682. this.targetObject[ this.propertyName ] = buffer[ offset ];
  2683. this.targetObject.needsUpdate = true;
  2684. },
  2685. function setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  2686. this.targetObject[ this.propertyName ] = buffer[ offset ];
  2687. this.targetObject.matrixWorldNeedsUpdate = true;
  2688. }
  2689. ], [
  2690. // EntireArray
  2691. function setValue_array( buffer, offset ) {
  2692. var dest = this.resolvedProperty;
  2693. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  2694. dest[ i ] = buffer[ offset ++ ];
  2695. }
  2696. },
  2697. function setValue_array_setNeedsUpdate( buffer, offset ) {
  2698. var dest = this.resolvedProperty;
  2699. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  2700. dest[ i ] = buffer[ offset ++ ];
  2701. }
  2702. this.targetObject.needsUpdate = true;
  2703. },
  2704. function setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  2705. var dest = this.resolvedProperty;
  2706. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  2707. dest[ i ] = buffer[ offset ++ ];
  2708. }
  2709. this.targetObject.matrixWorldNeedsUpdate = true;
  2710. }
  2711. ], [
  2712. // ArrayElement
  2713. function setValue_arrayElement( buffer, offset ) {
  2714. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  2715. },
  2716. function setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  2717. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  2718. this.targetObject.needsUpdate = true;
  2719. },
  2720. function setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  2721. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  2722. this.targetObject.matrixWorldNeedsUpdate = true;
  2723. }
  2724. ], [
  2725. // HasToFromArray
  2726. function setValue_fromArray( buffer, offset ) {
  2727. this.resolvedProperty.fromArray( buffer, offset );
  2728. },
  2729. function setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  2730. this.resolvedProperty.fromArray( buffer, offset );
  2731. this.targetObject.needsUpdate = true;
  2732. },
  2733. function setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  2734. this.resolvedProperty.fromArray( buffer, offset );
  2735. this.targetObject.matrixWorldNeedsUpdate = true;
  2736. }
  2737. ]
  2738. ],
  2739. getValue: function getValue_unbound( targetArray, offset ) {
  2740. this.bind();
  2741. this.getValue( targetArray, offset );
  2742. // Note: This class uses a State pattern on a per-method basis:
  2743. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  2744. // prototype version of these methods with one that represents
  2745. // the bound state. When the property is not found, the methods
  2746. // become no-ops.
  2747. },
  2748. setValue: function getValue_unbound( sourceArray, offset ) {
  2749. this.bind();
  2750. this.setValue( sourceArray, offset );
  2751. },
  2752. // create getter / setter pair for a property in the scene graph
  2753. bind: function () {
  2754. var targetObject = this.node,
  2755. parsedPath = this.parsedPath,
  2756. objectName = parsedPath.objectName,
  2757. propertyName = parsedPath.propertyName,
  2758. propertyIndex = parsedPath.propertyIndex;
  2759. if ( ! targetObject ) {
  2760. targetObject = PropertyBinding.findNode( this.rootNode, parsedPath.nodeName ) || this.rootNode;
  2761. this.node = targetObject;
  2762. }
  2763. // set fail state so we can just 'return' on error
  2764. this.getValue = this._getValue_unavailable;
  2765. this.setValue = this._setValue_unavailable;
  2766. // ensure there is a value node
  2767. if ( ! targetObject ) {
  2768. console.error( 'THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.' );
  2769. return;
  2770. }
  2771. if ( objectName ) {
  2772. var objectIndex = parsedPath.objectIndex;
  2773. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  2774. switch ( objectName ) {
  2775. case 'materials':
  2776. if ( ! targetObject.material ) {
  2777. console.error( 'THREE.PropertyBinding: Can not bind to material as node does not have a material.', this );
  2778. return;
  2779. }
  2780. if ( ! targetObject.material.materials ) {
  2781. console.error( 'THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this );
  2782. return;
  2783. }
  2784. targetObject = targetObject.material.materials;
  2785. break;
  2786. case 'bones':
  2787. if ( ! targetObject.skeleton ) {
  2788. console.error( 'THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this );
  2789. return;
  2790. }
  2791. // potential future optimization: skip this if propertyIndex is already an integer
  2792. // and convert the integer string to a true integer.
  2793. targetObject = targetObject.skeleton.bones;
  2794. // support resolving morphTarget names into indices.
  2795. for ( var i = 0; i < targetObject.length; i ++ ) {
  2796. if ( targetObject[ i ].name === objectIndex ) {
  2797. objectIndex = i;
  2798. break;
  2799. }
  2800. }
  2801. break;
  2802. default:
  2803. if ( targetObject[ objectName ] === undefined ) {
  2804. console.error( 'THREE.PropertyBinding: Can not bind to objectName of node undefined.', this );
  2805. return;
  2806. }
  2807. targetObject = targetObject[ objectName ];
  2808. }
  2809. if ( objectIndex !== undefined ) {
  2810. if ( targetObject[ objectIndex ] === undefined ) {
  2811. console.error( 'THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject );
  2812. return;
  2813. }
  2814. targetObject = targetObject[ objectIndex ];
  2815. }
  2816. }
  2817. // resolve property
  2818. var nodeProperty = targetObject[ propertyName ];
  2819. if ( nodeProperty === undefined ) {
  2820. var nodeName = parsedPath.nodeName;
  2821. console.error( 'THREE.PropertyBinding: Trying to update property for track: ' + nodeName +
  2822. '.' + propertyName + ' but it wasn\'t found.', targetObject );
  2823. return;
  2824. }
  2825. // determine versioning scheme
  2826. var versioning = this.Versioning.None;
  2827. if ( targetObject.needsUpdate !== undefined ) { // material
  2828. versioning = this.Versioning.NeedsUpdate;
  2829. this.targetObject = targetObject;
  2830. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  2831. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  2832. this.targetObject = targetObject;
  2833. }
  2834. // determine how the property gets bound
  2835. var bindingType = this.BindingType.Direct;
  2836. if ( propertyIndex !== undefined ) {
  2837. // access a sub element of the property array (only primitives are supported right now)
  2838. if ( propertyName === "morphTargetInfluences" ) {
  2839. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  2840. // support resolving morphTarget names into indices.
  2841. if ( ! targetObject.geometry ) {
  2842. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this );
  2843. return;
  2844. }
  2845. if ( targetObject.geometry.isBufferGeometry ) {
  2846. if ( ! targetObject.geometry.morphAttributes ) {
  2847. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this );
  2848. return;
  2849. }
  2850. for ( var i = 0; i < this.node.geometry.morphAttributes.position.length; i ++ ) {
  2851. if ( targetObject.geometry.morphAttributes.position[ i ].name === propertyIndex ) {
  2852. propertyIndex = i;
  2853. break;
  2854. }
  2855. }
  2856. } else {
  2857. if ( ! targetObject.geometry.morphTargets ) {
  2858. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphTargets.', this );
  2859. return;
  2860. }
  2861. for ( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {
  2862. if ( targetObject.geometry.morphTargets[ i ].name === propertyIndex ) {
  2863. propertyIndex = i;
  2864. break;
  2865. }
  2866. }
  2867. }
  2868. }
  2869. bindingType = this.BindingType.ArrayElement;
  2870. this.resolvedProperty = nodeProperty;
  2871. this.propertyIndex = propertyIndex;
  2872. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  2873. // must use copy for Object3D.Euler/Quaternion
  2874. bindingType = this.BindingType.HasFromToArray;
  2875. this.resolvedProperty = nodeProperty;
  2876. } else if ( Array.isArray( nodeProperty ) ) {
  2877. bindingType = this.BindingType.EntireArray;
  2878. this.resolvedProperty = nodeProperty;
  2879. } else {
  2880. this.propertyName = propertyName;
  2881. }
  2882. // select getter / setter
  2883. this.getValue = this.GetterByBindingType[ bindingType ];
  2884. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  2885. },
  2886. unbind: function () {
  2887. this.node = null;
  2888. // back to the prototype version of getValue / setValue
  2889. // note: avoiding to mutate the shape of 'this' via 'delete'
  2890. this.getValue = this._getValue_unbound;
  2891. this.setValue = this._setValue_unbound;
  2892. }
  2893. } );
  2894. //!\ DECLARE ALIAS AFTER assign prototype !
  2895. Object.assign( PropertyBinding.prototype, {
  2896. // initial state of these methods that calls 'bind'
  2897. _getValue_unbound: PropertyBinding.prototype.getValue,
  2898. _setValue_unbound: PropertyBinding.prototype.setValue,
  2899. } );
  2900. /**
  2901. *
  2902. * Buffered scene graph property that allows weighted accumulation.
  2903. *
  2904. *
  2905. * @author Ben Houston / http://clara.io/
  2906. * @author David Sarno / http://lighthaus.us/
  2907. * @author tschw
  2908. */
  2909. function PropertyMixer( binding, typeName, valueSize ) {
  2910. this.binding = binding;
  2911. this.valueSize = valueSize;
  2912. var bufferType = Float64Array,
  2913. mixFunction;
  2914. switch ( typeName ) {
  2915. case 'quaternion':
  2916. mixFunction = this._slerp;
  2917. break;
  2918. case 'string':
  2919. case 'bool':
  2920. bufferType = Array;
  2921. mixFunction = this._select;
  2922. break;
  2923. default:
  2924. mixFunction = this._lerp;
  2925. }
  2926. this.buffer = new bufferType( valueSize * 4 );
  2927. // layout: [ incoming | accu0 | accu1 | orig ]
  2928. //
  2929. // interpolators can use .buffer as their .result
  2930. // the data then goes to 'incoming'
  2931. //
  2932. // 'accu0' and 'accu1' are used frame-interleaved for
  2933. // the cumulative result and are compared to detect
  2934. // changes
  2935. //
  2936. // 'orig' stores the original state of the property
  2937. this._mixBufferRegion = mixFunction;
  2938. this.cumulativeWeight = 0;
  2939. this.useCount = 0;
  2940. this.referenceCount = 0;
  2941. }
  2942. Object.assign( PropertyMixer.prototype, {
  2943. // accumulate data in the 'incoming' region into 'accu<i>'
  2944. accumulate: function ( accuIndex, weight ) {
  2945. // note: happily accumulating nothing when weight = 0, the caller knows
  2946. // the weight and shouldn't have made the call in the first place
  2947. var buffer = this.buffer,
  2948. stride = this.valueSize,
  2949. offset = accuIndex * stride + stride,
  2950. currentWeight = this.cumulativeWeight;
  2951. if ( currentWeight === 0 ) {
  2952. // accuN := incoming * weight
  2953. for ( var i = 0; i !== stride; ++ i ) {
  2954. buffer[ offset + i ] = buffer[ i ];
  2955. }
  2956. currentWeight = weight;
  2957. } else {
  2958. // accuN := accuN + incoming * weight
  2959. currentWeight += weight;
  2960. var mix = weight / currentWeight;
  2961. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  2962. }
  2963. this.cumulativeWeight = currentWeight;
  2964. },
  2965. // apply the state of 'accu<i>' to the binding when accus differ
  2966. apply: function ( accuIndex ) {
  2967. var stride = this.valueSize,
  2968. buffer = this.buffer,
  2969. offset = accuIndex * stride + stride,
  2970. weight = this.cumulativeWeight,
  2971. binding = this.binding;
  2972. this.cumulativeWeight = 0;
  2973. if ( weight < 1 ) {
  2974. // accuN := accuN + original * ( 1 - cumulativeWeight )
  2975. var originalValueOffset = stride * 3;
  2976. this._mixBufferRegion(
  2977. buffer, offset, originalValueOffset, 1 - weight, stride );
  2978. }
  2979. for ( var i = stride, e = stride + stride; i !== e; ++ i ) {
  2980. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  2981. // value has changed -> update scene graph
  2982. binding.setValue( buffer, offset );
  2983. break;
  2984. }
  2985. }
  2986. },
  2987. // remember the state of the bound property and copy it to both accus
  2988. saveOriginalState: function () {
  2989. var binding = this.binding;
  2990. var buffer = this.buffer,
  2991. stride = this.valueSize,
  2992. originalValueOffset = stride * 3;
  2993. binding.getValue( buffer, originalValueOffset );
  2994. // accu[0..1] := orig -- initially detect changes against the original
  2995. for ( var i = stride, e = originalValueOffset; i !== e; ++ i ) {
  2996. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  2997. }
  2998. this.cumulativeWeight = 0;
  2999. },
  3000. // apply the state previously taken via 'saveOriginalState' to the binding
  3001. restoreOriginalState: function () {
  3002. var originalValueOffset = this.valueSize * 3;
  3003. this.binding.setValue( this.buffer, originalValueOffset );
  3004. },
  3005. // mix functions
  3006. _select: function ( buffer, dstOffset, srcOffset, t, stride ) {
  3007. if ( t >= 0.5 ) {
  3008. for ( var i = 0; i !== stride; ++ i ) {
  3009. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  3010. }
  3011. }
  3012. },
  3013. _slerp: function ( buffer, dstOffset, srcOffset, t ) {
  3014. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t );
  3015. },
  3016. _lerp: function ( buffer, dstOffset, srcOffset, t, stride ) {
  3017. var s = 1 - t;
  3018. for ( var i = 0; i !== stride; ++ i ) {
  3019. var j = dstOffset + i;
  3020. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  3021. }
  3022. }
  3023. } );
  3024. /**
  3025. * @author tschw
  3026. * @author Ben Houston / http://clara.io/
  3027. * @author David Sarno / http://lighthaus.us/
  3028. */
  3029. var AnimationUtils = {
  3030. // same as Array.prototype.slice, but also works on typed arrays
  3031. arraySlice: function ( array, from, to ) {
  3032. if ( AnimationUtils.isTypedArray( array ) ) {
  3033. // in ios9 array.subarray(from, undefined) will return empty array
  3034. // but array.subarray(from) or array.subarray(from, len) is correct
  3035. return new array.constructor( array.subarray( from, to !== undefined ? to : array.length ) );
  3036. }
  3037. return array.slice( from, to );
  3038. },
  3039. // converts an array to a specific type
  3040. convertArray: function ( array, type, forceClone ) {
  3041. if ( ! array || // let 'undefined' and 'null' pass
  3042. ! forceClone && array.constructor === type ) return array;
  3043. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  3044. return new type( array ); // create typed array
  3045. }
  3046. return Array.prototype.slice.call( array ); // create Array
  3047. },
  3048. isTypedArray: function ( object ) {
  3049. return ArrayBuffer.isView( object ) &&
  3050. ! ( object instanceof DataView );
  3051. },
  3052. // returns an array by which times and values can be sorted
  3053. getKeyframeOrder: function ( times ) {
  3054. function compareTime( i, j ) {
  3055. return times[ i ] - times[ j ];
  3056. }
  3057. var n = times.length;
  3058. var result = new Array( n );
  3059. for ( var i = 0; i !== n; ++ i ) result[ i ] = i;
  3060. result.sort( compareTime );
  3061. return result;
  3062. },
  3063. // uses the array previously returned by 'getKeyframeOrder' to sort data
  3064. sortedArray: function ( values, stride, order ) {
  3065. var nValues = values.length;
  3066. var result = new values.constructor( nValues );
  3067. for ( var i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  3068. var srcOffset = order[ i ] * stride;
  3069. for ( var j = 0; j !== stride; ++ j ) {
  3070. result[ dstOffset ++ ] = values[ srcOffset + j ];
  3071. }
  3072. }
  3073. return result;
  3074. },
  3075. // function for parsing AOS keyframe formats
  3076. flattenJSON: function ( jsonKeys, times, values, valuePropertyName ) {
  3077. var i = 1, key = jsonKeys[ 0 ];
  3078. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  3079. key = jsonKeys[ i ++ ];
  3080. }
  3081. if ( key === undefined ) return; // no data
  3082. var value = key[ valuePropertyName ];
  3083. if ( value === undefined ) return; // no data
  3084. if ( Array.isArray( value ) ) {
  3085. do {
  3086. value = key[ valuePropertyName ];
  3087. if ( value !== undefined ) {
  3088. times.push( key.time );
  3089. values.push.apply( values, value ); // push all elements
  3090. }
  3091. key = jsonKeys[ i ++ ];
  3092. } while ( key !== undefined );
  3093. } else if ( value.toArray !== undefined ) {
  3094. // ...assume THREE.Math-ish
  3095. do {
  3096. value = key[ valuePropertyName ];
  3097. if ( value !== undefined ) {
  3098. times.push( key.time );
  3099. value.toArray( values, values.length );
  3100. }
  3101. key = jsonKeys[ i ++ ];
  3102. } while ( key !== undefined );
  3103. } else {
  3104. // otherwise push as-is
  3105. do {
  3106. value = key[ valuePropertyName ];
  3107. if ( value !== undefined ) {
  3108. times.push( key.time );
  3109. values.push( value );
  3110. }
  3111. key = jsonKeys[ i ++ ];
  3112. } while ( key !== undefined );
  3113. }
  3114. }
  3115. };
  3116. /**
  3117. * Fast and simple cubic spline interpolant.
  3118. *
  3119. * It was derived from a Hermitian construction setting the first derivative
  3120. * at each sample position to the linear slope between neighboring positions
  3121. * over their parameter interval.
  3122. *
  3123. * @author tschw
  3124. */
  3125. function CubicInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  3126. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  3127. this._weightPrev = - 0;
  3128. this._offsetPrev = - 0;
  3129. this._weightNext = - 0;
  3130. this._offsetNext = - 0;
  3131. }
  3132. CubicInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  3133. constructor: CubicInterpolant,
  3134. DefaultSettings_: {
  3135. endingStart: ZeroCurvatureEnding,
  3136. endingEnd: ZeroCurvatureEnding
  3137. },
  3138. intervalChanged_: function ( i1, t0, t1 ) {
  3139. var pp = this.parameterPositions,
  3140. iPrev = i1 - 2,
  3141. iNext = i1 + 1,
  3142. tPrev = pp[ iPrev ],
  3143. tNext = pp[ iNext ];
  3144. if ( tPrev === undefined ) {
  3145. switch ( this.getSettings_().endingStart ) {
  3146. case ZeroSlopeEnding:
  3147. // f'(t0) = 0
  3148. iPrev = i1;
  3149. tPrev = 2 * t0 - t1;
  3150. break;
  3151. case WrapAroundEnding:
  3152. // use the other end of the curve
  3153. iPrev = pp.length - 2;
  3154. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  3155. break;
  3156. default: // ZeroCurvatureEnding
  3157. // f''(t0) = 0 a.k.a. Natural Spline
  3158. iPrev = i1;
  3159. tPrev = t1;
  3160. }
  3161. }
  3162. if ( tNext === undefined ) {
  3163. switch ( this.getSettings_().endingEnd ) {
  3164. case ZeroSlopeEnding:
  3165. // f'(tN) = 0
  3166. iNext = i1;
  3167. tNext = 2 * t1 - t0;
  3168. break;
  3169. case WrapAroundEnding:
  3170. // use the other end of the curve
  3171. iNext = 1;
  3172. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  3173. break;
  3174. default: // ZeroCurvatureEnding
  3175. // f''(tN) = 0, a.k.a. Natural Spline
  3176. iNext = i1 - 1;
  3177. tNext = t0;
  3178. }
  3179. }
  3180. var halfDt = ( t1 - t0 ) * 0.5,
  3181. stride = this.valueSize;
  3182. this._weightPrev = halfDt / ( t0 - tPrev );
  3183. this._weightNext = halfDt / ( tNext - t1 );
  3184. this._offsetPrev = iPrev * stride;
  3185. this._offsetNext = iNext * stride;
  3186. },
  3187. interpolate_: function ( i1, t0, t, t1 ) {
  3188. var result = this.resultBuffer,
  3189. values = this.sampleValues,
  3190. stride = this.valueSize,
  3191. o1 = i1 * stride, o0 = o1 - stride,
  3192. oP = this._offsetPrev, oN = this._offsetNext,
  3193. wP = this._weightPrev, wN = this._weightNext,
  3194. p = ( t - t0 ) / ( t1 - t0 ),
  3195. pp = p * p,
  3196. ppp = pp * p;
  3197. // evaluate polynomials
  3198. var sP = - wP * ppp + 2 * wP * pp - wP * p;
  3199. var s0 = ( 1 + wP ) * ppp + ( - 1.5 - 2 * wP ) * pp + ( - 0.5 + wP ) * p + 1;
  3200. var s1 = ( - 1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  3201. var sN = wN * ppp - wN * pp;
  3202. // combine data linearly
  3203. for ( var i = 0; i !== stride; ++ i ) {
  3204. result[ i ] =
  3205. sP * values[ oP + i ] +
  3206. s0 * values[ o0 + i ] +
  3207. s1 * values[ o1 + i ] +
  3208. sN * values[ oN + i ];
  3209. }
  3210. return result;
  3211. }
  3212. } );
  3213. /**
  3214. *
  3215. * Interpolant that evaluates to the sample value at the position preceeding
  3216. * the parameter.
  3217. *
  3218. * @author tschw
  3219. */
  3220. function DiscreteInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  3221. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  3222. }
  3223. DiscreteInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  3224. constructor: DiscreteInterpolant,
  3225. interpolate_: function ( i1 /*, t0, t, t1 */ ) {
  3226. return this.copySampleValue_( i1 - 1 );
  3227. }
  3228. } );
  3229. var KeyframeTrackPrototype;
  3230. KeyframeTrackPrototype = {
  3231. TimeBufferType: Float32Array,
  3232. ValueBufferType: Float32Array,
  3233. DefaultInterpolation: InterpolateLinear,
  3234. InterpolantFactoryMethodDiscrete: function ( result ) {
  3235. return new DiscreteInterpolant( this.times, this.values, this.getValueSize(), result );
  3236. },
  3237. InterpolantFactoryMethodLinear: function ( result ) {
  3238. return new LinearInterpolant( this.times, this.values, this.getValueSize(), result );
  3239. },
  3240. InterpolantFactoryMethodSmooth: function ( result ) {
  3241. return new CubicInterpolant( this.times, this.values, this.getValueSize(), result );
  3242. },
  3243. setInterpolation: function ( interpolation ) {
  3244. var factoryMethod;
  3245. switch ( interpolation ) {
  3246. case InterpolateDiscrete:
  3247. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  3248. break;
  3249. case InterpolateLinear:
  3250. factoryMethod = this.InterpolantFactoryMethodLinear;
  3251. break;
  3252. case InterpolateSmooth:
  3253. factoryMethod = this.InterpolantFactoryMethodSmooth;
  3254. break;
  3255. }
  3256. if ( factoryMethod === undefined ) {
  3257. var message = "unsupported interpolation for " +
  3258. this.ValueTypeName + " keyframe track named " + this.name;
  3259. if ( this.createInterpolant === undefined ) {
  3260. // fall back to default, unless the default itself is messed up
  3261. if ( interpolation !== this.DefaultInterpolation ) {
  3262. this.setInterpolation( this.DefaultInterpolation );
  3263. } else {
  3264. throw new Error( message ); // fatal, in this case
  3265. }
  3266. }
  3267. console.warn( 'THREE.KeyframeTrackPrototype:', message );
  3268. return;
  3269. }
  3270. this.createInterpolant = factoryMethod;
  3271. },
  3272. getInterpolation: function () {
  3273. switch ( this.createInterpolant ) {
  3274. case this.InterpolantFactoryMethodDiscrete:
  3275. return InterpolateDiscrete;
  3276. case this.InterpolantFactoryMethodLinear:
  3277. return InterpolateLinear;
  3278. case this.InterpolantFactoryMethodSmooth:
  3279. return InterpolateSmooth;
  3280. }
  3281. },
  3282. getValueSize: function () {
  3283. return this.values.length / this.times.length;
  3284. },
  3285. // move all keyframes either forwards or backwards in time
  3286. shift: function ( timeOffset ) {
  3287. if ( timeOffset !== 0.0 ) {
  3288. var times = this.times;
  3289. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  3290. times[ i ] += timeOffset;
  3291. }
  3292. }
  3293. return this;
  3294. },
  3295. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  3296. scale: function ( timeScale ) {
  3297. if ( timeScale !== 1.0 ) {
  3298. var times = this.times;
  3299. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  3300. times[ i ] *= timeScale;
  3301. }
  3302. }
  3303. return this;
  3304. },
  3305. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  3306. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  3307. trim: function ( startTime, endTime ) {
  3308. var times = this.times,
  3309. nKeys = times.length,
  3310. from = 0,
  3311. to = nKeys - 1;
  3312. while ( from !== nKeys && times[ from ] < startTime ) ++ from;
  3313. while ( to !== - 1 && times[ to ] > endTime ) -- to;
  3314. ++ to; // inclusive -> exclusive bound
  3315. if ( from !== 0 || to !== nKeys ) {
  3316. // empty tracks are forbidden, so keep at least one keyframe
  3317. if ( from >= to ) to = Math.max( to, 1 ), from = to - 1;
  3318. var stride = this.getValueSize();
  3319. this.times = AnimationUtils.arraySlice( times, from, to );
  3320. this.values = AnimationUtils.arraySlice( this.values, from * stride, to * stride );
  3321. }
  3322. return this;
  3323. },
  3324. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  3325. validate: function () {
  3326. var valid = true;
  3327. var valueSize = this.getValueSize();
  3328. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  3329. console.error( 'THREE.KeyframeTrackPrototype: Invalid value size in track.', this );
  3330. valid = false;
  3331. }
  3332. var times = this.times,
  3333. values = this.values,
  3334. nKeys = times.length;
  3335. if ( nKeys === 0 ) {
  3336. console.error( 'THREE.KeyframeTrackPrototype: Track is empty.', this );
  3337. valid = false;
  3338. }
  3339. var prevTime = null;
  3340. for ( var i = 0; i !== nKeys; i ++ ) {
  3341. var currTime = times[ i ];
  3342. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  3343. console.error( 'THREE.KeyframeTrackPrototype: Time is not a valid number.', this, i, currTime );
  3344. valid = false;
  3345. break;
  3346. }
  3347. if ( prevTime !== null && prevTime > currTime ) {
  3348. console.error( 'THREE.KeyframeTrackPrototype: Out of order keys.', this, i, currTime, prevTime );
  3349. valid = false;
  3350. break;
  3351. }
  3352. prevTime = currTime;
  3353. }
  3354. if ( values !== undefined ) {
  3355. if ( AnimationUtils.isTypedArray( values ) ) {
  3356. for ( var i = 0, n = values.length; i !== n; ++ i ) {
  3357. var value = values[ i ];
  3358. if ( isNaN( value ) ) {
  3359. console.error( 'THREE.KeyframeTrackPrototype: Value is not a valid number.', this, i, value );
  3360. valid = false;
  3361. break;
  3362. }
  3363. }
  3364. }
  3365. }
  3366. return valid;
  3367. },
  3368. // removes equivalent sequential keys as common in morph target sequences
  3369. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  3370. optimize: function () {
  3371. var times = this.times,
  3372. values = this.values,
  3373. stride = this.getValueSize(),
  3374. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  3375. writeIndex = 1,
  3376. lastIndex = times.length - 1;
  3377. for ( var i = 1; i < lastIndex; ++ i ) {
  3378. var keep = false;
  3379. var time = times[ i ];
  3380. var timeNext = times[ i + 1 ];
  3381. // remove adjacent keyframes scheduled at the same time
  3382. if ( time !== timeNext && ( i !== 1 || time !== time[ 0 ] ) ) {
  3383. if ( ! smoothInterpolation ) {
  3384. // remove unnecessary keyframes same as their neighbors
  3385. var offset = i * stride,
  3386. offsetP = offset - stride,
  3387. offsetN = offset + stride;
  3388. for ( var j = 0; j !== stride; ++ j ) {
  3389. var value = values[ offset + j ];
  3390. if ( value !== values[ offsetP + j ] ||
  3391. value !== values[ offsetN + j ] ) {
  3392. keep = true;
  3393. break;
  3394. }
  3395. }
  3396. } else keep = true;
  3397. }
  3398. // in-place compaction
  3399. if ( keep ) {
  3400. if ( i !== writeIndex ) {
  3401. times[ writeIndex ] = times[ i ];
  3402. var readOffset = i * stride,
  3403. writeOffset = writeIndex * stride;
  3404. for ( var j = 0; j !== stride; ++ j )
  3405. values[ writeOffset + j ] = values[ readOffset + j ];
  3406. }
  3407. ++ writeIndex;
  3408. }
  3409. }
  3410. // flush last keyframe (compaction looks ahead)
  3411. if ( lastIndex > 0 ) {
  3412. times[ writeIndex ] = times[ lastIndex ];
  3413. for ( var readOffset = lastIndex * stride, writeOffset = writeIndex * stride, j = 0; j !== stride; ++ j )
  3414. values[ writeOffset + j ] = values[ readOffset + j ];
  3415. ++ writeIndex;
  3416. }
  3417. if ( writeIndex !== times.length ) {
  3418. this.times = AnimationUtils.arraySlice( times, 0, writeIndex );
  3419. this.values = AnimationUtils.arraySlice( values, 0, writeIndex * stride );
  3420. }
  3421. return this;
  3422. }
  3423. };
  3424. function KeyframeTrackConstructor( name, times, values, interpolation ) {
  3425. if ( name === undefined ) throw new Error( 'track name is undefined' );
  3426. if ( times === undefined || times.length === 0 ) {
  3427. throw new Error( 'no keyframes in track named ' + name );
  3428. }
  3429. this.name = name;
  3430. this.times = AnimationUtils.convertArray( times, this.TimeBufferType );
  3431. this.values = AnimationUtils.convertArray( values, this.ValueBufferType );
  3432. this.setInterpolation( interpolation || this.DefaultInterpolation );
  3433. this.validate();
  3434. this.optimize();
  3435. }
  3436. /**
  3437. *
  3438. * A Track of vectored keyframe values.
  3439. *
  3440. *
  3441. * @author Ben Houston / http://clara.io/
  3442. * @author David Sarno / http://lighthaus.us/
  3443. * @author tschw
  3444. */
  3445. function VectorKeyframeTrack( name, times, values, interpolation ) {
  3446. KeyframeTrackConstructor.call( this, name, times, values, interpolation );
  3447. }
  3448. VectorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrackPrototype ), {
  3449. constructor: VectorKeyframeTrack,
  3450. ValueTypeName: 'vector'
  3451. // ValueBufferType is inherited
  3452. // DefaultInterpolation is inherited
  3453. } );
  3454. /**
  3455. * Spherical linear unit quaternion interpolant.
  3456. *
  3457. * @author tschw
  3458. */
  3459. function QuaternionLinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  3460. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  3461. }
  3462. QuaternionLinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  3463. constructor: QuaternionLinearInterpolant,
  3464. interpolate_: function ( i1, t0, t, t1 ) {
  3465. var result = this.resultBuffer,
  3466. values = this.sampleValues,
  3467. stride = this.valueSize,
  3468. offset = i1 * stride,
  3469. alpha = ( t - t0 ) / ( t1 - t0 );
  3470. for ( var end = offset + stride; offset !== end; offset += 4 ) {
  3471. Quaternion.slerpFlat( result, 0, values, offset - stride, values, offset, alpha );
  3472. }
  3473. return result;
  3474. }
  3475. } );
  3476. /**
  3477. *
  3478. * A Track of quaternion keyframe values.
  3479. *
  3480. * @author Ben Houston / http://clara.io/
  3481. * @author David Sarno / http://lighthaus.us/
  3482. * @author tschw
  3483. */
  3484. function QuaternionKeyframeTrack( name, times, values, interpolation ) {
  3485. KeyframeTrackConstructor.call( this, name, times, values, interpolation );
  3486. }
  3487. QuaternionKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrackPrototype ), {
  3488. constructor: QuaternionKeyframeTrack,
  3489. ValueTypeName: 'quaternion',
  3490. // ValueBufferType is inherited
  3491. DefaultInterpolation: InterpolateLinear,
  3492. InterpolantFactoryMethodLinear: function ( result ) {
  3493. return new QuaternionLinearInterpolant( this.times, this.values, this.getValueSize(), result );
  3494. },
  3495. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  3496. } );
  3497. /**
  3498. *
  3499. * A Track of numeric keyframe values.
  3500. *
  3501. * @author Ben Houston / http://clara.io/
  3502. * @author David Sarno / http://lighthaus.us/
  3503. * @author tschw
  3504. */
  3505. function NumberKeyframeTrack( name, times, values, interpolation ) {
  3506. KeyframeTrackConstructor.call( this, name, times, values, interpolation );
  3507. }
  3508. NumberKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrackPrototype ), {
  3509. constructor: NumberKeyframeTrack,
  3510. ValueTypeName: 'number'
  3511. // ValueBufferType is inherited
  3512. // DefaultInterpolation is inherited
  3513. } );
  3514. /**
  3515. *
  3516. * A Track that interpolates Strings
  3517. *
  3518. *
  3519. * @author Ben Houston / http://clara.io/
  3520. * @author David Sarno / http://lighthaus.us/
  3521. * @author tschw
  3522. */
  3523. function StringKeyframeTrack( name, times, values, interpolation ) {
  3524. KeyframeTrackConstructor.call( this, name, times, values, interpolation );
  3525. }
  3526. StringKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrackPrototype ), {
  3527. constructor: StringKeyframeTrack,
  3528. ValueTypeName: 'string',
  3529. ValueBufferType: Array,
  3530. DefaultInterpolation: InterpolateDiscrete,
  3531. InterpolantFactoryMethodLinear: undefined,
  3532. InterpolantFactoryMethodSmooth: undefined
  3533. } );
  3534. /**
  3535. *
  3536. * A Track of Boolean keyframe values.
  3537. *
  3538. *
  3539. * @author Ben Houston / http://clara.io/
  3540. * @author David Sarno / http://lighthaus.us/
  3541. * @author tschw
  3542. */
  3543. function BooleanKeyframeTrack( name, times, values ) {
  3544. KeyframeTrackConstructor.call( this, name, times, values );
  3545. }
  3546. BooleanKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrackPrototype ), {
  3547. constructor: BooleanKeyframeTrack,
  3548. ValueTypeName: 'bool',
  3549. ValueBufferType: Array,
  3550. DefaultInterpolation: InterpolateDiscrete,
  3551. InterpolantFactoryMethodLinear: undefined,
  3552. InterpolantFactoryMethodSmooth: undefined
  3553. // Note: Actually this track could have a optimized / compressed
  3554. // representation of a single value and a custom interpolant that
  3555. // computes "firstValue ^ isOdd( index )".
  3556. } );
  3557. /**
  3558. *
  3559. * A Track of keyframe values that represent color.
  3560. *
  3561. *
  3562. * @author Ben Houston / http://clara.io/
  3563. * @author David Sarno / http://lighthaus.us/
  3564. * @author tschw
  3565. */
  3566. function ColorKeyframeTrack( name, times, values, interpolation ) {
  3567. KeyframeTrackConstructor.call( this, name, times, values, interpolation );
  3568. }
  3569. ColorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrackPrototype ), {
  3570. constructor: ColorKeyframeTrack,
  3571. ValueTypeName: 'color'
  3572. // ValueBufferType is inherited
  3573. // DefaultInterpolation is inherited
  3574. // Note: Very basic implementation and nothing special yet.
  3575. // However, this is the place for color space parameterization.
  3576. } );
  3577. /**
  3578. *
  3579. * A timed sequence of keyframes for a specific property.
  3580. *
  3581. *
  3582. * @author Ben Houston / http://clara.io/
  3583. * @author David Sarno / http://lighthaus.us/
  3584. * @author tschw
  3585. */
  3586. function KeyframeTrack( name, times, values, interpolation ) {
  3587. KeyframeTrackConstructor.apply( this, name, times, values, interpolation );
  3588. }
  3589. KeyframeTrack.prototype = KeyframeTrackPrototype;
  3590. KeyframeTrackPrototype.constructor = KeyframeTrack;
  3591. // Static methods:
  3592. Object.assign( KeyframeTrack, {
  3593. // Serialization (in static context, because of constructor invocation
  3594. // and automatic invocation of .toJSON):
  3595. parse: function ( json ) {
  3596. if ( json.type === undefined ) {
  3597. throw new Error( 'track type undefined, can not parse' );
  3598. }
  3599. var trackType = KeyframeTrack._getTrackTypeForValueTypeName( json.type );
  3600. if ( json.times === undefined ) {
  3601. var times = [], values = [];
  3602. AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
  3603. json.times = times;
  3604. json.values = values;
  3605. }
  3606. // derived classes can define a static parse method
  3607. if ( trackType.parse !== undefined ) {
  3608. return trackType.parse( json );
  3609. } else {
  3610. // by default, we assume a constructor compatible with the base
  3611. return new trackType( json.name, json.times, json.values, json.interpolation );
  3612. }
  3613. },
  3614. toJSON: function ( track ) {
  3615. var trackType = track.constructor;
  3616. var json;
  3617. // derived classes can define a static toJSON method
  3618. if ( trackType.toJSON !== undefined ) {
  3619. json = trackType.toJSON( track );
  3620. } else {
  3621. // by default, we assume the data can be serialized as-is
  3622. json = {
  3623. 'name': track.name,
  3624. 'times': AnimationUtils.convertArray( track.times, Array ),
  3625. 'values': AnimationUtils.convertArray( track.values, Array )
  3626. };
  3627. var interpolation = track.getInterpolation();
  3628. if ( interpolation !== track.DefaultInterpolation ) {
  3629. json.interpolation = interpolation;
  3630. }
  3631. }
  3632. json.type = track.ValueTypeName; // mandatory
  3633. return json;
  3634. },
  3635. _getTrackTypeForValueTypeName: function ( typeName ) {
  3636. switch ( typeName.toLowerCase() ) {
  3637. case 'scalar':
  3638. case 'double':
  3639. case 'float':
  3640. case 'number':
  3641. case 'integer':
  3642. return NumberKeyframeTrack;
  3643. case 'vector':
  3644. case 'vector2':
  3645. case 'vector3':
  3646. case 'vector4':
  3647. return VectorKeyframeTrack;
  3648. case 'color':
  3649. return ColorKeyframeTrack;
  3650. case 'quaternion':
  3651. return QuaternionKeyframeTrack;
  3652. case 'bool':
  3653. case 'boolean':
  3654. return BooleanKeyframeTrack;
  3655. case 'string':
  3656. return StringKeyframeTrack;
  3657. }
  3658. throw new Error( 'Unsupported typeName: ' + typeName );
  3659. }
  3660. } );
  3661. /**
  3662. *
  3663. * Reusable set of Tracks that represent an animation.
  3664. *
  3665. * @author Ben Houston / http://clara.io/
  3666. * @author David Sarno / http://lighthaus.us/
  3667. */
  3668. function AnimationClip( name, duration, tracks ) {
  3669. this.name = name;
  3670. this.tracks = tracks;
  3671. this.duration = ( duration !== undefined ) ? duration : - 1;
  3672. this.uuid = _Math.generateUUID();
  3673. // this means it should figure out its duration by scanning the tracks
  3674. if ( this.duration < 0 ) {
  3675. this.resetDuration();
  3676. }
  3677. this.optimize();
  3678. }
  3679. Object.assign( AnimationClip, {
  3680. parse: function ( json ) {
  3681. var tracks = [],
  3682. jsonTracks = json.tracks,
  3683. frameTime = 1.0 / ( json.fps || 1.0 );
  3684. for ( var i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  3685. tracks.push( KeyframeTrack.parse( jsonTracks[ i ] ).scale( frameTime ) );
  3686. }
  3687. return new AnimationClip( json.name, json.duration, tracks );
  3688. },
  3689. toJSON: function ( clip ) {
  3690. var tracks = [],
  3691. clipTracks = clip.tracks;
  3692. var json = {
  3693. 'name': clip.name,
  3694. 'duration': clip.duration,
  3695. 'tracks': tracks
  3696. };
  3697. for ( var i = 0, n = clipTracks.length; i !== n; ++ i ) {
  3698. tracks.push( KeyframeTrack.toJSON( clipTracks[ i ] ) );
  3699. }
  3700. return json;
  3701. },
  3702. CreateFromMorphTargetSequence: function ( name, morphTargetSequence, fps, noLoop ) {
  3703. var numMorphTargets = morphTargetSequence.length;
  3704. var tracks = [];
  3705. for ( var i = 0; i < numMorphTargets; i ++ ) {
  3706. var times = [];
  3707. var values = [];
  3708. times.push(
  3709. ( i + numMorphTargets - 1 ) % numMorphTargets,
  3710. i,
  3711. ( i + 1 ) % numMorphTargets );
  3712. values.push( 0, 1, 0 );
  3713. var order = AnimationUtils.getKeyframeOrder( times );
  3714. times = AnimationUtils.sortedArray( times, 1, order );
  3715. values = AnimationUtils.sortedArray( values, 1, order );
  3716. // if there is a key at the first frame, duplicate it as the
  3717. // last frame as well for perfect loop.
  3718. if ( ! noLoop && times[ 0 ] === 0 ) {
  3719. times.push( numMorphTargets );
  3720. values.push( values[ 0 ] );
  3721. }
  3722. tracks.push(
  3723. new NumberKeyframeTrack(
  3724. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  3725. times, values
  3726. ).scale( 1.0 / fps ) );
  3727. }
  3728. return new AnimationClip( name, - 1, tracks );
  3729. },
  3730. findByName: function ( objectOrClipArray, name ) {
  3731. var clipArray = objectOrClipArray;
  3732. if ( ! Array.isArray( objectOrClipArray ) ) {
  3733. var o = objectOrClipArray;
  3734. clipArray = o.geometry && o.geometry.animations || o.animations;
  3735. }
  3736. for ( var i = 0; i < clipArray.length; i ++ ) {
  3737. if ( clipArray[ i ].name === name ) {
  3738. return clipArray[ i ];
  3739. }
  3740. }
  3741. return null;
  3742. },
  3743. CreateClipsFromMorphTargetSequences: function ( morphTargets, fps, noLoop ) {
  3744. var animationToMorphTargets = {};
  3745. // tested with https://regex101.com/ on trick sequences
  3746. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  3747. var pattern = /^([\w-]*?)([\d]+)$/;
  3748. // sort morph target names into animation groups based
  3749. // patterns like Walk_001, Walk_002, Run_001, Run_002
  3750. for ( var i = 0, il = morphTargets.length; i < il; i ++ ) {
  3751. var morphTarget = morphTargets[ i ];
  3752. var parts = morphTarget.name.match( pattern );
  3753. if ( parts && parts.length > 1 ) {
  3754. var name = parts[ 1 ];
  3755. var animationMorphTargets = animationToMorphTargets[ name ];
  3756. if ( ! animationMorphTargets ) {
  3757. animationToMorphTargets[ name ] = animationMorphTargets = [];
  3758. }
  3759. animationMorphTargets.push( morphTarget );
  3760. }
  3761. }
  3762. var clips = [];
  3763. for ( var name in animationToMorphTargets ) {
  3764. clips.push( AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps, noLoop ) );
  3765. }
  3766. return clips;
  3767. },
  3768. // parse the animation.hierarchy format
  3769. parseAnimation: function ( animation, bones ) {
  3770. if ( ! animation ) {
  3771. console.error( 'THREE.AnimationClip: No animation in JSONLoader data.' );
  3772. return null;
  3773. }
  3774. var addNonemptyTrack = function ( trackType, trackName, animationKeys, propertyName, destTracks ) {
  3775. // only return track if there are actually keys.
  3776. if ( animationKeys.length !== 0 ) {
  3777. var times = [];
  3778. var values = [];
  3779. AnimationUtils.flattenJSON( animationKeys, times, values, propertyName );
  3780. // empty keys are filtered out, so check again
  3781. if ( times.length !== 0 ) {
  3782. destTracks.push( new trackType( trackName, times, values ) );
  3783. }
  3784. }
  3785. };
  3786. var tracks = [];
  3787. var clipName = animation.name || 'default';
  3788. // automatic length determination in AnimationClip.
  3789. var duration = animation.length || - 1;
  3790. var fps = animation.fps || 30;
  3791. var hierarchyTracks = animation.hierarchy || [];
  3792. for ( var h = 0; h < hierarchyTracks.length; h ++ ) {
  3793. var animationKeys = hierarchyTracks[ h ].keys;
  3794. // skip empty tracks
  3795. if ( ! animationKeys || animationKeys.length === 0 ) continue;
  3796. // process morph targets
  3797. if ( animationKeys[ 0 ].morphTargets ) {
  3798. // figure out all morph targets used in this track
  3799. var morphTargetNames = {};
  3800. for ( var k = 0; k < animationKeys.length; k ++ ) {
  3801. if ( animationKeys[ k ].morphTargets ) {
  3802. for ( var m = 0; m < animationKeys[ k ].morphTargets.length; m ++ ) {
  3803. morphTargetNames[ animationKeys[ k ].morphTargets[ m ] ] = - 1;
  3804. }
  3805. }
  3806. }
  3807. // create a track for each morph target with all zero
  3808. // morphTargetInfluences except for the keys in which
  3809. // the morphTarget is named.
  3810. for ( var morphTargetName in morphTargetNames ) {
  3811. var times = [];
  3812. var values = [];
  3813. for ( var m = 0; m !== animationKeys[ k ].morphTargets.length; ++ m ) {
  3814. var animationKey = animationKeys[ k ];
  3815. times.push( animationKey.time );
  3816. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 );
  3817. }
  3818. tracks.push( new NumberKeyframeTrack( '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  3819. }
  3820. duration = morphTargetNames.length * ( fps || 1.0 );
  3821. } else {
  3822. // ...assume skeletal animation
  3823. var boneName = '.bones[' + bones[ h ].name + ']';
  3824. addNonemptyTrack(
  3825. VectorKeyframeTrack, boneName + '.position',
  3826. animationKeys, 'pos', tracks );
  3827. addNonemptyTrack(
  3828. QuaternionKeyframeTrack, boneName + '.quaternion',
  3829. animationKeys, 'rot', tracks );
  3830. addNonemptyTrack(
  3831. VectorKeyframeTrack, boneName + '.scale',
  3832. animationKeys, 'scl', tracks );
  3833. }
  3834. }
  3835. if ( tracks.length === 0 ) {
  3836. return null;
  3837. }
  3838. var clip = new AnimationClip( clipName, duration, tracks );
  3839. return clip;
  3840. }
  3841. } );
  3842. Object.assign( AnimationClip.prototype, {
  3843. resetDuration: function () {
  3844. var tracks = this.tracks, duration = 0;
  3845. for ( var i = 0, n = tracks.length; i !== n; ++ i ) {
  3846. var track = this.tracks[ i ];
  3847. duration = Math.max( duration, track.times[ track.times.length - 1 ] );
  3848. }
  3849. this.duration = duration;
  3850. },
  3851. trim: function () {
  3852. for ( var i = 0; i < this.tracks.length; i ++ ) {
  3853. this.tracks[ i ].trim( 0, this.duration );
  3854. }
  3855. return this;
  3856. },
  3857. optimize: function () {
  3858. for ( var i = 0; i < this.tracks.length; i ++ ) {
  3859. this.tracks[ i ].optimize();
  3860. }
  3861. return this;
  3862. }
  3863. } );
  3864. /**
  3865. *
  3866. * Player for AnimationClips.
  3867. *
  3868. *
  3869. * @author Ben Houston / http://clara.io/
  3870. * @author David Sarno / http://lighthaus.us/
  3871. * @author tschw
  3872. */
  3873. function AnimationMixer( root ) {
  3874. this._root = root;
  3875. this._initMemoryManager();
  3876. this._accuIndex = 0;
  3877. this.time = 0;
  3878. this.timeScale = 1.0;
  3879. }
  3880. Object.assign( AnimationMixer.prototype, EventDispatcher.prototype, {
  3881. _bindAction: function ( action, prototypeAction ) {
  3882. var root = action._localRoot || this._root,
  3883. tracks = action._clip.tracks,
  3884. nTracks = tracks.length,
  3885. bindings = action._propertyBindings,
  3886. interpolants = action._interpolants,
  3887. rootUuid = root.uuid,
  3888. bindingsByRoot = this._bindingsByRootAndName,
  3889. bindingsByName = bindingsByRoot[ rootUuid ];
  3890. if ( bindingsByName === undefined ) {
  3891. bindingsByName = {};
  3892. bindingsByRoot[ rootUuid ] = bindingsByName;
  3893. }
  3894. for ( var i = 0; i !== nTracks; ++ i ) {
  3895. var track = tracks[ i ],
  3896. trackName = track.name,
  3897. binding = bindingsByName[ trackName ];
  3898. if ( binding !== undefined ) {
  3899. bindings[ i ] = binding;
  3900. } else {
  3901. binding = bindings[ i ];
  3902. if ( binding !== undefined ) {
  3903. // existing binding, make sure the cache knows
  3904. if ( binding._cacheIndex === null ) {
  3905. ++ binding.referenceCount;
  3906. this._addInactiveBinding( binding, rootUuid, trackName );
  3907. }
  3908. continue;
  3909. }
  3910. var path = prototypeAction && prototypeAction.
  3911. _propertyBindings[ i ].binding.parsedPath;
  3912. binding = new PropertyMixer(
  3913. PropertyBinding.create( root, trackName, path ),
  3914. track.ValueTypeName, track.getValueSize() );
  3915. ++ binding.referenceCount;
  3916. this._addInactiveBinding( binding, rootUuid, trackName );
  3917. bindings[ i ] = binding;
  3918. }
  3919. interpolants[ i ].resultBuffer = binding.buffer;
  3920. }
  3921. },
  3922. _activateAction: function ( action ) {
  3923. if ( ! this._isActiveAction( action ) ) {
  3924. if ( action._cacheIndex === null ) {
  3925. // this action has been forgotten by the cache, but the user
  3926. // appears to be still using it -> rebind
  3927. var rootUuid = ( action._localRoot || this._root ).uuid,
  3928. clipUuid = action._clip.uuid,
  3929. actionsForClip = this._actionsByClip[ clipUuid ];
  3930. this._bindAction( action,
  3931. actionsForClip && actionsForClip.knownActions[ 0 ] );
  3932. this._addInactiveAction( action, clipUuid, rootUuid );
  3933. }
  3934. var bindings = action._propertyBindings;
  3935. // increment reference counts / sort out state
  3936. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  3937. var binding = bindings[ i ];
  3938. if ( binding.useCount ++ === 0 ) {
  3939. this._lendBinding( binding );
  3940. binding.saveOriginalState();
  3941. }
  3942. }
  3943. this._lendAction( action );
  3944. }
  3945. },
  3946. _deactivateAction: function ( action ) {
  3947. if ( this._isActiveAction( action ) ) {
  3948. var bindings = action._propertyBindings;
  3949. // decrement reference counts / sort out state
  3950. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  3951. var binding = bindings[ i ];
  3952. if ( -- binding.useCount === 0 ) {
  3953. binding.restoreOriginalState();
  3954. this._takeBackBinding( binding );
  3955. }
  3956. }
  3957. this._takeBackAction( action );
  3958. }
  3959. },
  3960. // Memory manager
  3961. _initMemoryManager: function () {
  3962. this._actions = []; // 'nActiveActions' followed by inactive ones
  3963. this._nActiveActions = 0;
  3964. this._actionsByClip = {};
  3965. // inside:
  3966. // {
  3967. // knownActions: Array< AnimationAction > - used as prototypes
  3968. // actionByRoot: AnimationAction - lookup
  3969. // }
  3970. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  3971. this._nActiveBindings = 0;
  3972. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  3973. this._controlInterpolants = []; // same game as above
  3974. this._nActiveControlInterpolants = 0;
  3975. var scope = this;
  3976. this.stats = {
  3977. actions: {
  3978. get total() {
  3979. return scope._actions.length;
  3980. },
  3981. get inUse() {
  3982. return scope._nActiveActions;
  3983. }
  3984. },
  3985. bindings: {
  3986. get total() {
  3987. return scope._bindings.length;
  3988. },
  3989. get inUse() {
  3990. return scope._nActiveBindings;
  3991. }
  3992. },
  3993. controlInterpolants: {
  3994. get total() {
  3995. return scope._controlInterpolants.length;
  3996. },
  3997. get inUse() {
  3998. return scope._nActiveControlInterpolants;
  3999. }
  4000. }
  4001. };
  4002. },
  4003. // Memory management for AnimationAction objects
  4004. _isActiveAction: function ( action ) {
  4005. var index = action._cacheIndex;
  4006. return index !== null && index < this._nActiveActions;
  4007. },
  4008. _addInactiveAction: function ( action, clipUuid, rootUuid ) {
  4009. var actions = this._actions,
  4010. actionsByClip = this._actionsByClip,
  4011. actionsForClip = actionsByClip[ clipUuid ];
  4012. if ( actionsForClip === undefined ) {
  4013. actionsForClip = {
  4014. knownActions: [ action ],
  4015. actionByRoot: {}
  4016. };
  4017. action._byClipCacheIndex = 0;
  4018. actionsByClip[ clipUuid ] = actionsForClip;
  4019. } else {
  4020. var knownActions = actionsForClip.knownActions;
  4021. action._byClipCacheIndex = knownActions.length;
  4022. knownActions.push( action );
  4023. }
  4024. action._cacheIndex = actions.length;
  4025. actions.push( action );
  4026. actionsForClip.actionByRoot[ rootUuid ] = action;
  4027. },
  4028. _removeInactiveAction: function ( action ) {
  4029. var actions = this._actions,
  4030. lastInactiveAction = actions[ actions.length - 1 ],
  4031. cacheIndex = action._cacheIndex;
  4032. lastInactiveAction._cacheIndex = cacheIndex;
  4033. actions[ cacheIndex ] = lastInactiveAction;
  4034. actions.pop();
  4035. action._cacheIndex = null;
  4036. var clipUuid = action._clip.uuid,
  4037. actionsByClip = this._actionsByClip,
  4038. actionsForClip = actionsByClip[ clipUuid ],
  4039. knownActionsForClip = actionsForClip.knownActions,
  4040. lastKnownAction =
  4041. knownActionsForClip[ knownActionsForClip.length - 1 ],
  4042. byClipCacheIndex = action._byClipCacheIndex;
  4043. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  4044. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  4045. knownActionsForClip.pop();
  4046. action._byClipCacheIndex = null;
  4047. var actionByRoot = actionsForClip.actionByRoot,
  4048. rootUuid = ( action._localRoot || this._root ).uuid;
  4049. delete actionByRoot[ rootUuid ];
  4050. if ( knownActionsForClip.length === 0 ) {
  4051. delete actionsByClip[ clipUuid ];
  4052. }
  4053. this._removeInactiveBindingsForAction( action );
  4054. },
  4055. _removeInactiveBindingsForAction: function ( action ) {
  4056. var bindings = action._propertyBindings;
  4057. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  4058. var binding = bindings[ i ];
  4059. if ( -- binding.referenceCount === 0 ) {
  4060. this._removeInactiveBinding( binding );
  4061. }
  4062. }
  4063. },
  4064. _lendAction: function ( action ) {
  4065. // [ active actions | inactive actions ]
  4066. // [ active actions >| inactive actions ]
  4067. // s a
  4068. // <-swap->
  4069. // a s
  4070. var actions = this._actions,
  4071. prevIndex = action._cacheIndex,
  4072. lastActiveIndex = this._nActiveActions ++,
  4073. firstInactiveAction = actions[ lastActiveIndex ];
  4074. action._cacheIndex = lastActiveIndex;
  4075. actions[ lastActiveIndex ] = action;
  4076. firstInactiveAction._cacheIndex = prevIndex;
  4077. actions[ prevIndex ] = firstInactiveAction;
  4078. },
  4079. _takeBackAction: function ( action ) {
  4080. // [ active actions | inactive actions ]
  4081. // [ active actions |< inactive actions ]
  4082. // a s
  4083. // <-swap->
  4084. // s a
  4085. var actions = this._actions,
  4086. prevIndex = action._cacheIndex,
  4087. firstInactiveIndex = -- this._nActiveActions,
  4088. lastActiveAction = actions[ firstInactiveIndex ];
  4089. action._cacheIndex = firstInactiveIndex;
  4090. actions[ firstInactiveIndex ] = action;
  4091. lastActiveAction._cacheIndex = prevIndex;
  4092. actions[ prevIndex ] = lastActiveAction;
  4093. },
  4094. // Memory management for PropertyMixer objects
  4095. _addInactiveBinding: function ( binding, rootUuid, trackName ) {
  4096. var bindingsByRoot = this._bindingsByRootAndName,
  4097. bindingByName = bindingsByRoot[ rootUuid ],
  4098. bindings = this._bindings;
  4099. if ( bindingByName === undefined ) {
  4100. bindingByName = {};
  4101. bindingsByRoot[ rootUuid ] = bindingByName;
  4102. }
  4103. bindingByName[ trackName ] = binding;
  4104. binding._cacheIndex = bindings.length;
  4105. bindings.push( binding );
  4106. },
  4107. _removeInactiveBinding: function ( binding ) {
  4108. var bindings = this._bindings,
  4109. propBinding = binding.binding,
  4110. rootUuid = propBinding.rootNode.uuid,
  4111. trackName = propBinding.path,
  4112. bindingsByRoot = this._bindingsByRootAndName,
  4113. bindingByName = bindingsByRoot[ rootUuid ],
  4114. lastInactiveBinding = bindings[ bindings.length - 1 ],
  4115. cacheIndex = binding._cacheIndex;
  4116. lastInactiveBinding._cacheIndex = cacheIndex;
  4117. bindings[ cacheIndex ] = lastInactiveBinding;
  4118. bindings.pop();
  4119. delete bindingByName[ trackName ];
  4120. remove_empty_map: {
  4121. for ( var _ in bindingByName ) break remove_empty_map; // eslint-disable-line no-unused-vars
  4122. delete bindingsByRoot[ rootUuid ];
  4123. }
  4124. },
  4125. _lendBinding: function ( binding ) {
  4126. var bindings = this._bindings,
  4127. prevIndex = binding._cacheIndex,
  4128. lastActiveIndex = this._nActiveBindings ++,
  4129. firstInactiveBinding = bindings[ lastActiveIndex ];
  4130. binding._cacheIndex = lastActiveIndex;
  4131. bindings[ lastActiveIndex ] = binding;
  4132. firstInactiveBinding._cacheIndex = prevIndex;
  4133. bindings[ prevIndex ] = firstInactiveBinding;
  4134. },
  4135. _takeBackBinding: function ( binding ) {
  4136. var bindings = this._bindings,
  4137. prevIndex = binding._cacheIndex,
  4138. firstInactiveIndex = -- this._nActiveBindings,
  4139. lastActiveBinding = bindings[ firstInactiveIndex ];
  4140. binding._cacheIndex = firstInactiveIndex;
  4141. bindings[ firstInactiveIndex ] = binding;
  4142. lastActiveBinding._cacheIndex = prevIndex;
  4143. bindings[ prevIndex ] = lastActiveBinding;
  4144. },
  4145. // Memory management of Interpolants for weight and time scale
  4146. _lendControlInterpolant: function () {
  4147. var interpolants = this._controlInterpolants,
  4148. lastActiveIndex = this._nActiveControlInterpolants ++,
  4149. interpolant = interpolants[ lastActiveIndex ];
  4150. if ( interpolant === undefined ) {
  4151. interpolant = new LinearInterpolant(
  4152. new Float32Array( 2 ), new Float32Array( 2 ),
  4153. 1, this._controlInterpolantsResultBuffer );
  4154. interpolant.__cacheIndex = lastActiveIndex;
  4155. interpolants[ lastActiveIndex ] = interpolant;
  4156. }
  4157. return interpolant;
  4158. },
  4159. _takeBackControlInterpolant: function ( interpolant ) {
  4160. var interpolants = this._controlInterpolants,
  4161. prevIndex = interpolant.__cacheIndex,
  4162. firstInactiveIndex = -- this._nActiveControlInterpolants,
  4163. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  4164. interpolant.__cacheIndex = firstInactiveIndex;
  4165. interpolants[ firstInactiveIndex ] = interpolant;
  4166. lastActiveInterpolant.__cacheIndex = prevIndex;
  4167. interpolants[ prevIndex ] = lastActiveInterpolant;
  4168. },
  4169. _controlInterpolantsResultBuffer: new Float32Array( 1 ),
  4170. // return an action for a clip optionally using a custom root target
  4171. // object (this method allocates a lot of dynamic memory in case a
  4172. // previously unknown clip/root combination is specified)
  4173. clipAction: function ( clip, optionalRoot ) {
  4174. var root = optionalRoot || this._root,
  4175. rootUuid = root.uuid,
  4176. clipObject = typeof clip === 'string' ?
  4177. AnimationClip.findByName( root, clip ) : clip,
  4178. clipUuid = clipObject !== null ? clipObject.uuid : clip,
  4179. actionsForClip = this._actionsByClip[ clipUuid ],
  4180. prototypeAction = null;
  4181. if ( actionsForClip !== undefined ) {
  4182. var existingAction =
  4183. actionsForClip.actionByRoot[ rootUuid ];
  4184. if ( existingAction !== undefined ) {
  4185. return existingAction;
  4186. }
  4187. // we know the clip, so we don't have to parse all
  4188. // the bindings again but can just copy
  4189. prototypeAction = actionsForClip.knownActions[ 0 ];
  4190. // also, take the clip from the prototype action
  4191. if ( clipObject === null )
  4192. clipObject = prototypeAction._clip;
  4193. }
  4194. // clip must be known when specified via string
  4195. if ( clipObject === null ) return null;
  4196. // allocate all resources required to run it
  4197. var newAction = new AnimationAction( this, clipObject, optionalRoot );
  4198. this._bindAction( newAction, prototypeAction );
  4199. // and make the action known to the memory manager
  4200. this._addInactiveAction( newAction, clipUuid, rootUuid );
  4201. return newAction;
  4202. },
  4203. // get an existing action
  4204. existingAction: function ( clip, optionalRoot ) {
  4205. var root = optionalRoot || this._root,
  4206. rootUuid = root.uuid,
  4207. clipObject = typeof clip === 'string' ?
  4208. AnimationClip.findByName( root, clip ) : clip,
  4209. clipUuid = clipObject ? clipObject.uuid : clip,
  4210. actionsForClip = this._actionsByClip[ clipUuid ];
  4211. if ( actionsForClip !== undefined ) {
  4212. return actionsForClip.actionByRoot[ rootUuid ] || null;
  4213. }
  4214. return null;
  4215. },
  4216. // deactivates all previously scheduled actions
  4217. stopAllAction: function () {
  4218. var actions = this._actions,
  4219. nActions = this._nActiveActions,
  4220. bindings = this._bindings,
  4221. nBindings = this._nActiveBindings;
  4222. this._nActiveActions = 0;
  4223. this._nActiveBindings = 0;
  4224. for ( var i = 0; i !== nActions; ++ i ) {
  4225. actions[ i ].reset();
  4226. }
  4227. for ( var i = 0; i !== nBindings; ++ i ) {
  4228. bindings[ i ].useCount = 0;
  4229. }
  4230. return this;
  4231. },
  4232. // advance the time and update apply the animation
  4233. update: function ( deltaTime ) {
  4234. deltaTime *= this.timeScale;
  4235. var actions = this._actions,
  4236. nActions = this._nActiveActions,
  4237. time = this.time += deltaTime,
  4238. timeDirection = Math.sign( deltaTime ),
  4239. accuIndex = this._accuIndex ^= 1;
  4240. // run active actions
  4241. for ( var i = 0; i !== nActions; ++ i ) {
  4242. var action = actions[ i ];
  4243. action._update( time, deltaTime, timeDirection, accuIndex );
  4244. }
  4245. // update scene graph
  4246. var bindings = this._bindings,
  4247. nBindings = this._nActiveBindings;
  4248. for ( var i = 0; i !== nBindings; ++ i ) {
  4249. bindings[ i ].apply( accuIndex );
  4250. }
  4251. return this;
  4252. },
  4253. // return this mixer's root target object
  4254. getRoot: function () {
  4255. return this._root;
  4256. },
  4257. // free all resources specific to a particular clip
  4258. uncacheClip: function ( clip ) {
  4259. var actions = this._actions,
  4260. clipUuid = clip.uuid,
  4261. actionsByClip = this._actionsByClip,
  4262. actionsForClip = actionsByClip[ clipUuid ];
  4263. if ( actionsForClip !== undefined ) {
  4264. // note: just calling _removeInactiveAction would mess up the
  4265. // iteration state and also require updating the state we can
  4266. // just throw away
  4267. var actionsToRemove = actionsForClip.knownActions;
  4268. for ( var i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  4269. var action = actionsToRemove[ i ];
  4270. this._deactivateAction( action );
  4271. var cacheIndex = action._cacheIndex,
  4272. lastInactiveAction = actions[ actions.length - 1 ];
  4273. action._cacheIndex = null;
  4274. action._byClipCacheIndex = null;
  4275. lastInactiveAction._cacheIndex = cacheIndex;
  4276. actions[ cacheIndex ] = lastInactiveAction;
  4277. actions.pop();
  4278. this._removeInactiveBindingsForAction( action );
  4279. }
  4280. delete actionsByClip[ clipUuid ];
  4281. }
  4282. },
  4283. // free all resources specific to a particular root target object
  4284. uncacheRoot: function ( root ) {
  4285. var rootUuid = root.uuid,
  4286. actionsByClip = this._actionsByClip;
  4287. for ( var clipUuid in actionsByClip ) {
  4288. var actionByRoot = actionsByClip[ clipUuid ].actionByRoot,
  4289. action = actionByRoot[ rootUuid ];
  4290. if ( action !== undefined ) {
  4291. this._deactivateAction( action );
  4292. this._removeInactiveAction( action );
  4293. }
  4294. }
  4295. var bindingsByRoot = this._bindingsByRootAndName,
  4296. bindingByName = bindingsByRoot[ rootUuid ];
  4297. if ( bindingByName !== undefined ) {
  4298. for ( var trackName in bindingByName ) {
  4299. var binding = bindingByName[ trackName ];
  4300. binding.restoreOriginalState();
  4301. this._removeInactiveBinding( binding );
  4302. }
  4303. }
  4304. },
  4305. // remove a targeted clip from the cache
  4306. uncacheAction: function ( clip, optionalRoot ) {
  4307. var action = this.existingAction( clip, optionalRoot );
  4308. if ( action !== null ) {
  4309. this._deactivateAction( action );
  4310. this._removeInactiveAction( action );
  4311. }
  4312. }
  4313. } );
  4314. /**
  4315. * @author TristanVALCKE / https://github.com/Itee
  4316. */
  4317. /* global QUnit */
  4318. QUnit.module( 'Animation', () => {
  4319. QUnit.module.todo( 'AnimationAction', () => {
  4320. // INSTANCING
  4321. QUnit.test( "Instancing", ( assert ) => {
  4322. var mixer = new AnimationMixer();
  4323. var clip = new AnimationClip();
  4324. assert.throws(
  4325. function () {
  4326. new AnimationAction();
  4327. },
  4328. new Error( "Mixer can't be null or undefined !" ),
  4329. "raised error instance about undefined or null mixer"
  4330. );
  4331. assert.throws(
  4332. function () {
  4333. new AnimationAction( mixer );
  4334. },
  4335. new Error( "Clip can't be null or undefined !" ),
  4336. "raised error instance about undefined or null clip"
  4337. );
  4338. var animationAction = new AnimationAction( mixer, clip );
  4339. assert.ok( animationAction, "animationAction instanciated" );
  4340. } );
  4341. // PRIVATE STUFF
  4342. QUnit.test( "_update", ( assert ) => {
  4343. assert.ok( false, "everything's gonna be alright" );
  4344. } );
  4345. QUnit.test( "_updateWeight", ( assert ) => {
  4346. assert.ok( false, "everything's gonna be alright" );
  4347. } );
  4348. QUnit.test( "_updateTimeScale", ( assert ) => {
  4349. assert.ok( false, "everything's gonna be alright" );
  4350. } );
  4351. QUnit.test( "_updateTime", ( assert ) => {
  4352. assert.ok( false, "everything's gonna be alright" );
  4353. } );
  4354. QUnit.test( "_setEndings", ( assert ) => {
  4355. assert.ok( false, "everything's gonna be alright" );
  4356. } );
  4357. QUnit.test( "_scheduleFading", ( assert ) => {
  4358. assert.ok( false, "everything's gonna be alright" );
  4359. } );
  4360. // PUBLIC STUFF
  4361. QUnit.test( "play", ( assert ) => {
  4362. assert.ok( false, "everything's gonna be alright" );
  4363. } );
  4364. QUnit.test( "stop", ( assert ) => {
  4365. assert.ok( false, "everything's gonna be alright" );
  4366. } );
  4367. QUnit.test( "reset", ( assert ) => {
  4368. assert.ok( false, "everything's gonna be alright" );
  4369. } );
  4370. QUnit.test( "isRunning", ( assert ) => {
  4371. assert.ok( false, "everything's gonna be alright" );
  4372. } );
  4373. QUnit.test( "isScheduled", ( assert ) => {
  4374. assert.ok( false, "everything's gonna be alright" );
  4375. } );
  4376. QUnit.test( "startAt", ( assert ) => {
  4377. assert.ok( false, "everything's gonna be alright" );
  4378. } );
  4379. QUnit.test( "setLoop", ( assert ) => {
  4380. assert.ok( false, "everything's gonna be alright" );
  4381. } );
  4382. QUnit.test( "setEffectiveWeight", ( assert ) => {
  4383. assert.ok( false, "everything's gonna be alright" );
  4384. } );
  4385. QUnit.test( "getEffectiveWeight", ( assert ) => {
  4386. assert.ok( false, "everything's gonna be alright" );
  4387. } );
  4388. QUnit.test( "fadeIn", ( assert ) => {
  4389. assert.ok( false, "everything's gonna be alright" );
  4390. } );
  4391. QUnit.test( "fadeOut", ( assert ) => {
  4392. assert.ok( false, "everything's gonna be alright" );
  4393. } );
  4394. QUnit.test( "crossFadeFrom", ( assert ) => {
  4395. assert.ok( false, "everything's gonna be alright" );
  4396. } );
  4397. QUnit.test( "crossFadeTo", ( assert ) => {
  4398. assert.ok( false, "everything's gonna be alright" );
  4399. } );
  4400. QUnit.test( "stopFading", ( assert ) => {
  4401. assert.ok( false, "everything's gonna be alright" );
  4402. } );
  4403. QUnit.test( "setEffectiveTimeScale", ( assert ) => {
  4404. assert.ok( false, "everything's gonna be alright" );
  4405. } );
  4406. QUnit.test( "getEffectiveTimeScale", ( assert ) => {
  4407. assert.ok( false, "everything's gonna be alright" );
  4408. } );
  4409. QUnit.test( "setDuration", ( assert ) => {
  4410. assert.ok( false, "everything's gonna be alright" );
  4411. } );
  4412. QUnit.test( "syncWith", ( assert ) => {
  4413. assert.ok( false, "everything's gonna be alright" );
  4414. } );
  4415. QUnit.test( "halt", ( assert ) => {
  4416. assert.ok( false, "everything's gonna be alright" );
  4417. } );
  4418. QUnit.test( "warp", ( assert ) => {
  4419. assert.ok( false, "everything's gonna be alright" );
  4420. } );
  4421. QUnit.test( "stopWarping", ( assert ) => {
  4422. assert.ok( false, "everything's gonna be alright" );
  4423. } );
  4424. QUnit.test( "getMixer", ( assert ) => {
  4425. assert.ok( false, "everything's gonna be alright" );
  4426. } );
  4427. QUnit.test( "getClip", ( assert ) => {
  4428. assert.ok( false, "everything's gonna be alright" );
  4429. } );
  4430. QUnit.test( "getRoot", ( assert ) => {
  4431. assert.ok( false, "everything's gonna be alright" );
  4432. } );
  4433. } );
  4434. } );
  4435. /**
  4436. * @author TristanVALCKE / https://github.com/Itee
  4437. */
  4438. /* global QUnit */
  4439. QUnit.module( 'Animation', () => {
  4440. QUnit.module.todo( 'AnimationClip', () => {
  4441. // INSTANCING
  4442. QUnit.test( "Instancing", ( assert ) => {
  4443. assert.ok( false, "everything's gonna be alright" );
  4444. } );
  4445. // STATIC STUFF
  4446. QUnit.test( "parse", ( assert ) => {
  4447. assert.ok( false, "everything's gonna be alright" );
  4448. } );
  4449. QUnit.test( "toJSON", ( assert ) => {
  4450. assert.ok( false, "everything's gonna be alright" );
  4451. } );
  4452. QUnit.test( "CreateFromMorphTargetSequence", ( assert ) => {
  4453. assert.ok( false, "everything's gonna be alright" );
  4454. } );
  4455. QUnit.test( "findByName", ( assert ) => {
  4456. assert.ok( false, "everything's gonna be alright" );
  4457. } );
  4458. QUnit.test( "CreateClipsFromMorphTargetSequences", ( assert ) => {
  4459. assert.ok( false, "everything's gonna be alright" );
  4460. } );
  4461. QUnit.test( "parseAnimation", ( assert ) => {
  4462. assert.ok( false, "everything's gonna be alright" );
  4463. } );
  4464. // PUBLIC STUFF
  4465. QUnit.test( "resetDuration", ( assert ) => {
  4466. assert.ok( false, "everything's gonna be alright" );
  4467. } );
  4468. QUnit.test( "trim", ( assert ) => {
  4469. assert.ok( false, "everything's gonna be alright" );
  4470. } );
  4471. QUnit.test( "optimize", ( assert ) => {
  4472. assert.ok( false, "everything's gonna be alright" );
  4473. } );
  4474. } );
  4475. } );
  4476. /**
  4477. * @author TristanVALCKE / https://github.com/Itee
  4478. */
  4479. /* global QUnit */
  4480. QUnit.module( 'Animation', () => {
  4481. QUnit.module.todo( 'AnimationMixer', () => {
  4482. // INHERITANCE
  4483. QUnit.test( "Extending", ( assert ) => {
  4484. assert.ok( false, "everything's gonna be alright" );
  4485. } );
  4486. // INSTANCING
  4487. QUnit.test( "Instancing", ( assert ) => {
  4488. assert.ok( false, "everything's gonna be alright" );
  4489. } );
  4490. // PRIVATE STUFF
  4491. QUnit.test( "_bindAction", ( assert ) => {
  4492. assert.ok( false, "everything's gonna be alright" );
  4493. } );
  4494. QUnit.test( "_activateAction", ( assert ) => {
  4495. assert.ok( false, "everything's gonna be alright" );
  4496. } );
  4497. QUnit.test( "_deactivateAction", ( assert ) => {
  4498. assert.ok( false, "everything's gonna be alright" );
  4499. } );
  4500. QUnit.test( "_initMemoryManager", ( assert ) => {
  4501. assert.ok( false, "everything's gonna be alright" );
  4502. } );
  4503. QUnit.test( "_isActiveAction", ( assert ) => {
  4504. assert.ok( false, "everything's gonna be alright" );
  4505. } );
  4506. QUnit.test( "_addInactiveAction", ( assert ) => {
  4507. assert.ok( false, "everything's gonna be alright" );
  4508. } );
  4509. QUnit.test( "_removeInactiveAction", ( assert ) => {
  4510. assert.ok( false, "everything's gonna be alright" );
  4511. } );
  4512. QUnit.test( "_removeInactiveBindingsForAction", ( assert ) => {
  4513. assert.ok( false, "everything's gonna be alright" );
  4514. } );
  4515. QUnit.test( "_lendAction", ( assert ) => {
  4516. assert.ok( false, "everything's gonna be alright" );
  4517. } );
  4518. QUnit.test( "_takeBackAction", ( assert ) => {
  4519. assert.ok( false, "everything's gonna be alright" );
  4520. } );
  4521. QUnit.test( "_addInactiveBinding", ( assert ) => {
  4522. assert.ok( false, "everything's gonna be alright" );
  4523. } );
  4524. QUnit.test( "_removeInactiveBinding", ( assert ) => {
  4525. assert.ok( false, "everything's gonna be alright" );
  4526. } );
  4527. QUnit.test( "_lendBinding", ( assert ) => {
  4528. assert.ok( false, "everything's gonna be alright" );
  4529. } );
  4530. QUnit.test( "_takeBackBinding", ( assert ) => {
  4531. assert.ok( false, "everything's gonna be alright" );
  4532. } );
  4533. QUnit.test( "_lendControlInterpolant", ( assert ) => {
  4534. assert.ok( false, "everything's gonna be alright" );
  4535. } );
  4536. QUnit.test( "_takeBackControlInterpolant", ( assert ) => {
  4537. assert.ok( false, "everything's gonna be alright" );
  4538. } );
  4539. QUnit.test( "_controlInterpolantsResultBuffer", ( assert ) => {
  4540. assert.ok( false, "everything's gonna be alright" );
  4541. } );
  4542. // PUBLIC STUFF
  4543. QUnit.test( "clipAction", ( assert ) => {
  4544. assert.ok( false, "everything's gonna be alright" );
  4545. } );
  4546. QUnit.test( "existingAction", ( assert ) => {
  4547. assert.ok( false, "everything's gonna be alright" );
  4548. } );
  4549. QUnit.test( "stopAllAction", ( assert ) => {
  4550. assert.ok( false, "everything's gonna be alright" );
  4551. } );
  4552. QUnit.test( "update", ( assert ) => {
  4553. assert.ok( false, "everything's gonna be alright" );
  4554. } );
  4555. QUnit.test( "getRoot", ( assert ) => {
  4556. assert.ok( false, "everything's gonna be alright" );
  4557. } );
  4558. QUnit.test( "uncacheClip", ( assert ) => {
  4559. assert.ok( false, "everything's gonna be alright" );
  4560. } );
  4561. QUnit.test( "uncacheRoot", ( assert ) => {
  4562. assert.ok( false, "everything's gonna be alright" );
  4563. } );
  4564. QUnit.test( "uncacheAction", ( assert ) => {
  4565. assert.ok( false, "everything's gonna be alright" );
  4566. } );
  4567. } );
  4568. } );
  4569. /**
  4570. *
  4571. * A group of objects that receives a shared animation state.
  4572. *
  4573. * Usage:
  4574. *
  4575. * - Add objects you would otherwise pass as 'root' to the
  4576. * constructor or the .clipAction method of AnimationMixer.
  4577. *
  4578. * - Instead pass this object as 'root'.
  4579. *
  4580. * - You can also add and remove objects later when the mixer
  4581. * is running.
  4582. *
  4583. * Note:
  4584. *
  4585. * Objects of this class appear as one object to the mixer,
  4586. * so cache control of the individual objects must be done
  4587. * on the group.
  4588. *
  4589. * Limitation:
  4590. *
  4591. * - The animated properties must be compatible among the
  4592. * all objects in the group.
  4593. *
  4594. * - A single property can either be controlled through a
  4595. * target group or directly, but not both.
  4596. *
  4597. * @author tschw
  4598. */
  4599. function AnimationObjectGroup() {
  4600. this.uuid = _Math.generateUUID();
  4601. // cached objects followed by the active ones
  4602. this._objects = Array.prototype.slice.call( arguments );
  4603. this.nCachedObjects_ = 0; // threshold
  4604. // note: read by PropertyBinding.Composite
  4605. var indices = {};
  4606. this._indicesByUUID = indices; // for bookkeeping
  4607. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  4608. indices[ arguments[ i ].uuid ] = i;
  4609. }
  4610. this._paths = []; // inside: string
  4611. this._parsedPaths = []; // inside: { we don't care, here }
  4612. this._bindings = []; // inside: Array< PropertyBinding >
  4613. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  4614. var scope = this;
  4615. this.stats = {
  4616. objects: {
  4617. get total() {
  4618. return scope._objects.length;
  4619. },
  4620. get inUse() {
  4621. return this.total - scope.nCachedObjects_;
  4622. }
  4623. },
  4624. get bindingsPerObject() {
  4625. return scope._bindings.length;
  4626. }
  4627. };
  4628. }
  4629. Object.assign( AnimationObjectGroup.prototype, {
  4630. isAnimationObjectGroup: true,
  4631. add: function () {
  4632. var objects = this._objects,
  4633. nObjects = objects.length,
  4634. nCachedObjects = this.nCachedObjects_,
  4635. indicesByUUID = this._indicesByUUID,
  4636. paths = this._paths,
  4637. parsedPaths = this._parsedPaths,
  4638. bindings = this._bindings,
  4639. nBindings = bindings.length;
  4640. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  4641. var object = arguments[ i ],
  4642. uuid = object.uuid,
  4643. index = indicesByUUID[ uuid ],
  4644. knownObject = undefined;
  4645. if ( index === undefined ) {
  4646. // unknown object -> add it to the ACTIVE region
  4647. index = nObjects ++;
  4648. indicesByUUID[ uuid ] = index;
  4649. objects.push( object );
  4650. // accounting is done, now do the same for all bindings
  4651. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  4652. bindings[ j ].push( new PropertyBinding( object, paths[ j ], parsedPaths[ j ] ) );
  4653. }
  4654. } else if ( index < nCachedObjects ) {
  4655. knownObject = objects[ index ];
  4656. // move existing object to the ACTIVE region
  4657. var firstActiveIndex = -- nCachedObjects,
  4658. lastCachedObject = objects[ firstActiveIndex ];
  4659. indicesByUUID[ lastCachedObject.uuid ] = index;
  4660. objects[ index ] = lastCachedObject;
  4661. indicesByUUID[ uuid ] = firstActiveIndex;
  4662. objects[ firstActiveIndex ] = object;
  4663. // accounting is done, now do the same for all bindings
  4664. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  4665. var bindingsForPath = bindings[ j ],
  4666. lastCached = bindingsForPath[ firstActiveIndex ],
  4667. binding = bindingsForPath[ index ];
  4668. bindingsForPath[ index ] = lastCached;
  4669. if ( binding === undefined ) {
  4670. // since we do not bother to create new bindings
  4671. // for objects that are cached, the binding may
  4672. // or may not exist
  4673. binding = new PropertyBinding( object, paths[ j ], parsedPaths[ j ] );
  4674. }
  4675. bindingsForPath[ firstActiveIndex ] = binding;
  4676. }
  4677. } else if ( objects[ index ] !== knownObject ) {
  4678. console.error( 'THREE.AnimationObjectGroup: Different objects with the same UUID ' +
  4679. 'detected. Clean the caches or recreate your infrastructure when reloading scenes.' );
  4680. } // else the object is already where we want it to be
  4681. } // for arguments
  4682. this.nCachedObjects_ = nCachedObjects;
  4683. },
  4684. remove: function () {
  4685. var objects = this._objects,
  4686. nCachedObjects = this.nCachedObjects_,
  4687. indicesByUUID = this._indicesByUUID,
  4688. bindings = this._bindings,
  4689. nBindings = bindings.length;
  4690. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  4691. var object = arguments[ i ],
  4692. uuid = object.uuid,
  4693. index = indicesByUUID[ uuid ];
  4694. if ( index !== undefined && index >= nCachedObjects ) {
  4695. // move existing object into the CACHED region
  4696. var lastCachedIndex = nCachedObjects ++,
  4697. firstActiveObject = objects[ lastCachedIndex ];
  4698. indicesByUUID[ firstActiveObject.uuid ] = index;
  4699. objects[ index ] = firstActiveObject;
  4700. indicesByUUID[ uuid ] = lastCachedIndex;
  4701. objects[ lastCachedIndex ] = object;
  4702. // accounting is done, now do the same for all bindings
  4703. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  4704. var bindingsForPath = bindings[ j ],
  4705. firstActive = bindingsForPath[ lastCachedIndex ],
  4706. binding = bindingsForPath[ index ];
  4707. bindingsForPath[ index ] = firstActive;
  4708. bindingsForPath[ lastCachedIndex ] = binding;
  4709. }
  4710. }
  4711. } // for arguments
  4712. this.nCachedObjects_ = nCachedObjects;
  4713. },
  4714. // remove & forget
  4715. uncache: function () {
  4716. var objects = this._objects,
  4717. nObjects = objects.length,
  4718. nCachedObjects = this.nCachedObjects_,
  4719. indicesByUUID = this._indicesByUUID,
  4720. bindings = this._bindings,
  4721. nBindings = bindings.length;
  4722. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  4723. var object = arguments[ i ],
  4724. uuid = object.uuid,
  4725. index = indicesByUUID[ uuid ];
  4726. if ( index !== undefined ) {
  4727. delete indicesByUUID[ uuid ];
  4728. if ( index < nCachedObjects ) {
  4729. // object is cached, shrink the CACHED region
  4730. var firstActiveIndex = -- nCachedObjects,
  4731. lastCachedObject = objects[ firstActiveIndex ],
  4732. lastIndex = -- nObjects,
  4733. lastObject = objects[ lastIndex ];
  4734. // last cached object takes this object's place
  4735. indicesByUUID[ lastCachedObject.uuid ] = index;
  4736. objects[ index ] = lastCachedObject;
  4737. // last object goes to the activated slot and pop
  4738. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  4739. objects[ firstActiveIndex ] = lastObject;
  4740. objects.pop();
  4741. // accounting is done, now do the same for all bindings
  4742. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  4743. var bindingsForPath = bindings[ j ],
  4744. lastCached = bindingsForPath[ firstActiveIndex ],
  4745. last = bindingsForPath[ lastIndex ];
  4746. bindingsForPath[ index ] = lastCached;
  4747. bindingsForPath[ firstActiveIndex ] = last;
  4748. bindingsForPath.pop();
  4749. }
  4750. } else {
  4751. // object is active, just swap with the last and pop
  4752. var lastIndex = -- nObjects,
  4753. lastObject = objects[ lastIndex ];
  4754. indicesByUUID[ lastObject.uuid ] = index;
  4755. objects[ index ] = lastObject;
  4756. objects.pop();
  4757. // accounting is done, now do the same for all bindings
  4758. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  4759. var bindingsForPath = bindings[ j ];
  4760. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  4761. bindingsForPath.pop();
  4762. }
  4763. } // cached or active
  4764. } // if object is known
  4765. } // for arguments
  4766. this.nCachedObjects_ = nCachedObjects;
  4767. },
  4768. // Internal interface used by befriended PropertyBinding.Composite:
  4769. subscribe_: function ( path, parsedPath ) {
  4770. // returns an array of bindings for the given path that is changed
  4771. // according to the contained objects in the group
  4772. var indicesByPath = this._bindingsIndicesByPath,
  4773. index = indicesByPath[ path ],
  4774. bindings = this._bindings;
  4775. if ( index !== undefined ) return bindings[ index ];
  4776. var paths = this._paths,
  4777. parsedPaths = this._parsedPaths,
  4778. objects = this._objects,
  4779. nObjects = objects.length,
  4780. nCachedObjects = this.nCachedObjects_,
  4781. bindingsForPath = new Array( nObjects );
  4782. index = bindings.length;
  4783. indicesByPath[ path ] = index;
  4784. paths.push( path );
  4785. parsedPaths.push( parsedPath );
  4786. bindings.push( bindingsForPath );
  4787. for ( var i = nCachedObjects, n = objects.length; i !== n; ++ i ) {
  4788. var object = objects[ i ];
  4789. bindingsForPath[ i ] = new PropertyBinding( object, path, parsedPath );
  4790. }
  4791. return bindingsForPath;
  4792. },
  4793. unsubscribe_: function ( path ) {
  4794. // tells the group to forget about a property path and no longer
  4795. // update the array previously obtained with 'subscribe_'
  4796. var indicesByPath = this._bindingsIndicesByPath,
  4797. index = indicesByPath[ path ];
  4798. if ( index !== undefined ) {
  4799. var paths = this._paths,
  4800. parsedPaths = this._parsedPaths,
  4801. bindings = this._bindings,
  4802. lastBindingsIndex = bindings.length - 1,
  4803. lastBindings = bindings[ lastBindingsIndex ],
  4804. lastBindingsPath = path[ lastBindingsIndex ];
  4805. indicesByPath[ lastBindingsPath ] = index;
  4806. bindings[ index ] = lastBindings;
  4807. bindings.pop();
  4808. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  4809. parsedPaths.pop();
  4810. paths[ index ] = paths[ lastBindingsIndex ];
  4811. paths.pop();
  4812. }
  4813. }
  4814. } );
  4815. /**
  4816. * @author mrdoob / http://mrdoob.com/
  4817. * @author WestLangley / http://github.com/WestLangley
  4818. * @author bhouston / http://clara.io
  4819. */
  4820. function Euler( x, y, z, order ) {
  4821. this._x = x || 0;
  4822. this._y = y || 0;
  4823. this._z = z || 0;
  4824. this._order = order || Euler.DefaultOrder;
  4825. }
  4826. Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  4827. Euler.DefaultOrder = 'XYZ';
  4828. Object.defineProperties( Euler.prototype, {
  4829. x: {
  4830. get: function () {
  4831. return this._x;
  4832. },
  4833. set: function ( value ) {
  4834. this._x = value;
  4835. this.onChangeCallback();
  4836. }
  4837. },
  4838. y: {
  4839. get: function () {
  4840. return this._y;
  4841. },
  4842. set: function ( value ) {
  4843. this._y = value;
  4844. this.onChangeCallback();
  4845. }
  4846. },
  4847. z: {
  4848. get: function () {
  4849. return this._z;
  4850. },
  4851. set: function ( value ) {
  4852. this._z = value;
  4853. this.onChangeCallback();
  4854. }
  4855. },
  4856. order: {
  4857. get: function () {
  4858. return this._order;
  4859. },
  4860. set: function ( value ) {
  4861. this._order = value;
  4862. this.onChangeCallback();
  4863. }
  4864. }
  4865. } );
  4866. Object.assign( Euler.prototype, {
  4867. isEuler: true,
  4868. set: function ( x, y, z, order ) {
  4869. this._x = x;
  4870. this._y = y;
  4871. this._z = z;
  4872. this._order = order || this._order;
  4873. this.onChangeCallback();
  4874. return this;
  4875. },
  4876. clone: function () {
  4877. return new this.constructor( this._x, this._y, this._z, this._order );
  4878. },
  4879. copy: function ( euler ) {
  4880. this._x = euler._x;
  4881. this._y = euler._y;
  4882. this._z = euler._z;
  4883. this._order = euler._order;
  4884. this.onChangeCallback();
  4885. return this;
  4886. },
  4887. setFromRotationMatrix: function ( m, order, update ) {
  4888. var clamp = _Math.clamp;
  4889. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4890. var te = m.elements;
  4891. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  4892. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  4893. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  4894. order = order || this._order;
  4895. if ( order === 'XYZ' ) {
  4896. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  4897. if ( Math.abs( m13 ) < 0.99999 ) {
  4898. this._x = Math.atan2( - m23, m33 );
  4899. this._z = Math.atan2( - m12, m11 );
  4900. } else {
  4901. this._x = Math.atan2( m32, m22 );
  4902. this._z = 0;
  4903. }
  4904. } else if ( order === 'YXZ' ) {
  4905. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  4906. if ( Math.abs( m23 ) < 0.99999 ) {
  4907. this._y = Math.atan2( m13, m33 );
  4908. this._z = Math.atan2( m21, m22 );
  4909. } else {
  4910. this._y = Math.atan2( - m31, m11 );
  4911. this._z = 0;
  4912. }
  4913. } else if ( order === 'ZXY' ) {
  4914. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  4915. if ( Math.abs( m32 ) < 0.99999 ) {
  4916. this._y = Math.atan2( - m31, m33 );
  4917. this._z = Math.atan2( - m12, m22 );
  4918. } else {
  4919. this._y = 0;
  4920. this._z = Math.atan2( m21, m11 );
  4921. }
  4922. } else if ( order === 'ZYX' ) {
  4923. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  4924. if ( Math.abs( m31 ) < 0.99999 ) {
  4925. this._x = Math.atan2( m32, m33 );
  4926. this._z = Math.atan2( m21, m11 );
  4927. } else {
  4928. this._x = 0;
  4929. this._z = Math.atan2( - m12, m22 );
  4930. }
  4931. } else if ( order === 'YZX' ) {
  4932. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  4933. if ( Math.abs( m21 ) < 0.99999 ) {
  4934. this._x = Math.atan2( - m23, m22 );
  4935. this._y = Math.atan2( - m31, m11 );
  4936. } else {
  4937. this._x = 0;
  4938. this._y = Math.atan2( m13, m33 );
  4939. }
  4940. } else if ( order === 'XZY' ) {
  4941. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  4942. if ( Math.abs( m12 ) < 0.99999 ) {
  4943. this._x = Math.atan2( m32, m22 );
  4944. this._y = Math.atan2( m13, m11 );
  4945. } else {
  4946. this._x = Math.atan2( - m23, m33 );
  4947. this._y = 0;
  4948. }
  4949. } else {
  4950. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order );
  4951. }
  4952. this._order = order;
  4953. if ( update !== false ) this.onChangeCallback();
  4954. return this;
  4955. },
  4956. setFromQuaternion: function () {
  4957. var matrix = new Matrix4();
  4958. return function setFromQuaternion( q, order, update ) {
  4959. matrix.makeRotationFromQuaternion( q );
  4960. return this.setFromRotationMatrix( matrix, order, update );
  4961. };
  4962. }(),
  4963. setFromVector3: function ( v, order ) {
  4964. return this.set( v.x, v.y, v.z, order || this._order );
  4965. },
  4966. reorder: function () {
  4967. // WARNING: this discards revolution information -bhouston
  4968. var q = new Quaternion();
  4969. return function reorder( newOrder ) {
  4970. q.setFromEuler( this );
  4971. return this.setFromQuaternion( q, newOrder );
  4972. };
  4973. }(),
  4974. equals: function ( euler ) {
  4975. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  4976. },
  4977. fromArray: function ( array ) {
  4978. this._x = array[ 0 ];
  4979. this._y = array[ 1 ];
  4980. this._z = array[ 2 ];
  4981. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  4982. this.onChangeCallback();
  4983. return this;
  4984. },
  4985. toArray: function ( array, offset ) {
  4986. if ( array === undefined ) array = [];
  4987. if ( offset === undefined ) offset = 0;
  4988. array[ offset ] = this._x;
  4989. array[ offset + 1 ] = this._y;
  4990. array[ offset + 2 ] = this._z;
  4991. array[ offset + 3 ] = this._order;
  4992. return array;
  4993. },
  4994. toVector3: function ( optionalResult ) {
  4995. if ( optionalResult ) {
  4996. return optionalResult.set( this._x, this._y, this._z );
  4997. } else {
  4998. return new Vector3( this._x, this._y, this._z );
  4999. }
  5000. },
  5001. onChange: function ( callback ) {
  5002. this.onChangeCallback = callback;
  5003. return this;
  5004. },
  5005. onChangeCallback: function () {}
  5006. } );
  5007. /**
  5008. * @author mrdoob / http://mrdoob.com/
  5009. */
  5010. function Layers() {
  5011. this.mask = 1 | 0;
  5012. }
  5013. Object.assign( Layers.prototype, {
  5014. set: function ( channel ) {
  5015. this.mask = 1 << channel | 0;
  5016. },
  5017. enable: function ( channel ) {
  5018. this.mask |= 1 << channel | 0;
  5019. },
  5020. toggle: function ( channel ) {
  5021. this.mask ^= 1 << channel | 0;
  5022. },
  5023. disable: function ( channel ) {
  5024. this.mask &= ~ ( 1 << channel | 0 );
  5025. },
  5026. test: function ( layers ) {
  5027. return ( this.mask & layers.mask ) !== 0;
  5028. }
  5029. } );
  5030. /**
  5031. * @author alteredq / http://alteredqualia.com/
  5032. * @author WestLangley / http://github.com/WestLangley
  5033. * @author bhouston / http://clara.io
  5034. * @author tschw
  5035. */
  5036. function Matrix3() {
  5037. this.elements = [
  5038. 1, 0, 0,
  5039. 0, 1, 0,
  5040. 0, 0, 1
  5041. ];
  5042. if ( arguments.length > 0 ) {
  5043. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  5044. }
  5045. }
  5046. Object.assign( Matrix3.prototype, {
  5047. isMatrix3: true,
  5048. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  5049. var te = this.elements;
  5050. te[ 0 ] = n11; te[ 1 ] = n21; te[ 2 ] = n31;
  5051. te[ 3 ] = n12; te[ 4 ] = n22; te[ 5 ] = n32;
  5052. te[ 6 ] = n13; te[ 7 ] = n23; te[ 8 ] = n33;
  5053. return this;
  5054. },
  5055. identity: function () {
  5056. this.set(
  5057. 1, 0, 0,
  5058. 0, 1, 0,
  5059. 0, 0, 1
  5060. );
  5061. return this;
  5062. },
  5063. clone: function () {
  5064. return new this.constructor().fromArray( this.elements );
  5065. },
  5066. copy: function ( m ) {
  5067. var te = this.elements;
  5068. var me = m.elements;
  5069. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ];
  5070. te[ 3 ] = me[ 3 ]; te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ];
  5071. te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ]; te[ 8 ] = me[ 8 ];
  5072. return this;
  5073. },
  5074. setFromMatrix4: function ( m ) {
  5075. var me = m.elements;
  5076. this.set(
  5077. me[ 0 ], me[ 4 ], me[ 8 ],
  5078. me[ 1 ], me[ 5 ], me[ 9 ],
  5079. me[ 2 ], me[ 6 ], me[ 10 ]
  5080. );
  5081. return this;
  5082. },
  5083. applyToBufferAttribute: function () {
  5084. var v1 = new Vector3();
  5085. return function applyToBufferAttribute( attribute ) {
  5086. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  5087. v1.x = attribute.getX( i );
  5088. v1.y = attribute.getY( i );
  5089. v1.z = attribute.getZ( i );
  5090. v1.applyMatrix3( this );
  5091. attribute.setXYZ( i, v1.x, v1.y, v1.z );
  5092. }
  5093. return attribute;
  5094. };
  5095. }(),
  5096. multiply: function ( m ) {
  5097. return this.multiplyMatrices( this, m );
  5098. },
  5099. premultiply: function ( m ) {
  5100. return this.multiplyMatrices( m, this );
  5101. },
  5102. multiplyMatrices: function ( a, b ) {
  5103. var ae = a.elements;
  5104. var be = b.elements;
  5105. var te = this.elements;
  5106. var a11 = ae[ 0 ], a12 = ae[ 3 ], a13 = ae[ 6 ];
  5107. var a21 = ae[ 1 ], a22 = ae[ 4 ], a23 = ae[ 7 ];
  5108. var a31 = ae[ 2 ], a32 = ae[ 5 ], a33 = ae[ 8 ];
  5109. var b11 = be[ 0 ], b12 = be[ 3 ], b13 = be[ 6 ];
  5110. var b21 = be[ 1 ], b22 = be[ 4 ], b23 = be[ 7 ];
  5111. var b31 = be[ 2 ], b32 = be[ 5 ], b33 = be[ 8 ];
  5112. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31;
  5113. te[ 3 ] = a11 * b12 + a12 * b22 + a13 * b32;
  5114. te[ 6 ] = a11 * b13 + a12 * b23 + a13 * b33;
  5115. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31;
  5116. te[ 4 ] = a21 * b12 + a22 * b22 + a23 * b32;
  5117. te[ 7 ] = a21 * b13 + a22 * b23 + a23 * b33;
  5118. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31;
  5119. te[ 5 ] = a31 * b12 + a32 * b22 + a33 * b32;
  5120. te[ 8 ] = a31 * b13 + a32 * b23 + a33 * b33;
  5121. return this;
  5122. },
  5123. multiplyScalar: function ( s ) {
  5124. var te = this.elements;
  5125. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  5126. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  5127. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  5128. return this;
  5129. },
  5130. determinant: function () {
  5131. var te = this.elements;
  5132. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  5133. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  5134. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  5135. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  5136. },
  5137. getInverse: function ( matrix, throwOnDegenerate ) {
  5138. if ( matrix && matrix.isMatrix4 ) {
  5139. console.error( "THREE.Matrix3: .getInverse() no longer takes a Matrix4 argument." );
  5140. }
  5141. var me = matrix.elements,
  5142. te = this.elements,
  5143. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ],
  5144. n12 = me[ 3 ], n22 = me[ 4 ], n32 = me[ 5 ],
  5145. n13 = me[ 6 ], n23 = me[ 7 ], n33 = me[ 8 ],
  5146. t11 = n33 * n22 - n32 * n23,
  5147. t12 = n32 * n13 - n33 * n12,
  5148. t13 = n23 * n12 - n22 * n13,
  5149. det = n11 * t11 + n21 * t12 + n31 * t13;
  5150. if ( det === 0 ) {
  5151. var msg = "THREE.Matrix3: .getInverse() can't invert matrix, determinant is 0";
  5152. if ( throwOnDegenerate === true ) {
  5153. throw new Error( msg );
  5154. } else {
  5155. console.warn( msg );
  5156. }
  5157. return this.identity();
  5158. }
  5159. var detInv = 1 / det;
  5160. te[ 0 ] = t11 * detInv;
  5161. te[ 1 ] = ( n31 * n23 - n33 * n21 ) * detInv;
  5162. te[ 2 ] = ( n32 * n21 - n31 * n22 ) * detInv;
  5163. te[ 3 ] = t12 * detInv;
  5164. te[ 4 ] = ( n33 * n11 - n31 * n13 ) * detInv;
  5165. te[ 5 ] = ( n31 * n12 - n32 * n11 ) * detInv;
  5166. te[ 6 ] = t13 * detInv;
  5167. te[ 7 ] = ( n21 * n13 - n23 * n11 ) * detInv;
  5168. te[ 8 ] = ( n22 * n11 - n21 * n12 ) * detInv;
  5169. return this;
  5170. },
  5171. transpose: function () {
  5172. var tmp, m = this.elements;
  5173. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  5174. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  5175. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  5176. return this;
  5177. },
  5178. getNormalMatrix: function ( matrix4 ) {
  5179. return this.setFromMatrix4( matrix4 ).getInverse( this ).transpose();
  5180. },
  5181. transposeIntoArray: function ( r ) {
  5182. var m = this.elements;
  5183. r[ 0 ] = m[ 0 ];
  5184. r[ 1 ] = m[ 3 ];
  5185. r[ 2 ] = m[ 6 ];
  5186. r[ 3 ] = m[ 1 ];
  5187. r[ 4 ] = m[ 4 ];
  5188. r[ 5 ] = m[ 7 ];
  5189. r[ 6 ] = m[ 2 ];
  5190. r[ 7 ] = m[ 5 ];
  5191. r[ 8 ] = m[ 8 ];
  5192. return this;
  5193. },
  5194. setUvTransform: function ( tx, ty, sx, sy, rotation, cx, cy ) {
  5195. var c = Math.cos( rotation );
  5196. var s = Math.sin( rotation );
  5197. this.set(
  5198. sx * c, sx * s, - sx * ( c * cx + s * cy ) + cx + tx,
  5199. - sy * s, sy * c, - sy * ( - s * cx + c * cy ) + cy + ty,
  5200. 0, 0, 1
  5201. );
  5202. },
  5203. scale: function ( sx, sy ) {
  5204. var te = this.elements;
  5205. te[ 0 ] *= sx; te[ 3 ] *= sx; te[ 6 ] *= sx;
  5206. te[ 1 ] *= sy; te[ 4 ] *= sy; te[ 7 ] *= sy;
  5207. return this;
  5208. },
  5209. rotate: function ( theta ) {
  5210. var c = Math.cos( theta );
  5211. var s = Math.sin( theta );
  5212. var te = this.elements;
  5213. var a11 = te[ 0 ], a12 = te[ 3 ], a13 = te[ 6 ];
  5214. var a21 = te[ 1 ], a22 = te[ 4 ], a23 = te[ 7 ];
  5215. te[ 0 ] = c * a11 + s * a21;
  5216. te[ 3 ] = c * a12 + s * a22;
  5217. te[ 6 ] = c * a13 + s * a23;
  5218. te[ 1 ] = - s * a11 + c * a21;
  5219. te[ 4 ] = - s * a12 + c * a22;
  5220. te[ 7 ] = - s * a13 + c * a23;
  5221. return this;
  5222. },
  5223. translate: function ( tx, ty ) {
  5224. var te = this.elements;
  5225. te[ 0 ] += tx * te[ 2 ]; te[ 3 ] += tx * te[ 5 ]; te[ 6 ] += tx * te[ 8 ];
  5226. te[ 1 ] += ty * te[ 2 ]; te[ 4 ] += ty * te[ 5 ]; te[ 7 ] += ty * te[ 8 ];
  5227. return this;
  5228. },
  5229. equals: function ( matrix ) {
  5230. var te = this.elements;
  5231. var me = matrix.elements;
  5232. for ( var i = 0; i < 9; i ++ ) {
  5233. if ( te[ i ] !== me[ i ] ) return false;
  5234. }
  5235. return true;
  5236. },
  5237. fromArray: function ( array, offset ) {
  5238. if ( offset === undefined ) offset = 0;
  5239. for ( var i = 0; i < 9; i ++ ) {
  5240. this.elements[ i ] = array[ i + offset ];
  5241. }
  5242. return this;
  5243. },
  5244. toArray: function ( array, offset ) {
  5245. if ( array === undefined ) array = [];
  5246. if ( offset === undefined ) offset = 0;
  5247. var te = this.elements;
  5248. array[ offset ] = te[ 0 ];
  5249. array[ offset + 1 ] = te[ 1 ];
  5250. array[ offset + 2 ] = te[ 2 ];
  5251. array[ offset + 3 ] = te[ 3 ];
  5252. array[ offset + 4 ] = te[ 4 ];
  5253. array[ offset + 5 ] = te[ 5 ];
  5254. array[ offset + 6 ] = te[ 6 ];
  5255. array[ offset + 7 ] = te[ 7 ];
  5256. array[ offset + 8 ] = te[ 8 ];
  5257. return array;
  5258. }
  5259. } );
  5260. /**
  5261. * @author mrdoob / http://mrdoob.com/
  5262. * @author mikael emtinger / http://gomo.se/
  5263. * @author alteredq / http://alteredqualia.com/
  5264. * @author WestLangley / http://github.com/WestLangley
  5265. * @author elephantatwork / www.elephantatwork.ch
  5266. */
  5267. var object3DId = 0;
  5268. function Object3D() {
  5269. Object.defineProperty( this, 'id', { value: object3DId ++ } );
  5270. this.uuid = _Math.generateUUID();
  5271. this.name = '';
  5272. this.type = 'Object3D';
  5273. this.parent = null;
  5274. this.children = [];
  5275. this.up = Object3D.DefaultUp.clone();
  5276. var position = new Vector3();
  5277. var rotation = new Euler();
  5278. var quaternion = new Quaternion();
  5279. var scale = new Vector3( 1, 1, 1 );
  5280. function onRotationChange() {
  5281. quaternion.setFromEuler( rotation, false );
  5282. }
  5283. function onQuaternionChange() {
  5284. rotation.setFromQuaternion( quaternion, undefined, false );
  5285. }
  5286. rotation.onChange( onRotationChange );
  5287. quaternion.onChange( onQuaternionChange );
  5288. Object.defineProperties( this, {
  5289. position: {
  5290. enumerable: true,
  5291. value: position
  5292. },
  5293. rotation: {
  5294. enumerable: true,
  5295. value: rotation
  5296. },
  5297. quaternion: {
  5298. enumerable: true,
  5299. value: quaternion
  5300. },
  5301. scale: {
  5302. enumerable: true,
  5303. value: scale
  5304. },
  5305. modelViewMatrix: {
  5306. value: new Matrix4()
  5307. },
  5308. normalMatrix: {
  5309. value: new Matrix3()
  5310. }
  5311. } );
  5312. this.matrix = new Matrix4();
  5313. this.matrixWorld = new Matrix4();
  5314. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  5315. this.matrixWorldNeedsUpdate = false;
  5316. this.layers = new Layers();
  5317. this.visible = true;
  5318. this.castShadow = false;
  5319. this.receiveShadow = false;
  5320. this.frustumCulled = true;
  5321. this.renderOrder = 0;
  5322. this.userData = {};
  5323. }
  5324. Object3D.DefaultUp = new Vector3( 0, 1, 0 );
  5325. Object3D.DefaultMatrixAutoUpdate = true;
  5326. Object.assign( Object3D.prototype, EventDispatcher.prototype, {
  5327. isObject3D: true,
  5328. onBeforeRender: function () {},
  5329. onAfterRender: function () {},
  5330. applyMatrix: function ( matrix ) {
  5331. this.matrix.multiplyMatrices( matrix, this.matrix );
  5332. this.matrix.decompose( this.position, this.quaternion, this.scale );
  5333. },
  5334. applyQuaternion: function ( q ) {
  5335. this.quaternion.premultiply( q );
  5336. return this;
  5337. },
  5338. setRotationFromAxisAngle: function ( axis, angle ) {
  5339. // assumes axis is normalized
  5340. this.quaternion.setFromAxisAngle( axis, angle );
  5341. },
  5342. setRotationFromEuler: function ( euler ) {
  5343. this.quaternion.setFromEuler( euler, true );
  5344. },
  5345. setRotationFromMatrix: function ( m ) {
  5346. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  5347. this.quaternion.setFromRotationMatrix( m );
  5348. },
  5349. setRotationFromQuaternion: function ( q ) {
  5350. // assumes q is normalized
  5351. this.quaternion.copy( q );
  5352. },
  5353. rotateOnAxis: function () {
  5354. // rotate object on axis in object space
  5355. // axis is assumed to be normalized
  5356. var q1 = new Quaternion();
  5357. return function rotateOnAxis( axis, angle ) {
  5358. q1.setFromAxisAngle( axis, angle );
  5359. this.quaternion.multiply( q1 );
  5360. return this;
  5361. };
  5362. }(),
  5363. rotateOnWorldAxis: function () {
  5364. // rotate object on axis in world space
  5365. // axis is assumed to be normalized
  5366. // method assumes no rotated parent
  5367. var q1 = new Quaternion();
  5368. return function rotateOnWorldAxis( axis, angle ) {
  5369. q1.setFromAxisAngle( axis, angle );
  5370. this.quaternion.premultiply( q1 );
  5371. return this;
  5372. };
  5373. }(),
  5374. rotateX: function () {
  5375. var v1 = new Vector3( 1, 0, 0 );
  5376. return function rotateX( angle ) {
  5377. return this.rotateOnAxis( v1, angle );
  5378. };
  5379. }(),
  5380. rotateY: function () {
  5381. var v1 = new Vector3( 0, 1, 0 );
  5382. return function rotateY( angle ) {
  5383. return this.rotateOnAxis( v1, angle );
  5384. };
  5385. }(),
  5386. rotateZ: function () {
  5387. var v1 = new Vector3( 0, 0, 1 );
  5388. return function rotateZ( angle ) {
  5389. return this.rotateOnAxis( v1, angle );
  5390. };
  5391. }(),
  5392. translateOnAxis: function () {
  5393. // translate object by distance along axis in object space
  5394. // axis is assumed to be normalized
  5395. var v1 = new Vector3();
  5396. return function translateOnAxis( axis, distance ) {
  5397. v1.copy( axis ).applyQuaternion( this.quaternion );
  5398. this.position.add( v1.multiplyScalar( distance ) );
  5399. return this;
  5400. };
  5401. }(),
  5402. translateX: function () {
  5403. var v1 = new Vector3( 1, 0, 0 );
  5404. return function translateX( distance ) {
  5405. return this.translateOnAxis( v1, distance );
  5406. };
  5407. }(),
  5408. translateY: function () {
  5409. var v1 = new Vector3( 0, 1, 0 );
  5410. return function translateY( distance ) {
  5411. return this.translateOnAxis( v1, distance );
  5412. };
  5413. }(),
  5414. translateZ: function () {
  5415. var v1 = new Vector3( 0, 0, 1 );
  5416. return function translateZ( distance ) {
  5417. return this.translateOnAxis( v1, distance );
  5418. };
  5419. }(),
  5420. localToWorld: function ( vector ) {
  5421. return vector.applyMatrix4( this.matrixWorld );
  5422. },
  5423. worldToLocal: function () {
  5424. var m1 = new Matrix4();
  5425. return function worldToLocal( vector ) {
  5426. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  5427. };
  5428. }(),
  5429. lookAt: function () {
  5430. // This method does not support objects with rotated and/or translated parent(s)
  5431. var m1 = new Matrix4();
  5432. var vector = new Vector3();
  5433. return function lookAt( x, y, z ) {
  5434. if ( x.isVector3 ) {
  5435. vector.copy( x );
  5436. } else {
  5437. vector.set( x, y, z );
  5438. }
  5439. if ( this.isCamera ) {
  5440. m1.lookAt( this.position, vector, this.up );
  5441. } else {
  5442. m1.lookAt( vector, this.position, this.up );
  5443. }
  5444. this.quaternion.setFromRotationMatrix( m1 );
  5445. };
  5446. }(),
  5447. add: function ( object ) {
  5448. if ( arguments.length > 1 ) {
  5449. for ( var i = 0; i < arguments.length; i ++ ) {
  5450. this.add( arguments[ i ] );
  5451. }
  5452. return this;
  5453. }
  5454. if ( object === this ) {
  5455. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  5456. return this;
  5457. }
  5458. if ( ( object && object.isObject3D ) ) {
  5459. if ( object.parent !== null ) {
  5460. object.parent.remove( object );
  5461. }
  5462. object.parent = this;
  5463. object.dispatchEvent( { type: 'added' } );
  5464. this.children.push( object );
  5465. } else {
  5466. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  5467. }
  5468. return this;
  5469. },
  5470. remove: function ( object ) {
  5471. if ( arguments.length > 1 ) {
  5472. for ( var i = 0; i < arguments.length; i ++ ) {
  5473. this.remove( arguments[ i ] );
  5474. }
  5475. return this;
  5476. }
  5477. var index = this.children.indexOf( object );
  5478. if ( index !== - 1 ) {
  5479. object.parent = null;
  5480. object.dispatchEvent( { type: 'removed' } );
  5481. this.children.splice( index, 1 );
  5482. }
  5483. return this;
  5484. },
  5485. getObjectById: function ( id ) {
  5486. return this.getObjectByProperty( 'id', id );
  5487. },
  5488. getObjectByName: function ( name ) {
  5489. return this.getObjectByProperty( 'name', name );
  5490. },
  5491. getObjectByProperty: function ( name, value ) {
  5492. if ( this[ name ] === value ) return this;
  5493. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  5494. var child = this.children[ i ];
  5495. var object = child.getObjectByProperty( name, value );
  5496. if ( object !== undefined ) {
  5497. return object;
  5498. }
  5499. }
  5500. return undefined;
  5501. },
  5502. getWorldPosition: function ( optionalTarget ) {
  5503. var result = optionalTarget || new Vector3();
  5504. this.updateMatrixWorld( true );
  5505. return result.setFromMatrixPosition( this.matrixWorld );
  5506. },
  5507. getWorldQuaternion: function () {
  5508. var position = new Vector3();
  5509. var scale = new Vector3();
  5510. return function getWorldQuaternion( optionalTarget ) {
  5511. var result = optionalTarget || new Quaternion();
  5512. this.updateMatrixWorld( true );
  5513. this.matrixWorld.decompose( position, result, scale );
  5514. return result;
  5515. };
  5516. }(),
  5517. getWorldRotation: function () {
  5518. var quaternion = new Quaternion();
  5519. return function getWorldRotation( optionalTarget ) {
  5520. var result = optionalTarget || new Euler();
  5521. this.getWorldQuaternion( quaternion );
  5522. return result.setFromQuaternion( quaternion, this.rotation.order, false );
  5523. };
  5524. }(),
  5525. getWorldScale: function () {
  5526. var position = new Vector3();
  5527. var quaternion = new Quaternion();
  5528. return function getWorldScale( optionalTarget ) {
  5529. var result = optionalTarget || new Vector3();
  5530. this.updateMatrixWorld( true );
  5531. this.matrixWorld.decompose( position, quaternion, result );
  5532. return result;
  5533. };
  5534. }(),
  5535. getWorldDirection: function () {
  5536. var quaternion = new Quaternion();
  5537. return function getWorldDirection( optionalTarget ) {
  5538. var result = optionalTarget || new Vector3();
  5539. this.getWorldQuaternion( quaternion );
  5540. return result.set( 0, 0, 1 ).applyQuaternion( quaternion );
  5541. };
  5542. }(),
  5543. raycast: function () {},
  5544. traverse: function ( callback ) {
  5545. callback( this );
  5546. var children = this.children;
  5547. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5548. children[ i ].traverse( callback );
  5549. }
  5550. },
  5551. traverseVisible: function ( callback ) {
  5552. if ( this.visible === false ) return;
  5553. callback( this );
  5554. var children = this.children;
  5555. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5556. children[ i ].traverseVisible( callback );
  5557. }
  5558. },
  5559. traverseAncestors: function ( callback ) {
  5560. var parent = this.parent;
  5561. if ( parent !== null ) {
  5562. callback( parent );
  5563. parent.traverseAncestors( callback );
  5564. }
  5565. },
  5566. updateMatrix: function () {
  5567. this.matrix.compose( this.position, this.quaternion, this.scale );
  5568. this.matrixWorldNeedsUpdate = true;
  5569. },
  5570. updateMatrixWorld: function ( force ) {
  5571. if ( this.matrixAutoUpdate ) this.updateMatrix();
  5572. if ( this.matrixWorldNeedsUpdate || force ) {
  5573. if ( this.parent === null ) {
  5574. this.matrixWorld.copy( this.matrix );
  5575. } else {
  5576. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  5577. }
  5578. this.matrixWorldNeedsUpdate = false;
  5579. force = true;
  5580. }
  5581. // update children
  5582. var children = this.children;
  5583. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5584. children[ i ].updateMatrixWorld( force );
  5585. }
  5586. },
  5587. toJSON: function ( meta ) {
  5588. // meta is a string when called from JSON.stringify
  5589. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  5590. var output = {};
  5591. // meta is a hash used to collect geometries, materials.
  5592. // not providing it implies that this is the root object
  5593. // being serialized.
  5594. if ( isRootObject ) {
  5595. // initialize meta obj
  5596. meta = {
  5597. geometries: {},
  5598. materials: {},
  5599. textures: {},
  5600. images: {}
  5601. };
  5602. output.metadata = {
  5603. version: 4.5,
  5604. type: 'Object',
  5605. generator: 'Object3D.toJSON'
  5606. };
  5607. }
  5608. // standard Object3D serialization
  5609. var object = {};
  5610. object.uuid = this.uuid;
  5611. object.type = this.type;
  5612. if ( this.name !== '' ) object.name = this.name;
  5613. if ( this.castShadow === true ) object.castShadow = true;
  5614. if ( this.receiveShadow === true ) object.receiveShadow = true;
  5615. if ( this.visible === false ) object.visible = false;
  5616. if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
  5617. object.matrix = this.matrix.toArray();
  5618. //
  5619. function serialize( library, element ) {
  5620. if ( library[ element.uuid ] === undefined ) {
  5621. library[ element.uuid ] = element.toJSON( meta );
  5622. }
  5623. return element.uuid;
  5624. }
  5625. if ( this.geometry !== undefined ) {
  5626. object.geometry = serialize( meta.geometries, this.geometry );
  5627. }
  5628. if ( this.material !== undefined ) {
  5629. if ( Array.isArray( this.material ) ) {
  5630. var uuids = [];
  5631. for ( var i = 0, l = this.material.length; i < l; i ++ ) {
  5632. uuids.push( serialize( meta.materials, this.material[ i ] ) );
  5633. }
  5634. object.material = uuids;
  5635. } else {
  5636. object.material = serialize( meta.materials, this.material );
  5637. }
  5638. }
  5639. //
  5640. if ( this.children.length > 0 ) {
  5641. object.children = [];
  5642. for ( var i = 0; i < this.children.length; i ++ ) {
  5643. object.children.push( this.children[ i ].toJSON( meta ).object );
  5644. }
  5645. }
  5646. if ( isRootObject ) {
  5647. var geometries = extractFromCache( meta.geometries );
  5648. var materials = extractFromCache( meta.materials );
  5649. var textures = extractFromCache( meta.textures );
  5650. var images = extractFromCache( meta.images );
  5651. if ( geometries.length > 0 ) output.geometries = geometries;
  5652. if ( materials.length > 0 ) output.materials = materials;
  5653. if ( textures.length > 0 ) output.textures = textures;
  5654. if ( images.length > 0 ) output.images = images;
  5655. }
  5656. output.object = object;
  5657. return output;
  5658. // extract data from the cache hash
  5659. // remove metadata on each item
  5660. // and return as array
  5661. function extractFromCache( cache ) {
  5662. var values = [];
  5663. for ( var key in cache ) {
  5664. var data = cache[ key ];
  5665. delete data.metadata;
  5666. values.push( data );
  5667. }
  5668. return values;
  5669. }
  5670. },
  5671. clone: function ( recursive ) {
  5672. return new this.constructor().copy( this, recursive );
  5673. },
  5674. copy: function ( source, recursive ) {
  5675. if ( recursive === undefined ) recursive = true;
  5676. this.name = source.name;
  5677. this.up.copy( source.up );
  5678. this.position.copy( source.position );
  5679. this.quaternion.copy( source.quaternion );
  5680. this.scale.copy( source.scale );
  5681. this.matrix.copy( source.matrix );
  5682. this.matrixWorld.copy( source.matrixWorld );
  5683. this.matrixAutoUpdate = source.matrixAutoUpdate;
  5684. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  5685. this.layers.mask = source.layers.mask;
  5686. this.visible = source.visible;
  5687. this.castShadow = source.castShadow;
  5688. this.receiveShadow = source.receiveShadow;
  5689. this.frustumCulled = source.frustumCulled;
  5690. this.renderOrder = source.renderOrder;
  5691. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  5692. if ( recursive === true ) {
  5693. for ( var i = 0; i < source.children.length; i ++ ) {
  5694. var child = source.children[ i ];
  5695. this.add( child.clone() );
  5696. }
  5697. }
  5698. return this;
  5699. }
  5700. } );
  5701. /**
  5702. * @author tschw
  5703. * @author TristanVALCKE / https://github.com/Itee
  5704. */
  5705. /* global QUnit */
  5706. QUnit.module( "Animation", () => {
  5707. QUnit.module.todo( "AnimationObjectGroup", () => {
  5708. var ObjectA = new Object3D(),
  5709. ObjectB = new Object3D(),
  5710. ObjectC = new Object3D(),
  5711. PathA = 'object.position',
  5712. PathB = 'object.rotation',
  5713. PathC = 'object.scale',
  5714. ParsedPathA = PropertyBinding.parseTrackName( PathA ),
  5715. ParsedPathB = PropertyBinding.parseTrackName( PathB ),
  5716. ParsedPathC = PropertyBinding.parseTrackName( PathC );
  5717. // INSTANCING
  5718. QUnit.test( "Instancing", ( assert ) => {
  5719. assert.ok( false, "everything's gonna be alright" );
  5720. } );
  5721. // PRIVATE STUFF
  5722. QUnit.test( "subscribe_", ( assert ) => {
  5723. assert.ok( false, "everything's gonna be alright" );
  5724. } ); // Todo: Naming guys -_-'
  5725. QUnit.test( "unsubscribe_", ( assert ) => {
  5726. assert.ok( false, "everything's gonna be alright" );
  5727. } ); // Todo: Naming guys -_-'
  5728. // PUBLIC STUFF
  5729. QUnit.test( "isAnimationObjectGroup", ( assert ) => {
  5730. assert.ok( false, "everything's gonna be alright" );
  5731. } );
  5732. QUnit.test( "add", ( assert ) => {
  5733. assert.ok( false, "everything's gonna be alright" );
  5734. } );
  5735. QUnit.test( "remove", ( assert ) => {
  5736. assert.ok( false, "everything's gonna be alright" );
  5737. } );
  5738. QUnit.test( "uncache", ( assert ) => {
  5739. assert.ok( false, "everything's gonna be alright" );
  5740. } );
  5741. // OTHERS
  5742. QUnit.test( "smoke test", ( assert ) => {
  5743. var expect = function expect( testIndex, group, bindings, path, cached, roots ) {
  5744. var rootNodes = [], pathsOk = true, nodesOk = true;
  5745. for ( var i = group.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  5746. if ( bindings[ i ].path !== path ) pathsOk = false;
  5747. rootNodes.push( bindings[ i ].rootNode );
  5748. }
  5749. for ( var i = 0, n = roots.length; i !== n; ++ i ) {
  5750. if ( rootNodes.indexOf( roots[ i ] ) === - 1 ) nodesOk = false;
  5751. }
  5752. assert.ok( pathsOk, QUnit.testIndex + " paths" );
  5753. assert.ok( nodesOk, QUnit.testIndex + " nodes" );
  5754. assert.ok( group.nCachedObjects_ === cached, QUnit.testIndex + " cache size" );
  5755. assert.ok( bindings.length - group.nCachedObjects_ === roots.length, QUnit.testIndex + " object count" );
  5756. };
  5757. // initial state
  5758. var groupA = new AnimationObjectGroup();
  5759. assert.ok( groupA instanceof AnimationObjectGroup, "constructor (w/o args)" );
  5760. var bindingsAA = groupA.subscribe_( PathA, ParsedPathA );
  5761. expect( 0, groupA, bindingsAA, PathA, 0, [] );
  5762. var groupB = new AnimationObjectGroup( ObjectA, ObjectB );
  5763. assert.ok( groupB instanceof AnimationObjectGroup, "constructor (with args)" );
  5764. var bindingsBB = groupB.subscribe_( PathB, ParsedPathB );
  5765. expect( 1, groupB, bindingsBB, PathB, 0, [ ObjectA, ObjectB ] );
  5766. // add
  5767. groupA.add( ObjectA, ObjectB );
  5768. expect( 2, groupA, bindingsAA, PathA, 0, [ ObjectA, ObjectB ] );
  5769. groupB.add( ObjectC );
  5770. expect( 3, groupB, bindingsBB, PathB, 0, [ ObjectA, ObjectB, ObjectC ] );
  5771. // remove
  5772. groupA.remove( ObjectA, ObjectC );
  5773. expect( 4, groupA, bindingsAA, PathA, 1, [ ObjectB ] );
  5774. groupB.remove( ObjectA, ObjectB, ObjectC );
  5775. expect( 5, groupB, bindingsBB, PathB, 3, [] );
  5776. // subscribe after re-add
  5777. groupA.add( ObjectC );
  5778. expect( 6, groupA, bindingsAA, PathA, 1, [ ObjectB, ObjectC ] );
  5779. var bindingsAC = groupA.subscribe_( PathC, ParsedPathC );
  5780. expect( 7, groupA, bindingsAC, PathC, 1, [ ObjectB, ObjectC ] );
  5781. // re-add after subscribe
  5782. var bindingsBC = groupB.subscribe_( PathC, ParsedPathC );
  5783. groupB.add( ObjectA, ObjectB );
  5784. expect( 8, groupB, bindingsBB, PathB, 1, [ ObjectA, ObjectB ] );
  5785. // unsubscribe
  5786. var copyOfBindingsBC = bindingsBC.slice();
  5787. groupB.unsubscribe_( PathC );
  5788. groupB.add( ObjectC );
  5789. assert.deepEqual( bindingsBC, copyOfBindingsBC, "no more update after unsubscribe" );
  5790. // uncache active
  5791. groupB.uncache( ObjectA );
  5792. expect( 9, groupB, bindingsBB, PathB, 0, [ ObjectB, ObjectC ] );
  5793. // uncache cached
  5794. groupA.uncache( ObjectA );
  5795. expect( 10, groupA, bindingsAC, PathC, 0, [ ObjectB, ObjectC ] );
  5796. } );
  5797. } );
  5798. } );
  5799. /**
  5800. * @author TristanVALCKE / https://github.com/Itee
  5801. */
  5802. /* global QUnit */
  5803. QUnit.module( 'Animation', () => {
  5804. QUnit.module.todo( 'AnimationUtils', () => {
  5805. // PUBLIC STUFF
  5806. QUnit.test( "arraySlice", ( assert ) => {
  5807. assert.ok( false, "everything's gonna be alright" );
  5808. } );
  5809. QUnit.test( "convertArray", ( assert ) => {
  5810. assert.ok( false, "everything's gonna be alright" );
  5811. } );
  5812. QUnit.test( "isTypedArray", ( assert ) => {
  5813. assert.ok( false, "everything's gonna be alright" );
  5814. } );
  5815. QUnit.test( "getKeyframeOrder", ( assert ) => {
  5816. assert.ok( false, "everything's gonna be alright" );
  5817. } );
  5818. QUnit.test( "sortedArray", ( assert ) => {
  5819. assert.ok( false, "everything's gonna be alright" );
  5820. } );
  5821. QUnit.test( "flattenJSON", ( assert ) => {
  5822. assert.ok( false, "everything's gonna be alright" );
  5823. } );
  5824. } );
  5825. } );
  5826. /**
  5827. * @author TristanVALCKE / https://github.com/Itee
  5828. */
  5829. /* global QUnit */
  5830. QUnit.module( 'Animation', () => {
  5831. QUnit.module.todo( 'KeyframeTrack', () => {
  5832. // INSTANCING
  5833. QUnit.test( "Instancing", ( assert ) => {
  5834. assert.ok( false, "everything's gonna be alright" );
  5835. } );
  5836. // STATIC STUFF
  5837. QUnit.test( "parse", ( assert ) => {
  5838. assert.ok( false, "everything's gonna be alright" );
  5839. } );
  5840. QUnit.test( "toJSON", ( assert ) => {
  5841. assert.ok( false, "everything's gonna be alright" );
  5842. } );
  5843. QUnit.test( "_getTrackTypeForValueTypeName", ( assert ) => {
  5844. assert.ok( false, "everything's gonna be alright" );
  5845. } );
  5846. // PUBLIC STUFF
  5847. QUnit.test( "TimeBufferType", ( assert ) => {
  5848. assert.ok( false, "everything's gonna be alright" );
  5849. } );
  5850. QUnit.test( "ValueBufferType", ( assert ) => {
  5851. assert.ok( false, "everything's gonna be alright" );
  5852. } );
  5853. QUnit.test( "DefaultInterpolation", ( assert ) => {
  5854. assert.ok( false, "everything's gonna be alright" );
  5855. } );
  5856. QUnit.test( "InterpolantFactoryMethodDiscrete", ( assert ) => {
  5857. assert.ok( false, "everything's gonna be alright" );
  5858. } );
  5859. QUnit.test( "InterpolantFactoryMethodLinear", ( assert ) => {
  5860. assert.ok( false, "everything's gonna be alright" );
  5861. } );
  5862. QUnit.test( "InterpolantFactoryMethodSmooth", ( assert ) => {
  5863. assert.ok( false, "everything's gonna be alright" );
  5864. } );
  5865. QUnit.test( "setInterpolation", ( assert ) => {
  5866. assert.ok( false, "everything's gonna be alright" );
  5867. } );
  5868. QUnit.test( "getInterpolation", ( assert ) => {
  5869. assert.ok( false, "everything's gonna be alright" );
  5870. } );
  5871. QUnit.test( "getValueSize", ( assert ) => {
  5872. assert.ok( false, "everything's gonna be alright" );
  5873. } );
  5874. QUnit.test( "shift", ( assert ) => {
  5875. assert.ok( false, "everything's gonna be alright" );
  5876. } );
  5877. QUnit.test( "scale", ( assert ) => {
  5878. assert.ok( false, "everything's gonna be alright" );
  5879. } );
  5880. QUnit.test( "trim", ( assert ) => {
  5881. assert.ok( false, "everything's gonna be alright" );
  5882. } );
  5883. QUnit.test( "validate", ( assert ) => {
  5884. assert.ok( false, "everything's gonna be alright" );
  5885. } );
  5886. QUnit.test( "optimize", ( assert ) => {
  5887. assert.ok( false, "everything's gonna be alright" );
  5888. } );
  5889. } );
  5890. } );
  5891. /**
  5892. * @author mrdoob / http://mrdoob.com/
  5893. */
  5894. var ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  5895. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  5896. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  5897. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  5898. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  5899. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  5900. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  5901. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  5902. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  5903. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  5904. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  5905. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  5906. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  5907. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  5908. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  5909. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  5910. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  5911. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  5912. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  5913. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'rebeccapurple': 0x663399, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  5914. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  5915. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  5916. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  5917. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  5918. function Color( r, g, b ) {
  5919. if ( g === undefined && b === undefined ) {
  5920. // r is THREE.Color, hex or string
  5921. return this.set( r );
  5922. }
  5923. return this.setRGB( r, g, b );
  5924. }
  5925. Object.assign( Color.prototype, {
  5926. isColor: true,
  5927. r: 1, g: 1, b: 1,
  5928. set: function ( value ) {
  5929. if ( value && value.isColor ) {
  5930. this.copy( value );
  5931. } else if ( typeof value === 'number' ) {
  5932. this.setHex( value );
  5933. } else if ( typeof value === 'string' ) {
  5934. this.setStyle( value );
  5935. }
  5936. return this;
  5937. },
  5938. setScalar: function ( scalar ) {
  5939. this.r = scalar;
  5940. this.g = scalar;
  5941. this.b = scalar;
  5942. return this;
  5943. },
  5944. setHex: function ( hex ) {
  5945. hex = Math.floor( hex );
  5946. this.r = ( hex >> 16 & 255 ) / 255;
  5947. this.g = ( hex >> 8 & 255 ) / 255;
  5948. this.b = ( hex & 255 ) / 255;
  5949. return this;
  5950. },
  5951. setRGB: function ( r, g, b ) {
  5952. this.r = r;
  5953. this.g = g;
  5954. this.b = b;
  5955. return this;
  5956. },
  5957. setHSL: function () {
  5958. function hue2rgb( p, q, t ) {
  5959. if ( t < 0 ) t += 1;
  5960. if ( t > 1 ) t -= 1;
  5961. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  5962. if ( t < 1 / 2 ) return q;
  5963. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  5964. return p;
  5965. }
  5966. return function setHSL( h, s, l ) {
  5967. // h,s,l ranges are in 0.0 - 1.0
  5968. h = _Math.euclideanModulo( h, 1 );
  5969. s = _Math.clamp( s, 0, 1 );
  5970. l = _Math.clamp( l, 0, 1 );
  5971. if ( s === 0 ) {
  5972. this.r = this.g = this.b = l;
  5973. } else {
  5974. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  5975. var q = ( 2 * l ) - p;
  5976. this.r = hue2rgb( q, p, h + 1 / 3 );
  5977. this.g = hue2rgb( q, p, h );
  5978. this.b = hue2rgb( q, p, h - 1 / 3 );
  5979. }
  5980. return this;
  5981. };
  5982. }(),
  5983. setStyle: function ( style ) {
  5984. function handleAlpha( string ) {
  5985. if ( string === undefined ) return;
  5986. if ( parseFloat( string ) < 1 ) {
  5987. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  5988. }
  5989. }
  5990. var m;
  5991. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  5992. // rgb / hsl
  5993. var color;
  5994. var name = m[ 1 ];
  5995. var components = m[ 2 ];
  5996. switch ( name ) {
  5997. case 'rgb':
  5998. case 'rgba':
  5999. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  6000. // rgb(255,0,0) rgba(255,0,0,0.5)
  6001. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  6002. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  6003. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  6004. handleAlpha( color[ 5 ] );
  6005. return this;
  6006. }
  6007. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  6008. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  6009. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  6010. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  6011. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  6012. handleAlpha( color[ 5 ] );
  6013. return this;
  6014. }
  6015. break;
  6016. case 'hsl':
  6017. case 'hsla':
  6018. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  6019. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  6020. var h = parseFloat( color[ 1 ] ) / 360;
  6021. var s = parseInt( color[ 2 ], 10 ) / 100;
  6022. var l = parseInt( color[ 3 ], 10 ) / 100;
  6023. handleAlpha( color[ 5 ] );
  6024. return this.setHSL( h, s, l );
  6025. }
  6026. break;
  6027. }
  6028. } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  6029. // hex color
  6030. var hex = m[ 1 ];
  6031. var size = hex.length;
  6032. if ( size === 3 ) {
  6033. // #ff0
  6034. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  6035. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  6036. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  6037. return this;
  6038. } else if ( size === 6 ) {
  6039. // #ff0000
  6040. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  6041. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  6042. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  6043. return this;
  6044. }
  6045. }
  6046. if ( style && style.length > 0 ) {
  6047. // color keywords
  6048. var hex = ColorKeywords[ style ];
  6049. if ( hex !== undefined ) {
  6050. // red
  6051. this.setHex( hex );
  6052. } else {
  6053. // unknown color
  6054. console.warn( 'THREE.Color: Unknown color ' + style );
  6055. }
  6056. }
  6057. return this;
  6058. },
  6059. clone: function () {
  6060. return new this.constructor( this.r, this.g, this.b );
  6061. },
  6062. copy: function ( color ) {
  6063. this.r = color.r;
  6064. this.g = color.g;
  6065. this.b = color.b;
  6066. return this;
  6067. },
  6068. copyGammaToLinear: function ( color, gammaFactor ) {
  6069. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  6070. this.r = Math.pow( color.r, gammaFactor );
  6071. this.g = Math.pow( color.g, gammaFactor );
  6072. this.b = Math.pow( color.b, gammaFactor );
  6073. return this;
  6074. },
  6075. copyLinearToGamma: function ( color, gammaFactor ) {
  6076. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  6077. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  6078. this.r = Math.pow( color.r, safeInverse );
  6079. this.g = Math.pow( color.g, safeInverse );
  6080. this.b = Math.pow( color.b, safeInverse );
  6081. return this;
  6082. },
  6083. convertGammaToLinear: function () {
  6084. var r = this.r, g = this.g, b = this.b;
  6085. this.r = r * r;
  6086. this.g = g * g;
  6087. this.b = b * b;
  6088. return this;
  6089. },
  6090. convertLinearToGamma: function () {
  6091. this.r = Math.sqrt( this.r );
  6092. this.g = Math.sqrt( this.g );
  6093. this.b = Math.sqrt( this.b );
  6094. return this;
  6095. },
  6096. getHex: function () {
  6097. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  6098. },
  6099. getHexString: function () {
  6100. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  6101. },
  6102. getHSL: function ( optionalTarget ) {
  6103. // h,s,l ranges are in 0.0 - 1.0
  6104. var hsl = optionalTarget || { h: 0, s: 0, l: 0 };
  6105. var r = this.r, g = this.g, b = this.b;
  6106. var max = Math.max( r, g, b );
  6107. var min = Math.min( r, g, b );
  6108. var hue, saturation;
  6109. var lightness = ( min + max ) / 2.0;
  6110. if ( min === max ) {
  6111. hue = 0;
  6112. saturation = 0;
  6113. } else {
  6114. var delta = max - min;
  6115. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  6116. switch ( max ) {
  6117. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  6118. case g: hue = ( b - r ) / delta + 2; break;
  6119. case b: hue = ( r - g ) / delta + 4; break;
  6120. }
  6121. hue /= 6;
  6122. }
  6123. hsl.h = hue;
  6124. hsl.s = saturation;
  6125. hsl.l = lightness;
  6126. return hsl;
  6127. },
  6128. getStyle: function () {
  6129. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  6130. },
  6131. offsetHSL: function ( h, s, l ) {
  6132. var hsl = this.getHSL();
  6133. hsl.h += h; hsl.s += s; hsl.l += l;
  6134. this.setHSL( hsl.h, hsl.s, hsl.l );
  6135. return this;
  6136. },
  6137. add: function ( color ) {
  6138. this.r += color.r;
  6139. this.g += color.g;
  6140. this.b += color.b;
  6141. return this;
  6142. },
  6143. addColors: function ( color1, color2 ) {
  6144. this.r = color1.r + color2.r;
  6145. this.g = color1.g + color2.g;
  6146. this.b = color1.b + color2.b;
  6147. return this;
  6148. },
  6149. addScalar: function ( s ) {
  6150. this.r += s;
  6151. this.g += s;
  6152. this.b += s;
  6153. return this;
  6154. },
  6155. sub: function ( color ) {
  6156. this.r = Math.max( 0, this.r - color.r );
  6157. this.g = Math.max( 0, this.g - color.g );
  6158. this.b = Math.max( 0, this.b - color.b );
  6159. return this;
  6160. },
  6161. multiply: function ( color ) {
  6162. this.r *= color.r;
  6163. this.g *= color.g;
  6164. this.b *= color.b;
  6165. return this;
  6166. },
  6167. multiplyScalar: function ( s ) {
  6168. this.r *= s;
  6169. this.g *= s;
  6170. this.b *= s;
  6171. return this;
  6172. },
  6173. lerp: function ( color, alpha ) {
  6174. this.r += ( color.r - this.r ) * alpha;
  6175. this.g += ( color.g - this.g ) * alpha;
  6176. this.b += ( color.b - this.b ) * alpha;
  6177. return this;
  6178. },
  6179. equals: function ( c ) {
  6180. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  6181. },
  6182. fromArray: function ( array, offset ) {
  6183. if ( offset === undefined ) offset = 0;
  6184. this.r = array[ offset ];
  6185. this.g = array[ offset + 1 ];
  6186. this.b = array[ offset + 2 ];
  6187. return this;
  6188. },
  6189. toArray: function ( array, offset ) {
  6190. if ( array === undefined ) array = [];
  6191. if ( offset === undefined ) offset = 0;
  6192. array[ offset ] = this.r;
  6193. array[ offset + 1 ] = this.g;
  6194. array[ offset + 2 ] = this.b;
  6195. return array;
  6196. },
  6197. toJSON: function () {
  6198. return this.getHex();
  6199. }
  6200. } );
  6201. /**
  6202. * @author mrdoob / http://mrdoob.com/
  6203. * @author alteredq / http://alteredqualia.com/
  6204. */
  6205. function Face3( a, b, c, normal, color, materialIndex ) {
  6206. this.a = a;
  6207. this.b = b;
  6208. this.c = c;
  6209. this.normal = ( normal && normal.isVector3 ) ? normal : new Vector3();
  6210. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  6211. this.color = ( color && color.isColor ) ? color : new Color();
  6212. this.vertexColors = Array.isArray( color ) ? color : [];
  6213. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  6214. }
  6215. Object.assign( Face3.prototype, {
  6216. clone: function () {
  6217. return new this.constructor().copy( this );
  6218. },
  6219. copy: function ( source ) {
  6220. this.a = source.a;
  6221. this.b = source.b;
  6222. this.c = source.c;
  6223. this.normal.copy( source.normal );
  6224. this.color.copy( source.color );
  6225. this.materialIndex = source.materialIndex;
  6226. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  6227. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  6228. }
  6229. for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  6230. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  6231. }
  6232. return this;
  6233. }
  6234. } );
  6235. /**
  6236. * @author bhouston / http://clara.io
  6237. * @author WestLangley / http://github.com/WestLangley
  6238. */
  6239. function Box3( min, max ) {
  6240. this.min = ( min !== undefined ) ? min : new Vector3( + Infinity, + Infinity, + Infinity );
  6241. this.max = ( max !== undefined ) ? max : new Vector3( - Infinity, - Infinity, - Infinity );
  6242. }
  6243. Object.assign( Box3.prototype, {
  6244. isBox3: true,
  6245. set: function ( min, max ) {
  6246. this.min.copy( min );
  6247. this.max.copy( max );
  6248. return this;
  6249. },
  6250. setFromArray: function ( array ) {
  6251. var minX = + Infinity;
  6252. var minY = + Infinity;
  6253. var minZ = + Infinity;
  6254. var maxX = - Infinity;
  6255. var maxY = - Infinity;
  6256. var maxZ = - Infinity;
  6257. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  6258. var x = array[ i ];
  6259. var y = array[ i + 1 ];
  6260. var z = array[ i + 2 ];
  6261. if ( x < minX ) minX = x;
  6262. if ( y < minY ) minY = y;
  6263. if ( z < minZ ) minZ = z;
  6264. if ( x > maxX ) maxX = x;
  6265. if ( y > maxY ) maxY = y;
  6266. if ( z > maxZ ) maxZ = z;
  6267. }
  6268. this.min.set( minX, minY, minZ );
  6269. this.max.set( maxX, maxY, maxZ );
  6270. return this;
  6271. },
  6272. setFromBufferAttribute: function ( attribute ) {
  6273. var minX = + Infinity;
  6274. var minY = + Infinity;
  6275. var minZ = + Infinity;
  6276. var maxX = - Infinity;
  6277. var maxY = - Infinity;
  6278. var maxZ = - Infinity;
  6279. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  6280. var x = attribute.getX( i );
  6281. var y = attribute.getY( i );
  6282. var z = attribute.getZ( i );
  6283. if ( x < minX ) minX = x;
  6284. if ( y < minY ) minY = y;
  6285. if ( z < minZ ) minZ = z;
  6286. if ( x > maxX ) maxX = x;
  6287. if ( y > maxY ) maxY = y;
  6288. if ( z > maxZ ) maxZ = z;
  6289. }
  6290. this.min.set( minX, minY, minZ );
  6291. this.max.set( maxX, maxY, maxZ );
  6292. return this;
  6293. },
  6294. setFromPoints: function ( points ) {
  6295. this.makeEmpty();
  6296. for ( var i = 0, il = points.length; i < il; i ++ ) {
  6297. this.expandByPoint( points[ i ] );
  6298. }
  6299. return this;
  6300. },
  6301. setFromCenterAndSize: function () {
  6302. var v1 = new Vector3();
  6303. return function setFromCenterAndSize( center, size ) {
  6304. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  6305. this.min.copy( center ).sub( halfSize );
  6306. this.max.copy( center ).add( halfSize );
  6307. return this;
  6308. };
  6309. }(),
  6310. setFromObject: function ( object ) {
  6311. this.makeEmpty();
  6312. return this.expandByObject( object );
  6313. },
  6314. clone: function () {
  6315. return new this.constructor().copy( this );
  6316. },
  6317. copy: function ( box ) {
  6318. this.min.copy( box.min );
  6319. this.max.copy( box.max );
  6320. return this;
  6321. },
  6322. makeEmpty: function () {
  6323. this.min.x = this.min.y = this.min.z = + Infinity;
  6324. this.max.x = this.max.y = this.max.z = - Infinity;
  6325. return this;
  6326. },
  6327. isEmpty: function () {
  6328. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  6329. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  6330. },
  6331. getCenter: function ( optionalTarget ) {
  6332. var result = optionalTarget || new Vector3();
  6333. return this.isEmpty() ? result.set( 0, 0, 0 ) : result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  6334. },
  6335. getSize: function ( optionalTarget ) {
  6336. var result = optionalTarget || new Vector3();
  6337. return this.isEmpty() ? result.set( 0, 0, 0 ) : result.subVectors( this.max, this.min );
  6338. },
  6339. expandByPoint: function ( point ) {
  6340. this.min.min( point );
  6341. this.max.max( point );
  6342. return this;
  6343. },
  6344. expandByVector: function ( vector ) {
  6345. this.min.sub( vector );
  6346. this.max.add( vector );
  6347. return this;
  6348. },
  6349. expandByScalar: function ( scalar ) {
  6350. this.min.addScalar( - scalar );
  6351. this.max.addScalar( scalar );
  6352. return this;
  6353. },
  6354. expandByObject: function () {
  6355. // Computes the world-axis-aligned bounding box of an object (including its children),
  6356. // accounting for both the object's, and children's, world transforms
  6357. var scope, i, l;
  6358. var v1 = new Vector3();
  6359. function traverse( node ) {
  6360. var geometry = node.geometry;
  6361. if ( geometry !== undefined ) {
  6362. if ( geometry.isGeometry ) {
  6363. var vertices = geometry.vertices;
  6364. for ( i = 0, l = vertices.length; i < l; i ++ ) {
  6365. v1.copy( vertices[ i ] );
  6366. v1.applyMatrix4( node.matrixWorld );
  6367. scope.expandByPoint( v1 );
  6368. }
  6369. } else if ( geometry.isBufferGeometry ) {
  6370. var attribute = geometry.attributes.position;
  6371. if ( attribute !== undefined ) {
  6372. for ( i = 0, l = attribute.count; i < l; i ++ ) {
  6373. v1.fromBufferAttribute( attribute, i ).applyMatrix4( node.matrixWorld );
  6374. scope.expandByPoint( v1 );
  6375. }
  6376. }
  6377. }
  6378. }
  6379. }
  6380. return function expandByObject( object ) {
  6381. scope = this;
  6382. object.updateMatrixWorld( true );
  6383. object.traverse( traverse );
  6384. return this;
  6385. };
  6386. }(),
  6387. containsPoint: function ( point ) {
  6388. return point.x < this.min.x || point.x > this.max.x ||
  6389. point.y < this.min.y || point.y > this.max.y ||
  6390. point.z < this.min.z || point.z > this.max.z ? false : true;
  6391. },
  6392. containsBox: function ( box ) {
  6393. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  6394. this.min.y <= box.min.y && box.max.y <= this.max.y &&
  6395. this.min.z <= box.min.z && box.max.z <= this.max.z;
  6396. },
  6397. getParameter: function ( point, optionalTarget ) {
  6398. // This can potentially have a divide by zero if the box
  6399. // has a size dimension of 0.
  6400. var result = optionalTarget || new Vector3();
  6401. return result.set(
  6402. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  6403. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  6404. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  6405. );
  6406. },
  6407. intersectsBox: function ( box ) {
  6408. // using 6 splitting planes to rule out intersections.
  6409. return box.max.x < this.min.x || box.min.x > this.max.x ||
  6410. box.max.y < this.min.y || box.min.y > this.max.y ||
  6411. box.max.z < this.min.z || box.min.z > this.max.z ? false : true;
  6412. },
  6413. intersectsSphere: ( function () {
  6414. var closestPoint = new Vector3();
  6415. return function intersectsSphere( sphere ) {
  6416. // Find the point on the AABB closest to the sphere center.
  6417. this.clampPoint( sphere.center, closestPoint );
  6418. // If that point is inside the sphere, the AABB and sphere intersect.
  6419. return closestPoint.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  6420. };
  6421. } )(),
  6422. intersectsPlane: function ( plane ) {
  6423. // We compute the minimum and maximum dot product values. If those values
  6424. // are on the same side (back or front) of the plane, then there is no intersection.
  6425. var min, max;
  6426. if ( plane.normal.x > 0 ) {
  6427. min = plane.normal.x * this.min.x;
  6428. max = plane.normal.x * this.max.x;
  6429. } else {
  6430. min = plane.normal.x * this.max.x;
  6431. max = plane.normal.x * this.min.x;
  6432. }
  6433. if ( plane.normal.y > 0 ) {
  6434. min += plane.normal.y * this.min.y;
  6435. max += plane.normal.y * this.max.y;
  6436. } else {
  6437. min += plane.normal.y * this.max.y;
  6438. max += plane.normal.y * this.min.y;
  6439. }
  6440. if ( plane.normal.z > 0 ) {
  6441. min += plane.normal.z * this.min.z;
  6442. max += plane.normal.z * this.max.z;
  6443. } else {
  6444. min += plane.normal.z * this.max.z;
  6445. max += plane.normal.z * this.min.z;
  6446. }
  6447. return ( min <= plane.constant && max >= plane.constant );
  6448. },
  6449. clampPoint: function ( point, optionalTarget ) {
  6450. var result = optionalTarget || new Vector3();
  6451. return result.copy( point ).clamp( this.min, this.max );
  6452. },
  6453. distanceToPoint: function () {
  6454. var v1 = new Vector3();
  6455. return function distanceToPoint( point ) {
  6456. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  6457. return clampedPoint.sub( point ).length();
  6458. };
  6459. }(),
  6460. getBoundingSphere: function () {
  6461. var v1 = new Vector3();
  6462. return function getBoundingSphere( optionalTarget ) {
  6463. var result = optionalTarget || new Sphere();
  6464. this.getCenter( result.center );
  6465. result.radius = this.getSize( v1 ).length() * 0.5;
  6466. return result;
  6467. };
  6468. }(),
  6469. intersect: function ( box ) {
  6470. this.min.max( box.min );
  6471. this.max.min( box.max );
  6472. // 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.
  6473. if ( this.isEmpty() ) this.makeEmpty();
  6474. return this;
  6475. },
  6476. union: function ( box ) {
  6477. this.min.min( box.min );
  6478. this.max.max( box.max );
  6479. return this;
  6480. },
  6481. applyMatrix4: function () {
  6482. var points = [
  6483. new Vector3(),
  6484. new Vector3(),
  6485. new Vector3(),
  6486. new Vector3(),
  6487. new Vector3(),
  6488. new Vector3(),
  6489. new Vector3(),
  6490. new Vector3()
  6491. ];
  6492. return function applyMatrix4( matrix ) {
  6493. // transform of empty box is an empty box.
  6494. if ( this.isEmpty() ) return this;
  6495. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  6496. points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  6497. points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  6498. points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  6499. points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  6500. points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  6501. points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  6502. points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  6503. points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  6504. this.setFromPoints( points );
  6505. return this;
  6506. };
  6507. }(),
  6508. translate: function ( offset ) {
  6509. this.min.add( offset );
  6510. this.max.add( offset );
  6511. return this;
  6512. },
  6513. equals: function ( box ) {
  6514. return box.min.equals( this.min ) && box.max.equals( this.max );
  6515. }
  6516. } );
  6517. /**
  6518. * @author bhouston / http://clara.io
  6519. * @author mrdoob / http://mrdoob.com/
  6520. */
  6521. function Sphere( center, radius ) {
  6522. this.center = ( center !== undefined ) ? center : new Vector3();
  6523. this.radius = ( radius !== undefined ) ? radius : 0;
  6524. }
  6525. Object.assign( Sphere.prototype, {
  6526. set: function ( center, radius ) {
  6527. this.center.copy( center );
  6528. this.radius = radius;
  6529. return this;
  6530. },
  6531. setFromPoints: function () {
  6532. var box = new Box3();
  6533. return function setFromPoints( points, optionalCenter ) {
  6534. var center = this.center;
  6535. if ( optionalCenter !== undefined ) {
  6536. center.copy( optionalCenter );
  6537. } else {
  6538. box.setFromPoints( points ).getCenter( center );
  6539. }
  6540. var maxRadiusSq = 0;
  6541. for ( var i = 0, il = points.length; i < il; i ++ ) {
  6542. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  6543. }
  6544. this.radius = Math.sqrt( maxRadiusSq );
  6545. return this;
  6546. };
  6547. }(),
  6548. clone: function () {
  6549. return new this.constructor().copy( this );
  6550. },
  6551. copy: function ( sphere ) {
  6552. this.center.copy( sphere.center );
  6553. this.radius = sphere.radius;
  6554. return this;
  6555. },
  6556. empty: function () {
  6557. return ( this.radius <= 0 );
  6558. },
  6559. containsPoint: function ( point ) {
  6560. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  6561. },
  6562. distanceToPoint: function ( point ) {
  6563. return ( point.distanceTo( this.center ) - this.radius );
  6564. },
  6565. intersectsSphere: function ( sphere ) {
  6566. var radiusSum = this.radius + sphere.radius;
  6567. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  6568. },
  6569. intersectsBox: function ( box ) {
  6570. return box.intersectsSphere( this );
  6571. },
  6572. intersectsPlane: function ( plane ) {
  6573. return Math.abs( plane.distanceToPoint( this.center ) ) <= this.radius;
  6574. },
  6575. clampPoint: function ( point, optionalTarget ) {
  6576. var deltaLengthSq = this.center.distanceToSquared( point );
  6577. var result = optionalTarget || new Vector3();
  6578. result.copy( point );
  6579. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  6580. result.sub( this.center ).normalize();
  6581. result.multiplyScalar( this.radius ).add( this.center );
  6582. }
  6583. return result;
  6584. },
  6585. getBoundingBox: function ( optionalTarget ) {
  6586. var box = optionalTarget || new Box3();
  6587. box.set( this.center, this.center );
  6588. box.expandByScalar( this.radius );
  6589. return box;
  6590. },
  6591. applyMatrix4: function ( matrix ) {
  6592. this.center.applyMatrix4( matrix );
  6593. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  6594. return this;
  6595. },
  6596. translate: function ( offset ) {
  6597. this.center.add( offset );
  6598. return this;
  6599. },
  6600. equals: function ( sphere ) {
  6601. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  6602. }
  6603. } );
  6604. /**
  6605. * @author mrdoob / http://mrdoob.com/
  6606. * @author philogb / http://blog.thejit.org/
  6607. * @author egraether / http://egraether.com/
  6608. * @author zz85 / http://www.lab4games.net/zz85/blog
  6609. */
  6610. function Vector2( x, y ) {
  6611. this.x = x || 0;
  6612. this.y = y || 0;
  6613. }
  6614. Object.defineProperties( Vector2.prototype, {
  6615. "width": {
  6616. get: function () {
  6617. return this.x;
  6618. },
  6619. set: function ( value ) {
  6620. this.x = value;
  6621. }
  6622. },
  6623. "height": {
  6624. get: function () {
  6625. return this.y;
  6626. },
  6627. set: function ( value ) {
  6628. this.y = value;
  6629. }
  6630. }
  6631. } );
  6632. Object.assign( Vector2.prototype, {
  6633. isVector2: true,
  6634. set: function ( x, y ) {
  6635. this.x = x;
  6636. this.y = y;
  6637. return this;
  6638. },
  6639. setScalar: function ( scalar ) {
  6640. this.x = scalar;
  6641. this.y = scalar;
  6642. return this;
  6643. },
  6644. setX: function ( x ) {
  6645. this.x = x;
  6646. return this;
  6647. },
  6648. setY: function ( y ) {
  6649. this.y = y;
  6650. return this;
  6651. },
  6652. setComponent: function ( index, value ) {
  6653. switch ( index ) {
  6654. case 0: this.x = value; break;
  6655. case 1: this.y = value; break;
  6656. default: throw new Error( 'index is out of range: ' + index );
  6657. }
  6658. return this;
  6659. },
  6660. getComponent: function ( index ) {
  6661. switch ( index ) {
  6662. case 0: return this.x;
  6663. case 1: return this.y;
  6664. default: throw new Error( 'index is out of range: ' + index );
  6665. }
  6666. },
  6667. clone: function () {
  6668. return new this.constructor( this.x, this.y );
  6669. },
  6670. copy: function ( v ) {
  6671. this.x = v.x;
  6672. this.y = v.y;
  6673. return this;
  6674. },
  6675. add: function ( v, w ) {
  6676. if ( w !== undefined ) {
  6677. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  6678. return this.addVectors( v, w );
  6679. }
  6680. this.x += v.x;
  6681. this.y += v.y;
  6682. return this;
  6683. },
  6684. addScalar: function ( s ) {
  6685. this.x += s;
  6686. this.y += s;
  6687. return this;
  6688. },
  6689. addVectors: function ( a, b ) {
  6690. this.x = a.x + b.x;
  6691. this.y = a.y + b.y;
  6692. return this;
  6693. },
  6694. addScaledVector: function ( v, s ) {
  6695. this.x += v.x * s;
  6696. this.y += v.y * s;
  6697. return this;
  6698. },
  6699. sub: function ( v, w ) {
  6700. if ( w !== undefined ) {
  6701. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  6702. return this.subVectors( v, w );
  6703. }
  6704. this.x -= v.x;
  6705. this.y -= v.y;
  6706. return this;
  6707. },
  6708. subScalar: function ( s ) {
  6709. this.x -= s;
  6710. this.y -= s;
  6711. return this;
  6712. },
  6713. subVectors: function ( a, b ) {
  6714. this.x = a.x - b.x;
  6715. this.y = a.y - b.y;
  6716. return this;
  6717. },
  6718. multiply: function ( v ) {
  6719. this.x *= v.x;
  6720. this.y *= v.y;
  6721. return this;
  6722. },
  6723. multiplyScalar: function ( scalar ) {
  6724. this.x *= scalar;
  6725. this.y *= scalar;
  6726. return this;
  6727. },
  6728. divide: function ( v ) {
  6729. this.x /= v.x;
  6730. this.y /= v.y;
  6731. return this;
  6732. },
  6733. divideScalar: function ( scalar ) {
  6734. return this.multiplyScalar( 1 / scalar );
  6735. },
  6736. applyMatrix3: function ( m ) {
  6737. var x = this.x, y = this.y;
  6738. var e = m.elements;
  6739. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ];
  6740. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ];
  6741. return this;
  6742. },
  6743. min: function ( v ) {
  6744. this.x = Math.min( this.x, v.x );
  6745. this.y = Math.min( this.y, v.y );
  6746. return this;
  6747. },
  6748. max: function ( v ) {
  6749. this.x = Math.max( this.x, v.x );
  6750. this.y = Math.max( this.y, v.y );
  6751. return this;
  6752. },
  6753. clamp: function ( min, max ) {
  6754. // assumes min < max, componentwise
  6755. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  6756. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  6757. return this;
  6758. },
  6759. clampScalar: function () {
  6760. var min = new Vector2();
  6761. var max = new Vector2();
  6762. return function clampScalar( minVal, maxVal ) {
  6763. min.set( minVal, minVal );
  6764. max.set( maxVal, maxVal );
  6765. return this.clamp( min, max );
  6766. };
  6767. }(),
  6768. clampLength: function ( min, max ) {
  6769. var length = this.length();
  6770. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  6771. },
  6772. floor: function () {
  6773. this.x = Math.floor( this.x );
  6774. this.y = Math.floor( this.y );
  6775. return this;
  6776. },
  6777. ceil: function () {
  6778. this.x = Math.ceil( this.x );
  6779. this.y = Math.ceil( this.y );
  6780. return this;
  6781. },
  6782. round: function () {
  6783. this.x = Math.round( this.x );
  6784. this.y = Math.round( this.y );
  6785. return this;
  6786. },
  6787. roundToZero: function () {
  6788. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  6789. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  6790. return this;
  6791. },
  6792. negate: function () {
  6793. this.x = - this.x;
  6794. this.y = - this.y;
  6795. return this;
  6796. },
  6797. dot: function ( v ) {
  6798. return this.x * v.x + this.y * v.y;
  6799. },
  6800. lengthSq: function () {
  6801. return this.x * this.x + this.y * this.y;
  6802. },
  6803. length: function () {
  6804. return Math.sqrt( this.x * this.x + this.y * this.y );
  6805. },
  6806. manhattanLength: function () {
  6807. return Math.abs( this.x ) + Math.abs( this.y );
  6808. },
  6809. normalize: function () {
  6810. return this.divideScalar( this.length() || 1 );
  6811. },
  6812. angle: function () {
  6813. // computes the angle in radians with respect to the positive x-axis
  6814. var angle = Math.atan2( this.y, this.x );
  6815. if ( angle < 0 ) angle += 2 * Math.PI;
  6816. return angle;
  6817. },
  6818. distanceTo: function ( v ) {
  6819. return Math.sqrt( this.distanceToSquared( v ) );
  6820. },
  6821. distanceToSquared: function ( v ) {
  6822. var dx = this.x - v.x, dy = this.y - v.y;
  6823. return dx * dx + dy * dy;
  6824. },
  6825. manhattanDistanceTo: function ( v ) {
  6826. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y );
  6827. },
  6828. setLength: function ( length ) {
  6829. return this.normalize().multiplyScalar( length );
  6830. },
  6831. lerp: function ( v, alpha ) {
  6832. this.x += ( v.x - this.x ) * alpha;
  6833. this.y += ( v.y - this.y ) * alpha;
  6834. return this;
  6835. },
  6836. lerpVectors: function ( v1, v2, alpha ) {
  6837. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  6838. },
  6839. equals: function ( v ) {
  6840. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  6841. },
  6842. fromArray: function ( array, offset ) {
  6843. if ( offset === undefined ) offset = 0;
  6844. this.x = array[ offset ];
  6845. this.y = array[ offset + 1 ];
  6846. return this;
  6847. },
  6848. toArray: function ( array, offset ) {
  6849. if ( array === undefined ) array = [];
  6850. if ( offset === undefined ) offset = 0;
  6851. array[ offset ] = this.x;
  6852. array[ offset + 1 ] = this.y;
  6853. return array;
  6854. },
  6855. fromBufferAttribute: function ( attribute, index, offset ) {
  6856. if ( offset !== undefined ) {
  6857. console.warn( 'THREE.Vector2: offset has been removed from .fromBufferAttribute().' );
  6858. }
  6859. this.x = attribute.getX( index );
  6860. this.y = attribute.getY( index );
  6861. return this;
  6862. },
  6863. rotateAround: function ( center, angle ) {
  6864. var c = Math.cos( angle ), s = Math.sin( angle );
  6865. var x = this.x - center.x;
  6866. var y = this.y - center.y;
  6867. this.x = x * c - y * s + center.x;
  6868. this.y = x * s + y * c + center.y;
  6869. return this;
  6870. }
  6871. } );
  6872. /**
  6873. * @author mrdoob / http://mrdoob.com/
  6874. * @author kile / http://kile.stravaganza.org/
  6875. * @author alteredq / http://alteredqualia.com/
  6876. * @author mikael emtinger / http://gomo.se/
  6877. * @author zz85 / http://www.lab4games.net/zz85/blog
  6878. * @author bhouston / http://clara.io
  6879. */
  6880. var geometryId = 0; // Geometry uses even numbers as Id
  6881. function Geometry() {
  6882. Object.defineProperty( this, 'id', { value: geometryId += 2 } );
  6883. this.uuid = _Math.generateUUID();
  6884. this.name = '';
  6885. this.type = 'Geometry';
  6886. this.vertices = [];
  6887. this.colors = [];
  6888. this.faces = [];
  6889. this.faceVertexUvs = [[]];
  6890. this.morphTargets = [];
  6891. this.morphNormals = [];
  6892. this.skinWeights = [];
  6893. this.skinIndices = [];
  6894. this.lineDistances = [];
  6895. this.boundingBox = null;
  6896. this.boundingSphere = null;
  6897. // update flags
  6898. this.elementsNeedUpdate = false;
  6899. this.verticesNeedUpdate = false;
  6900. this.uvsNeedUpdate = false;
  6901. this.normalsNeedUpdate = false;
  6902. this.colorsNeedUpdate = false;
  6903. this.lineDistancesNeedUpdate = false;
  6904. this.groupsNeedUpdate = false;
  6905. }
  6906. Object.assign( Geometry.prototype, EventDispatcher.prototype, {
  6907. isGeometry: true,
  6908. applyMatrix: function ( matrix ) {
  6909. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  6910. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  6911. var vertex = this.vertices[ i ];
  6912. vertex.applyMatrix4( matrix );
  6913. }
  6914. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  6915. var face = this.faces[ i ];
  6916. face.normal.applyMatrix3( normalMatrix ).normalize();
  6917. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  6918. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  6919. }
  6920. }
  6921. if ( this.boundingBox !== null ) {
  6922. this.computeBoundingBox();
  6923. }
  6924. if ( this.boundingSphere !== null ) {
  6925. this.computeBoundingSphere();
  6926. }
  6927. this.verticesNeedUpdate = true;
  6928. this.normalsNeedUpdate = true;
  6929. return this;
  6930. },
  6931. rotateX: function () {
  6932. // rotate geometry around world x-axis
  6933. var m1 = new Matrix4();
  6934. return function rotateX( angle ) {
  6935. m1.makeRotationX( angle );
  6936. this.applyMatrix( m1 );
  6937. return this;
  6938. };
  6939. }(),
  6940. rotateY: function () {
  6941. // rotate geometry around world y-axis
  6942. var m1 = new Matrix4();
  6943. return function rotateY( angle ) {
  6944. m1.makeRotationY( angle );
  6945. this.applyMatrix( m1 );
  6946. return this;
  6947. };
  6948. }(),
  6949. rotateZ: function () {
  6950. // rotate geometry around world z-axis
  6951. var m1 = new Matrix4();
  6952. return function rotateZ( angle ) {
  6953. m1.makeRotationZ( angle );
  6954. this.applyMatrix( m1 );
  6955. return this;
  6956. };
  6957. }(),
  6958. translate: function () {
  6959. // translate geometry
  6960. var m1 = new Matrix4();
  6961. return function translate( x, y, z ) {
  6962. m1.makeTranslation( x, y, z );
  6963. this.applyMatrix( m1 );
  6964. return this;
  6965. };
  6966. }(),
  6967. scale: function () {
  6968. // scale geometry
  6969. var m1 = new Matrix4();
  6970. return function scale( x, y, z ) {
  6971. m1.makeScale( x, y, z );
  6972. this.applyMatrix( m1 );
  6973. return this;
  6974. };
  6975. }(),
  6976. lookAt: function () {
  6977. var obj = new Object3D();
  6978. return function lookAt( vector ) {
  6979. obj.lookAt( vector );
  6980. obj.updateMatrix();
  6981. this.applyMatrix( obj.matrix );
  6982. };
  6983. }(),
  6984. fromBufferGeometry: function ( geometry ) {
  6985. var scope = this;
  6986. var indices = geometry.index !== null ? geometry.index.array : undefined;
  6987. var attributes = geometry.attributes;
  6988. var positions = attributes.position.array;
  6989. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  6990. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  6991. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  6992. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  6993. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  6994. var tempNormals = [];
  6995. var tempUVs = [];
  6996. var tempUVs2 = [];
  6997. for ( var i = 0, j = 0; i < positions.length; i += 3, j += 2 ) {
  6998. scope.vertices.push( new Vector3( positions[ i ], positions[ i + 1 ], positions[ i + 2 ] ) );
  6999. if ( normals !== undefined ) {
  7000. tempNormals.push( new Vector3( normals[ i ], normals[ i + 1 ], normals[ i + 2 ] ) );
  7001. }
  7002. if ( colors !== undefined ) {
  7003. scope.colors.push( new Color( colors[ i ], colors[ i + 1 ], colors[ i + 2 ] ) );
  7004. }
  7005. if ( uvs !== undefined ) {
  7006. tempUVs.push( new Vector2( uvs[ j ], uvs[ j + 1 ] ) );
  7007. }
  7008. if ( uvs2 !== undefined ) {
  7009. tempUVs2.push( new Vector2( uvs2[ j ], uvs2[ j + 1 ] ) );
  7010. }
  7011. }
  7012. function addFace( a, b, c, materialIndex ) {
  7013. var vertexNormals = normals !== undefined ? [ tempNormals[ a ].clone(), tempNormals[ b ].clone(), tempNormals[ c ].clone() ] : [];
  7014. var vertexColors = colors !== undefined ? [ scope.colors[ a ].clone(), scope.colors[ b ].clone(), scope.colors[ c ].clone() ] : [];
  7015. var face = new Face3( a, b, c, vertexNormals, vertexColors, materialIndex );
  7016. scope.faces.push( face );
  7017. if ( uvs !== undefined ) {
  7018. scope.faceVertexUvs[ 0 ].push( [ tempUVs[ a ].clone(), tempUVs[ b ].clone(), tempUVs[ c ].clone() ] );
  7019. }
  7020. if ( uvs2 !== undefined ) {
  7021. scope.faceVertexUvs[ 1 ].push( [ tempUVs2[ a ].clone(), tempUVs2[ b ].clone(), tempUVs2[ c ].clone() ] );
  7022. }
  7023. }
  7024. var groups = geometry.groups;
  7025. if ( groups.length > 0 ) {
  7026. for ( var i = 0; i < groups.length; i ++ ) {
  7027. var group = groups[ i ];
  7028. var start = group.start;
  7029. var count = group.count;
  7030. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  7031. if ( indices !== undefined ) {
  7032. addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ], group.materialIndex );
  7033. } else {
  7034. addFace( j, j + 1, j + 2, group.materialIndex );
  7035. }
  7036. }
  7037. }
  7038. } else {
  7039. if ( indices !== undefined ) {
  7040. for ( var i = 0; i < indices.length; i += 3 ) {
  7041. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  7042. }
  7043. } else {
  7044. for ( var i = 0; i < positions.length / 3; i += 3 ) {
  7045. addFace( i, i + 1, i + 2 );
  7046. }
  7047. }
  7048. }
  7049. this.computeFaceNormals();
  7050. if ( geometry.boundingBox !== null ) {
  7051. this.boundingBox = geometry.boundingBox.clone();
  7052. }
  7053. if ( geometry.boundingSphere !== null ) {
  7054. this.boundingSphere = geometry.boundingSphere.clone();
  7055. }
  7056. return this;
  7057. },
  7058. center: function () {
  7059. this.computeBoundingBox();
  7060. var offset = this.boundingBox.getCenter().negate();
  7061. this.translate( offset.x, offset.y, offset.z );
  7062. return offset;
  7063. },
  7064. normalize: function () {
  7065. this.computeBoundingSphere();
  7066. var center = this.boundingSphere.center;
  7067. var radius = this.boundingSphere.radius;
  7068. var s = radius === 0 ? 1 : 1.0 / radius;
  7069. var matrix = new Matrix4();
  7070. matrix.set(
  7071. s, 0, 0, - s * center.x,
  7072. 0, s, 0, - s * center.y,
  7073. 0, 0, s, - s * center.z,
  7074. 0, 0, 0, 1
  7075. );
  7076. this.applyMatrix( matrix );
  7077. return this;
  7078. },
  7079. computeFaceNormals: function () {
  7080. var cb = new Vector3(), ab = new Vector3();
  7081. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7082. var face = this.faces[ f ];
  7083. var vA = this.vertices[ face.a ];
  7084. var vB = this.vertices[ face.b ];
  7085. var vC = this.vertices[ face.c ];
  7086. cb.subVectors( vC, vB );
  7087. ab.subVectors( vA, vB );
  7088. cb.cross( ab );
  7089. cb.normalize();
  7090. face.normal.copy( cb );
  7091. }
  7092. },
  7093. computeVertexNormals: function ( areaWeighted ) {
  7094. if ( areaWeighted === undefined ) areaWeighted = true;
  7095. var v, vl, f, fl, face, vertices;
  7096. vertices = new Array( this.vertices.length );
  7097. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  7098. vertices[ v ] = new Vector3();
  7099. }
  7100. if ( areaWeighted ) {
  7101. // vertex normals weighted by triangle areas
  7102. // http://www.iquilezles.org/www/articles/normals/normals.htm
  7103. var vA, vB, vC;
  7104. var cb = new Vector3(), ab = new Vector3();
  7105. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7106. face = this.faces[ f ];
  7107. vA = this.vertices[ face.a ];
  7108. vB = this.vertices[ face.b ];
  7109. vC = this.vertices[ face.c ];
  7110. cb.subVectors( vC, vB );
  7111. ab.subVectors( vA, vB );
  7112. cb.cross( ab );
  7113. vertices[ face.a ].add( cb );
  7114. vertices[ face.b ].add( cb );
  7115. vertices[ face.c ].add( cb );
  7116. }
  7117. } else {
  7118. this.computeFaceNormals();
  7119. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7120. face = this.faces[ f ];
  7121. vertices[ face.a ].add( face.normal );
  7122. vertices[ face.b ].add( face.normal );
  7123. vertices[ face.c ].add( face.normal );
  7124. }
  7125. }
  7126. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  7127. vertices[ v ].normalize();
  7128. }
  7129. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7130. face = this.faces[ f ];
  7131. var vertexNormals = face.vertexNormals;
  7132. if ( vertexNormals.length === 3 ) {
  7133. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  7134. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  7135. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  7136. } else {
  7137. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  7138. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  7139. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  7140. }
  7141. }
  7142. if ( this.faces.length > 0 ) {
  7143. this.normalsNeedUpdate = true;
  7144. }
  7145. },
  7146. computeFlatVertexNormals: function () {
  7147. var f, fl, face;
  7148. this.computeFaceNormals();
  7149. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7150. face = this.faces[ f ];
  7151. var vertexNormals = face.vertexNormals;
  7152. if ( vertexNormals.length === 3 ) {
  7153. vertexNormals[ 0 ].copy( face.normal );
  7154. vertexNormals[ 1 ].copy( face.normal );
  7155. vertexNormals[ 2 ].copy( face.normal );
  7156. } else {
  7157. vertexNormals[ 0 ] = face.normal.clone();
  7158. vertexNormals[ 1 ] = face.normal.clone();
  7159. vertexNormals[ 2 ] = face.normal.clone();
  7160. }
  7161. }
  7162. if ( this.faces.length > 0 ) {
  7163. this.normalsNeedUpdate = true;
  7164. }
  7165. },
  7166. computeMorphNormals: function () {
  7167. var i, il, f, fl, face;
  7168. // save original normals
  7169. // - create temp variables on first access
  7170. // otherwise just copy (for faster repeated calls)
  7171. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7172. face = this.faces[ f ];
  7173. if ( ! face.__originalFaceNormal ) {
  7174. face.__originalFaceNormal = face.normal.clone();
  7175. } else {
  7176. face.__originalFaceNormal.copy( face.normal );
  7177. }
  7178. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  7179. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  7180. if ( ! face.__originalVertexNormals[ i ] ) {
  7181. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  7182. } else {
  7183. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  7184. }
  7185. }
  7186. }
  7187. // use temp geometry to compute face and vertex normals for each morph
  7188. var tmpGeo = new Geometry();
  7189. tmpGeo.faces = this.faces;
  7190. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  7191. // create on first access
  7192. if ( ! this.morphNormals[ i ] ) {
  7193. this.morphNormals[ i ] = {};
  7194. this.morphNormals[ i ].faceNormals = [];
  7195. this.morphNormals[ i ].vertexNormals = [];
  7196. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  7197. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  7198. var faceNormal, vertexNormals;
  7199. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7200. faceNormal = new Vector3();
  7201. vertexNormals = { a: new Vector3(), b: new Vector3(), c: new Vector3() };
  7202. dstNormalsFace.push( faceNormal );
  7203. dstNormalsVertex.push( vertexNormals );
  7204. }
  7205. }
  7206. var morphNormals = this.morphNormals[ i ];
  7207. // set vertices to morph target
  7208. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  7209. // compute morph normals
  7210. tmpGeo.computeFaceNormals();
  7211. tmpGeo.computeVertexNormals();
  7212. // store morph normals
  7213. var faceNormal, vertexNormals;
  7214. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7215. face = this.faces[ f ];
  7216. faceNormal = morphNormals.faceNormals[ f ];
  7217. vertexNormals = morphNormals.vertexNormals[ f ];
  7218. faceNormal.copy( face.normal );
  7219. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  7220. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  7221. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  7222. }
  7223. }
  7224. // restore original normals
  7225. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7226. face = this.faces[ f ];
  7227. face.normal = face.__originalFaceNormal;
  7228. face.vertexNormals = face.__originalVertexNormals;
  7229. }
  7230. },
  7231. computeLineDistances: function () {
  7232. var d = 0;
  7233. var vertices = this.vertices;
  7234. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  7235. if ( i > 0 ) {
  7236. d += vertices[ i ].distanceTo( vertices[ i - 1 ] );
  7237. }
  7238. this.lineDistances[ i ] = d;
  7239. }
  7240. },
  7241. computeBoundingBox: function () {
  7242. if ( this.boundingBox === null ) {
  7243. this.boundingBox = new Box3();
  7244. }
  7245. this.boundingBox.setFromPoints( this.vertices );
  7246. },
  7247. computeBoundingSphere: function () {
  7248. if ( this.boundingSphere === null ) {
  7249. this.boundingSphere = new Sphere();
  7250. }
  7251. this.boundingSphere.setFromPoints( this.vertices );
  7252. },
  7253. merge: function ( geometry, matrix, materialIndexOffset ) {
  7254. if ( ! ( geometry && geometry.isGeometry ) ) {
  7255. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  7256. return;
  7257. }
  7258. var normalMatrix,
  7259. vertexOffset = this.vertices.length,
  7260. vertices1 = this.vertices,
  7261. vertices2 = geometry.vertices,
  7262. faces1 = this.faces,
  7263. faces2 = geometry.faces,
  7264. uvs1 = this.faceVertexUvs[ 0 ],
  7265. uvs2 = geometry.faceVertexUvs[ 0 ],
  7266. colors1 = this.colors,
  7267. colors2 = geometry.colors;
  7268. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  7269. if ( matrix !== undefined ) {
  7270. normalMatrix = new Matrix3().getNormalMatrix( matrix );
  7271. }
  7272. // vertices
  7273. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  7274. var vertex = vertices2[ i ];
  7275. var vertexCopy = vertex.clone();
  7276. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  7277. vertices1.push( vertexCopy );
  7278. }
  7279. // colors
  7280. for ( var i = 0, il = colors2.length; i < il; i ++ ) {
  7281. colors1.push( colors2[ i ].clone() );
  7282. }
  7283. // faces
  7284. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  7285. var face = faces2[ i ], faceCopy, normal, color,
  7286. faceVertexNormals = face.vertexNormals,
  7287. faceVertexColors = face.vertexColors;
  7288. faceCopy = new Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  7289. faceCopy.normal.copy( face.normal );
  7290. if ( normalMatrix !== undefined ) {
  7291. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  7292. }
  7293. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  7294. normal = faceVertexNormals[ j ].clone();
  7295. if ( normalMatrix !== undefined ) {
  7296. normal.applyMatrix3( normalMatrix ).normalize();
  7297. }
  7298. faceCopy.vertexNormals.push( normal );
  7299. }
  7300. faceCopy.color.copy( face.color );
  7301. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  7302. color = faceVertexColors[ j ];
  7303. faceCopy.vertexColors.push( color.clone() );
  7304. }
  7305. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  7306. faces1.push( faceCopy );
  7307. }
  7308. // uvs
  7309. for ( i = 0, il = uvs2.length; i < il; i ++ ) {
  7310. var uv = uvs2[ i ], uvCopy = [];
  7311. if ( uv === undefined ) {
  7312. continue;
  7313. }
  7314. for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
  7315. uvCopy.push( uv[ j ].clone() );
  7316. }
  7317. uvs1.push( uvCopy );
  7318. }
  7319. },
  7320. mergeMesh: function ( mesh ) {
  7321. if ( ! ( mesh && mesh.isMesh ) ) {
  7322. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  7323. return;
  7324. }
  7325. mesh.matrixAutoUpdate && mesh.updateMatrix();
  7326. this.merge( mesh.geometry, mesh.matrix );
  7327. },
  7328. /*
  7329. * Checks for duplicate vertices with hashmap.
  7330. * Duplicated vertices are removed
  7331. * and faces' vertices are updated.
  7332. */
  7333. mergeVertices: function () {
  7334. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  7335. var unique = [], changes = [];
  7336. var v, key;
  7337. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  7338. var precision = Math.pow( 10, precisionPoints );
  7339. var i, il, face;
  7340. var indices, j, jl;
  7341. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  7342. v = this.vertices[ i ];
  7343. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  7344. if ( verticesMap[ key ] === undefined ) {
  7345. verticesMap[ key ] = i;
  7346. unique.push( this.vertices[ i ] );
  7347. changes[ i ] = unique.length - 1;
  7348. } else {
  7349. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  7350. changes[ i ] = changes[ verticesMap[ key ] ];
  7351. }
  7352. }
  7353. // if faces are completely degenerate after merging vertices, we
  7354. // have to remove them from the geometry.
  7355. var faceIndicesToRemove = [];
  7356. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  7357. face = this.faces[ i ];
  7358. face.a = changes[ face.a ];
  7359. face.b = changes[ face.b ];
  7360. face.c = changes[ face.c ];
  7361. indices = [ face.a, face.b, face.c ];
  7362. // if any duplicate vertices are found in a Face3
  7363. // we have to remove the face as nothing can be saved
  7364. for ( var n = 0; n < 3; n ++ ) {
  7365. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  7366. faceIndicesToRemove.push( i );
  7367. break;
  7368. }
  7369. }
  7370. }
  7371. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  7372. var idx = faceIndicesToRemove[ i ];
  7373. this.faces.splice( idx, 1 );
  7374. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  7375. this.faceVertexUvs[ j ].splice( idx, 1 );
  7376. }
  7377. }
  7378. // Use unique set of vertices
  7379. var diff = this.vertices.length - unique.length;
  7380. this.vertices = unique;
  7381. return diff;
  7382. },
  7383. sortFacesByMaterialIndex: function () {
  7384. var faces = this.faces;
  7385. var length = faces.length;
  7386. // tag faces
  7387. for ( var i = 0; i < length; i ++ ) {
  7388. faces[ i ]._id = i;
  7389. }
  7390. // sort faces
  7391. function materialIndexSort( a, b ) {
  7392. return a.materialIndex - b.materialIndex;
  7393. }
  7394. faces.sort( materialIndexSort );
  7395. // sort uvs
  7396. var uvs1 = this.faceVertexUvs[ 0 ];
  7397. var uvs2 = this.faceVertexUvs[ 1 ];
  7398. var newUvs1, newUvs2;
  7399. if ( uvs1 && uvs1.length === length ) newUvs1 = [];
  7400. if ( uvs2 && uvs2.length === length ) newUvs2 = [];
  7401. for ( var i = 0; i < length; i ++ ) {
  7402. var id = faces[ i ]._id;
  7403. if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
  7404. if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
  7405. }
  7406. if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
  7407. if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
  7408. },
  7409. toJSON: function () {
  7410. var data = {
  7411. metadata: {
  7412. version: 4.5,
  7413. type: 'Geometry',
  7414. generator: 'Geometry.toJSON'
  7415. }
  7416. };
  7417. // standard Geometry serialization
  7418. data.uuid = this.uuid;
  7419. data.type = this.type;
  7420. if ( this.name !== '' ) data.name = this.name;
  7421. if ( this.parameters !== undefined ) {
  7422. var parameters = this.parameters;
  7423. for ( var key in parameters ) {
  7424. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  7425. }
  7426. return data;
  7427. }
  7428. var vertices = [];
  7429. for ( var i = 0; i < this.vertices.length; i ++ ) {
  7430. var vertex = this.vertices[ i ];
  7431. vertices.push( vertex.x, vertex.y, vertex.z );
  7432. }
  7433. var faces = [];
  7434. var normals = [];
  7435. var normalsHash = {};
  7436. var colors = [];
  7437. var colorsHash = {};
  7438. var uvs = [];
  7439. var uvsHash = {};
  7440. for ( var i = 0; i < this.faces.length; i ++ ) {
  7441. var face = this.faces[ i ];
  7442. var hasMaterial = true;
  7443. var hasFaceUv = false; // deprecated
  7444. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  7445. var hasFaceNormal = face.normal.length() > 0;
  7446. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  7447. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  7448. var hasFaceVertexColor = face.vertexColors.length > 0;
  7449. var faceType = 0;
  7450. faceType = setBit( faceType, 0, 0 ); // isQuad
  7451. faceType = setBit( faceType, 1, hasMaterial );
  7452. faceType = setBit( faceType, 2, hasFaceUv );
  7453. faceType = setBit( faceType, 3, hasFaceVertexUv );
  7454. faceType = setBit( faceType, 4, hasFaceNormal );
  7455. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  7456. faceType = setBit( faceType, 6, hasFaceColor );
  7457. faceType = setBit( faceType, 7, hasFaceVertexColor );
  7458. faces.push( faceType );
  7459. faces.push( face.a, face.b, face.c );
  7460. faces.push( face.materialIndex );
  7461. if ( hasFaceVertexUv ) {
  7462. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  7463. faces.push(
  7464. getUvIndex( faceVertexUvs[ 0 ] ),
  7465. getUvIndex( faceVertexUvs[ 1 ] ),
  7466. getUvIndex( faceVertexUvs[ 2 ] )
  7467. );
  7468. }
  7469. if ( hasFaceNormal ) {
  7470. faces.push( getNormalIndex( face.normal ) );
  7471. }
  7472. if ( hasFaceVertexNormal ) {
  7473. var vertexNormals = face.vertexNormals;
  7474. faces.push(
  7475. getNormalIndex( vertexNormals[ 0 ] ),
  7476. getNormalIndex( vertexNormals[ 1 ] ),
  7477. getNormalIndex( vertexNormals[ 2 ] )
  7478. );
  7479. }
  7480. if ( hasFaceColor ) {
  7481. faces.push( getColorIndex( face.color ) );
  7482. }
  7483. if ( hasFaceVertexColor ) {
  7484. var vertexColors = face.vertexColors;
  7485. faces.push(
  7486. getColorIndex( vertexColors[ 0 ] ),
  7487. getColorIndex( vertexColors[ 1 ] ),
  7488. getColorIndex( vertexColors[ 2 ] )
  7489. );
  7490. }
  7491. }
  7492. function setBit( value, position, enabled ) {
  7493. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  7494. }
  7495. function getNormalIndex( normal ) {
  7496. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  7497. if ( normalsHash[ hash ] !== undefined ) {
  7498. return normalsHash[ hash ];
  7499. }
  7500. normalsHash[ hash ] = normals.length / 3;
  7501. normals.push( normal.x, normal.y, normal.z );
  7502. return normalsHash[ hash ];
  7503. }
  7504. function getColorIndex( color ) {
  7505. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  7506. if ( colorsHash[ hash ] !== undefined ) {
  7507. return colorsHash[ hash ];
  7508. }
  7509. colorsHash[ hash ] = colors.length;
  7510. colors.push( color.getHex() );
  7511. return colorsHash[ hash ];
  7512. }
  7513. function getUvIndex( uv ) {
  7514. var hash = uv.x.toString() + uv.y.toString();
  7515. if ( uvsHash[ hash ] !== undefined ) {
  7516. return uvsHash[ hash ];
  7517. }
  7518. uvsHash[ hash ] = uvs.length / 2;
  7519. uvs.push( uv.x, uv.y );
  7520. return uvsHash[ hash ];
  7521. }
  7522. data.data = {};
  7523. data.data.vertices = vertices;
  7524. data.data.normals = normals;
  7525. if ( colors.length > 0 ) data.data.colors = colors;
  7526. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  7527. data.data.faces = faces;
  7528. return data;
  7529. },
  7530. clone: function () {
  7531. /*
  7532. // Handle primitives
  7533. var parameters = this.parameters;
  7534. if ( parameters !== undefined ) {
  7535. var values = [];
  7536. for ( var key in parameters ) {
  7537. values.push( parameters[ key ] );
  7538. }
  7539. var geometry = Object.create( this.constructor.prototype );
  7540. this.constructor.apply( geometry, values );
  7541. return geometry;
  7542. }
  7543. return new this.constructor().copy( this );
  7544. */
  7545. return new Geometry().copy( this );
  7546. },
  7547. copy: function ( source ) {
  7548. var i, il, j, jl, k, kl;
  7549. // reset
  7550. this.vertices = [];
  7551. this.colors = [];
  7552. this.faces = [];
  7553. this.faceVertexUvs = [[]];
  7554. this.morphTargets = [];
  7555. this.morphNormals = [];
  7556. this.skinWeights = [];
  7557. this.skinIndices = [];
  7558. this.lineDistances = [];
  7559. this.boundingBox = null;
  7560. this.boundingSphere = null;
  7561. // name
  7562. this.name = source.name;
  7563. // vertices
  7564. var vertices = source.vertices;
  7565. for ( i = 0, il = vertices.length; i < il; i ++ ) {
  7566. this.vertices.push( vertices[ i ].clone() );
  7567. }
  7568. // colors
  7569. var colors = source.colors;
  7570. for ( i = 0, il = colors.length; i < il; i ++ ) {
  7571. this.colors.push( colors[ i ].clone() );
  7572. }
  7573. // faces
  7574. var faces = source.faces;
  7575. for ( i = 0, il = faces.length; i < il; i ++ ) {
  7576. this.faces.push( faces[ i ].clone() );
  7577. }
  7578. // face vertex uvs
  7579. for ( i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  7580. var faceVertexUvs = source.faceVertexUvs[ i ];
  7581. if ( this.faceVertexUvs[ i ] === undefined ) {
  7582. this.faceVertexUvs[ i ] = [];
  7583. }
  7584. for ( j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  7585. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  7586. for ( k = 0, kl = uvs.length; k < kl; k ++ ) {
  7587. var uv = uvs[ k ];
  7588. uvsCopy.push( uv.clone() );
  7589. }
  7590. this.faceVertexUvs[ i ].push( uvsCopy );
  7591. }
  7592. }
  7593. // morph targets
  7594. var morphTargets = source.morphTargets;
  7595. for ( i = 0, il = morphTargets.length; i < il; i ++ ) {
  7596. var morphTarget = {};
  7597. morphTarget.name = morphTargets[ i ].name;
  7598. // vertices
  7599. if ( morphTargets[ i ].vertices !== undefined ) {
  7600. morphTarget.vertices = [];
  7601. for ( j = 0, jl = morphTargets[ i ].vertices.length; j < jl; j ++ ) {
  7602. morphTarget.vertices.push( morphTargets[ i ].vertices[ j ].clone() );
  7603. }
  7604. }
  7605. // normals
  7606. if ( morphTargets[ i ].normals !== undefined ) {
  7607. morphTarget.normals = [];
  7608. for ( j = 0, jl = morphTargets[ i ].normals.length; j < jl; j ++ ) {
  7609. morphTarget.normals.push( morphTargets[ i ].normals[ j ].clone() );
  7610. }
  7611. }
  7612. this.morphTargets.push( morphTarget );
  7613. }
  7614. // morph normals
  7615. var morphNormals = source.morphNormals;
  7616. for ( i = 0, il = morphNormals.length; i < il; i ++ ) {
  7617. var morphNormal = {};
  7618. // vertex normals
  7619. if ( morphNormals[ i ].vertexNormals !== undefined ) {
  7620. morphNormal.vertexNormals = [];
  7621. for ( j = 0, jl = morphNormals[ i ].vertexNormals.length; j < jl; j ++ ) {
  7622. var srcVertexNormal = morphNormals[ i ].vertexNormals[ j ];
  7623. var destVertexNormal = {};
  7624. destVertexNormal.a = srcVertexNormal.a.clone();
  7625. destVertexNormal.b = srcVertexNormal.b.clone();
  7626. destVertexNormal.c = srcVertexNormal.c.clone();
  7627. morphNormal.vertexNormals.push( destVertexNormal );
  7628. }
  7629. }
  7630. // face normals
  7631. if ( morphNormals[ i ].faceNormals !== undefined ) {
  7632. morphNormal.faceNormals = [];
  7633. for ( j = 0, jl = morphNormals[ i ].faceNormals.length; j < jl; j ++ ) {
  7634. morphNormal.faceNormals.push( morphNormals[ i ].faceNormals[ j ].clone() );
  7635. }
  7636. }
  7637. this.morphNormals.push( morphNormal );
  7638. }
  7639. // skin weights
  7640. var skinWeights = source.skinWeights;
  7641. for ( i = 0, il = skinWeights.length; i < il; i ++ ) {
  7642. this.skinWeights.push( skinWeights[ i ].clone() );
  7643. }
  7644. // skin indices
  7645. var skinIndices = source.skinIndices;
  7646. for ( i = 0, il = skinIndices.length; i < il; i ++ ) {
  7647. this.skinIndices.push( skinIndices[ i ].clone() );
  7648. }
  7649. // line distances
  7650. var lineDistances = source.lineDistances;
  7651. for ( i = 0, il = lineDistances.length; i < il; i ++ ) {
  7652. this.lineDistances.push( lineDistances[ i ] );
  7653. }
  7654. // bounding box
  7655. var boundingBox = source.boundingBox;
  7656. if ( boundingBox !== null ) {
  7657. this.boundingBox = boundingBox.clone();
  7658. }
  7659. // bounding sphere
  7660. var boundingSphere = source.boundingSphere;
  7661. if ( boundingSphere !== null ) {
  7662. this.boundingSphere = boundingSphere.clone();
  7663. }
  7664. // update flags
  7665. this.elementsNeedUpdate = source.elementsNeedUpdate;
  7666. this.verticesNeedUpdate = source.verticesNeedUpdate;
  7667. this.uvsNeedUpdate = source.uvsNeedUpdate;
  7668. this.normalsNeedUpdate = source.normalsNeedUpdate;
  7669. this.colorsNeedUpdate = source.colorsNeedUpdate;
  7670. this.lineDistancesNeedUpdate = source.lineDistancesNeedUpdate;
  7671. this.groupsNeedUpdate = source.groupsNeedUpdate;
  7672. return this;
  7673. },
  7674. dispose: function () {
  7675. this.dispatchEvent( { type: 'dispose' } );
  7676. }
  7677. } );
  7678. /**
  7679. * @author supereggbert / http://www.paulbrunt.co.uk/
  7680. * @author philogb / http://blog.thejit.org/
  7681. * @author mikael emtinger / http://gomo.se/
  7682. * @author egraether / http://egraether.com/
  7683. * @author WestLangley / http://github.com/WestLangley
  7684. */
  7685. function Vector4( x, y, z, w ) {
  7686. this.x = x || 0;
  7687. this.y = y || 0;
  7688. this.z = z || 0;
  7689. this.w = ( w !== undefined ) ? w : 1;
  7690. }
  7691. Object.assign( Vector4.prototype, {
  7692. isVector4: true,
  7693. set: function ( x, y, z, w ) {
  7694. this.x = x;
  7695. this.y = y;
  7696. this.z = z;
  7697. this.w = w;
  7698. return this;
  7699. },
  7700. setScalar: function ( scalar ) {
  7701. this.x = scalar;
  7702. this.y = scalar;
  7703. this.z = scalar;
  7704. this.w = scalar;
  7705. return this;
  7706. },
  7707. setX: function ( x ) {
  7708. this.x = x;
  7709. return this;
  7710. },
  7711. setY: function ( y ) {
  7712. this.y = y;
  7713. return this;
  7714. },
  7715. setZ: function ( z ) {
  7716. this.z = z;
  7717. return this;
  7718. },
  7719. setW: function ( w ) {
  7720. this.w = w;
  7721. return this;
  7722. },
  7723. setComponent: function ( index, value ) {
  7724. switch ( index ) {
  7725. case 0: this.x = value; break;
  7726. case 1: this.y = value; break;
  7727. case 2: this.z = value; break;
  7728. case 3: this.w = value; break;
  7729. default: throw new Error( 'index is out of range: ' + index );
  7730. }
  7731. return this;
  7732. },
  7733. getComponent: function ( index ) {
  7734. switch ( index ) {
  7735. case 0: return this.x;
  7736. case 1: return this.y;
  7737. case 2: return this.z;
  7738. case 3: return this.w;
  7739. default: throw new Error( 'index is out of range: ' + index );
  7740. }
  7741. },
  7742. clone: function () {
  7743. return new this.constructor( this.x, this.y, this.z, this.w );
  7744. },
  7745. copy: function ( v ) {
  7746. this.x = v.x;
  7747. this.y = v.y;
  7748. this.z = v.z;
  7749. this.w = ( v.w !== undefined ) ? v.w : 1;
  7750. return this;
  7751. },
  7752. add: function ( v, w ) {
  7753. if ( w !== undefined ) {
  7754. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  7755. return this.addVectors( v, w );
  7756. }
  7757. this.x += v.x;
  7758. this.y += v.y;
  7759. this.z += v.z;
  7760. this.w += v.w;
  7761. return this;
  7762. },
  7763. addScalar: function ( s ) {
  7764. this.x += s;
  7765. this.y += s;
  7766. this.z += s;
  7767. this.w += s;
  7768. return this;
  7769. },
  7770. addVectors: function ( a, b ) {
  7771. this.x = a.x + b.x;
  7772. this.y = a.y + b.y;
  7773. this.z = a.z + b.z;
  7774. this.w = a.w + b.w;
  7775. return this;
  7776. },
  7777. addScaledVector: function ( v, s ) {
  7778. this.x += v.x * s;
  7779. this.y += v.y * s;
  7780. this.z += v.z * s;
  7781. this.w += v.w * s;
  7782. return this;
  7783. },
  7784. sub: function ( v, w ) {
  7785. if ( w !== undefined ) {
  7786. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  7787. return this.subVectors( v, w );
  7788. }
  7789. this.x -= v.x;
  7790. this.y -= v.y;
  7791. this.z -= v.z;
  7792. this.w -= v.w;
  7793. return this;
  7794. },
  7795. subScalar: function ( s ) {
  7796. this.x -= s;
  7797. this.y -= s;
  7798. this.z -= s;
  7799. this.w -= s;
  7800. return this;
  7801. },
  7802. subVectors: function ( a, b ) {
  7803. this.x = a.x - b.x;
  7804. this.y = a.y - b.y;
  7805. this.z = a.z - b.z;
  7806. this.w = a.w - b.w;
  7807. return this;
  7808. },
  7809. multiplyScalar: function ( scalar ) {
  7810. this.x *= scalar;
  7811. this.y *= scalar;
  7812. this.z *= scalar;
  7813. this.w *= scalar;
  7814. return this;
  7815. },
  7816. applyMatrix4: function ( m ) {
  7817. var x = this.x, y = this.y, z = this.z, w = this.w;
  7818. var e = m.elements;
  7819. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  7820. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  7821. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  7822. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  7823. return this;
  7824. },
  7825. divideScalar: function ( scalar ) {
  7826. return this.multiplyScalar( 1 / scalar );
  7827. },
  7828. setAxisAngleFromQuaternion: function ( q ) {
  7829. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  7830. // q is assumed to be normalized
  7831. this.w = 2 * Math.acos( q.w );
  7832. var s = Math.sqrt( 1 - q.w * q.w );
  7833. if ( s < 0.0001 ) {
  7834. this.x = 1;
  7835. this.y = 0;
  7836. this.z = 0;
  7837. } else {
  7838. this.x = q.x / s;
  7839. this.y = q.y / s;
  7840. this.z = q.z / s;
  7841. }
  7842. return this;
  7843. },
  7844. setAxisAngleFromRotationMatrix: function ( m ) {
  7845. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  7846. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  7847. var angle, x, y, z, // variables for result
  7848. epsilon = 0.01, // margin to allow for rounding errors
  7849. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  7850. te = m.elements,
  7851. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  7852. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  7853. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  7854. if ( ( Math.abs( m12 - m21 ) < epsilon ) &&
  7855. ( Math.abs( m13 - m31 ) < epsilon ) &&
  7856. ( Math.abs( m23 - m32 ) < epsilon ) ) {
  7857. // singularity found
  7858. // first check for identity matrix which must have +1 for all terms
  7859. // in leading diagonal and zero in other terms
  7860. if ( ( Math.abs( m12 + m21 ) < epsilon2 ) &&
  7861. ( Math.abs( m13 + m31 ) < epsilon2 ) &&
  7862. ( Math.abs( m23 + m32 ) < epsilon2 ) &&
  7863. ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  7864. // this singularity is identity matrix so angle = 0
  7865. this.set( 1, 0, 0, 0 );
  7866. return this; // zero angle, arbitrary axis
  7867. }
  7868. // otherwise this singularity is angle = 180
  7869. angle = Math.PI;
  7870. var xx = ( m11 + 1 ) / 2;
  7871. var yy = ( m22 + 1 ) / 2;
  7872. var zz = ( m33 + 1 ) / 2;
  7873. var xy = ( m12 + m21 ) / 4;
  7874. var xz = ( m13 + m31 ) / 4;
  7875. var yz = ( m23 + m32 ) / 4;
  7876. if ( ( xx > yy ) && ( xx > zz ) ) {
  7877. // m11 is the largest diagonal term
  7878. if ( xx < epsilon ) {
  7879. x = 0;
  7880. y = 0.707106781;
  7881. z = 0.707106781;
  7882. } else {
  7883. x = Math.sqrt( xx );
  7884. y = xy / x;
  7885. z = xz / x;
  7886. }
  7887. } else if ( yy > zz ) {
  7888. // m22 is the largest diagonal term
  7889. if ( yy < epsilon ) {
  7890. x = 0.707106781;
  7891. y = 0;
  7892. z = 0.707106781;
  7893. } else {
  7894. y = Math.sqrt( yy );
  7895. x = xy / y;
  7896. z = yz / y;
  7897. }
  7898. } else {
  7899. // m33 is the largest diagonal term so base result on this
  7900. if ( zz < epsilon ) {
  7901. x = 0.707106781;
  7902. y = 0.707106781;
  7903. z = 0;
  7904. } else {
  7905. z = Math.sqrt( zz );
  7906. x = xz / z;
  7907. y = yz / z;
  7908. }
  7909. }
  7910. this.set( x, y, z, angle );
  7911. return this; // return 180 deg rotation
  7912. }
  7913. // as we have reached here there are no singularities so we can handle normally
  7914. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 ) +
  7915. ( m13 - m31 ) * ( m13 - m31 ) +
  7916. ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  7917. if ( Math.abs( s ) < 0.001 ) s = 1;
  7918. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  7919. // caught by singularity test above, but I've left it in just in case
  7920. this.x = ( m32 - m23 ) / s;
  7921. this.y = ( m13 - m31 ) / s;
  7922. this.z = ( m21 - m12 ) / s;
  7923. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  7924. return this;
  7925. },
  7926. min: function ( v ) {
  7927. this.x = Math.min( this.x, v.x );
  7928. this.y = Math.min( this.y, v.y );
  7929. this.z = Math.min( this.z, v.z );
  7930. this.w = Math.min( this.w, v.w );
  7931. return this;
  7932. },
  7933. max: function ( v ) {
  7934. this.x = Math.max( this.x, v.x );
  7935. this.y = Math.max( this.y, v.y );
  7936. this.z = Math.max( this.z, v.z );
  7937. this.w = Math.max( this.w, v.w );
  7938. return this;
  7939. },
  7940. clamp: function ( min, max ) {
  7941. // assumes min < max, componentwise
  7942. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  7943. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  7944. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  7945. this.w = Math.max( min.w, Math.min( max.w, this.w ) );
  7946. return this;
  7947. },
  7948. clampScalar: function () {
  7949. var min, max;
  7950. return function clampScalar( minVal, maxVal ) {
  7951. if ( min === undefined ) {
  7952. min = new Vector4();
  7953. max = new Vector4();
  7954. }
  7955. min.set( minVal, minVal, minVal, minVal );
  7956. max.set( maxVal, maxVal, maxVal, maxVal );
  7957. return this.clamp( min, max );
  7958. };
  7959. }(),
  7960. clampLength: function ( min, max ) {
  7961. var length = this.length();
  7962. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  7963. },
  7964. floor: function () {
  7965. this.x = Math.floor( this.x );
  7966. this.y = Math.floor( this.y );
  7967. this.z = Math.floor( this.z );
  7968. this.w = Math.floor( this.w );
  7969. return this;
  7970. },
  7971. ceil: function () {
  7972. this.x = Math.ceil( this.x );
  7973. this.y = Math.ceil( this.y );
  7974. this.z = Math.ceil( this.z );
  7975. this.w = Math.ceil( this.w );
  7976. return this;
  7977. },
  7978. round: function () {
  7979. this.x = Math.round( this.x );
  7980. this.y = Math.round( this.y );
  7981. this.z = Math.round( this.z );
  7982. this.w = Math.round( this.w );
  7983. return this;
  7984. },
  7985. roundToZero: function () {
  7986. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  7987. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  7988. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  7989. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  7990. return this;
  7991. },
  7992. negate: function () {
  7993. this.x = - this.x;
  7994. this.y = - this.y;
  7995. this.z = - this.z;
  7996. this.w = - this.w;
  7997. return this;
  7998. },
  7999. dot: function ( v ) {
  8000. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  8001. },
  8002. lengthSq: function () {
  8003. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  8004. },
  8005. length: function () {
  8006. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  8007. },
  8008. manhattanLength: function () {
  8009. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  8010. },
  8011. normalize: function () {
  8012. return this.divideScalar( this.length() || 1 );
  8013. },
  8014. setLength: function ( length ) {
  8015. return this.normalize().multiplyScalar( length );
  8016. },
  8017. lerp: function ( v, alpha ) {
  8018. this.x += ( v.x - this.x ) * alpha;
  8019. this.y += ( v.y - this.y ) * alpha;
  8020. this.z += ( v.z - this.z ) * alpha;
  8021. this.w += ( v.w - this.w ) * alpha;
  8022. return this;
  8023. },
  8024. lerpVectors: function ( v1, v2, alpha ) {
  8025. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  8026. },
  8027. equals: function ( v ) {
  8028. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  8029. },
  8030. fromArray: function ( array, offset ) {
  8031. if ( offset === undefined ) offset = 0;
  8032. this.x = array[ offset ];
  8033. this.y = array[ offset + 1 ];
  8034. this.z = array[ offset + 2 ];
  8035. this.w = array[ offset + 3 ];
  8036. return this;
  8037. },
  8038. toArray: function ( array, offset ) {
  8039. if ( array === undefined ) array = [];
  8040. if ( offset === undefined ) offset = 0;
  8041. array[ offset ] = this.x;
  8042. array[ offset + 1 ] = this.y;
  8043. array[ offset + 2 ] = this.z;
  8044. array[ offset + 3 ] = this.w;
  8045. return array;
  8046. },
  8047. fromBufferAttribute: function ( attribute, index, offset ) {
  8048. if ( offset !== undefined ) {
  8049. console.warn( 'THREE.Vector4: offset has been removed from .fromBufferAttribute().' );
  8050. }
  8051. this.x = attribute.getX( index );
  8052. this.y = attribute.getY( index );
  8053. this.z = attribute.getZ( index );
  8054. this.w = attribute.getW( index );
  8055. return this;
  8056. }
  8057. } );
  8058. /**
  8059. * @author mrdoob / http://mrdoob.com/
  8060. */
  8061. function BufferAttribute( array, itemSize, normalized ) {
  8062. if ( Array.isArray( array ) ) {
  8063. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  8064. }
  8065. this.uuid = _Math.generateUUID();
  8066. this.name = '';
  8067. this.array = array;
  8068. this.itemSize = itemSize;
  8069. this.count = array !== undefined ? array.length / itemSize : 0;
  8070. this.normalized = normalized === true;
  8071. this.dynamic = false;
  8072. this.updateRange = { offset: 0, count: - 1 };
  8073. this.onUploadCallback = function () {};
  8074. this.version = 0;
  8075. }
  8076. Object.defineProperty( BufferAttribute.prototype, 'needsUpdate', {
  8077. set: function ( value ) {
  8078. if ( value === true ) this.version ++;
  8079. }
  8080. } );
  8081. Object.assign( BufferAttribute.prototype, {
  8082. isBufferAttribute: true,
  8083. setArray: function ( array ) {
  8084. if ( Array.isArray( array ) ) {
  8085. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  8086. }
  8087. this.count = array !== undefined ? array.length / this.itemSize : 0;
  8088. this.array = array;
  8089. },
  8090. setDynamic: function ( value ) {
  8091. this.dynamic = value;
  8092. return this;
  8093. },
  8094. copy: function ( source ) {
  8095. this.array = new source.array.constructor( source.array );
  8096. this.itemSize = source.itemSize;
  8097. this.count = source.count;
  8098. this.normalized = source.normalized;
  8099. this.dynamic = source.dynamic;
  8100. return this;
  8101. },
  8102. copyAt: function ( index1, attribute, index2 ) {
  8103. index1 *= this.itemSize;
  8104. index2 *= attribute.itemSize;
  8105. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  8106. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  8107. }
  8108. return this;
  8109. },
  8110. copyArray: function ( array ) {
  8111. this.array.set( array );
  8112. return this;
  8113. },
  8114. copyColorsArray: function ( colors ) {
  8115. var array = this.array, offset = 0;
  8116. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  8117. var color = colors[ i ];
  8118. if ( color === undefined ) {
  8119. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  8120. color = new Color();
  8121. }
  8122. array[ offset ++ ] = color.r;
  8123. array[ offset ++ ] = color.g;
  8124. array[ offset ++ ] = color.b;
  8125. }
  8126. return this;
  8127. },
  8128. copyIndicesArray: function ( indices ) {
  8129. var array = this.array, offset = 0;
  8130. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  8131. var index = indices[ i ];
  8132. array[ offset ++ ] = index.a;
  8133. array[ offset ++ ] = index.b;
  8134. array[ offset ++ ] = index.c;
  8135. }
  8136. return this;
  8137. },
  8138. copyVector2sArray: function ( vectors ) {
  8139. var array = this.array, offset = 0;
  8140. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  8141. var vector = vectors[ i ];
  8142. if ( vector === undefined ) {
  8143. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  8144. vector = new Vector2();
  8145. }
  8146. array[ offset ++ ] = vector.x;
  8147. array[ offset ++ ] = vector.y;
  8148. }
  8149. return this;
  8150. },
  8151. copyVector3sArray: function ( vectors ) {
  8152. var array = this.array, offset = 0;
  8153. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  8154. var vector = vectors[ i ];
  8155. if ( vector === undefined ) {
  8156. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  8157. vector = new Vector3();
  8158. }
  8159. array[ offset ++ ] = vector.x;
  8160. array[ offset ++ ] = vector.y;
  8161. array[ offset ++ ] = vector.z;
  8162. }
  8163. return this;
  8164. },
  8165. copyVector4sArray: function ( vectors ) {
  8166. var array = this.array, offset = 0;
  8167. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  8168. var vector = vectors[ i ];
  8169. if ( vector === undefined ) {
  8170. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  8171. vector = new Vector4();
  8172. }
  8173. array[ offset ++ ] = vector.x;
  8174. array[ offset ++ ] = vector.y;
  8175. array[ offset ++ ] = vector.z;
  8176. array[ offset ++ ] = vector.w;
  8177. }
  8178. return this;
  8179. },
  8180. set: function ( value, offset ) {
  8181. if ( offset === undefined ) offset = 0;
  8182. this.array.set( value, offset );
  8183. return this;
  8184. },
  8185. getX: function ( index ) {
  8186. return this.array[ index * this.itemSize ];
  8187. },
  8188. setX: function ( index, x ) {
  8189. this.array[ index * this.itemSize ] = x;
  8190. return this;
  8191. },
  8192. getY: function ( index ) {
  8193. return this.array[ index * this.itemSize + 1 ];
  8194. },
  8195. setY: function ( index, y ) {
  8196. this.array[ index * this.itemSize + 1 ] = y;
  8197. return this;
  8198. },
  8199. getZ: function ( index ) {
  8200. return this.array[ index * this.itemSize + 2 ];
  8201. },
  8202. setZ: function ( index, z ) {
  8203. this.array[ index * this.itemSize + 2 ] = z;
  8204. return this;
  8205. },
  8206. getW: function ( index ) {
  8207. return this.array[ index * this.itemSize + 3 ];
  8208. },
  8209. setW: function ( index, w ) {
  8210. this.array[ index * this.itemSize + 3 ] = w;
  8211. return this;
  8212. },
  8213. setXY: function ( index, x, y ) {
  8214. index *= this.itemSize;
  8215. this.array[ index + 0 ] = x;
  8216. this.array[ index + 1 ] = y;
  8217. return this;
  8218. },
  8219. setXYZ: function ( index, x, y, z ) {
  8220. index *= this.itemSize;
  8221. this.array[ index + 0 ] = x;
  8222. this.array[ index + 1 ] = y;
  8223. this.array[ index + 2 ] = z;
  8224. return this;
  8225. },
  8226. setXYZW: function ( index, x, y, z, w ) {
  8227. index *= this.itemSize;
  8228. this.array[ index + 0 ] = x;
  8229. this.array[ index + 1 ] = y;
  8230. this.array[ index + 2 ] = z;
  8231. this.array[ index + 3 ] = w;
  8232. return this;
  8233. },
  8234. onUpload: function ( callback ) {
  8235. this.onUploadCallback = callback;
  8236. return this;
  8237. },
  8238. clone: function () {
  8239. return new this.constructor( this.array, this.itemSize ).copy( this );
  8240. }
  8241. } );
  8242. function Uint16BufferAttribute( array, itemSize, normalized ) {
  8243. BufferAttribute.call( this, new Uint16Array( array ), itemSize, normalized );
  8244. }
  8245. Uint16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  8246. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  8247. function Uint32BufferAttribute( array, itemSize, normalized ) {
  8248. BufferAttribute.call( this, new Uint32Array( array ), itemSize, normalized );
  8249. }
  8250. Uint32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  8251. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  8252. function Float32BufferAttribute( array, itemSize, normalized ) {
  8253. BufferAttribute.call( this, new Float32Array( array ), itemSize, normalized );
  8254. }
  8255. Float32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  8256. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  8257. /**
  8258. * @author mrdoob / http://mrdoob.com/
  8259. */
  8260. function DirectGeometry() {
  8261. this.indices = [];
  8262. this.vertices = [];
  8263. this.normals = [];
  8264. this.colors = [];
  8265. this.uvs = [];
  8266. this.uvs2 = [];
  8267. this.groups = [];
  8268. this.morphTargets = {};
  8269. this.skinWeights = [];
  8270. this.skinIndices = [];
  8271. // this.lineDistances = [];
  8272. this.boundingBox = null;
  8273. this.boundingSphere = null;
  8274. // update flags
  8275. this.verticesNeedUpdate = false;
  8276. this.normalsNeedUpdate = false;
  8277. this.colorsNeedUpdate = false;
  8278. this.uvsNeedUpdate = false;
  8279. this.groupsNeedUpdate = false;
  8280. }
  8281. Object.assign( DirectGeometry.prototype, {
  8282. computeGroups: function ( geometry ) {
  8283. var group;
  8284. var groups = [];
  8285. var materialIndex = undefined;
  8286. var faces = geometry.faces;
  8287. for ( var i = 0; i < faces.length; i ++ ) {
  8288. var face = faces[ i ];
  8289. // materials
  8290. if ( face.materialIndex !== materialIndex ) {
  8291. materialIndex = face.materialIndex;
  8292. if ( group !== undefined ) {
  8293. group.count = ( i * 3 ) - group.start;
  8294. groups.push( group );
  8295. }
  8296. group = {
  8297. start: i * 3,
  8298. materialIndex: materialIndex
  8299. };
  8300. }
  8301. }
  8302. if ( group !== undefined ) {
  8303. group.count = ( i * 3 ) - group.start;
  8304. groups.push( group );
  8305. }
  8306. this.groups = groups;
  8307. },
  8308. fromGeometry: function ( geometry ) {
  8309. var faces = geometry.faces;
  8310. var vertices = geometry.vertices;
  8311. var faceVertexUvs = geometry.faceVertexUvs;
  8312. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  8313. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  8314. // morphs
  8315. var morphTargets = geometry.morphTargets;
  8316. var morphTargetsLength = morphTargets.length;
  8317. var morphTargetsPosition;
  8318. if ( morphTargetsLength > 0 ) {
  8319. morphTargetsPosition = [];
  8320. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  8321. morphTargetsPosition[ i ] = [];
  8322. }
  8323. this.morphTargets.position = morphTargetsPosition;
  8324. }
  8325. var morphNormals = geometry.morphNormals;
  8326. var morphNormalsLength = morphNormals.length;
  8327. var morphTargetsNormal;
  8328. if ( morphNormalsLength > 0 ) {
  8329. morphTargetsNormal = [];
  8330. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  8331. morphTargetsNormal[ i ] = [];
  8332. }
  8333. this.morphTargets.normal = morphTargetsNormal;
  8334. }
  8335. // skins
  8336. var skinIndices = geometry.skinIndices;
  8337. var skinWeights = geometry.skinWeights;
  8338. var hasSkinIndices = skinIndices.length === vertices.length;
  8339. var hasSkinWeights = skinWeights.length === vertices.length;
  8340. //
  8341. for ( var i = 0; i < faces.length; i ++ ) {
  8342. var face = faces[ i ];
  8343. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  8344. var vertexNormals = face.vertexNormals;
  8345. if ( vertexNormals.length === 3 ) {
  8346. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  8347. } else {
  8348. var normal = face.normal;
  8349. this.normals.push( normal, normal, normal );
  8350. }
  8351. var vertexColors = face.vertexColors;
  8352. if ( vertexColors.length === 3 ) {
  8353. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  8354. } else {
  8355. var color = face.color;
  8356. this.colors.push( color, color, color );
  8357. }
  8358. if ( hasFaceVertexUv === true ) {
  8359. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  8360. if ( vertexUvs !== undefined ) {
  8361. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  8362. } else {
  8363. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  8364. this.uvs.push( new Vector2(), new Vector2(), new Vector2() );
  8365. }
  8366. }
  8367. if ( hasFaceVertexUv2 === true ) {
  8368. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  8369. if ( vertexUvs !== undefined ) {
  8370. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  8371. } else {
  8372. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  8373. this.uvs2.push( new Vector2(), new Vector2(), new Vector2() );
  8374. }
  8375. }
  8376. // morphs
  8377. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  8378. var morphTarget = morphTargets[ j ].vertices;
  8379. morphTargetsPosition[ j ].push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  8380. }
  8381. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  8382. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  8383. morphTargetsNormal[ j ].push( morphNormal.a, morphNormal.b, morphNormal.c );
  8384. }
  8385. // skins
  8386. if ( hasSkinIndices ) {
  8387. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  8388. }
  8389. if ( hasSkinWeights ) {
  8390. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  8391. }
  8392. }
  8393. this.computeGroups( geometry );
  8394. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  8395. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  8396. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  8397. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  8398. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  8399. return this;
  8400. }
  8401. } );
  8402. /**
  8403. * @author alteredq / http://alteredqualia.com/
  8404. * @author mrdoob / http://mrdoob.com/
  8405. */
  8406. var bufferGeometryId = 1; // BufferGeometry uses odd numbers as Id
  8407. function BufferGeometry() {
  8408. Object.defineProperty( this, 'id', { value: bufferGeometryId += 2 } );
  8409. this.uuid = _Math.generateUUID();
  8410. this.name = '';
  8411. this.type = 'BufferGeometry';
  8412. this.index = null;
  8413. this.attributes = {};
  8414. this.morphAttributes = {};
  8415. this.groups = [];
  8416. this.boundingBox = null;
  8417. this.boundingSphere = null;
  8418. this.drawRange = { start: 0, count: Infinity };
  8419. }
  8420. Object.assign( BufferGeometry.prototype, EventDispatcher.prototype, {
  8421. isBufferGeometry: true,
  8422. getIndex: function () {
  8423. return this.index;
  8424. },
  8425. setIndex: function ( index ) {
  8426. if ( Array.isArray( index ) ) {
  8427. this.index = new ( arrayMax( index ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( index, 1 );
  8428. } else {
  8429. this.index = index;
  8430. }
  8431. },
  8432. addAttribute: function ( name, attribute ) {
  8433. if ( ! ( attribute && attribute.isBufferAttribute ) && ! ( attribute && attribute.isInterleavedBufferAttribute ) ) {
  8434. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  8435. this.addAttribute( name, new BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  8436. return;
  8437. }
  8438. if ( name === 'index' ) {
  8439. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  8440. this.setIndex( attribute );
  8441. return;
  8442. }
  8443. this.attributes[ name ] = attribute;
  8444. return this;
  8445. },
  8446. getAttribute: function ( name ) {
  8447. return this.attributes[ name ];
  8448. },
  8449. removeAttribute: function ( name ) {
  8450. delete this.attributes[ name ];
  8451. return this;
  8452. },
  8453. addGroup: function ( start, count, materialIndex ) {
  8454. this.groups.push( {
  8455. start: start,
  8456. count: count,
  8457. materialIndex: materialIndex !== undefined ? materialIndex : 0
  8458. } );
  8459. },
  8460. clearGroups: function () {
  8461. this.groups = [];
  8462. },
  8463. setDrawRange: function ( start, count ) {
  8464. this.drawRange.start = start;
  8465. this.drawRange.count = count;
  8466. },
  8467. applyMatrix: function ( matrix ) {
  8468. var position = this.attributes.position;
  8469. if ( position !== undefined ) {
  8470. matrix.applyToBufferAttribute( position );
  8471. position.needsUpdate = true;
  8472. }
  8473. var normal = this.attributes.normal;
  8474. if ( normal !== undefined ) {
  8475. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  8476. normalMatrix.applyToBufferAttribute( normal );
  8477. normal.needsUpdate = true;
  8478. }
  8479. if ( this.boundingBox !== null ) {
  8480. this.computeBoundingBox();
  8481. }
  8482. if ( this.boundingSphere !== null ) {
  8483. this.computeBoundingSphere();
  8484. }
  8485. return this;
  8486. },
  8487. rotateX: function () {
  8488. // rotate geometry around world x-axis
  8489. var m1 = new Matrix4();
  8490. return function rotateX( angle ) {
  8491. m1.makeRotationX( angle );
  8492. this.applyMatrix( m1 );
  8493. return this;
  8494. };
  8495. }(),
  8496. rotateY: function () {
  8497. // rotate geometry around world y-axis
  8498. var m1 = new Matrix4();
  8499. return function rotateY( angle ) {
  8500. m1.makeRotationY( angle );
  8501. this.applyMatrix( m1 );
  8502. return this;
  8503. };
  8504. }(),
  8505. rotateZ: function () {
  8506. // rotate geometry around world z-axis
  8507. var m1 = new Matrix4();
  8508. return function rotateZ( angle ) {
  8509. m1.makeRotationZ( angle );
  8510. this.applyMatrix( m1 );
  8511. return this;
  8512. };
  8513. }(),
  8514. translate: function () {
  8515. // translate geometry
  8516. var m1 = new Matrix4();
  8517. return function translate( x, y, z ) {
  8518. m1.makeTranslation( x, y, z );
  8519. this.applyMatrix( m1 );
  8520. return this;
  8521. };
  8522. }(),
  8523. scale: function () {
  8524. // scale geometry
  8525. var m1 = new Matrix4();
  8526. return function scale( x, y, z ) {
  8527. m1.makeScale( x, y, z );
  8528. this.applyMatrix( m1 );
  8529. return this;
  8530. };
  8531. }(),
  8532. lookAt: function () {
  8533. var obj = new Object3D();
  8534. return function lookAt( vector ) {
  8535. obj.lookAt( vector );
  8536. obj.updateMatrix();
  8537. this.applyMatrix( obj.matrix );
  8538. };
  8539. }(),
  8540. center: function () {
  8541. this.computeBoundingBox();
  8542. var offset = this.boundingBox.getCenter().negate();
  8543. this.translate( offset.x, offset.y, offset.z );
  8544. return offset;
  8545. },
  8546. setFromObject: function ( object ) {
  8547. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  8548. var geometry = object.geometry;
  8549. if ( object.isPoints || object.isLine ) {
  8550. var positions = new Float32BufferAttribute( geometry.vertices.length * 3, 3 );
  8551. var colors = new Float32BufferAttribute( geometry.colors.length * 3, 3 );
  8552. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  8553. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  8554. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  8555. var lineDistances = new Float32BufferAttribute( geometry.lineDistances.length, 1 );
  8556. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  8557. }
  8558. if ( geometry.boundingSphere !== null ) {
  8559. this.boundingSphere = geometry.boundingSphere.clone();
  8560. }
  8561. if ( geometry.boundingBox !== null ) {
  8562. this.boundingBox = geometry.boundingBox.clone();
  8563. }
  8564. } else if ( object.isMesh ) {
  8565. if ( geometry && geometry.isGeometry ) {
  8566. this.fromGeometry( geometry );
  8567. }
  8568. }
  8569. return this;
  8570. },
  8571. updateFromObject: function ( object ) {
  8572. var geometry = object.geometry;
  8573. if ( object.isMesh ) {
  8574. var direct = geometry.__directGeometry;
  8575. if ( geometry.elementsNeedUpdate === true ) {
  8576. direct = undefined;
  8577. geometry.elementsNeedUpdate = false;
  8578. }
  8579. if ( direct === undefined ) {
  8580. return this.fromGeometry( geometry );
  8581. }
  8582. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  8583. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  8584. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  8585. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  8586. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  8587. geometry.verticesNeedUpdate = false;
  8588. geometry.normalsNeedUpdate = false;
  8589. geometry.colorsNeedUpdate = false;
  8590. geometry.uvsNeedUpdate = false;
  8591. geometry.groupsNeedUpdate = false;
  8592. geometry = direct;
  8593. }
  8594. var attribute;
  8595. if ( geometry.verticesNeedUpdate === true ) {
  8596. attribute = this.attributes.position;
  8597. if ( attribute !== undefined ) {
  8598. attribute.copyVector3sArray( geometry.vertices );
  8599. attribute.needsUpdate = true;
  8600. }
  8601. geometry.verticesNeedUpdate = false;
  8602. }
  8603. if ( geometry.normalsNeedUpdate === true ) {
  8604. attribute = this.attributes.normal;
  8605. if ( attribute !== undefined ) {
  8606. attribute.copyVector3sArray( geometry.normals );
  8607. attribute.needsUpdate = true;
  8608. }
  8609. geometry.normalsNeedUpdate = false;
  8610. }
  8611. if ( geometry.colorsNeedUpdate === true ) {
  8612. attribute = this.attributes.color;
  8613. if ( attribute !== undefined ) {
  8614. attribute.copyColorsArray( geometry.colors );
  8615. attribute.needsUpdate = true;
  8616. }
  8617. geometry.colorsNeedUpdate = false;
  8618. }
  8619. if ( geometry.uvsNeedUpdate ) {
  8620. attribute = this.attributes.uv;
  8621. if ( attribute !== undefined ) {
  8622. attribute.copyVector2sArray( geometry.uvs );
  8623. attribute.needsUpdate = true;
  8624. }
  8625. geometry.uvsNeedUpdate = false;
  8626. }
  8627. if ( geometry.lineDistancesNeedUpdate ) {
  8628. attribute = this.attributes.lineDistance;
  8629. if ( attribute !== undefined ) {
  8630. attribute.copyArray( geometry.lineDistances );
  8631. attribute.needsUpdate = true;
  8632. }
  8633. geometry.lineDistancesNeedUpdate = false;
  8634. }
  8635. if ( geometry.groupsNeedUpdate ) {
  8636. geometry.computeGroups( object.geometry );
  8637. this.groups = geometry.groups;
  8638. geometry.groupsNeedUpdate = false;
  8639. }
  8640. return this;
  8641. },
  8642. fromGeometry: function ( geometry ) {
  8643. geometry.__directGeometry = new DirectGeometry().fromGeometry( geometry );
  8644. return this.fromDirectGeometry( geometry.__directGeometry );
  8645. },
  8646. fromDirectGeometry: function ( geometry ) {
  8647. var positions = new Float32Array( geometry.vertices.length * 3 );
  8648. this.addAttribute( 'position', new BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  8649. if ( geometry.normals.length > 0 ) {
  8650. var normals = new Float32Array( geometry.normals.length * 3 );
  8651. this.addAttribute( 'normal', new BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  8652. }
  8653. if ( geometry.colors.length > 0 ) {
  8654. var colors = new Float32Array( geometry.colors.length * 3 );
  8655. this.addAttribute( 'color', new BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  8656. }
  8657. if ( geometry.uvs.length > 0 ) {
  8658. var uvs = new Float32Array( geometry.uvs.length * 2 );
  8659. this.addAttribute( 'uv', new BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  8660. }
  8661. if ( geometry.uvs2.length > 0 ) {
  8662. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  8663. this.addAttribute( 'uv2', new BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  8664. }
  8665. if ( geometry.indices.length > 0 ) {
  8666. var TypeArray = arrayMax( geometry.indices ) > 65535 ? Uint32Array : Uint16Array;
  8667. var indices = new TypeArray( geometry.indices.length * 3 );
  8668. this.setIndex( new BufferAttribute( indices, 1 ).copyIndicesArray( geometry.indices ) );
  8669. }
  8670. // groups
  8671. this.groups = geometry.groups;
  8672. // morphs
  8673. for ( var name in geometry.morphTargets ) {
  8674. var array = [];
  8675. var morphTargets = geometry.morphTargets[ name ];
  8676. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  8677. var morphTarget = morphTargets[ i ];
  8678. var attribute = new Float32BufferAttribute( morphTarget.length * 3, 3 );
  8679. array.push( attribute.copyVector3sArray( morphTarget ) );
  8680. }
  8681. this.morphAttributes[ name ] = array;
  8682. }
  8683. // skinning
  8684. if ( geometry.skinIndices.length > 0 ) {
  8685. var skinIndices = new Float32BufferAttribute( geometry.skinIndices.length * 4, 4 );
  8686. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  8687. }
  8688. if ( geometry.skinWeights.length > 0 ) {
  8689. var skinWeights = new Float32BufferAttribute( geometry.skinWeights.length * 4, 4 );
  8690. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  8691. }
  8692. //
  8693. if ( geometry.boundingSphere !== null ) {
  8694. this.boundingSphere = geometry.boundingSphere.clone();
  8695. }
  8696. if ( geometry.boundingBox !== null ) {
  8697. this.boundingBox = geometry.boundingBox.clone();
  8698. }
  8699. return this;
  8700. },
  8701. computeBoundingBox: function () {
  8702. if ( this.boundingBox === null ) {
  8703. this.boundingBox = new Box3();
  8704. }
  8705. var position = this.attributes.position;
  8706. if ( position !== undefined ) {
  8707. this.boundingBox.setFromBufferAttribute( position );
  8708. } else {
  8709. this.boundingBox.makeEmpty();
  8710. }
  8711. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  8712. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  8713. }
  8714. },
  8715. computeBoundingSphere: function () {
  8716. var box = new Box3();
  8717. var vector = new Vector3();
  8718. return function computeBoundingSphere() {
  8719. if ( this.boundingSphere === null ) {
  8720. this.boundingSphere = new Sphere();
  8721. }
  8722. var position = this.attributes.position;
  8723. if ( position ) {
  8724. var center = this.boundingSphere.center;
  8725. box.setFromBufferAttribute( position );
  8726. box.getCenter( center );
  8727. // hoping to find a boundingSphere with a radius smaller than the
  8728. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  8729. var maxRadiusSq = 0;
  8730. for ( var i = 0, il = position.count; i < il; i ++ ) {
  8731. vector.x = position.getX( i );
  8732. vector.y = position.getY( i );
  8733. vector.z = position.getZ( i );
  8734. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  8735. }
  8736. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  8737. if ( isNaN( this.boundingSphere.radius ) ) {
  8738. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  8739. }
  8740. }
  8741. };
  8742. }(),
  8743. computeFaceNormals: function () {
  8744. // backwards compatibility
  8745. },
  8746. computeVertexNormals: function () {
  8747. var index = this.index;
  8748. var attributes = this.attributes;
  8749. var groups = this.groups;
  8750. if ( attributes.position ) {
  8751. var positions = attributes.position.array;
  8752. if ( attributes.normal === undefined ) {
  8753. this.addAttribute( 'normal', new BufferAttribute( new Float32Array( positions.length ), 3 ) );
  8754. } else {
  8755. // reset existing normals to zero
  8756. var array = attributes.normal.array;
  8757. for ( var i = 0, il = array.length; i < il; i ++ ) {
  8758. array[ i ] = 0;
  8759. }
  8760. }
  8761. var normals = attributes.normal.array;
  8762. var vA, vB, vC;
  8763. var pA = new Vector3(), pB = new Vector3(), pC = new Vector3();
  8764. var cb = new Vector3(), ab = new Vector3();
  8765. // indexed elements
  8766. if ( index ) {
  8767. var indices = index.array;
  8768. if ( groups.length === 0 ) {
  8769. this.addGroup( 0, indices.length );
  8770. }
  8771. for ( var j = 0, jl = groups.length; j < jl; ++ j ) {
  8772. var group = groups[ j ];
  8773. var start = group.start;
  8774. var count = group.count;
  8775. for ( var i = start, il = start + count; i < il; i += 3 ) {
  8776. vA = indices[ i + 0 ] * 3;
  8777. vB = indices[ i + 1 ] * 3;
  8778. vC = indices[ i + 2 ] * 3;
  8779. pA.fromArray( positions, vA );
  8780. pB.fromArray( positions, vB );
  8781. pC.fromArray( positions, vC );
  8782. cb.subVectors( pC, pB );
  8783. ab.subVectors( pA, pB );
  8784. cb.cross( ab );
  8785. normals[ vA ] += cb.x;
  8786. normals[ vA + 1 ] += cb.y;
  8787. normals[ vA + 2 ] += cb.z;
  8788. normals[ vB ] += cb.x;
  8789. normals[ vB + 1 ] += cb.y;
  8790. normals[ vB + 2 ] += cb.z;
  8791. normals[ vC ] += cb.x;
  8792. normals[ vC + 1 ] += cb.y;
  8793. normals[ vC + 2 ] += cb.z;
  8794. }
  8795. }
  8796. } else {
  8797. // non-indexed elements (unconnected triangle soup)
  8798. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  8799. pA.fromArray( positions, i );
  8800. pB.fromArray( positions, i + 3 );
  8801. pC.fromArray( positions, i + 6 );
  8802. cb.subVectors( pC, pB );
  8803. ab.subVectors( pA, pB );
  8804. cb.cross( ab );
  8805. normals[ i ] = cb.x;
  8806. normals[ i + 1 ] = cb.y;
  8807. normals[ i + 2 ] = cb.z;
  8808. normals[ i + 3 ] = cb.x;
  8809. normals[ i + 4 ] = cb.y;
  8810. normals[ i + 5 ] = cb.z;
  8811. normals[ i + 6 ] = cb.x;
  8812. normals[ i + 7 ] = cb.y;
  8813. normals[ i + 8 ] = cb.z;
  8814. }
  8815. }
  8816. this.normalizeNormals();
  8817. attributes.normal.needsUpdate = true;
  8818. }
  8819. },
  8820. merge: function ( geometry, offset ) {
  8821. if ( ! ( geometry && geometry.isBufferGeometry ) ) {
  8822. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  8823. return;
  8824. }
  8825. if ( offset === undefined ) offset = 0;
  8826. var attributes = this.attributes;
  8827. for ( var key in attributes ) {
  8828. if ( geometry.attributes[ key ] === undefined ) continue;
  8829. var attribute1 = attributes[ key ];
  8830. var attributeArray1 = attribute1.array;
  8831. var attribute2 = geometry.attributes[ key ];
  8832. var attributeArray2 = attribute2.array;
  8833. var attributeSize = attribute2.itemSize;
  8834. for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length; i ++, j ++ ) {
  8835. attributeArray1[ j ] = attributeArray2[ i ];
  8836. }
  8837. }
  8838. return this;
  8839. },
  8840. normalizeNormals: function () {
  8841. var vector = new Vector3();
  8842. return function normalizeNormals() {
  8843. var normals = this.attributes.normal;
  8844. for ( var i = 0, il = normals.count; i < il; i ++ ) {
  8845. vector.x = normals.getX( i );
  8846. vector.y = normals.getY( i );
  8847. vector.z = normals.getZ( i );
  8848. vector.normalize();
  8849. normals.setXYZ( i, vector.x, vector.y, vector.z );
  8850. }
  8851. };
  8852. }(),
  8853. toNonIndexed: function () {
  8854. if ( this.index === null ) {
  8855. console.warn( 'THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.' );
  8856. return this;
  8857. }
  8858. var geometry2 = new BufferGeometry();
  8859. var indices = this.index.array;
  8860. var attributes = this.attributes;
  8861. for ( var name in attributes ) {
  8862. var attribute = attributes[ name ];
  8863. var array = attribute.array;
  8864. var itemSize = attribute.itemSize;
  8865. var array2 = new array.constructor( indices.length * itemSize );
  8866. var index = 0, index2 = 0;
  8867. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  8868. index = indices[ i ] * itemSize;
  8869. for ( var j = 0; j < itemSize; j ++ ) {
  8870. array2[ index2 ++ ] = array[ index ++ ];
  8871. }
  8872. }
  8873. geometry2.addAttribute( name, new BufferAttribute( array2, itemSize ) );
  8874. }
  8875. return geometry2;
  8876. },
  8877. toJSON: function () {
  8878. var data = {
  8879. metadata: {
  8880. version: 4.5,
  8881. type: 'BufferGeometry',
  8882. generator: 'BufferGeometry.toJSON'
  8883. }
  8884. };
  8885. // standard BufferGeometry serialization
  8886. data.uuid = this.uuid;
  8887. data.type = this.type;
  8888. if ( this.name !== '' ) data.name = this.name;
  8889. if ( this.parameters !== undefined ) {
  8890. var parameters = this.parameters;
  8891. for ( var key in parameters ) {
  8892. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  8893. }
  8894. return data;
  8895. }
  8896. data.data = { attributes: {} };
  8897. var index = this.index;
  8898. if ( index !== null ) {
  8899. var array = Array.prototype.slice.call( index.array );
  8900. data.data.index = {
  8901. type: index.array.constructor.name,
  8902. array: array
  8903. };
  8904. }
  8905. var attributes = this.attributes;
  8906. for ( var key in attributes ) {
  8907. var attribute = attributes[ key ];
  8908. var array = Array.prototype.slice.call( attribute.array );
  8909. data.data.attributes[ key ] = {
  8910. itemSize: attribute.itemSize,
  8911. type: attribute.array.constructor.name,
  8912. array: array,
  8913. normalized: attribute.normalized
  8914. };
  8915. }
  8916. var groups = this.groups;
  8917. if ( groups.length > 0 ) {
  8918. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  8919. }
  8920. var boundingSphere = this.boundingSphere;
  8921. if ( boundingSphere !== null ) {
  8922. data.data.boundingSphere = {
  8923. center: boundingSphere.center.toArray(),
  8924. radius: boundingSphere.radius
  8925. };
  8926. }
  8927. return data;
  8928. },
  8929. clone: function () {
  8930. /*
  8931. // Handle primitives
  8932. var parameters = this.parameters;
  8933. if ( parameters !== undefined ) {
  8934. var values = [];
  8935. for ( var key in parameters ) {
  8936. values.push( parameters[ key ] );
  8937. }
  8938. var geometry = Object.create( this.constructor.prototype );
  8939. this.constructor.apply( geometry, values );
  8940. return geometry;
  8941. }
  8942. return new this.constructor().copy( this );
  8943. */
  8944. return new BufferGeometry().copy( this );
  8945. },
  8946. copy: function ( source ) {
  8947. var name, i, l;
  8948. // reset
  8949. this.index = null;
  8950. this.attributes = {};
  8951. this.morphAttributes = {};
  8952. this.groups = [];
  8953. this.boundingBox = null;
  8954. this.boundingSphere = null;
  8955. // name
  8956. this.name = source.name;
  8957. // index
  8958. var index = source.index;
  8959. if ( index !== null ) {
  8960. this.setIndex( index.clone() );
  8961. }
  8962. // attributes
  8963. var attributes = source.attributes;
  8964. for ( name in attributes ) {
  8965. var attribute = attributes[ name ];
  8966. this.addAttribute( name, attribute.clone() );
  8967. }
  8968. // morph attributes
  8969. var morphAttributes = source.morphAttributes;
  8970. for ( name in morphAttributes ) {
  8971. var array = [];
  8972. var morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  8973. for ( i = 0, l = morphAttribute.length; i < l; i ++ ) {
  8974. array.push( morphAttribute[ i ].clone() );
  8975. }
  8976. this.morphAttributes[ name ] = array;
  8977. }
  8978. // groups
  8979. var groups = source.groups;
  8980. for ( i = 0, l = groups.length; i < l; i ++ ) {
  8981. var group = groups[ i ];
  8982. this.addGroup( group.start, group.count, group.materialIndex );
  8983. }
  8984. // bounding box
  8985. var boundingBox = source.boundingBox;
  8986. if ( boundingBox !== null ) {
  8987. this.boundingBox = boundingBox.clone();
  8988. }
  8989. // bounding sphere
  8990. var boundingSphere = source.boundingSphere;
  8991. if ( boundingSphere !== null ) {
  8992. this.boundingSphere = boundingSphere.clone();
  8993. }
  8994. // draw range
  8995. this.drawRange.start = source.drawRange.start;
  8996. this.drawRange.count = source.drawRange.count;
  8997. return this;
  8998. },
  8999. dispose: function () {
  9000. this.dispatchEvent( { type: 'dispose' } );
  9001. }
  9002. } );
  9003. /**
  9004. * @author mrdoob / http://mrdoob.com/
  9005. * @author Mugen87 / https://github.com/Mugen87
  9006. */
  9007. // BoxGeometry
  9008. function BoxGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  9009. Geometry.call( this );
  9010. this.type = 'BoxGeometry';
  9011. this.parameters = {
  9012. width: width,
  9013. height: height,
  9014. depth: depth,
  9015. widthSegments: widthSegments,
  9016. heightSegments: heightSegments,
  9017. depthSegments: depthSegments
  9018. };
  9019. this.fromBufferGeometry( new BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) );
  9020. this.mergeVertices();
  9021. }
  9022. BoxGeometry.prototype = Object.create( Geometry.prototype );
  9023. BoxGeometry.prototype.constructor = BoxGeometry;
  9024. // BoxBufferGeometry
  9025. function BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  9026. BufferGeometry.call( this );
  9027. this.type = 'BoxBufferGeometry';
  9028. this.parameters = {
  9029. width: width,
  9030. height: height,
  9031. depth: depth,
  9032. widthSegments: widthSegments,
  9033. heightSegments: heightSegments,
  9034. depthSegments: depthSegments
  9035. };
  9036. var scope = this;
  9037. width = width || 1;
  9038. height = height || 1;
  9039. depth = depth || 1;
  9040. // segments
  9041. widthSegments = Math.floor( widthSegments ) || 1;
  9042. heightSegments = Math.floor( heightSegments ) || 1;
  9043. depthSegments = Math.floor( depthSegments ) || 1;
  9044. // buffers
  9045. var indices = [];
  9046. var vertices = [];
  9047. var normals = [];
  9048. var uvs = [];
  9049. // helper variables
  9050. var numberOfVertices = 0;
  9051. var groupStart = 0;
  9052. // build each side of the box geometry
  9053. buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px
  9054. buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
  9055. buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
  9056. buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
  9057. buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
  9058. buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
  9059. // build geometry
  9060. this.setIndex( indices );
  9061. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  9062. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  9063. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  9064. function buildPlane( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
  9065. var segmentWidth = width / gridX;
  9066. var segmentHeight = height / gridY;
  9067. var widthHalf = width / 2;
  9068. var heightHalf = height / 2;
  9069. var depthHalf = depth / 2;
  9070. var gridX1 = gridX + 1;
  9071. var gridY1 = gridY + 1;
  9072. var vertexCounter = 0;
  9073. var groupCount = 0;
  9074. var ix, iy;
  9075. var vector = new Vector3();
  9076. // generate vertices, normals and uvs
  9077. for ( iy = 0; iy < gridY1; iy ++ ) {
  9078. var y = iy * segmentHeight - heightHalf;
  9079. for ( ix = 0; ix < gridX1; ix ++ ) {
  9080. var x = ix * segmentWidth - widthHalf;
  9081. // set values to correct vector component
  9082. vector[ u ] = x * udir;
  9083. vector[ v ] = y * vdir;
  9084. vector[ w ] = depthHalf;
  9085. // now apply vector to vertex buffer
  9086. vertices.push( vector.x, vector.y, vector.z );
  9087. // set values to correct vector component
  9088. vector[ u ] = 0;
  9089. vector[ v ] = 0;
  9090. vector[ w ] = depth > 0 ? 1 : - 1;
  9091. // now apply vector to normal buffer
  9092. normals.push( vector.x, vector.y, vector.z );
  9093. // uvs
  9094. uvs.push( ix / gridX );
  9095. uvs.push( 1 - ( iy / gridY ) );
  9096. // counters
  9097. vertexCounter += 1;
  9098. }
  9099. }
  9100. // indices
  9101. // 1. you need three indices to draw a single face
  9102. // 2. a single segment consists of two faces
  9103. // 3. so we need to generate six (2*3) indices per segment
  9104. for ( iy = 0; iy < gridY; iy ++ ) {
  9105. for ( ix = 0; ix < gridX; ix ++ ) {
  9106. var a = numberOfVertices + ix + gridX1 * iy;
  9107. var b = numberOfVertices + ix + gridX1 * ( iy + 1 );
  9108. var c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
  9109. var d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
  9110. // faces
  9111. indices.push( a, b, d );
  9112. indices.push( b, c, d );
  9113. // increase counter
  9114. groupCount += 6;
  9115. }
  9116. }
  9117. // add a group to the geometry. this will ensure multi material support
  9118. scope.addGroup( groupStart, groupCount, materialIndex );
  9119. // calculate new start value for groups
  9120. groupStart += groupCount;
  9121. // update total number of vertices
  9122. numberOfVertices += vertexCounter;
  9123. }
  9124. }
  9125. BoxBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  9126. BoxBufferGeometry.prototype.constructor = BoxBufferGeometry;
  9127. /**
  9128. * @author bhouston / http://clara.io
  9129. */
  9130. function Ray( origin, direction ) {
  9131. this.origin = ( origin !== undefined ) ? origin : new Vector3();
  9132. this.direction = ( direction !== undefined ) ? direction : new Vector3();
  9133. }
  9134. Object.assign( Ray.prototype, {
  9135. set: function ( origin, direction ) {
  9136. this.origin.copy( origin );
  9137. this.direction.copy( direction );
  9138. return this;
  9139. },
  9140. clone: function () {
  9141. return new this.constructor().copy( this );
  9142. },
  9143. copy: function ( ray ) {
  9144. this.origin.copy( ray.origin );
  9145. this.direction.copy( ray.direction );
  9146. return this;
  9147. },
  9148. at: function ( t, optionalTarget ) {
  9149. var result = optionalTarget || new Vector3();
  9150. return result.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  9151. },
  9152. lookAt: function ( v ) {
  9153. this.direction.copy( v ).sub( this.origin ).normalize();
  9154. return this;
  9155. },
  9156. recast: function () {
  9157. var v1 = new Vector3();
  9158. return function recast( t ) {
  9159. this.origin.copy( this.at( t, v1 ) );
  9160. return this;
  9161. };
  9162. }(),
  9163. closestPointToPoint: function ( point, optionalTarget ) {
  9164. var result = optionalTarget || new Vector3();
  9165. result.subVectors( point, this.origin );
  9166. var directionDistance = result.dot( this.direction );
  9167. if ( directionDistance < 0 ) {
  9168. return result.copy( this.origin );
  9169. }
  9170. return result.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  9171. },
  9172. distanceToPoint: function ( point ) {
  9173. return Math.sqrt( this.distanceSqToPoint( point ) );
  9174. },
  9175. distanceSqToPoint: function () {
  9176. var v1 = new Vector3();
  9177. return function distanceSqToPoint( point ) {
  9178. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  9179. // point behind the ray
  9180. if ( directionDistance < 0 ) {
  9181. return this.origin.distanceToSquared( point );
  9182. }
  9183. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  9184. return v1.distanceToSquared( point );
  9185. };
  9186. }(),
  9187. distanceSqToSegment: function () {
  9188. var segCenter = new Vector3();
  9189. var segDir = new Vector3();
  9190. var diff = new Vector3();
  9191. return function distanceSqToSegment( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  9192. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  9193. // It returns the min distance between the ray and the segment
  9194. // defined by v0 and v1
  9195. // It can also set two optional targets :
  9196. // - The closest point on the ray
  9197. // - The closest point on the segment
  9198. segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  9199. segDir.copy( v1 ).sub( v0 ).normalize();
  9200. diff.copy( this.origin ).sub( segCenter );
  9201. var segExtent = v0.distanceTo( v1 ) * 0.5;
  9202. var a01 = - this.direction.dot( segDir );
  9203. var b0 = diff.dot( this.direction );
  9204. var b1 = - diff.dot( segDir );
  9205. var c = diff.lengthSq();
  9206. var det = Math.abs( 1 - a01 * a01 );
  9207. var s0, s1, sqrDist, extDet;
  9208. if ( det > 0 ) {
  9209. // The ray and segment are not parallel.
  9210. s0 = a01 * b1 - b0;
  9211. s1 = a01 * b0 - b1;
  9212. extDet = segExtent * det;
  9213. if ( s0 >= 0 ) {
  9214. if ( s1 >= - extDet ) {
  9215. if ( s1 <= extDet ) {
  9216. // region 0
  9217. // Minimum at interior points of ray and segment.
  9218. var invDet = 1 / det;
  9219. s0 *= invDet;
  9220. s1 *= invDet;
  9221. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  9222. } else {
  9223. // region 1
  9224. s1 = segExtent;
  9225. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  9226. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  9227. }
  9228. } else {
  9229. // region 5
  9230. s1 = - segExtent;
  9231. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  9232. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  9233. }
  9234. } else {
  9235. if ( s1 <= - extDet ) {
  9236. // region 4
  9237. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  9238. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  9239. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  9240. } else if ( s1 <= extDet ) {
  9241. // region 3
  9242. s0 = 0;
  9243. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  9244. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  9245. } else {
  9246. // region 2
  9247. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  9248. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  9249. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  9250. }
  9251. }
  9252. } else {
  9253. // Ray and segment are parallel.
  9254. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  9255. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  9256. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  9257. }
  9258. if ( optionalPointOnRay ) {
  9259. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  9260. }
  9261. if ( optionalPointOnSegment ) {
  9262. optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
  9263. }
  9264. return sqrDist;
  9265. };
  9266. }(),
  9267. intersectSphere: function () {
  9268. var v1 = new Vector3();
  9269. return function intersectSphere( sphere, optionalTarget ) {
  9270. v1.subVectors( sphere.center, this.origin );
  9271. var tca = v1.dot( this.direction );
  9272. var d2 = v1.dot( v1 ) - tca * tca;
  9273. var radius2 = sphere.radius * sphere.radius;
  9274. if ( d2 > radius2 ) return null;
  9275. var thc = Math.sqrt( radius2 - d2 );
  9276. // t0 = first intersect point - entrance on front of sphere
  9277. var t0 = tca - thc;
  9278. // t1 = second intersect point - exit point on back of sphere
  9279. var t1 = tca + thc;
  9280. // test to see if both t0 and t1 are behind the ray - if so, return null
  9281. if ( t0 < 0 && t1 < 0 ) return null;
  9282. // test to see if t0 is behind the ray:
  9283. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  9284. // in order to always return an intersect point that is in front of the ray.
  9285. if ( t0 < 0 ) return this.at( t1, optionalTarget );
  9286. // else t0 is in front of the ray, so return the first collision point scaled by t0
  9287. return this.at( t0, optionalTarget );
  9288. };
  9289. }(),
  9290. intersectsSphere: function ( sphere ) {
  9291. return this.distanceToPoint( sphere.center ) <= sphere.radius;
  9292. },
  9293. distanceToPlane: function ( plane ) {
  9294. var denominator = plane.normal.dot( this.direction );
  9295. if ( denominator === 0 ) {
  9296. // line is coplanar, return origin
  9297. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  9298. return 0;
  9299. }
  9300. // Null is preferable to undefined since undefined means.... it is undefined
  9301. return null;
  9302. }
  9303. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  9304. // Return if the ray never intersects the plane
  9305. return t >= 0 ? t : null;
  9306. },
  9307. intersectPlane: function ( plane, optionalTarget ) {
  9308. var t = this.distanceToPlane( plane );
  9309. if ( t === null ) {
  9310. return null;
  9311. }
  9312. return this.at( t, optionalTarget );
  9313. },
  9314. intersectsPlane: function ( plane ) {
  9315. // check if the ray lies on the plane first
  9316. var distToPoint = plane.distanceToPoint( this.origin );
  9317. if ( distToPoint === 0 ) {
  9318. return true;
  9319. }
  9320. var denominator = plane.normal.dot( this.direction );
  9321. if ( denominator * distToPoint < 0 ) {
  9322. return true;
  9323. }
  9324. // ray origin is behind the plane (and is pointing behind it)
  9325. return false;
  9326. },
  9327. intersectBox: function ( box, optionalTarget ) {
  9328. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  9329. var invdirx = 1 / this.direction.x,
  9330. invdiry = 1 / this.direction.y,
  9331. invdirz = 1 / this.direction.z;
  9332. var origin = this.origin;
  9333. if ( invdirx >= 0 ) {
  9334. tmin = ( box.min.x - origin.x ) * invdirx;
  9335. tmax = ( box.max.x - origin.x ) * invdirx;
  9336. } else {
  9337. tmin = ( box.max.x - origin.x ) * invdirx;
  9338. tmax = ( box.min.x - origin.x ) * invdirx;
  9339. }
  9340. if ( invdiry >= 0 ) {
  9341. tymin = ( box.min.y - origin.y ) * invdiry;
  9342. tymax = ( box.max.y - origin.y ) * invdiry;
  9343. } else {
  9344. tymin = ( box.max.y - origin.y ) * invdiry;
  9345. tymax = ( box.min.y - origin.y ) * invdiry;
  9346. }
  9347. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  9348. // These lines also handle the case where tmin or tmax is NaN
  9349. // (result of 0 * Infinity). x !== x returns true if x is NaN
  9350. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  9351. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  9352. if ( invdirz >= 0 ) {
  9353. tzmin = ( box.min.z - origin.z ) * invdirz;
  9354. tzmax = ( box.max.z - origin.z ) * invdirz;
  9355. } else {
  9356. tzmin = ( box.max.z - origin.z ) * invdirz;
  9357. tzmax = ( box.min.z - origin.z ) * invdirz;
  9358. }
  9359. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  9360. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  9361. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  9362. //return point closest to the ray (positive side)
  9363. if ( tmax < 0 ) return null;
  9364. return this.at( tmin >= 0 ? tmin : tmax, optionalTarget );
  9365. },
  9366. intersectsBox: ( function () {
  9367. var v = new Vector3();
  9368. return function intersectsBox( box ) {
  9369. return this.intersectBox( box, v ) !== null;
  9370. };
  9371. } )(),
  9372. intersectTriangle: function () {
  9373. // Compute the offset origin, edges, and normal.
  9374. var diff = new Vector3();
  9375. var edge1 = new Vector3();
  9376. var edge2 = new Vector3();
  9377. var normal = new Vector3();
  9378. return function intersectTriangle( a, b, c, backfaceCulling, optionalTarget ) {
  9379. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  9380. edge1.subVectors( b, a );
  9381. edge2.subVectors( c, a );
  9382. normal.crossVectors( edge1, edge2 );
  9383. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  9384. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  9385. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  9386. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  9387. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  9388. var DdN = this.direction.dot( normal );
  9389. var sign;
  9390. if ( DdN > 0 ) {
  9391. if ( backfaceCulling ) return null;
  9392. sign = 1;
  9393. } else if ( DdN < 0 ) {
  9394. sign = - 1;
  9395. DdN = - DdN;
  9396. } else {
  9397. return null;
  9398. }
  9399. diff.subVectors( this.origin, a );
  9400. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  9401. // b1 < 0, no intersection
  9402. if ( DdQxE2 < 0 ) {
  9403. return null;
  9404. }
  9405. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  9406. // b2 < 0, no intersection
  9407. if ( DdE1xQ < 0 ) {
  9408. return null;
  9409. }
  9410. // b1+b2 > 1, no intersection
  9411. if ( DdQxE2 + DdE1xQ > DdN ) {
  9412. return null;
  9413. }
  9414. // Line intersects triangle, check if ray does.
  9415. var QdN = - sign * diff.dot( normal );
  9416. // t < 0, no intersection
  9417. if ( QdN < 0 ) {
  9418. return null;
  9419. }
  9420. // Ray intersects triangle.
  9421. return this.at( QdN / DdN, optionalTarget );
  9422. };
  9423. }(),
  9424. applyMatrix4: function ( matrix4 ) {
  9425. this.origin.applyMatrix4( matrix4 );
  9426. this.direction.transformDirection( matrix4 );
  9427. return this;
  9428. },
  9429. equals: function ( ray ) {
  9430. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  9431. }
  9432. } );
  9433. /**
  9434. * @author bhouston / http://clara.io
  9435. */
  9436. function Line3( start, end ) {
  9437. this.start = ( start !== undefined ) ? start : new Vector3();
  9438. this.end = ( end !== undefined ) ? end : new Vector3();
  9439. }
  9440. Object.assign( Line3.prototype, {
  9441. set: function ( start, end ) {
  9442. this.start.copy( start );
  9443. this.end.copy( end );
  9444. return this;
  9445. },
  9446. clone: function () {
  9447. return new this.constructor().copy( this );
  9448. },
  9449. copy: function ( line ) {
  9450. this.start.copy( line.start );
  9451. this.end.copy( line.end );
  9452. return this;
  9453. },
  9454. getCenter: function ( optionalTarget ) {
  9455. var result = optionalTarget || new Vector3();
  9456. return result.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  9457. },
  9458. delta: function ( optionalTarget ) {
  9459. var result = optionalTarget || new Vector3();
  9460. return result.subVectors( this.end, this.start );
  9461. },
  9462. distanceSq: function () {
  9463. return this.start.distanceToSquared( this.end );
  9464. },
  9465. distance: function () {
  9466. return this.start.distanceTo( this.end );
  9467. },
  9468. at: function ( t, optionalTarget ) {
  9469. var result = optionalTarget || new Vector3();
  9470. return this.delta( result ).multiplyScalar( t ).add( this.start );
  9471. },
  9472. closestPointToPointParameter: function () {
  9473. var startP = new Vector3();
  9474. var startEnd = new Vector3();
  9475. return function closestPointToPointParameter( point, clampToLine ) {
  9476. startP.subVectors( point, this.start );
  9477. startEnd.subVectors( this.end, this.start );
  9478. var startEnd2 = startEnd.dot( startEnd );
  9479. var startEnd_startP = startEnd.dot( startP );
  9480. var t = startEnd_startP / startEnd2;
  9481. if ( clampToLine ) {
  9482. t = _Math.clamp( t, 0, 1 );
  9483. }
  9484. return t;
  9485. };
  9486. }(),
  9487. closestPointToPoint: function ( point, clampToLine, optionalTarget ) {
  9488. var t = this.closestPointToPointParameter( point, clampToLine );
  9489. var result = optionalTarget || new Vector3();
  9490. return this.delta( result ).multiplyScalar( t ).add( this.start );
  9491. },
  9492. applyMatrix4: function ( matrix ) {
  9493. this.start.applyMatrix4( matrix );
  9494. this.end.applyMatrix4( matrix );
  9495. return this;
  9496. },
  9497. equals: function ( line ) {
  9498. return line.start.equals( this.start ) && line.end.equals( this.end );
  9499. }
  9500. } );
  9501. /**
  9502. * @author bhouston / http://clara.io
  9503. */
  9504. function Plane( normal, constant ) {
  9505. // normal is assumed to be normalized
  9506. this.normal = ( normal !== undefined ) ? normal : new Vector3( 1, 0, 0 );
  9507. this.constant = ( constant !== undefined ) ? constant : 0;
  9508. }
  9509. Object.assign( Plane.prototype, {
  9510. set: function ( normal, constant ) {
  9511. this.normal.copy( normal );
  9512. this.constant = constant;
  9513. return this;
  9514. },
  9515. setComponents: function ( x, y, z, w ) {
  9516. this.normal.set( x, y, z );
  9517. this.constant = w;
  9518. return this;
  9519. },
  9520. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  9521. this.normal.copy( normal );
  9522. this.constant = - point.dot( this.normal );
  9523. return this;
  9524. },
  9525. setFromCoplanarPoints: function () {
  9526. var v1 = new Vector3();
  9527. var v2 = new Vector3();
  9528. return function setFromCoplanarPoints( a, b, c ) {
  9529. var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
  9530. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  9531. this.setFromNormalAndCoplanarPoint( normal, a );
  9532. return this;
  9533. };
  9534. }(),
  9535. clone: function () {
  9536. return new this.constructor().copy( this );
  9537. },
  9538. copy: function ( plane ) {
  9539. this.normal.copy( plane.normal );
  9540. this.constant = plane.constant;
  9541. return this;
  9542. },
  9543. normalize: function () {
  9544. // Note: will lead to a divide by zero if the plane is invalid.
  9545. var inverseNormalLength = 1.0 / this.normal.length();
  9546. this.normal.multiplyScalar( inverseNormalLength );
  9547. this.constant *= inverseNormalLength;
  9548. return this;
  9549. },
  9550. negate: function () {
  9551. this.constant *= - 1;
  9552. this.normal.negate();
  9553. return this;
  9554. },
  9555. distanceToPoint: function ( point ) {
  9556. return this.normal.dot( point ) + this.constant;
  9557. },
  9558. distanceToSphere: function ( sphere ) {
  9559. return this.distanceToPoint( sphere.center ) - sphere.radius;
  9560. },
  9561. projectPoint: function ( point, optionalTarget ) {
  9562. var result = optionalTarget || new Vector3();
  9563. return result.copy( this.normal ).multiplyScalar( - this.distanceToPoint( point ) ).add( point );
  9564. },
  9565. intersectLine: function () {
  9566. var v1 = new Vector3();
  9567. return function intersectLine( line, optionalTarget ) {
  9568. var result = optionalTarget || new Vector3();
  9569. var direction = line.delta( v1 );
  9570. var denominator = this.normal.dot( direction );
  9571. if ( denominator === 0 ) {
  9572. // line is coplanar, return origin
  9573. if ( this.distanceToPoint( line.start ) === 0 ) {
  9574. return result.copy( line.start );
  9575. }
  9576. // Unsure if this is the correct method to handle this case.
  9577. return undefined;
  9578. }
  9579. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  9580. if ( t < 0 || t > 1 ) {
  9581. return undefined;
  9582. }
  9583. return result.copy( direction ).multiplyScalar( t ).add( line.start );
  9584. };
  9585. }(),
  9586. intersectsLine: function ( line ) {
  9587. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  9588. var startSign = this.distanceToPoint( line.start );
  9589. var endSign = this.distanceToPoint( line.end );
  9590. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  9591. },
  9592. intersectsBox: function ( box ) {
  9593. return box.intersectsPlane( this );
  9594. },
  9595. intersectsSphere: function ( sphere ) {
  9596. return sphere.intersectsPlane( this );
  9597. },
  9598. coplanarPoint: function ( optionalTarget ) {
  9599. var result = optionalTarget || new Vector3();
  9600. return result.copy( this.normal ).multiplyScalar( - this.constant );
  9601. },
  9602. applyMatrix4: function () {
  9603. var v1 = new Vector3();
  9604. var m1 = new Matrix3();
  9605. return function applyMatrix4( matrix, optionalNormalMatrix ) {
  9606. var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
  9607. var referencePoint = this.coplanarPoint( v1 ).applyMatrix4( matrix );
  9608. var normal = this.normal.applyMatrix3( normalMatrix ).normalize();
  9609. this.constant = - referencePoint.dot( normal );
  9610. return this;
  9611. };
  9612. }(),
  9613. translate: function ( offset ) {
  9614. this.constant -= offset.dot( this.normal );
  9615. return this;
  9616. },
  9617. equals: function ( plane ) {
  9618. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  9619. }
  9620. } );
  9621. /**
  9622. * @author bhouston / http://clara.io
  9623. * @author mrdoob / http://mrdoob.com/
  9624. */
  9625. function Triangle( a, b, c ) {
  9626. this.a = ( a !== undefined ) ? a : new Vector3();
  9627. this.b = ( b !== undefined ) ? b : new Vector3();
  9628. this.c = ( c !== undefined ) ? c : new Vector3();
  9629. }
  9630. Object.assign( Triangle, {
  9631. normal: function () {
  9632. var v0 = new Vector3();
  9633. return function normal( a, b, c, optionalTarget ) {
  9634. var result = optionalTarget || new Vector3();
  9635. result.subVectors( c, b );
  9636. v0.subVectors( a, b );
  9637. result.cross( v0 );
  9638. var resultLengthSq = result.lengthSq();
  9639. if ( resultLengthSq > 0 ) {
  9640. return result.multiplyScalar( 1 / Math.sqrt( resultLengthSq ) );
  9641. }
  9642. return result.set( 0, 0, 0 );
  9643. };
  9644. }(),
  9645. // static/instance method to calculate barycentric coordinates
  9646. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  9647. barycoordFromPoint: function () {
  9648. var v0 = new Vector3();
  9649. var v1 = new Vector3();
  9650. var v2 = new Vector3();
  9651. return function barycoordFromPoint( point, a, b, c, optionalTarget ) {
  9652. v0.subVectors( c, a );
  9653. v1.subVectors( b, a );
  9654. v2.subVectors( point, a );
  9655. var dot00 = v0.dot( v0 );
  9656. var dot01 = v0.dot( v1 );
  9657. var dot02 = v0.dot( v2 );
  9658. var dot11 = v1.dot( v1 );
  9659. var dot12 = v1.dot( v2 );
  9660. var denom = ( dot00 * dot11 - dot01 * dot01 );
  9661. var result = optionalTarget || new Vector3();
  9662. // collinear or singular triangle
  9663. if ( denom === 0 ) {
  9664. // arbitrary location outside of triangle?
  9665. // not sure if this is the best idea, maybe should be returning undefined
  9666. return result.set( - 2, - 1, - 1 );
  9667. }
  9668. var invDenom = 1 / denom;
  9669. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  9670. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  9671. // barycentric coordinates must always sum to 1
  9672. return result.set( 1 - u - v, v, u );
  9673. };
  9674. }(),
  9675. containsPoint: function () {
  9676. var v1 = new Vector3();
  9677. return function containsPoint( point, a, b, c ) {
  9678. var result = Triangle.barycoordFromPoint( point, a, b, c, v1 );
  9679. return ( result.x >= 0 ) && ( result.y >= 0 ) && ( ( result.x + result.y ) <= 1 );
  9680. };
  9681. }()
  9682. } );
  9683. Object.assign( Triangle.prototype, {
  9684. set: function ( a, b, c ) {
  9685. this.a.copy( a );
  9686. this.b.copy( b );
  9687. this.c.copy( c );
  9688. return this;
  9689. },
  9690. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  9691. this.a.copy( points[ i0 ] );
  9692. this.b.copy( points[ i1 ] );
  9693. this.c.copy( points[ i2 ] );
  9694. return this;
  9695. },
  9696. clone: function () {
  9697. return new this.constructor().copy( this );
  9698. },
  9699. copy: function ( triangle ) {
  9700. this.a.copy( triangle.a );
  9701. this.b.copy( triangle.b );
  9702. this.c.copy( triangle.c );
  9703. return this;
  9704. },
  9705. area: function () {
  9706. var v0 = new Vector3();
  9707. var v1 = new Vector3();
  9708. return function area() {
  9709. v0.subVectors( this.c, this.b );
  9710. v1.subVectors( this.a, this.b );
  9711. return v0.cross( v1 ).length() * 0.5;
  9712. };
  9713. }(),
  9714. midpoint: function ( optionalTarget ) {
  9715. var result = optionalTarget || new Vector3();
  9716. return result.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  9717. },
  9718. normal: function ( optionalTarget ) {
  9719. return Triangle.normal( this.a, this.b, this.c, optionalTarget );
  9720. },
  9721. plane: function ( optionalTarget ) {
  9722. var result = optionalTarget || new Plane();
  9723. return result.setFromCoplanarPoints( this.a, this.b, this.c );
  9724. },
  9725. barycoordFromPoint: function ( point, optionalTarget ) {
  9726. return Triangle.barycoordFromPoint( point, this.a, this.b, this.c, optionalTarget );
  9727. },
  9728. containsPoint: function ( point ) {
  9729. return Triangle.containsPoint( point, this.a, this.b, this.c );
  9730. },
  9731. closestPointToPoint: function () {
  9732. var plane = new Plane();
  9733. var edgeList = [ new Line3(), new Line3(), new Line3() ];
  9734. var projectedPoint = new Vector3();
  9735. var closestPoint = new Vector3();
  9736. return function closestPointToPoint( point, optionalTarget ) {
  9737. var result = optionalTarget || new Vector3();
  9738. var minDistance = Infinity;
  9739. // project the point onto the plane of the triangle
  9740. plane.setFromCoplanarPoints( this.a, this.b, this.c );
  9741. plane.projectPoint( point, projectedPoint );
  9742. // check if the projection lies within the triangle
  9743. if ( this.containsPoint( projectedPoint ) === true ) {
  9744. // if so, this is the closest point
  9745. result.copy( projectedPoint );
  9746. } else {
  9747. // if not, the point falls outside the triangle. the result is the closest point to the triangle's edges or vertices
  9748. edgeList[ 0 ].set( this.a, this.b );
  9749. edgeList[ 1 ].set( this.b, this.c );
  9750. edgeList[ 2 ].set( this.c, this.a );
  9751. for ( var i = 0; i < edgeList.length; i ++ ) {
  9752. edgeList[ i ].closestPointToPoint( projectedPoint, true, closestPoint );
  9753. var distance = projectedPoint.distanceToSquared( closestPoint );
  9754. if ( distance < minDistance ) {
  9755. minDistance = distance;
  9756. result.copy( closestPoint );
  9757. }
  9758. }
  9759. }
  9760. return result;
  9761. };
  9762. }(),
  9763. equals: function ( triangle ) {
  9764. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  9765. }
  9766. } );
  9767. /**
  9768. * @author mrdoob / http://mrdoob.com/
  9769. * @author alteredq / http://alteredqualia.com/
  9770. */
  9771. var materialId = 0;
  9772. function Material() {
  9773. Object.defineProperty( this, 'id', { value: materialId ++ } );
  9774. this.uuid = _Math.generateUUID();
  9775. this.name = '';
  9776. this.type = 'Material';
  9777. this.fog = true;
  9778. this.lights = true;
  9779. this.blending = NormalBlending;
  9780. this.side = FrontSide;
  9781. this.flatShading = false;
  9782. this.vertexColors = NoColors; // THREE.NoColors, THREE.VertexColors, THREE.FaceColors
  9783. this.opacity = 1;
  9784. this.transparent = false;
  9785. this.blendSrc = SrcAlphaFactor;
  9786. this.blendDst = OneMinusSrcAlphaFactor;
  9787. this.blendEquation = AddEquation;
  9788. this.blendSrcAlpha = null;
  9789. this.blendDstAlpha = null;
  9790. this.blendEquationAlpha = null;
  9791. this.depthFunc = LessEqualDepth;
  9792. this.depthTest = true;
  9793. this.depthWrite = true;
  9794. this.clippingPlanes = null;
  9795. this.clipIntersection = false;
  9796. this.clipShadows = false;
  9797. this.colorWrite = true;
  9798. this.precision = null; // override the renderer's default precision for this material
  9799. this.polygonOffset = false;
  9800. this.polygonOffsetFactor = 0;
  9801. this.polygonOffsetUnits = 0;
  9802. this.dithering = false;
  9803. this.alphaTest = 0;
  9804. this.premultipliedAlpha = false;
  9805. this.overdraw = 0; // Overdrawn pixels (typically between 0 and 1) for fixing antialiasing gaps in CanvasRenderer
  9806. this.visible = true;
  9807. this.userData = {};
  9808. this.needsUpdate = true;
  9809. }
  9810. Object.assign( Material.prototype, EventDispatcher.prototype, {
  9811. isMaterial: true,
  9812. onBeforeCompile: function () {},
  9813. setValues: function ( values ) {
  9814. if ( values === undefined ) return;
  9815. for ( var key in values ) {
  9816. var newValue = values[ key ];
  9817. if ( newValue === undefined ) {
  9818. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  9819. continue;
  9820. }
  9821. // for backward compatability if shading is set in the constructor
  9822. if ( key === 'shading' ) {
  9823. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  9824. this.flatShading = ( newValue === FlatShading ) ? true : false;
  9825. continue;
  9826. }
  9827. var currentValue = this[ key ];
  9828. if ( currentValue === undefined ) {
  9829. console.warn( "THREE." + this.type + ": '" + key + "' is not a property of this material." );
  9830. continue;
  9831. }
  9832. if ( currentValue && currentValue.isColor ) {
  9833. currentValue.set( newValue );
  9834. } else if ( ( currentValue && currentValue.isVector3 ) && ( newValue && newValue.isVector3 ) ) {
  9835. currentValue.copy( newValue );
  9836. } else if ( key === 'overdraw' ) {
  9837. // ensure overdraw is backwards-compatible with legacy boolean type
  9838. this[ key ] = Number( newValue );
  9839. } else {
  9840. this[ key ] = newValue;
  9841. }
  9842. }
  9843. },
  9844. toJSON: function ( meta ) {
  9845. var isRoot = ( meta === undefined || typeof meta === 'string' );
  9846. if ( isRoot ) {
  9847. meta = {
  9848. textures: {},
  9849. images: {}
  9850. };
  9851. }
  9852. var data = {
  9853. metadata: {
  9854. version: 4.5,
  9855. type: 'Material',
  9856. generator: 'Material.toJSON'
  9857. }
  9858. };
  9859. // standard Material serialization
  9860. data.uuid = this.uuid;
  9861. data.type = this.type;
  9862. if ( this.name !== '' ) data.name = this.name;
  9863. if ( this.color && this.color.isColor ) data.color = this.color.getHex();
  9864. if ( this.roughness !== undefined ) data.roughness = this.roughness;
  9865. if ( this.metalness !== undefined ) data.metalness = this.metalness;
  9866. if ( this.emissive && this.emissive.isColor ) data.emissive = this.emissive.getHex();
  9867. if ( this.emissiveIntensity !== 1 ) data.emissiveIntensity = this.emissiveIntensity;
  9868. if ( this.specular && this.specular.isColor ) data.specular = this.specular.getHex();
  9869. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  9870. if ( this.clearCoat !== undefined ) data.clearCoat = this.clearCoat;
  9871. if ( this.clearCoatRoughness !== undefined ) data.clearCoatRoughness = this.clearCoatRoughness;
  9872. if ( this.map && this.map.isTexture ) data.map = this.map.toJSON( meta ).uuid;
  9873. if ( this.alphaMap && this.alphaMap.isTexture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  9874. if ( this.lightMap && this.lightMap.isTexture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  9875. if ( this.bumpMap && this.bumpMap.isTexture ) {
  9876. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  9877. data.bumpScale = this.bumpScale;
  9878. }
  9879. if ( this.normalMap && this.normalMap.isTexture ) {
  9880. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  9881. data.normalScale = this.normalScale.toArray();
  9882. }
  9883. if ( this.displacementMap && this.displacementMap.isTexture ) {
  9884. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  9885. data.displacementScale = this.displacementScale;
  9886. data.displacementBias = this.displacementBias;
  9887. }
  9888. if ( this.roughnessMap && this.roughnessMap.isTexture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;
  9889. if ( this.metalnessMap && this.metalnessMap.isTexture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;
  9890. if ( this.emissiveMap && this.emissiveMap.isTexture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid;
  9891. if ( this.specularMap && this.specularMap.isTexture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  9892. if ( this.envMap && this.envMap.isTexture ) {
  9893. data.envMap = this.envMap.toJSON( meta ).uuid;
  9894. data.reflectivity = this.reflectivity; // Scale behind envMap
  9895. }
  9896. if ( this.gradientMap && this.gradientMap.isTexture ) {
  9897. data.gradientMap = this.gradientMap.toJSON( meta ).uuid;
  9898. }
  9899. if ( this.size !== undefined ) data.size = this.size;
  9900. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  9901. if ( this.blending !== NormalBlending ) data.blending = this.blending;
  9902. if ( this.flatShading === true ) data.flatShading = this.flatShading;
  9903. if ( this.side !== FrontSide ) data.side = this.side;
  9904. if ( this.vertexColors !== NoColors ) data.vertexColors = this.vertexColors;
  9905. if ( this.opacity < 1 ) data.opacity = this.opacity;
  9906. if ( this.transparent === true ) data.transparent = this.transparent;
  9907. data.depthFunc = this.depthFunc;
  9908. data.depthTest = this.depthTest;
  9909. data.depthWrite = this.depthWrite;
  9910. // rotation (SpriteMaterial)
  9911. if ( this.rotation !== 0 ) data.rotation = this.rotation;
  9912. if ( this.linewidth !== 1 ) data.linewidth = this.linewidth;
  9913. if ( this.dashSize !== undefined ) data.dashSize = this.dashSize;
  9914. if ( this.gapSize !== undefined ) data.gapSize = this.gapSize;
  9915. if ( this.scale !== undefined ) data.scale = this.scale;
  9916. if ( this.dithering === true ) data.dithering = true;
  9917. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  9918. if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = this.premultipliedAlpha;
  9919. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  9920. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  9921. if ( this.wireframeLinecap !== 'round' ) data.wireframeLinecap = this.wireframeLinecap;
  9922. if ( this.wireframeLinejoin !== 'round' ) data.wireframeLinejoin = this.wireframeLinejoin;
  9923. if ( this.morphTargets === true ) data.morphTargets = true;
  9924. if ( this.skinning === true ) data.skinning = true;
  9925. if ( this.visible === false ) data.visible = false;
  9926. if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
  9927. // TODO: Copied from Object3D.toJSON
  9928. function extractFromCache( cache ) {
  9929. var values = [];
  9930. for ( var key in cache ) {
  9931. var data = cache[ key ];
  9932. delete data.metadata;
  9933. values.push( data );
  9934. }
  9935. return values;
  9936. }
  9937. if ( isRoot ) {
  9938. var textures = extractFromCache( meta.textures );
  9939. var images = extractFromCache( meta.images );
  9940. if ( textures.length > 0 ) data.textures = textures;
  9941. if ( images.length > 0 ) data.images = images;
  9942. }
  9943. return data;
  9944. },
  9945. clone: function () {
  9946. return new this.constructor().copy( this );
  9947. },
  9948. copy: function ( source ) {
  9949. this.name = source.name;
  9950. this.fog = source.fog;
  9951. this.lights = source.lights;
  9952. this.blending = source.blending;
  9953. this.side = source.side;
  9954. this.flatShading = source.flatShading;
  9955. this.vertexColors = source.vertexColors;
  9956. this.opacity = source.opacity;
  9957. this.transparent = source.transparent;
  9958. this.blendSrc = source.blendSrc;
  9959. this.blendDst = source.blendDst;
  9960. this.blendEquation = source.blendEquation;
  9961. this.blendSrcAlpha = source.blendSrcAlpha;
  9962. this.blendDstAlpha = source.blendDstAlpha;
  9963. this.blendEquationAlpha = source.blendEquationAlpha;
  9964. this.depthFunc = source.depthFunc;
  9965. this.depthTest = source.depthTest;
  9966. this.depthWrite = source.depthWrite;
  9967. this.colorWrite = source.colorWrite;
  9968. this.precision = source.precision;
  9969. this.polygonOffset = source.polygonOffset;
  9970. this.polygonOffsetFactor = source.polygonOffsetFactor;
  9971. this.polygonOffsetUnits = source.polygonOffsetUnits;
  9972. this.dithering = source.dithering;
  9973. this.alphaTest = source.alphaTest;
  9974. this.premultipliedAlpha = source.premultipliedAlpha;
  9975. this.overdraw = source.overdraw;
  9976. this.visible = source.visible;
  9977. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  9978. this.clipShadows = source.clipShadows;
  9979. this.clipIntersection = source.clipIntersection;
  9980. var srcPlanes = source.clippingPlanes,
  9981. dstPlanes = null;
  9982. if ( srcPlanes !== null ) {
  9983. var n = srcPlanes.length;
  9984. dstPlanes = new Array( n );
  9985. for ( var i = 0; i !== n; ++ i )
  9986. dstPlanes[ i ] = srcPlanes[ i ].clone();
  9987. }
  9988. this.clippingPlanes = dstPlanes;
  9989. return this;
  9990. },
  9991. dispose: function () {
  9992. this.dispatchEvent( { type: 'dispose' } );
  9993. }
  9994. } );
  9995. /**
  9996. * @author mrdoob / http://mrdoob.com/
  9997. * @author alteredq / http://alteredqualia.com/
  9998. *
  9999. * parameters = {
  10000. * color: <hex>,
  10001. * opacity: <float>,
  10002. * map: new THREE.Texture( <Image> ),
  10003. *
  10004. * lightMap: new THREE.Texture( <Image> ),
  10005. * lightMapIntensity: <float>
  10006. *
  10007. * aoMap: new THREE.Texture( <Image> ),
  10008. * aoMapIntensity: <float>
  10009. *
  10010. * specularMap: new THREE.Texture( <Image> ),
  10011. *
  10012. * alphaMap: new THREE.Texture( <Image> ),
  10013. *
  10014. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  10015. * combine: THREE.Multiply,
  10016. * reflectivity: <float>,
  10017. * refractionRatio: <float>,
  10018. *
  10019. * depthTest: <bool>,
  10020. * depthWrite: <bool>,
  10021. *
  10022. * wireframe: <boolean>,
  10023. * wireframeLinewidth: <float>,
  10024. *
  10025. * skinning: <bool>,
  10026. * morphTargets: <bool>
  10027. * }
  10028. */
  10029. function MeshBasicMaterial( parameters ) {
  10030. Material.call( this );
  10031. this.type = 'MeshBasicMaterial';
  10032. this.color = new Color( 0xffffff ); // emissive
  10033. this.map = null;
  10034. this.lightMap = null;
  10035. this.lightMapIntensity = 1.0;
  10036. this.aoMap = null;
  10037. this.aoMapIntensity = 1.0;
  10038. this.specularMap = null;
  10039. this.alphaMap = null;
  10040. this.envMap = null;
  10041. this.combine = MultiplyOperation;
  10042. this.reflectivity = 1;
  10043. this.refractionRatio = 0.98;
  10044. this.wireframe = false;
  10045. this.wireframeLinewidth = 1;
  10046. this.wireframeLinecap = 'round';
  10047. this.wireframeLinejoin = 'round';
  10048. this.skinning = false;
  10049. this.morphTargets = false;
  10050. this.lights = false;
  10051. this.setValues( parameters );
  10052. }
  10053. MeshBasicMaterial.prototype = Object.create( Material.prototype );
  10054. MeshBasicMaterial.prototype.constructor = MeshBasicMaterial;
  10055. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  10056. MeshBasicMaterial.prototype.copy = function ( source ) {
  10057. Material.prototype.copy.call( this, source );
  10058. this.color.copy( source.color );
  10059. this.map = source.map;
  10060. this.lightMap = source.lightMap;
  10061. this.lightMapIntensity = source.lightMapIntensity;
  10062. this.aoMap = source.aoMap;
  10063. this.aoMapIntensity = source.aoMapIntensity;
  10064. this.specularMap = source.specularMap;
  10065. this.alphaMap = source.alphaMap;
  10066. this.envMap = source.envMap;
  10067. this.combine = source.combine;
  10068. this.reflectivity = source.reflectivity;
  10069. this.refractionRatio = source.refractionRatio;
  10070. this.wireframe = source.wireframe;
  10071. this.wireframeLinewidth = source.wireframeLinewidth;
  10072. this.wireframeLinecap = source.wireframeLinecap;
  10073. this.wireframeLinejoin = source.wireframeLinejoin;
  10074. this.skinning = source.skinning;
  10075. this.morphTargets = source.morphTargets;
  10076. return this;
  10077. };
  10078. /**
  10079. * @author mrdoob / http://mrdoob.com/
  10080. * @author alteredq / http://alteredqualia.com/
  10081. * @author mikael emtinger / http://gomo.se/
  10082. * @author jonobr1 / http://jonobr1.com/
  10083. */
  10084. function Mesh( geometry, material ) {
  10085. Object3D.call( this );
  10086. this.type = 'Mesh';
  10087. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  10088. this.material = material !== undefined ? material : new MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  10089. this.drawMode = TrianglesDrawMode;
  10090. this.updateMorphTargets();
  10091. }
  10092. Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
  10093. constructor: Mesh,
  10094. isMesh: true,
  10095. setDrawMode: function ( value ) {
  10096. this.drawMode = value;
  10097. },
  10098. copy: function ( source ) {
  10099. Object3D.prototype.copy.call( this, source );
  10100. this.drawMode = source.drawMode;
  10101. if ( source.morphTargetInfluences !== undefined ) {
  10102. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  10103. }
  10104. if ( source.morphTargetDictionary !== undefined ) {
  10105. this.morphTargetDictionary = Object.assign( {}, source.morphTargetDictionary );
  10106. }
  10107. return this;
  10108. },
  10109. updateMorphTargets: function () {
  10110. var geometry = this.geometry;
  10111. var m, ml, name;
  10112. if ( geometry.isBufferGeometry ) {
  10113. var morphAttributes = geometry.morphAttributes;
  10114. var keys = Object.keys( morphAttributes );
  10115. if ( keys.length > 0 ) {
  10116. var morphAttribute = morphAttributes[ keys[ 0 ] ];
  10117. if ( morphAttribute !== undefined ) {
  10118. this.morphTargetInfluences = [];
  10119. this.morphTargetDictionary = {};
  10120. for ( m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  10121. name = morphAttribute[ m ].name || String( m );
  10122. this.morphTargetInfluences.push( 0 );
  10123. this.morphTargetDictionary[ name ] = m;
  10124. }
  10125. }
  10126. }
  10127. } else {
  10128. var morphTargets = geometry.morphTargets;
  10129. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  10130. this.morphTargetInfluences = [];
  10131. this.morphTargetDictionary = {};
  10132. for ( m = 0, ml = morphTargets.length; m < ml; m ++ ) {
  10133. name = morphTargets[ m ].name || String( m );
  10134. this.morphTargetInfluences.push( 0 );
  10135. this.morphTargetDictionary[ name ] = m;
  10136. }
  10137. }
  10138. }
  10139. },
  10140. raycast: ( function () {
  10141. var inverseMatrix = new Matrix4();
  10142. var ray = new Ray();
  10143. var sphere = new Sphere();
  10144. var vA = new Vector3();
  10145. var vB = new Vector3();
  10146. var vC = new Vector3();
  10147. var tempA = new Vector3();
  10148. var tempB = new Vector3();
  10149. var tempC = new Vector3();
  10150. var uvA = new Vector2();
  10151. var uvB = new Vector2();
  10152. var uvC = new Vector2();
  10153. var barycoord = new Vector3();
  10154. var intersectionPoint = new Vector3();
  10155. var intersectionPointWorld = new Vector3();
  10156. function uvIntersection( point, p1, p2, p3, uv1, uv2, uv3 ) {
  10157. Triangle.barycoordFromPoint( point, p1, p2, p3, barycoord );
  10158. uv1.multiplyScalar( barycoord.x );
  10159. uv2.multiplyScalar( barycoord.y );
  10160. uv3.multiplyScalar( barycoord.z );
  10161. uv1.add( uv2 ).add( uv3 );
  10162. return uv1.clone();
  10163. }
  10164. function checkIntersection( object, material, raycaster, ray, pA, pB, pC, point ) {
  10165. var intersect;
  10166. if ( material.side === BackSide ) {
  10167. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  10168. } else {
  10169. intersect = ray.intersectTriangle( pA, pB, pC, material.side !== DoubleSide, point );
  10170. }
  10171. if ( intersect === null ) return null;
  10172. intersectionPointWorld.copy( point );
  10173. intersectionPointWorld.applyMatrix4( object.matrixWorld );
  10174. var distance = raycaster.ray.origin.distanceTo( intersectionPointWorld );
  10175. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  10176. return {
  10177. distance: distance,
  10178. point: intersectionPointWorld.clone(),
  10179. object: object
  10180. };
  10181. }
  10182. function checkBufferGeometryIntersection( object, raycaster, ray, position, uv, a, b, c ) {
  10183. vA.fromBufferAttribute( position, a );
  10184. vB.fromBufferAttribute( position, b );
  10185. vC.fromBufferAttribute( position, c );
  10186. var intersection = checkIntersection( object, object.material, raycaster, ray, vA, vB, vC, intersectionPoint );
  10187. if ( intersection ) {
  10188. if ( uv ) {
  10189. uvA.fromBufferAttribute( uv, a );
  10190. uvB.fromBufferAttribute( uv, b );
  10191. uvC.fromBufferAttribute( uv, c );
  10192. intersection.uv = uvIntersection( intersectionPoint, vA, vB, vC, uvA, uvB, uvC );
  10193. }
  10194. intersection.face = new Face3( a, b, c, Triangle.normal( vA, vB, vC ) );
  10195. intersection.faceIndex = a;
  10196. }
  10197. return intersection;
  10198. }
  10199. return function raycast( raycaster, intersects ) {
  10200. var geometry = this.geometry;
  10201. var material = this.material;
  10202. var matrixWorld = this.matrixWorld;
  10203. if ( material === undefined ) return;
  10204. // Checking boundingSphere distance to ray
  10205. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  10206. sphere.copy( geometry.boundingSphere );
  10207. sphere.applyMatrix4( matrixWorld );
  10208. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  10209. //
  10210. inverseMatrix.getInverse( matrixWorld );
  10211. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  10212. // Check boundingBox before continuing
  10213. if ( geometry.boundingBox !== null ) {
  10214. if ( ray.intersectsBox( geometry.boundingBox ) === false ) return;
  10215. }
  10216. var intersection;
  10217. if ( geometry.isBufferGeometry ) {
  10218. var a, b, c;
  10219. var index = geometry.index;
  10220. var position = geometry.attributes.position;
  10221. var uv = geometry.attributes.uv;
  10222. var i, l;
  10223. if ( index !== null ) {
  10224. // indexed buffer geometry
  10225. for ( i = 0, l = index.count; i < l; i += 3 ) {
  10226. a = index.getX( i );
  10227. b = index.getX( i + 1 );
  10228. c = index.getX( i + 2 );
  10229. intersection = checkBufferGeometryIntersection( this, raycaster, ray, position, uv, a, b, c );
  10230. if ( intersection ) {
  10231. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indices buffer semantics
  10232. intersects.push( intersection );
  10233. }
  10234. }
  10235. } else if ( position !== undefined ) {
  10236. // non-indexed buffer geometry
  10237. for ( i = 0, l = position.count; i < l; i += 3 ) {
  10238. a = i;
  10239. b = i + 1;
  10240. c = i + 2;
  10241. intersection = checkBufferGeometryIntersection( this, raycaster, ray, position, uv, a, b, c );
  10242. if ( intersection ) {
  10243. intersection.index = a; // triangle number in positions buffer semantics
  10244. intersects.push( intersection );
  10245. }
  10246. }
  10247. }
  10248. } else if ( geometry.isGeometry ) {
  10249. var fvA, fvB, fvC;
  10250. var isMultiMaterial = Array.isArray( material );
  10251. var vertices = geometry.vertices;
  10252. var faces = geometry.faces;
  10253. var uvs;
  10254. var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
  10255. if ( faceVertexUvs.length > 0 ) uvs = faceVertexUvs;
  10256. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  10257. var face = faces[ f ];
  10258. var faceMaterial = isMultiMaterial ? material[ face.materialIndex ] : material;
  10259. if ( faceMaterial === undefined ) continue;
  10260. fvA = vertices[ face.a ];
  10261. fvB = vertices[ face.b ];
  10262. fvC = vertices[ face.c ];
  10263. if ( faceMaterial.morphTargets === true ) {
  10264. var morphTargets = geometry.morphTargets;
  10265. var morphInfluences = this.morphTargetInfluences;
  10266. vA.set( 0, 0, 0 );
  10267. vB.set( 0, 0, 0 );
  10268. vC.set( 0, 0, 0 );
  10269. for ( var t = 0, tl = morphTargets.length; t < tl; t ++ ) {
  10270. var influence = morphInfluences[ t ];
  10271. if ( influence === 0 ) continue;
  10272. var targets = morphTargets[ t ].vertices;
  10273. vA.addScaledVector( tempA.subVectors( targets[ face.a ], fvA ), influence );
  10274. vB.addScaledVector( tempB.subVectors( targets[ face.b ], fvB ), influence );
  10275. vC.addScaledVector( tempC.subVectors( targets[ face.c ], fvC ), influence );
  10276. }
  10277. vA.add( fvA );
  10278. vB.add( fvB );
  10279. vC.add( fvC );
  10280. fvA = vA;
  10281. fvB = vB;
  10282. fvC = vC;
  10283. }
  10284. intersection = checkIntersection( this, faceMaterial, raycaster, ray, fvA, fvB, fvC, intersectionPoint );
  10285. if ( intersection ) {
  10286. if ( uvs && uvs[ f ] ) {
  10287. var uvs_f = uvs[ f ];
  10288. uvA.copy( uvs_f[ 0 ] );
  10289. uvB.copy( uvs_f[ 1 ] );
  10290. uvC.copy( uvs_f[ 2 ] );
  10291. intersection.uv = uvIntersection( intersectionPoint, fvA, fvB, fvC, uvA, uvB, uvC );
  10292. }
  10293. intersection.face = face;
  10294. intersection.faceIndex = f;
  10295. intersects.push( intersection );
  10296. }
  10297. }
  10298. }
  10299. };
  10300. }() ),
  10301. clone: function () {
  10302. return new this.constructor( this.geometry, this.material ).copy( this );
  10303. }
  10304. } );
  10305. /**
  10306. * @author TristanVALCKE / https://github.com/Itee
  10307. * @author Anonymous
  10308. */
  10309. /* global QUnit */
  10310. QUnit.module( 'Animation', () => {
  10311. QUnit.module.todo( 'PropertyBinding', () => {
  10312. // INSTANCING
  10313. QUnit.test( "Instancing", ( assert ) => {
  10314. assert.ok( false, "everything's gonna be alright" );
  10315. } );
  10316. // STATIC STUFF
  10317. QUnit.test( "Composite", ( assert ) => {
  10318. assert.ok( false, "everything's gonna be alright" );
  10319. } );
  10320. QUnit.test( "create", ( assert ) => {
  10321. assert.ok( false, "everything's gonna be alright" );
  10322. } );
  10323. QUnit.test( 'sanitizeNodeName', ( assert ) => {
  10324. assert.equal(
  10325. PropertyBinding.sanitizeNodeName( 'valid-name-123_' ),
  10326. 'valid-name-123_',
  10327. 'Leaves valid name intact.'
  10328. );
  10329. assert.equal(
  10330. PropertyBinding.sanitizeNodeName( 'space separated name 123_ -' ),
  10331. 'space_separated_name_123__-',
  10332. 'Replaces spaces with underscores.'
  10333. );
  10334. assert.equal(
  10335. PropertyBinding.sanitizeNodeName( '"invalid" name %123%_' ),
  10336. 'invalid_name_123_',
  10337. 'Strips invalid characters.'
  10338. );
  10339. } );
  10340. QUnit.test( 'parseTrackName', ( assert ) => {
  10341. var paths = [
  10342. [
  10343. '.property',
  10344. {
  10345. nodeName: undefined,
  10346. objectName: undefined,
  10347. objectIndex: undefined,
  10348. propertyName: 'property',
  10349. propertyIndex: undefined
  10350. }
  10351. ],
  10352. [
  10353. 'nodeName.property',
  10354. {
  10355. nodeName: 'nodeName',
  10356. objectName: undefined,
  10357. objectIndex: undefined,
  10358. propertyName: 'property',
  10359. propertyIndex: undefined
  10360. }
  10361. ],
  10362. [
  10363. 'a.property',
  10364. {
  10365. nodeName: 'a',
  10366. objectName: undefined,
  10367. objectIndex: undefined,
  10368. propertyName: 'property',
  10369. propertyIndex: undefined
  10370. }
  10371. ],
  10372. [
  10373. 'no.de.Name.property',
  10374. {
  10375. nodeName: 'no.de.Name',
  10376. objectName: undefined,
  10377. objectIndex: undefined,
  10378. propertyName: 'property',
  10379. propertyIndex: undefined
  10380. }
  10381. ],
  10382. [
  10383. 'no.d-e.Name.property',
  10384. {
  10385. nodeName: 'no.d-e.Name',
  10386. objectName: undefined,
  10387. objectIndex: undefined,
  10388. propertyName: 'property',
  10389. propertyIndex: undefined
  10390. }
  10391. ],
  10392. [
  10393. 'nodeName.property[accessor]',
  10394. {
  10395. nodeName: 'nodeName',
  10396. objectName: undefined,
  10397. objectIndex: undefined,
  10398. propertyName: 'property',
  10399. propertyIndex: 'accessor'
  10400. }
  10401. ],
  10402. [
  10403. 'nodeName.material.property[accessor]',
  10404. {
  10405. nodeName: 'nodeName',
  10406. objectName: 'material',
  10407. objectIndex: undefined,
  10408. propertyName: 'property',
  10409. propertyIndex: 'accessor'
  10410. }
  10411. ],
  10412. [
  10413. 'no.de.Name.material.property',
  10414. {
  10415. nodeName: 'no.de.Name',
  10416. objectName: 'material',
  10417. objectIndex: undefined,
  10418. propertyName: 'property',
  10419. propertyIndex: undefined
  10420. }
  10421. ],
  10422. [
  10423. 'no.de.Name.material[materialIndex].property',
  10424. {
  10425. nodeName: 'no.de.Name',
  10426. objectName: 'material',
  10427. objectIndex: 'materialIndex',
  10428. propertyName: 'property',
  10429. propertyIndex: undefined
  10430. }
  10431. ],
  10432. [
  10433. 'uuid.property[accessor]',
  10434. {
  10435. nodeName: 'uuid',
  10436. objectName: undefined,
  10437. objectIndex: undefined,
  10438. propertyName: 'property',
  10439. propertyIndex: 'accessor'
  10440. }
  10441. ],
  10442. [
  10443. 'uuid.objectName[objectIndex].propertyName[propertyIndex]',
  10444. {
  10445. nodeName: 'uuid',
  10446. objectName: 'objectName',
  10447. objectIndex: 'objectIndex',
  10448. propertyName: 'propertyName',
  10449. propertyIndex: 'propertyIndex'
  10450. }
  10451. ],
  10452. [
  10453. 'parentName/nodeName.property',
  10454. {
  10455. // directoryName is currently unused.
  10456. nodeName: 'nodeName',
  10457. objectName: undefined,
  10458. objectIndex: undefined,
  10459. propertyName: 'property',
  10460. propertyIndex: undefined
  10461. }
  10462. ],
  10463. [
  10464. 'parentName/no.de.Name.property',
  10465. {
  10466. // directoryName is currently unused.
  10467. nodeName: 'no.de.Name',
  10468. objectName: undefined,
  10469. objectIndex: undefined,
  10470. propertyName: 'property',
  10471. propertyIndex: undefined
  10472. }
  10473. ],
  10474. [
  10475. 'parentName/parentName/nodeName.property[index]',
  10476. {
  10477. // directoryName is currently unused.
  10478. nodeName: 'nodeName',
  10479. objectName: undefined,
  10480. objectIndex: undefined,
  10481. propertyName: 'property',
  10482. propertyIndex: 'index'
  10483. }
  10484. ],
  10485. [
  10486. '.bone[Armature.DEF_cog].position',
  10487. {
  10488. nodeName: undefined,
  10489. objectName: 'bone',
  10490. objectIndex: 'Armature.DEF_cog',
  10491. propertyName: 'position',
  10492. propertyIndex: undefined
  10493. }
  10494. ],
  10495. [
  10496. 'scene:helium_balloon_model:helium_balloon_model.position',
  10497. {
  10498. nodeName: 'helium_balloon_model',
  10499. objectName: undefined,
  10500. objectIndex: undefined,
  10501. propertyName: 'position',
  10502. propertyIndex: undefined
  10503. }
  10504. ]
  10505. ];
  10506. paths.forEach( function ( path ) {
  10507. assert.smartEqual(
  10508. PropertyBinding.parseTrackName( path[ 0 ] ),
  10509. path[ 1 ],
  10510. 'Parses track name: ' + path[ 0 ]
  10511. );
  10512. } );
  10513. } );
  10514. QUnit.test( "findNode", ( assert ) => {
  10515. assert.ok( false, "everything's gonna be alright" );
  10516. } );
  10517. // PUBLIC STUFF
  10518. QUnit.test( "BindingType", ( assert ) => {
  10519. assert.ok( false, "everything's gonna be alright" );
  10520. } );
  10521. QUnit.test( "Versioning", ( assert ) => {
  10522. assert.ok( false, "everything's gonna be alright" );
  10523. } );
  10524. QUnit.test( "GetterByBindingType", ( assert ) => {
  10525. assert.ok( false, "everything's gonna be alright" );
  10526. } );
  10527. QUnit.test( "SetterByBindingTypeAndVersioning", ( assert ) => {
  10528. assert.ok( false, "everything's gonna be alright" );
  10529. } );
  10530. QUnit.test( "getValue", ( assert ) => {
  10531. assert.ok( false, "everything's gonna be alright" );
  10532. } );
  10533. QUnit.test( 'setValue', ( assert ) => {
  10534. var paths = [
  10535. '.material.opacity',
  10536. '.material[opacity]'
  10537. ];
  10538. paths.forEach( function ( path ) {
  10539. var originalValue = 0;
  10540. var expectedValue = 1;
  10541. var geometry = new BoxGeometry();
  10542. var material = new MeshBasicMaterial();
  10543. material.opacity = originalValue;
  10544. var mesh = new Mesh( geometry, material );
  10545. var binding = new PropertyBinding( mesh, path, null );
  10546. binding.bind();
  10547. assert.equal(
  10548. material.opacity,
  10549. originalValue,
  10550. 'Sets property of material with "' + path + '" (pre-setValue)'
  10551. );
  10552. binding.setValue( [ expectedValue ], 0 );
  10553. assert.equal(
  10554. material.opacity,
  10555. expectedValue,
  10556. 'Sets property of material with "' + path + '" (post-setValue)'
  10557. );
  10558. } );
  10559. } );
  10560. QUnit.test( "bind", ( assert ) => {
  10561. assert.ok( false, "everything's gonna be alright" );
  10562. } );
  10563. QUnit.test( "unbind", ( assert ) => {
  10564. assert.ok( false, "everything's gonna be alright" );
  10565. } );
  10566. // OTHERS
  10567. QUnit.test( "_getValue_unavailable", ( assert ) => {
  10568. assert.ok( false, "everything's gonna be alright" );
  10569. } );
  10570. QUnit.test( "_setValue_unavailable", ( assert ) => {
  10571. assert.ok( false, "everything's gonna be alright" );
  10572. } );
  10573. } );
  10574. } );
  10575. /**
  10576. * @author TristanVALCKE / https://github.com/Itee
  10577. */
  10578. /* global QUnit */
  10579. QUnit.module( 'Animation', () => {
  10580. QUnit.module.todo( 'PropertyMixer', () => {
  10581. // INSTANCING
  10582. QUnit.test( "Instancing", ( assert ) => {
  10583. assert.ok( false, "everything's gonna be alright" );
  10584. } );
  10585. // PRIVATE STUFF
  10586. QUnit.test( "_select", ( assert ) => {
  10587. assert.ok( false, "everything's gonna be alright" );
  10588. } );
  10589. QUnit.test( "_slerp", ( assert ) => {
  10590. assert.ok( false, "everything's gonna be alright" );
  10591. } );
  10592. QUnit.test( "_lerp", ( assert ) => {
  10593. assert.ok( false, "everything's gonna be alright" );
  10594. } );
  10595. // PUBLIC STUFF
  10596. QUnit.test( "accumulate", ( assert ) => {
  10597. assert.ok( false, "everything's gonna be alright" );
  10598. } );
  10599. QUnit.test( "apply", ( assert ) => {
  10600. assert.ok( false, "everything's gonna be alright" );
  10601. } );
  10602. QUnit.test( "saveOriginalState", ( assert ) => {
  10603. assert.ok( false, "everything's gonna be alright" );
  10604. } );
  10605. QUnit.test( "restoreOriginalState", ( assert ) => {
  10606. assert.ok( false, "everything's gonna be alright" );
  10607. } );
  10608. } );
  10609. } );
  10610. /**
  10611. * @author TristanVALCKE / https://github.com/Itee
  10612. */
  10613. /* global QUnit */
  10614. QUnit.module( 'Animation', () => {
  10615. QUnit.module( 'Tracks', () => {
  10616. QUnit.module.todo( 'BooleanKeyframeTrack', () => {
  10617. QUnit.test( 'write me !', ( assert ) => {
  10618. assert.ok( false, "everything's gonna be alright" );
  10619. } );
  10620. } );
  10621. } );
  10622. } );
  10623. /**
  10624. * @author TristanVALCKE / https://github.com/Itee
  10625. */
  10626. /* global QUnit */
  10627. QUnit.module( 'Animation', () => {
  10628. QUnit.module( 'Tracks', () => {
  10629. QUnit.module.todo( 'ColorKeyframeTrack', () => {
  10630. QUnit.test( 'write me !', ( assert ) => {
  10631. assert.ok( false, "everything's gonna be alright" );
  10632. } );
  10633. } );
  10634. } );
  10635. } );
  10636. /**
  10637. * @author TristanVALCKE / https://github.com/Itee
  10638. */
  10639. /* global QUnit */
  10640. QUnit.module( 'Animation', () => {
  10641. QUnit.module( 'Tracks', () => {
  10642. QUnit.module.todo( 'NumberKeyframeTrack', () => {
  10643. QUnit.test( 'write me !', ( assert ) => {
  10644. assert.ok( false, "everything's gonna be alright" );
  10645. } );
  10646. } );
  10647. } );
  10648. } );
  10649. /**
  10650. * @author TristanVALCKE / https://github.com/Itee
  10651. */
  10652. /* global QUnit */
  10653. QUnit.module( 'Animation', () => {
  10654. QUnit.module( 'Tracks', () => {
  10655. QUnit.module.todo( 'QuaternionKeyframeTrack', () => {
  10656. QUnit.test( 'write me !', ( assert ) => {
  10657. assert.ok( false, "everything's gonna be alright" );
  10658. } );
  10659. } );
  10660. } );
  10661. } );
  10662. /**
  10663. * @author TristanVALCKE / https://github.com/Itee
  10664. */
  10665. /* global QUnit */
  10666. QUnit.module( 'Animation', () => {
  10667. QUnit.module( 'Tracks', () => {
  10668. QUnit.module.todo( 'StringKeyframeTrack', () => {
  10669. QUnit.test( 'write me !', ( assert ) => {
  10670. assert.ok( false, "everything's gonna be alright" );
  10671. } );
  10672. } );
  10673. } );
  10674. } );
  10675. /**
  10676. * @author TristanVALCKE / https://github.com/Itee
  10677. */
  10678. /* global QUnit */
  10679. QUnit.module( 'Animation', () => {
  10680. QUnit.module( 'Tracks', () => {
  10681. QUnit.module.todo( 'VectorKeyframeTrack', () => {
  10682. QUnit.test( 'write me !', ( assert ) => {
  10683. assert.ok( false, "everything's gonna be alright" );
  10684. } );
  10685. } );
  10686. } );
  10687. } );
  10688. /**
  10689. * @author mrdoob / http://mrdoob.com/
  10690. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  10691. */
  10692. function Audio( listener ) {
  10693. Object3D.call( this );
  10694. this.type = 'Audio';
  10695. this.context = listener.context;
  10696. this.gain = this.context.createGain();
  10697. this.gain.connect( listener.getInput() );
  10698. this.autoplay = false;
  10699. this.buffer = null;
  10700. this.loop = false;
  10701. this.startTime = 0;
  10702. this.offset = 0;
  10703. this.playbackRate = 1;
  10704. this.isPlaying = false;
  10705. this.hasPlaybackControl = true;
  10706. this.sourceType = 'empty';
  10707. this.filters = [];
  10708. }
  10709. Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
  10710. constructor: Audio,
  10711. getOutput: function () {
  10712. return this.gain;
  10713. },
  10714. setNodeSource: function ( audioNode ) {
  10715. this.hasPlaybackControl = false;
  10716. this.sourceType = 'audioNode';
  10717. this.source = audioNode;
  10718. this.connect();
  10719. return this;
  10720. },
  10721. setBuffer: function ( audioBuffer ) {
  10722. this.buffer = audioBuffer;
  10723. this.sourceType = 'buffer';
  10724. if ( this.autoplay ) this.play();
  10725. return this;
  10726. },
  10727. play: function () {
  10728. if ( this.isPlaying === true ) {
  10729. console.warn( 'THREE.Audio: Audio is already playing.' );
  10730. return;
  10731. }
  10732. if ( this.hasPlaybackControl === false ) {
  10733. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  10734. return;
  10735. }
  10736. var source = this.context.createBufferSource();
  10737. source.buffer = this.buffer;
  10738. source.loop = this.loop;
  10739. source.onended = this.onEnded.bind( this );
  10740. source.playbackRate.setValueAtTime( this.playbackRate, this.startTime );
  10741. this.startTime = this.context.currentTime;
  10742. source.start( this.startTime, this.offset );
  10743. this.isPlaying = true;
  10744. this.source = source;
  10745. return this.connect();
  10746. },
  10747. pause: function () {
  10748. if ( this.hasPlaybackControl === false ) {
  10749. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  10750. return;
  10751. }
  10752. if ( this.isPlaying === true ) {
  10753. this.source.stop();
  10754. this.offset += ( this.context.currentTime - this.startTime ) * this.playbackRate;
  10755. this.isPlaying = false;
  10756. }
  10757. return this;
  10758. },
  10759. stop: function () {
  10760. if ( this.hasPlaybackControl === false ) {
  10761. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  10762. return;
  10763. }
  10764. this.source.stop();
  10765. this.offset = 0;
  10766. this.isPlaying = false;
  10767. return this;
  10768. },
  10769. connect: function () {
  10770. if ( this.filters.length > 0 ) {
  10771. this.source.connect( this.filters[ 0 ] );
  10772. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  10773. this.filters[ i - 1 ].connect( this.filters[ i ] );
  10774. }
  10775. this.filters[ this.filters.length - 1 ].connect( this.getOutput() );
  10776. } else {
  10777. this.source.connect( this.getOutput() );
  10778. }
  10779. return this;
  10780. },
  10781. disconnect: function () {
  10782. if ( this.filters.length > 0 ) {
  10783. this.source.disconnect( this.filters[ 0 ] );
  10784. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  10785. this.filters[ i - 1 ].disconnect( this.filters[ i ] );
  10786. }
  10787. this.filters[ this.filters.length - 1 ].disconnect( this.getOutput() );
  10788. } else {
  10789. this.source.disconnect( this.getOutput() );
  10790. }
  10791. return this;
  10792. },
  10793. getFilters: function () {
  10794. return this.filters;
  10795. },
  10796. setFilters: function ( value ) {
  10797. if ( ! value ) value = [];
  10798. if ( this.isPlaying === true ) {
  10799. this.disconnect();
  10800. this.filters = value;
  10801. this.connect();
  10802. } else {
  10803. this.filters = value;
  10804. }
  10805. return this;
  10806. },
  10807. getFilter: function () {
  10808. return this.getFilters()[ 0 ];
  10809. },
  10810. setFilter: function ( filter ) {
  10811. return this.setFilters( filter ? [ filter ] : [] );
  10812. },
  10813. setPlaybackRate: function ( value ) {
  10814. if ( this.hasPlaybackControl === false ) {
  10815. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  10816. return;
  10817. }
  10818. this.playbackRate = value;
  10819. if ( this.isPlaying === true ) {
  10820. this.source.playbackRate.setValueAtTime( this.playbackRate, this.context.currentTime );
  10821. }
  10822. return this;
  10823. },
  10824. getPlaybackRate: function () {
  10825. return this.playbackRate;
  10826. },
  10827. onEnded: function () {
  10828. this.isPlaying = false;
  10829. },
  10830. getLoop: function () {
  10831. if ( this.hasPlaybackControl === false ) {
  10832. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  10833. return false;
  10834. }
  10835. return this.loop;
  10836. },
  10837. setLoop: function ( value ) {
  10838. if ( this.hasPlaybackControl === false ) {
  10839. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  10840. return;
  10841. }
  10842. this.loop = value;
  10843. if ( this.isPlaying === true ) {
  10844. this.source.loop = this.loop;
  10845. }
  10846. return this;
  10847. },
  10848. getVolume: function () {
  10849. return this.gain.gain.value;
  10850. },
  10851. setVolume: function ( value ) {
  10852. this.gain.gain.value = value;
  10853. return this;
  10854. }
  10855. } );
  10856. /**
  10857. * @author TristanVALCKE / https://github.com/Itee
  10858. */
  10859. /* global QUnit */
  10860. QUnit.module( 'Audios', () => {
  10861. QUnit.module.todo( 'Audio', () => {
  10862. // INHERITANCE
  10863. QUnit.test( "Extending", ( assert ) => {
  10864. assert.ok( false, "everything's gonna be alright" );
  10865. } );
  10866. // INSTANCING
  10867. QUnit.test( "Instancing", ( assert ) => {
  10868. assert.ok( false, "everything's gonna be alright" );
  10869. } );
  10870. // PUBLIC STUFF
  10871. QUnit.test( "getOutput", ( assert ) => {
  10872. assert.ok( false, "everything's gonna be alright" );
  10873. } );
  10874. QUnit.test( "setNodeSource", ( assert ) => {
  10875. assert.ok( false, "everything's gonna be alright" );
  10876. } );
  10877. QUnit.test( "setBuffer", ( assert ) => {
  10878. assert.ok( false, "everything's gonna be alright" );
  10879. } );
  10880. QUnit.test( "play", ( assert ) => {
  10881. assert.ok( false, "everything's gonna be alright" );
  10882. } );
  10883. QUnit.test( "pause", ( assert ) => {
  10884. assert.ok( false, "everything's gonna be alright" );
  10885. } );
  10886. QUnit.test( "stop", ( assert ) => {
  10887. assert.ok( false, "everything's gonna be alright" );
  10888. } );
  10889. QUnit.test( "connect", ( assert ) => {
  10890. assert.ok( false, "everything's gonna be alright" );
  10891. } );
  10892. QUnit.test( "disconnect", ( assert ) => {
  10893. assert.ok( false, "everything's gonna be alright" );
  10894. } );
  10895. QUnit.test( "getFilters", ( assert ) => {
  10896. assert.ok( false, "everything's gonna be alright" );
  10897. } );
  10898. QUnit.test( "setFilters", ( assert ) => {
  10899. assert.ok( false, "everything's gonna be alright" );
  10900. } );
  10901. QUnit.test( "getFilter", ( assert ) => {
  10902. assert.ok( false, "everything's gonna be alright" );
  10903. } );
  10904. QUnit.test( "setFilter", ( assert ) => {
  10905. assert.ok( false, "everything's gonna be alright" );
  10906. } );
  10907. QUnit.test( "setPlaybackRate", ( assert ) => {
  10908. assert.ok( false, "everything's gonna be alright" );
  10909. } );
  10910. QUnit.test( "getPlaybackRate", ( assert ) => {
  10911. assert.ok( false, "everything's gonna be alright" );
  10912. } );
  10913. QUnit.test( "onEnded", ( assert ) => {
  10914. assert.ok( false, "everything's gonna be alright" );
  10915. } );
  10916. QUnit.test( "getLoop", ( assert ) => {
  10917. assert.ok( false, "everything's gonna be alright" );
  10918. } );
  10919. QUnit.test( "setLoop", ( assert ) => {
  10920. assert.ok( false, "everything's gonna be alright" );
  10921. } );
  10922. QUnit.test( "getVolume", ( assert ) => {
  10923. assert.ok( false, "everything's gonna be alright" );
  10924. } );
  10925. QUnit.test( "setVolume", ( assert ) => {
  10926. assert.ok( false, "everything's gonna be alright" );
  10927. } );
  10928. } );
  10929. } );
  10930. /**
  10931. * @author mrdoob / http://mrdoob.com/
  10932. */
  10933. function AudioAnalyser( audio, fftSize ) {
  10934. this.analyser = audio.context.createAnalyser();
  10935. this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
  10936. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  10937. audio.getOutput().connect( this.analyser );
  10938. }
  10939. Object.assign( AudioAnalyser.prototype, {
  10940. getFrequencyData: function () {
  10941. this.analyser.getByteFrequencyData( this.data );
  10942. return this.data;
  10943. },
  10944. getAverageFrequency: function () {
  10945. var value = 0, data = this.getFrequencyData();
  10946. for ( var i = 0; i < data.length; i ++ ) {
  10947. value += data[ i ];
  10948. }
  10949. return value / data.length;
  10950. }
  10951. } );
  10952. /**
  10953. * @author TristanVALCKE / https://github.com/Itee
  10954. */
  10955. /* global QUnit */
  10956. QUnit.module( 'Audios', () => {
  10957. QUnit.module.todo( 'AudioAnalyser', () => {
  10958. // INSTANCING
  10959. QUnit.test( "Instancing", ( assert ) => {
  10960. assert.ok( false, "everything's gonna be alright" );
  10961. } );
  10962. // PUBLIC STUFF
  10963. QUnit.test( "getFrequencyData", ( assert ) => {
  10964. assert.ok( false, "everything's gonna be alright" );
  10965. } );
  10966. QUnit.test( "getAverageFrequency", ( assert ) => {
  10967. assert.ok( false, "everything's gonna be alright" );
  10968. } );
  10969. } );
  10970. } );
  10971. var context;
  10972. var AudioContext = {
  10973. getContext: function () {
  10974. if ( context === undefined ) {
  10975. context = new ( window.AudioContext || window.webkitAudioContext )();
  10976. }
  10977. return context;
  10978. },
  10979. setContext: function ( value ) {
  10980. context = value;
  10981. }
  10982. };
  10983. /**
  10984. * @author TristanVALCKE / https://github.com/Itee
  10985. */
  10986. /* global QUnit */
  10987. QUnit.module( 'Audios', () => {
  10988. QUnit.module.todo( 'AudioContext', () => {
  10989. // PUBLIC STUFF
  10990. QUnit.test( "getContext", ( assert ) => {
  10991. assert.ok( false, "everything's gonna be alright" );
  10992. } );
  10993. QUnit.test( "setContext", ( assert ) => {
  10994. assert.ok( false, "everything's gonna be alright" );
  10995. } );
  10996. } );
  10997. } );
  10998. /**
  10999. * @author mrdoob / http://mrdoob.com/
  11000. */
  11001. function AudioListener() {
  11002. Object3D.call( this );
  11003. this.type = 'AudioListener';
  11004. this.context = AudioContext.getContext();
  11005. this.gain = this.context.createGain();
  11006. this.gain.connect( this.context.destination );
  11007. this.filter = null;
  11008. }
  11009. AudioListener.prototype = Object.assign( Object.create( Object3D.prototype ), {
  11010. constructor: AudioListener,
  11011. getInput: function () {
  11012. return this.gain;
  11013. },
  11014. removeFilter: function ( ) {
  11015. if ( this.filter !== null ) {
  11016. this.gain.disconnect( this.filter );
  11017. this.filter.disconnect( this.context.destination );
  11018. this.gain.connect( this.context.destination );
  11019. this.filter = null;
  11020. }
  11021. },
  11022. getFilter: function () {
  11023. return this.filter;
  11024. },
  11025. setFilter: function ( value ) {
  11026. if ( this.filter !== null ) {
  11027. this.gain.disconnect( this.filter );
  11028. this.filter.disconnect( this.context.destination );
  11029. } else {
  11030. this.gain.disconnect( this.context.destination );
  11031. }
  11032. this.filter = value;
  11033. this.gain.connect( this.filter );
  11034. this.filter.connect( this.context.destination );
  11035. },
  11036. getMasterVolume: function () {
  11037. return this.gain.gain.value;
  11038. },
  11039. setMasterVolume: function ( value ) {
  11040. this.gain.gain.value = value;
  11041. },
  11042. updateMatrixWorld: ( function () {
  11043. var position = new Vector3();
  11044. var quaternion = new Quaternion();
  11045. var scale = new Vector3();
  11046. var orientation = new Vector3();
  11047. return function updateMatrixWorld( force ) {
  11048. Object3D.prototype.updateMatrixWorld.call( this, force );
  11049. var listener = this.context.listener;
  11050. var up = this.up;
  11051. this.matrixWorld.decompose( position, quaternion, scale );
  11052. orientation.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  11053. if ( listener.positionX ) {
  11054. listener.positionX.setValueAtTime( position.x, this.context.currentTime );
  11055. listener.positionY.setValueAtTime( position.y, this.context.currentTime );
  11056. listener.positionZ.setValueAtTime( position.z, this.context.currentTime );
  11057. listener.forwardX.setValueAtTime( orientation.x, this.context.currentTime );
  11058. listener.forwardY.setValueAtTime( orientation.y, this.context.currentTime );
  11059. listener.forwardZ.setValueAtTime( orientation.z, this.context.currentTime );
  11060. listener.upX.setValueAtTime( up.x, this.context.currentTime );
  11061. listener.upY.setValueAtTime( up.y, this.context.currentTime );
  11062. listener.upZ.setValueAtTime( up.z, this.context.currentTime );
  11063. } else {
  11064. listener.setPosition( position.x, position.y, position.z );
  11065. listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
  11066. }
  11067. };
  11068. } )()
  11069. } );
  11070. /**
  11071. * @author TristanVALCKE / https://github.com/Itee
  11072. */
  11073. /* global QUnit */
  11074. QUnit.module( 'Audios', () => {
  11075. QUnit.module.todo( 'AudioListener', () => {
  11076. // INHERITANCE
  11077. QUnit.test( "Extending", ( assert ) => {
  11078. assert.ok( false, "everything's gonna be alright" );
  11079. } );
  11080. // INSTANCING
  11081. QUnit.test( "Instancing", ( assert ) => {
  11082. assert.ok( false, "everything's gonna be alright" );
  11083. } );
  11084. // PUBLIC STUFF
  11085. QUnit.test( "getInput", ( assert ) => {
  11086. assert.ok( false, "everything's gonna be alright" );
  11087. } );
  11088. QUnit.test( "removeFilter", ( assert ) => {
  11089. assert.ok( false, "everything's gonna be alright" );
  11090. } );
  11091. QUnit.test( "getFilter", ( assert ) => {
  11092. assert.ok( false, "everything's gonna be alright" );
  11093. } );
  11094. QUnit.test( "setFilter", ( assert ) => {
  11095. assert.ok( false, "everything's gonna be alright" );
  11096. } );
  11097. QUnit.test( "getMasterVolume", ( assert ) => {
  11098. assert.ok( false, "everything's gonna be alright" );
  11099. } );
  11100. QUnit.test( "setMasterVolume", ( assert ) => {
  11101. assert.ok( false, "everything's gonna be alright" );
  11102. } );
  11103. QUnit.test( "updateMatrixWorld", ( assert ) => {
  11104. assert.ok( false, "everything's gonna be alright" );
  11105. } );
  11106. } );
  11107. } );
  11108. /**
  11109. * @author mrdoob / http://mrdoob.com/
  11110. */
  11111. function PositionalAudio( listener ) {
  11112. Audio.call( this, listener );
  11113. this.panner = this.context.createPanner();
  11114. this.panner.connect( this.gain );
  11115. }
  11116. PositionalAudio.prototype = Object.assign( Object.create( Audio.prototype ), {
  11117. constructor: PositionalAudio,
  11118. getOutput: function () {
  11119. return this.panner;
  11120. },
  11121. getRefDistance: function () {
  11122. return this.panner.refDistance;
  11123. },
  11124. setRefDistance: function ( value ) {
  11125. this.panner.refDistance = value;
  11126. },
  11127. getRolloffFactor: function () {
  11128. return this.panner.rolloffFactor;
  11129. },
  11130. setRolloffFactor: function ( value ) {
  11131. this.panner.rolloffFactor = value;
  11132. },
  11133. getDistanceModel: function () {
  11134. return this.panner.distanceModel;
  11135. },
  11136. setDistanceModel: function ( value ) {
  11137. this.panner.distanceModel = value;
  11138. },
  11139. getMaxDistance: function () {
  11140. return this.panner.maxDistance;
  11141. },
  11142. setMaxDistance: function ( value ) {
  11143. this.panner.maxDistance = value;
  11144. },
  11145. updateMatrixWorld: ( function () {
  11146. var position = new Vector3();
  11147. return function updateMatrixWorld( force ) {
  11148. Object3D.prototype.updateMatrixWorld.call( this, force );
  11149. position.setFromMatrixPosition( this.matrixWorld );
  11150. this.panner.setPosition( position.x, position.y, position.z );
  11151. };
  11152. } )()
  11153. } );
  11154. /**
  11155. * @author TristanVALCKE / https://github.com/Itee
  11156. */
  11157. /* global QUnit */
  11158. QUnit.module( 'Audios', () => {
  11159. QUnit.module.todo( 'PositionalAudio', () => {
  11160. // INHERITANCE
  11161. QUnit.test( "Extending", ( assert ) => {
  11162. assert.ok( false, "everything's gonna be alright" );
  11163. } );
  11164. // INSTANCING
  11165. QUnit.test( "Instancing", ( assert ) => {
  11166. assert.ok( false, "everything's gonna be alright" );
  11167. } );
  11168. // PUBLIC STUFF
  11169. QUnit.test( "getOutput", ( assert ) => {
  11170. assert.ok( false, "everything's gonna be alright" );
  11171. } );
  11172. QUnit.test( "getRefDistance", ( assert ) => {
  11173. assert.ok( false, "everything's gonna be alright" );
  11174. } );
  11175. QUnit.test( "setRefDistance", ( assert ) => {
  11176. assert.ok( false, "everything's gonna be alright" );
  11177. } );
  11178. QUnit.test( "getRolloffFactor", ( assert ) => {
  11179. assert.ok( false, "everything's gonna be alright" );
  11180. } );
  11181. QUnit.test( "setRolloffFactor", ( assert ) => {
  11182. assert.ok( false, "everything's gonna be alright" );
  11183. } );
  11184. QUnit.test( "getDistanceModel", ( assert ) => {
  11185. assert.ok( false, "everything's gonna be alright" );
  11186. } );
  11187. QUnit.test( "setDistanceModel", ( assert ) => {
  11188. assert.ok( false, "everything's gonna be alright" );
  11189. } );
  11190. QUnit.test( "getMaxDistance", ( assert ) => {
  11191. assert.ok( false, "everything's gonna be alright" );
  11192. } );
  11193. QUnit.test( "setMaxDistance", ( assert ) => {
  11194. assert.ok( false, "everything's gonna be alright" );
  11195. } );
  11196. QUnit.test( "updateMatrixWorld", ( assert ) => {
  11197. assert.ok( false, "everything's gonna be alright" );
  11198. } );
  11199. } );
  11200. } );
  11201. /**
  11202. * @author mrdoob / http://mrdoob.com/
  11203. * @author mikael emtinger / http://gomo.se/
  11204. * @author WestLangley / http://github.com/WestLangley
  11205. */
  11206. function Camera() {
  11207. Object3D.call( this );
  11208. this.type = 'Camera';
  11209. this.matrixWorldInverse = new Matrix4();
  11210. this.projectionMatrix = new Matrix4();
  11211. }
  11212. Camera.prototype = Object.assign( Object.create( Object3D.prototype ), {
  11213. constructor: Camera,
  11214. isCamera: true,
  11215. copy: function ( source, recursive ) {
  11216. Object3D.prototype.copy.call( this, source, recursive );
  11217. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  11218. this.projectionMatrix.copy( source.projectionMatrix );
  11219. return this;
  11220. },
  11221. getWorldDirection: function () {
  11222. var quaternion = new Quaternion();
  11223. return function getWorldDirection( optionalTarget ) {
  11224. var result = optionalTarget || new Vector3();
  11225. this.getWorldQuaternion( quaternion );
  11226. return result.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  11227. };
  11228. }(),
  11229. updateMatrixWorld: function ( force ) {
  11230. Object3D.prototype.updateMatrixWorld.call( this, force );
  11231. this.matrixWorldInverse.getInverse( this.matrixWorld );
  11232. },
  11233. clone: function () {
  11234. return new this.constructor().copy( this );
  11235. }
  11236. } );
  11237. /**
  11238. * @author mrdoob / http://mrdoob.com/
  11239. * @author greggman / http://games.greggman.com/
  11240. * @author zz85 / http://www.lab4games.net/zz85/blog
  11241. * @author tschw
  11242. */
  11243. function PerspectiveCamera( fov, aspect, near, far ) {
  11244. Camera.call( this );
  11245. this.type = 'PerspectiveCamera';
  11246. this.fov = fov !== undefined ? fov : 50;
  11247. this.zoom = 1;
  11248. this.near = near !== undefined ? near : 0.1;
  11249. this.far = far !== undefined ? far : 2000;
  11250. this.focus = 10;
  11251. this.aspect = aspect !== undefined ? aspect : 1;
  11252. this.view = null;
  11253. this.filmGauge = 35; // width of the film (default in millimeters)
  11254. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  11255. this.updateProjectionMatrix();
  11256. }
  11257. PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  11258. constructor: PerspectiveCamera,
  11259. isPerspectiveCamera: true,
  11260. copy: function ( source, recursive ) {
  11261. Camera.prototype.copy.call( this, source, recursive );
  11262. this.fov = source.fov;
  11263. this.zoom = source.zoom;
  11264. this.near = source.near;
  11265. this.far = source.far;
  11266. this.focus = source.focus;
  11267. this.aspect = source.aspect;
  11268. this.view = source.view === null ? null : Object.assign( {}, source.view );
  11269. this.filmGauge = source.filmGauge;
  11270. this.filmOffset = source.filmOffset;
  11271. return this;
  11272. },
  11273. /**
  11274. * Sets the FOV by focal length in respect to the current .filmGauge.
  11275. *
  11276. * The default film gauge is 35, so that the focal length can be specified for
  11277. * a 35mm (full frame) camera.
  11278. *
  11279. * Values for focal length and film gauge must have the same unit.
  11280. */
  11281. setFocalLength: function ( focalLength ) {
  11282. // see http://www.bobatkins.com/photography/technical/field_of_view.html
  11283. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  11284. this.fov = _Math.RAD2DEG * 2 * Math.atan( vExtentSlope );
  11285. this.updateProjectionMatrix();
  11286. },
  11287. /**
  11288. * Calculates the focal length from the current .fov and .filmGauge.
  11289. */
  11290. getFocalLength: function () {
  11291. var vExtentSlope = Math.tan( _Math.DEG2RAD * 0.5 * this.fov );
  11292. return 0.5 * this.getFilmHeight() / vExtentSlope;
  11293. },
  11294. getEffectiveFOV: function () {
  11295. return _Math.RAD2DEG * 2 * Math.atan(
  11296. Math.tan( _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom );
  11297. },
  11298. getFilmWidth: function () {
  11299. // film not completely covered in portrait format (aspect < 1)
  11300. return this.filmGauge * Math.min( this.aspect, 1 );
  11301. },
  11302. getFilmHeight: function () {
  11303. // film not completely covered in landscape format (aspect > 1)
  11304. return this.filmGauge / Math.max( this.aspect, 1 );
  11305. },
  11306. /**
  11307. * Sets an offset in a larger frustum. This is useful for multi-window or
  11308. * multi-monitor/multi-machine setups.
  11309. *
  11310. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  11311. * the monitors are in grid like this
  11312. *
  11313. * +---+---+---+
  11314. * | A | B | C |
  11315. * +---+---+---+
  11316. * | D | E | F |
  11317. * +---+---+---+
  11318. *
  11319. * then for each monitor you would call it like this
  11320. *
  11321. * var w = 1920;
  11322. * var h = 1080;
  11323. * var fullWidth = w * 3;
  11324. * var fullHeight = h * 2;
  11325. *
  11326. * --A--
  11327. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  11328. * --B--
  11329. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  11330. * --C--
  11331. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  11332. * --D--
  11333. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  11334. * --E--
  11335. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  11336. * --F--
  11337. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  11338. *
  11339. * Note there is no reason monitors have to be the same size or in a grid.
  11340. */
  11341. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  11342. this.aspect = fullWidth / fullHeight;
  11343. if ( this.view === null ) {
  11344. this.view = {
  11345. enabled: true,
  11346. fullWidth: 1,
  11347. fullHeight: 1,
  11348. offsetX: 0,
  11349. offsetY: 0,
  11350. width: 1,
  11351. height: 1
  11352. };
  11353. }
  11354. this.view.enabled = true;
  11355. this.view.fullWidth = fullWidth;
  11356. this.view.fullHeight = fullHeight;
  11357. this.view.offsetX = x;
  11358. this.view.offsetY = y;
  11359. this.view.width = width;
  11360. this.view.height = height;
  11361. this.updateProjectionMatrix();
  11362. },
  11363. clearViewOffset: function () {
  11364. if ( this.view !== null ) {
  11365. this.view.enabled = false;
  11366. }
  11367. this.updateProjectionMatrix();
  11368. },
  11369. updateProjectionMatrix: function () {
  11370. var near = this.near,
  11371. top = near * Math.tan(
  11372. _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom,
  11373. height = 2 * top,
  11374. width = this.aspect * height,
  11375. left = - 0.5 * width,
  11376. view = this.view;
  11377. if ( this.view !== null && this.view.enabled ) {
  11378. var fullWidth = view.fullWidth,
  11379. fullHeight = view.fullHeight;
  11380. left += view.offsetX * width / fullWidth;
  11381. top -= view.offsetY * height / fullHeight;
  11382. width *= view.width / fullWidth;
  11383. height *= view.height / fullHeight;
  11384. }
  11385. var skew = this.filmOffset;
  11386. if ( skew !== 0 ) left += near * skew / this.getFilmWidth();
  11387. this.projectionMatrix.makePerspective( left, left + width, top, top - height, near, this.far );
  11388. },
  11389. toJSON: function ( meta ) {
  11390. var data = Object3D.prototype.toJSON.call( this, meta );
  11391. data.object.fov = this.fov;
  11392. data.object.zoom = this.zoom;
  11393. data.object.near = this.near;
  11394. data.object.far = this.far;
  11395. data.object.focus = this.focus;
  11396. data.object.aspect = this.aspect;
  11397. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  11398. data.object.filmGauge = this.filmGauge;
  11399. data.object.filmOffset = this.filmOffset;
  11400. return data;
  11401. }
  11402. } );
  11403. /**
  11404. * @author mrdoob / http://mrdoob.com/
  11405. */
  11406. function ArrayCamera( array ) {
  11407. PerspectiveCamera.call( this );
  11408. this.cameras = array || [];
  11409. }
  11410. ArrayCamera.prototype = Object.assign( Object.create( PerspectiveCamera.prototype ), {
  11411. constructor: ArrayCamera,
  11412. isArrayCamera: true
  11413. } );
  11414. /**
  11415. * @author TristanVALCKE / https://github.com/Itee
  11416. */
  11417. /* global QUnit */
  11418. QUnit.module( 'Cameras', () => {
  11419. QUnit.module.todo( 'ArrayCamera', () => {
  11420. // INHERITANCE
  11421. QUnit.test( "Extending", ( assert ) => {
  11422. assert.ok( false, "everything's gonna be alright" );
  11423. } );
  11424. // INSTANCING
  11425. QUnit.test( "Instancing", ( assert ) => {
  11426. assert.ok( false, "everything's gonna be alright" );
  11427. } );
  11428. // PUBLIC STUFF
  11429. QUnit.test( "isArrayCamera", ( assert ) => {
  11430. assert.ok( false, "everything's gonna be alright" );
  11431. } );
  11432. } );
  11433. } );
  11434. /**
  11435. * @author simonThiele / https://github.com/simonThiele
  11436. * @author TristanVALCKE / https://github.com/Itee
  11437. */
  11438. /* global QUnit */
  11439. QUnit.module( 'Cameras', () => {
  11440. QUnit.module.todo( 'Camera', () => {
  11441. // INHERITANCE
  11442. QUnit.test( "Extending", ( assert ) => {
  11443. assert.ok( false, "everything's gonna be alright" );
  11444. } );
  11445. // INSTANCING
  11446. QUnit.test( "Instancing", ( assert ) => {
  11447. assert.ok( false, "everything's gonna be alright" );
  11448. } );
  11449. // PUBLIC STUFF
  11450. QUnit.test( "isCamera", ( assert ) => {
  11451. assert.ok( false, "everything's gonna be alright" );
  11452. } );
  11453. QUnit.test( "copy", ( assert ) => {
  11454. assert.ok( false, "everything's gonna be alright" );
  11455. } );
  11456. QUnit.test( "getWorldDirection", ( assert ) => {
  11457. assert.ok( false, "everything's gonna be alright" );
  11458. } );
  11459. QUnit.test( "updateMatrixWorld", ( assert ) => {
  11460. assert.ok( false, "everything's gonna be alright" );
  11461. } );
  11462. QUnit.test( "clone", ( assert ) => {
  11463. var cam = new Camera();
  11464. // fill the matrices with any nonsense values just to see if they get copied
  11465. cam.matrixWorldInverse.set( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 );
  11466. cam.projectionMatrix.set( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 );
  11467. var clonedCam = cam.clone();
  11468. // TODO: Uuuummmhhh DO NOT relie equality on object methods !
  11469. // TODO: What's append if matrix.equal is wrongly implemented ???
  11470. // TODO: this MUST be check by assert
  11471. assert.ok( cam.matrixWorldInverse.equals( clonedCam.matrixWorldInverse ), "matrixWorldInverse is equal" );
  11472. assert.ok( cam.projectionMatrix.equals( clonedCam.projectionMatrix ), "projectionMatrix is equal" );
  11473. } );
  11474. // OTHERS
  11475. // TODO: this should not be here !!! This is Object3D stuff !!!
  11476. QUnit.test( "lookAt", ( assert ) => {
  11477. var cam = new Camera();
  11478. cam.lookAt( new Vector3( 0, 1, - 1 ) );
  11479. assert.numEqual( cam.rotation.x * ( 180 / Math.PI ), 45, "x is equal" );
  11480. } );
  11481. } );
  11482. } );
  11483. /**
  11484. * @author mrdoob / http://mrdoob.com/
  11485. * @author alteredq / http://alteredqualia.com/
  11486. * @author szimek / https://github.com/szimek/
  11487. */
  11488. var textureId = 0;
  11489. function Texture( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  11490. Object.defineProperty( this, 'id', { value: textureId ++ } );
  11491. this.uuid = _Math.generateUUID();
  11492. this.name = '';
  11493. this.image = image !== undefined ? image : Texture.DEFAULT_IMAGE;
  11494. this.mipmaps = [];
  11495. this.mapping = mapping !== undefined ? mapping : Texture.DEFAULT_MAPPING;
  11496. this.wrapS = wrapS !== undefined ? wrapS : ClampToEdgeWrapping;
  11497. this.wrapT = wrapT !== undefined ? wrapT : ClampToEdgeWrapping;
  11498. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  11499. this.minFilter = minFilter !== undefined ? minFilter : LinearMipMapLinearFilter;
  11500. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  11501. this.format = format !== undefined ? format : RGBAFormat;
  11502. this.type = type !== undefined ? type : UnsignedByteType;
  11503. this.offset = new Vector2( 0, 0 );
  11504. this.repeat = new Vector2( 1, 1 );
  11505. this.center = new Vector2( 0, 0 );
  11506. this.rotation = 0;
  11507. this.matrixAutoUpdate = true;
  11508. this.matrix = new Matrix3();
  11509. this.generateMipmaps = true;
  11510. this.premultiplyAlpha = false;
  11511. this.flipY = true;
  11512. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  11513. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  11514. //
  11515. // Also changing the encoding after already used by a Material will not automatically make the Material
  11516. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  11517. this.encoding = encoding !== undefined ? encoding : LinearEncoding;
  11518. this.version = 0;
  11519. this.onUpdate = null;
  11520. }
  11521. Texture.DEFAULT_IMAGE = undefined;
  11522. Texture.DEFAULT_MAPPING = UVMapping;
  11523. Object.defineProperty( Texture.prototype, "needsUpdate", {
  11524. set: function ( value ) {
  11525. if ( value === true ) this.version ++;
  11526. }
  11527. } );
  11528. Object.assign( Texture.prototype, EventDispatcher.prototype, {
  11529. constructor: Texture,
  11530. isTexture: true,
  11531. clone: function () {
  11532. return new this.constructor().copy( this );
  11533. },
  11534. copy: function ( source ) {
  11535. this.name = source.name;
  11536. this.image = source.image;
  11537. this.mipmaps = source.mipmaps.slice( 0 );
  11538. this.mapping = source.mapping;
  11539. this.wrapS = source.wrapS;
  11540. this.wrapT = source.wrapT;
  11541. this.magFilter = source.magFilter;
  11542. this.minFilter = source.minFilter;
  11543. this.anisotropy = source.anisotropy;
  11544. this.format = source.format;
  11545. this.type = source.type;
  11546. this.offset.copy( source.offset );
  11547. this.repeat.copy( source.repeat );
  11548. this.center.copy( source.center );
  11549. this.rotation = source.rotation;
  11550. this.matrixAutoUpdate = source.matrixAutoUpdate;
  11551. this.matrix.copy( source.matrix );
  11552. this.generateMipmaps = source.generateMipmaps;
  11553. this.premultiplyAlpha = source.premultiplyAlpha;
  11554. this.flipY = source.flipY;
  11555. this.unpackAlignment = source.unpackAlignment;
  11556. this.encoding = source.encoding;
  11557. return this;
  11558. },
  11559. toJSON: function ( meta ) {
  11560. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  11561. if ( ! isRootObject && meta.textures[ this.uuid ] !== undefined ) {
  11562. return meta.textures[ this.uuid ];
  11563. }
  11564. function getDataURL( image ) {
  11565. var canvas;
  11566. if ( image instanceof HTMLCanvasElement ) {
  11567. canvas = image;
  11568. } else {
  11569. canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  11570. canvas.width = image.width;
  11571. canvas.height = image.height;
  11572. var context = canvas.getContext( '2d' );
  11573. if ( image instanceof ImageData ) {
  11574. context.putImageData( image, 0, 0 );
  11575. } else {
  11576. context.drawImage( image, 0, 0, image.width, image.height );
  11577. }
  11578. }
  11579. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  11580. return canvas.toDataURL( 'image/jpeg', 0.6 );
  11581. } else {
  11582. return canvas.toDataURL( 'image/png' );
  11583. }
  11584. }
  11585. var output = {
  11586. metadata: {
  11587. version: 4.5,
  11588. type: 'Texture',
  11589. generator: 'Texture.toJSON'
  11590. },
  11591. uuid: this.uuid,
  11592. name: this.name,
  11593. mapping: this.mapping,
  11594. repeat: [ this.repeat.x, this.repeat.y ],
  11595. offset: [ this.offset.x, this.offset.y ],
  11596. center: [ this.center.x, this.center.y ],
  11597. rotation: this.rotation,
  11598. wrap: [ this.wrapS, this.wrapT ],
  11599. minFilter: this.minFilter,
  11600. magFilter: this.magFilter,
  11601. anisotropy: this.anisotropy,
  11602. flipY: this.flipY
  11603. };
  11604. if ( this.image !== undefined ) {
  11605. // TODO: Move to THREE.Image
  11606. var image = this.image;
  11607. if ( image.uuid === undefined ) {
  11608. image.uuid = _Math.generateUUID(); // UGH
  11609. }
  11610. if ( ! isRootObject && meta.images[ image.uuid ] === undefined ) {
  11611. meta.images[ image.uuid ] = {
  11612. uuid: image.uuid,
  11613. url: getDataURL( image )
  11614. };
  11615. }
  11616. output.image = image.uuid;
  11617. }
  11618. if ( ! isRootObject ) {
  11619. meta.textures[ this.uuid ] = output;
  11620. }
  11621. return output;
  11622. },
  11623. dispose: function () {
  11624. this.dispatchEvent( { type: 'dispose' } );
  11625. },
  11626. transformUv: function ( uv ) {
  11627. if ( this.mapping !== UVMapping ) return;
  11628. uv.applyMatrix3( this.matrix );
  11629. if ( uv.x < 0 || uv.x > 1 ) {
  11630. switch ( this.wrapS ) {
  11631. case RepeatWrapping:
  11632. uv.x = uv.x - Math.floor( uv.x );
  11633. break;
  11634. case ClampToEdgeWrapping:
  11635. uv.x = uv.x < 0 ? 0 : 1;
  11636. break;
  11637. case MirroredRepeatWrapping:
  11638. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  11639. uv.x = Math.ceil( uv.x ) - uv.x;
  11640. } else {
  11641. uv.x = uv.x - Math.floor( uv.x );
  11642. }
  11643. break;
  11644. }
  11645. }
  11646. if ( uv.y < 0 || uv.y > 1 ) {
  11647. switch ( this.wrapT ) {
  11648. case RepeatWrapping:
  11649. uv.y = uv.y - Math.floor( uv.y );
  11650. break;
  11651. case ClampToEdgeWrapping:
  11652. uv.y = uv.y < 0 ? 0 : 1;
  11653. break;
  11654. case MirroredRepeatWrapping:
  11655. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  11656. uv.y = Math.ceil( uv.y ) - uv.y;
  11657. } else {
  11658. uv.y = uv.y - Math.floor( uv.y );
  11659. }
  11660. break;
  11661. }
  11662. }
  11663. if ( this.flipY ) {
  11664. uv.y = 1 - uv.y;
  11665. }
  11666. }
  11667. } );
  11668. /**
  11669. * @author szimek / https://github.com/szimek/
  11670. * @author alteredq / http://alteredqualia.com/
  11671. * @author Marius Kintel / https://github.com/kintel
  11672. */
  11673. /*
  11674. In options, we can specify:
  11675. * Texture parameters for an auto-generated target texture
  11676. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  11677. */
  11678. function WebGLRenderTarget( width, height, options ) {
  11679. this.uuid = _Math.generateUUID();
  11680. this.width = width;
  11681. this.height = height;
  11682. this.scissor = new Vector4( 0, 0, width, height );
  11683. this.scissorTest = false;
  11684. this.viewport = new Vector4( 0, 0, width, height );
  11685. options = options || {};
  11686. if ( options.minFilter === undefined ) options.minFilter = LinearFilter;
  11687. this.texture = new Texture( undefined, undefined, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
  11688. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  11689. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  11690. this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  11691. }
  11692. Object.assign( WebGLRenderTarget.prototype, EventDispatcher.prototype, {
  11693. isWebGLRenderTarget: true,
  11694. setSize: function ( width, height ) {
  11695. if ( this.width !== width || this.height !== height ) {
  11696. this.width = width;
  11697. this.height = height;
  11698. this.dispose();
  11699. }
  11700. this.viewport.set( 0, 0, width, height );
  11701. this.scissor.set( 0, 0, width, height );
  11702. },
  11703. clone: function () {
  11704. return new this.constructor().copy( this );
  11705. },
  11706. copy: function ( source ) {
  11707. this.width = source.width;
  11708. this.height = source.height;
  11709. this.viewport.copy( source.viewport );
  11710. this.texture = source.texture.clone();
  11711. this.depthBuffer = source.depthBuffer;
  11712. this.stencilBuffer = source.stencilBuffer;
  11713. this.depthTexture = source.depthTexture;
  11714. return this;
  11715. },
  11716. dispose: function () {
  11717. this.dispatchEvent( { type: 'dispose' } );
  11718. }
  11719. } );
  11720. /**
  11721. * @author TristanVALCKE / https://github.com/Itee
  11722. */
  11723. /* global QUnit */
  11724. QUnit.module( 'Cameras', () => {
  11725. QUnit.module.todo( 'CubeCamera', () => {
  11726. // INHERITANCE
  11727. QUnit.test( "Extending", ( assert ) => {
  11728. assert.ok( false, "everything's gonna be alright" );
  11729. } );
  11730. // INSTANCING
  11731. QUnit.test( "Instancing", ( assert ) => {
  11732. assert.ok( false, "everything's gonna be alright" );
  11733. } );
  11734. } );
  11735. } );
  11736. /**
  11737. * @author alteredq / http://alteredqualia.com/
  11738. * @author arose / http://github.com/arose
  11739. */
  11740. function OrthographicCamera( left, right, top, bottom, near, far ) {
  11741. Camera.call( this );
  11742. this.type = 'OrthographicCamera';
  11743. this.zoom = 1;
  11744. this.view = null;
  11745. this.left = left;
  11746. this.right = right;
  11747. this.top = top;
  11748. this.bottom = bottom;
  11749. this.near = ( near !== undefined ) ? near : 0.1;
  11750. this.far = ( far !== undefined ) ? far : 2000;
  11751. this.updateProjectionMatrix();
  11752. }
  11753. OrthographicCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  11754. constructor: OrthographicCamera,
  11755. isOrthographicCamera: true,
  11756. copy: function ( source, recursive ) {
  11757. Camera.prototype.copy.call( this, source, recursive );
  11758. this.left = source.left;
  11759. this.right = source.right;
  11760. this.top = source.top;
  11761. this.bottom = source.bottom;
  11762. this.near = source.near;
  11763. this.far = source.far;
  11764. this.zoom = source.zoom;
  11765. this.view = source.view === null ? null : Object.assign( {}, source.view );
  11766. return this;
  11767. },
  11768. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  11769. if ( this.view === null ) {
  11770. this.view = {
  11771. enabled: true,
  11772. fullWidth: 1,
  11773. fullHeight: 1,
  11774. offsetX: 0,
  11775. offsetY: 0,
  11776. width: 1,
  11777. height: 1
  11778. };
  11779. }
  11780. this.view.enabled = true;
  11781. this.view.fullWidth = fullWidth;
  11782. this.view.fullHeight = fullHeight;
  11783. this.view.offsetX = x;
  11784. this.view.offsetY = y;
  11785. this.view.width = width;
  11786. this.view.height = height;
  11787. this.updateProjectionMatrix();
  11788. },
  11789. clearViewOffset: function () {
  11790. if ( this.view !== null ) {
  11791. this.view.enabled = false;
  11792. }
  11793. this.updateProjectionMatrix();
  11794. },
  11795. updateProjectionMatrix: function () {
  11796. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  11797. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  11798. var cx = ( this.right + this.left ) / 2;
  11799. var cy = ( this.top + this.bottom ) / 2;
  11800. var left = cx - dx;
  11801. var right = cx + dx;
  11802. var top = cy + dy;
  11803. var bottom = cy - dy;
  11804. if ( this.view !== null && this.view.enabled ) {
  11805. var zoomW = this.zoom / ( this.view.width / this.view.fullWidth );
  11806. var zoomH = this.zoom / ( this.view.height / this.view.fullHeight );
  11807. var scaleW = ( this.right - this.left ) / this.view.width;
  11808. var scaleH = ( this.top - this.bottom ) / this.view.height;
  11809. left += scaleW * ( this.view.offsetX / zoomW );
  11810. right = left + scaleW * ( this.view.width / zoomW );
  11811. top -= scaleH * ( this.view.offsetY / zoomH );
  11812. bottom = top - scaleH * ( this.view.height / zoomH );
  11813. }
  11814. this.projectionMatrix.makeOrthographic( left, right, top, bottom, this.near, this.far );
  11815. },
  11816. toJSON: function ( meta ) {
  11817. var data = Object3D.prototype.toJSON.call( this, meta );
  11818. data.object.zoom = this.zoom;
  11819. data.object.left = this.left;
  11820. data.object.right = this.right;
  11821. data.object.top = this.top;
  11822. data.object.bottom = this.bottom;
  11823. data.object.near = this.near;
  11824. data.object.far = this.far;
  11825. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  11826. return data;
  11827. }
  11828. } );
  11829. /**
  11830. * @author simonThiele / https://github.com/simonThiele
  11831. * @author TristanVALCKE / https://github.com/Itee
  11832. */
  11833. /* global QUnit */
  11834. QUnit.module( 'Cameras', () => {
  11835. QUnit.module.todo( 'OrthographicCamera', () => {
  11836. // INHERITANCE
  11837. QUnit.test( "Extending", ( assert ) => {
  11838. assert.ok( false, "everything's gonna be alright" );
  11839. } );
  11840. // INSTANCING
  11841. QUnit.test( "Instancing", ( assert ) => {
  11842. assert.ok( false, "everything's gonna be alright" );
  11843. } );
  11844. // PUBLIC STUFF
  11845. QUnit.test( "isOrthographicCamera", ( assert ) => {
  11846. assert.ok( false, "everything's gonna be alright" );
  11847. } );
  11848. QUnit.test( "copy", ( assert ) => {
  11849. assert.ok( false, "everything's gonna be alright" );
  11850. } );
  11851. QUnit.test( "setViewOffset", ( assert ) => {
  11852. assert.ok( false, "everything's gonna be alright" );
  11853. } );
  11854. QUnit.test( "clearViewOffset", ( assert ) => {
  11855. assert.ok( false, "everything's gonna be alright" );
  11856. } );
  11857. QUnit.test( "updateProjectionMatrix", ( assert ) => {
  11858. var left = - 1, right = 1, top = 1, bottom = - 1, near = 1, far = 3;
  11859. var cam = new OrthographicCamera( left, right, top, bottom, near, far );
  11860. // updateProjectionMatrix is called in contructor
  11861. var pMatrix = cam.projectionMatrix.elements;
  11862. // orthographic projection is given my the 4x4 Matrix
  11863. // 2/r-l 0 0 -(l+r/r-l)
  11864. // 0 2/t-b 0 -(t+b/t-b)
  11865. // 0 0 -2/f-n -(f+n/f-n)
  11866. // 0 0 0 1
  11867. assert.ok( pMatrix[ 0 ] === 2 / ( right - left ), "m[0,0] === 2 / (r - l)" );
  11868. assert.ok( pMatrix[ 5 ] === 2 / ( top - bottom ), "m[1,1] === 2 / (t - b)" );
  11869. assert.ok( pMatrix[ 10 ] === - 2 / ( far - near ), "m[2,2] === -2 / (f - n)" );
  11870. assert.ok( pMatrix[ 12 ] === - ( ( right + left ) / ( right - left ) ), "m[3,0] === -(r+l/r-l)" );
  11871. assert.ok( pMatrix[ 13 ] === - ( ( top + bottom ) / ( top - bottom ) ), "m[3,1] === -(t+b/b-t)" );
  11872. assert.ok( pMatrix[ 14 ] === - ( ( far + near ) / ( far - near ) ), "m[3,2] === -(f+n/f-n)" );
  11873. } );
  11874. QUnit.test( "toJSON", ( assert ) => {
  11875. assert.ok( false, "everything's gonna be alright" );
  11876. } );
  11877. // OTHERS
  11878. // TODO: no no no clone is a camera methods that relied to copy method
  11879. QUnit.test( "clone", ( assert ) => {
  11880. var left = - 1.5, right = 1.5, top = 1, bottom = - 1, near = 0.1, far = 42;
  11881. var cam = new OrthographicCamera( left, right, top, bottom, near, far );
  11882. var clonedCam = cam.clone();
  11883. assert.ok( cam.left === clonedCam.left, "left is equal" );
  11884. assert.ok( cam.right === clonedCam.right, "right is equal" );
  11885. assert.ok( cam.top === clonedCam.top, "top is equal" );
  11886. assert.ok( cam.bottom === clonedCam.bottom, "bottom is equal" );
  11887. assert.ok( cam.near === clonedCam.near, "near is equal" );
  11888. assert.ok( cam.far === clonedCam.far, "far is equal" );
  11889. assert.ok( cam.zoom === clonedCam.zoom, "zoom is equal" );
  11890. } );
  11891. } );
  11892. } );
  11893. /**
  11894. * @author simonThiele / https://github.com/simonThiele
  11895. * @author TristanVALCKE / https://github.com/Itee
  11896. */
  11897. /* global QUnit */
  11898. QUnit.module( 'Cameras', () => {
  11899. QUnit.module.todo( 'PerspectiveCamera', () => {
  11900. // see e.g. math/Matrix4.js
  11901. var matrixEquals4 = function ( a, b, tolerance ) {
  11902. tolerance = tolerance || 0.0001;
  11903. if ( a.elements.length != b.elements.length ) {
  11904. return false;
  11905. }
  11906. for ( var i = 0, il = a.elements.length; i < il; i ++ ) {
  11907. var delta = a.elements[ i ] - b.elements[ i ];
  11908. if ( delta > tolerance ) {
  11909. return false;
  11910. }
  11911. }
  11912. return true;
  11913. };
  11914. // INHERITANCE
  11915. QUnit.test( "Extending", ( assert ) => {
  11916. assert.ok( false, "everything's gonna be alright" );
  11917. } );
  11918. // INSTANCING
  11919. QUnit.test( "Instancing", ( assert ) => {
  11920. assert.ok( false, "everything's gonna be alright" );
  11921. } );
  11922. // PUBLIC STUFF
  11923. QUnit.test( "isPerspectiveCamera", ( assert ) => {
  11924. assert.ok( false, "everything's gonna be alright" );
  11925. } );
  11926. QUnit.test( "copy", ( assert ) => {
  11927. assert.ok( false, "everything's gonna be alright" );
  11928. } );
  11929. QUnit.test( "setFocalLength", ( assert ) => {
  11930. assert.ok( false, "everything's gonna be alright" );
  11931. } );
  11932. QUnit.test( "getFocalLength", ( assert ) => {
  11933. assert.ok( false, "everything's gonna be alright" );
  11934. } );
  11935. QUnit.test( "getEffectiveFOV", ( assert ) => {
  11936. assert.ok( false, "everything's gonna be alright" );
  11937. } );
  11938. QUnit.test( "getFilmWidth", ( assert ) => {
  11939. assert.ok( false, "everything's gonna be alright" );
  11940. } );
  11941. QUnit.test( "getFilmHeight", ( assert ) => {
  11942. assert.ok( false, "everything's gonna be alright" );
  11943. } );
  11944. QUnit.test( "setViewOffset", ( assert ) => {
  11945. assert.ok( false, "everything's gonna be alright" );
  11946. } );
  11947. QUnit.test( "clearViewOffset", ( assert ) => {
  11948. assert.ok( false, "everything's gonna be alright" );
  11949. } );
  11950. QUnit.test( "updateProjectionMatrix", ( assert ) => {
  11951. var cam = new PerspectiveCamera( 75, 16 / 9, 0.1, 300.0 );
  11952. // updateProjectionMatrix is called in contructor
  11953. var m = cam.projectionMatrix;
  11954. // perspective projection is given my the 4x4 Matrix
  11955. // 2n/r-l 0 l+r/r-l 0
  11956. // 0 2n/t-b t+b/t-b 0
  11957. // 0 0 -(f+n/f-n) -(2fn/f-n)
  11958. // 0 0 -1 0
  11959. // this matrix was calculated by hand via glMatrix.perspective(75, 16 / 9, 0.1, 300.0, pMatrix)
  11960. // to get a reference matrix from plain WebGL
  11961. var reference = new Matrix4().set(
  11962. 0.7330642938613892, 0, 0, 0,
  11963. 0, 1.3032253980636597, 0, 0,
  11964. 0, 0, - 1.000666856765747, - 0.2000666856765747,
  11965. 0, 0, - 1, 0
  11966. );
  11967. // assert.ok( reference.equals(m) );
  11968. assert.ok( matrixEquals4( reference, m, 0.000001 ) );
  11969. } );
  11970. QUnit.test( "toJSON", ( assert ) => {
  11971. assert.ok( false, "everything's gonna be alright" );
  11972. } );
  11973. // OTHERS
  11974. // TODO: no no no clone is a camera methods that relied to copy method
  11975. QUnit.test( "clone", ( assert ) => {
  11976. var near = 1,
  11977. far = 3,
  11978. aspect = 16 / 9,
  11979. fov = 90;
  11980. var cam = new PerspectiveCamera( fov, aspect, near, far );
  11981. var clonedCam = cam.clone();
  11982. assert.ok( cam.fov === clonedCam.fov, "fov is equal" );
  11983. assert.ok( cam.aspect === clonedCam.aspect, "aspect is equal" );
  11984. assert.ok( cam.near === clonedCam.near, "near is equal" );
  11985. assert.ok( cam.far === clonedCam.far, "far is equal" );
  11986. assert.ok( cam.zoom === clonedCam.zoom, "zoom is equal" );
  11987. assert.ok( cam.projectionMatrix.equals( clonedCam.projectionMatrix ), "projectionMatrix is equal" );
  11988. } );
  11989. } );
  11990. } );
  11991. /**
  11992. * @author mrdoob / http://mrdoob.com/
  11993. */
  11994. function StereoCamera() {
  11995. this.type = 'StereoCamera';
  11996. this.aspect = 1;
  11997. this.eyeSep = 0.064;
  11998. this.cameraL = new PerspectiveCamera();
  11999. this.cameraL.layers.enable( 1 );
  12000. this.cameraL.matrixAutoUpdate = false;
  12001. this.cameraR = new PerspectiveCamera();
  12002. this.cameraR.layers.enable( 2 );
  12003. this.cameraR.matrixAutoUpdate = false;
  12004. }
  12005. Object.assign( StereoCamera.prototype, {
  12006. update: ( function () {
  12007. var instance, focus, fov, aspect, near, far, zoom, eyeSep;
  12008. var eyeRight = new Matrix4();
  12009. var eyeLeft = new Matrix4();
  12010. return function update( camera ) {
  12011. var needsUpdate = instance !== this || focus !== camera.focus || fov !== camera.fov ||
  12012. aspect !== camera.aspect * this.aspect || near !== camera.near ||
  12013. far !== camera.far || zoom !== camera.zoom || eyeSep !== this.eyeSep;
  12014. if ( needsUpdate ) {
  12015. instance = this;
  12016. focus = camera.focus;
  12017. fov = camera.fov;
  12018. aspect = camera.aspect * this.aspect;
  12019. near = camera.near;
  12020. far = camera.far;
  12021. zoom = camera.zoom;
  12022. // Off-axis stereoscopic effect based on
  12023. // http://paulbourke.net/stereographics/stereorender/
  12024. var projectionMatrix = camera.projectionMatrix.clone();
  12025. eyeSep = this.eyeSep / 2;
  12026. var eyeSepOnProjection = eyeSep * near / focus;
  12027. var ymax = ( near * Math.tan( _Math.DEG2RAD * fov * 0.5 ) ) / zoom;
  12028. var xmin, xmax;
  12029. // translate xOffset
  12030. eyeLeft.elements[ 12 ] = - eyeSep;
  12031. eyeRight.elements[ 12 ] = eyeSep;
  12032. // for left eye
  12033. xmin = - ymax * aspect + eyeSepOnProjection;
  12034. xmax = ymax * aspect + eyeSepOnProjection;
  12035. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  12036. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  12037. this.cameraL.projectionMatrix.copy( projectionMatrix );
  12038. // for right eye
  12039. xmin = - ymax * aspect - eyeSepOnProjection;
  12040. xmax = ymax * aspect - eyeSepOnProjection;
  12041. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  12042. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  12043. this.cameraR.projectionMatrix.copy( projectionMatrix );
  12044. }
  12045. this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( eyeLeft );
  12046. this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( eyeRight );
  12047. };
  12048. } )()
  12049. } );
  12050. /**
  12051. * @author TristanVALCKE / https://github.com/Itee
  12052. */
  12053. /* global QUnit */
  12054. QUnit.module( 'Cameras', () => {
  12055. QUnit.module.todo( 'StereoCamera', () => {
  12056. // INSTANCING
  12057. QUnit.test( "Instancing", ( assert ) => {
  12058. assert.ok( false, "everything's gonna be alright" );
  12059. } );
  12060. // PUBLIC STUFF
  12061. QUnit.test( "update", ( assert ) => {
  12062. assert.ok( false, "everything's gonna be alright" );
  12063. } );
  12064. } );
  12065. } );
  12066. /**
  12067. * @author simonThiele / https://github.com/simonThiele
  12068. */
  12069. /* global QUnit */
  12070. QUnit.module( 'Core', () => {
  12071. QUnit.module.todo( 'BufferAttribute', () => {
  12072. // INSTANCING
  12073. QUnit.test( "Instancing", ( assert ) => {
  12074. assert.throws(
  12075. function () {
  12076. var a = new BufferAttribute( [ 1, 2, 3, 4 ], 2, false );
  12077. },
  12078. /array should be a Typed Array/,
  12079. "Calling constructor with a simple array throws Error"
  12080. );
  12081. } );
  12082. // PROPERTIES
  12083. QUnit.test( "needsUpdate", ( assert ) => {
  12084. assert.ok( false, "everything's gonna be alright" );
  12085. } );
  12086. // PUBLIC STUFF
  12087. QUnit.test( "isBufferAttribute", ( assert ) => {
  12088. assert.ok( false, "everything's gonna be alright" );
  12089. } );
  12090. QUnit.test( "setArray", ( assert ) => {
  12091. var f32a = new Float32Array( [ 1, 2, 3, 4 ] );
  12092. var a = new BufferAttribute( f32a, 2, false );
  12093. a.setArray( f32a, 2 );
  12094. assert.strictEqual( a.count, 2, "Check item count" );
  12095. assert.strictEqual( a.array, f32a, "Check array" );
  12096. assert.throws(
  12097. function () {
  12098. a.setArray( [ 1, 2, 3, 4 ] );
  12099. },
  12100. /array should be a Typed Array/,
  12101. "Calling setArray with a simple array throws Error"
  12102. );
  12103. } );
  12104. QUnit.test( "setDynamic", ( assert ) => {
  12105. assert.ok( false, "everything's gonna be alright" );
  12106. } );
  12107. QUnit.test( "copy", ( assert ) => {
  12108. var attr = new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 5, 6 ] ), 3 );
  12109. attr.setDynamic( true );
  12110. attr.needsUpdate = true;
  12111. var attrCopy = new BufferAttribute().copy( attr );
  12112. assert.ok( attr.count === attrCopy.count, 'count is equal' );
  12113. assert.ok( attr.itemSize === attrCopy.itemSize, 'itemSize is equal' );
  12114. assert.ok( attr.dynamic === attrCopy.dynamic, 'dynamic is equal' );
  12115. assert.ok( attr.array.length === attrCopy.array.length, 'array length is equal' );
  12116. assert.ok( attr.version === 1 && attrCopy.version === 0, 'version is not copied which is good' );
  12117. } );
  12118. QUnit.test( "copyAt", ( assert ) => {
  12119. var attr = new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ] ), 3 );
  12120. var attr2 = new BufferAttribute( new Float32Array( 9 ), 3 );
  12121. attr2.copyAt( 1, attr, 2 );
  12122. attr2.copyAt( 0, attr, 1 );
  12123. attr2.copyAt( 2, attr, 0 );
  12124. var i = attr.array;
  12125. var i2 = attr2.array; // should be [4, 5, 6, 7, 8, 9, 1, 2, 3]
  12126. assert.ok( i2[ 0 ] === i[ 3 ] && i2[ 1 ] === i[ 4 ] && i2[ 2 ] === i[ 5 ], 'chunck copied to correct place' );
  12127. assert.ok( i2[ 3 ] === i[ 6 ] && i2[ 4 ] === i[ 7 ] && i2[ 5 ] === i[ 8 ], 'chunck copied to correct place' );
  12128. assert.ok( i2[ 6 ] === i[ 0 ] && i2[ 7 ] === i[ 1 ] && i2[ 8 ] === i[ 2 ], 'chunck copied to correct place' );
  12129. } );
  12130. QUnit.test( "copyArray", ( assert ) => {
  12131. var f32a = new Float32Array( [ 5, 6, 7, 8 ] );
  12132. var a = new BufferAttribute( new Float32Array( [ 1, 2, 3, 4 ] ), 2, false );
  12133. a.copyArray( f32a );
  12134. assert.deepEqual( a.array, f32a, "Check array has new values" );
  12135. } );
  12136. QUnit.test( "copyColorsArray", ( assert ) => {
  12137. var attr = new BufferAttribute( new Float32Array( 6 ), 3 );
  12138. attr.copyColorsArray( [
  12139. new Color( 0, 0.5, 1 ),
  12140. new Color( 0.25, 1, 0 )
  12141. ] );
  12142. var i = attr.array;
  12143. assert.ok( i[ 0 ] === 0 && i[ 1 ] === 0.5 && i[ 2 ] === 1, 'first color was copied correctly' );
  12144. assert.ok( i[ 3 ] === 0.25 && i[ 4 ] === 1 && i[ 5 ] === 0, 'second color was copied correctly' );
  12145. } );
  12146. QUnit.test( "copyIndicesArray", ( assert ) => {
  12147. var attr = new BufferAttribute( new Float32Array( 6 ), 3 );
  12148. attr.copyIndicesArray( [
  12149. {
  12150. a: 1,
  12151. b: 2,
  12152. c: 3
  12153. },
  12154. {
  12155. a: 4,
  12156. b: 5,
  12157. c: 6
  12158. }
  12159. ] );
  12160. var i = attr.array;
  12161. assert.ok( i[ 0 ] === 1 && i[ 1 ] === 2 && i[ 2 ] === 3, 'first indices were copied correctly' );
  12162. assert.ok( i[ 3 ] === 4 && i[ 4 ] === 5 && i[ 5 ] === 6, 'second indices were copied correctly' );
  12163. } );
  12164. QUnit.test( "copyVector2sArray", ( assert ) => {
  12165. var attr = new BufferAttribute( new Float32Array( 4 ), 2 );
  12166. attr.copyVector2sArray( [
  12167. new Vector2( 1, 2 ),
  12168. new Vector2( 4, 5 )
  12169. ] );
  12170. var i = attr.array;
  12171. assert.ok( i[ 0 ] === 1 && i[ 1 ] === 2, 'first vector was copied correctly' );
  12172. assert.ok( i[ 2 ] === 4 && i[ 3 ] === 5, 'second vector was copied correctly' );
  12173. } );
  12174. QUnit.test( "copyVector3sArray", ( assert ) => {
  12175. var attr = new BufferAttribute( new Float32Array( 6 ), 2 );
  12176. attr.copyVector3sArray( [
  12177. new Vector3( 1, 2, 3 ),
  12178. new Vector3( 10, 20, 30 )
  12179. ] );
  12180. var i = attr.array;
  12181. assert.ok( i[ 0 ] === 1 && i[ 1 ] === 2 && i[ 2 ] === 3, 'first vector was copied correctly' );
  12182. assert.ok( i[ 3 ] === 10 && i[ 4 ] === 20 && i[ 5 ] === 30, 'second vector was copied correctly' );
  12183. } );
  12184. QUnit.test( "copyVector4sArray", ( assert ) => {
  12185. var attr = new BufferAttribute( new Float32Array( 8 ), 2 );
  12186. attr.copyVector4sArray( [
  12187. new Vector4( 1, 2, 3, 4 ),
  12188. new Vector4( 10, 20, 30, 40 )
  12189. ] );
  12190. var i = attr.array;
  12191. assert.ok( i[ 0 ] === 1 && i[ 1 ] === 2 && i[ 2 ] === 3 && i[ 3 ] === 4, 'first vector was copied correctly' );
  12192. assert.ok( i[ 4 ] === 10 && i[ 5 ] === 20 && i[ 6 ] === 30 && i[ 7 ] === 40, 'second vector was copied correctly' );
  12193. } );
  12194. QUnit.test( "set", ( assert ) => {
  12195. var f32a = new Float32Array( [ 1, 2, 3, 4 ] );
  12196. var a = new BufferAttribute( f32a, 2, false );
  12197. var expected = new Float32Array( [ 9, 2, 8, 4 ] );
  12198. a.set( [ 9 ] );
  12199. a.set( [ 8 ], 2 );
  12200. assert.deepEqual( a.array, expected, "Check array has expected values" );
  12201. } );
  12202. QUnit.test( "set[X, Y, Z, W, XYZ, XYZW]/get[X, Y, Z, W]", ( assert ) => {
  12203. var f32a = new Float32Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] );
  12204. var a = new BufferAttribute( f32a, 4, false );
  12205. var expected = new Float32Array( [ 1, 2, - 3, - 4, - 5, - 6, 7, 8 ] );
  12206. a.setX( 1, a.getX( 1 ) * - 1 );
  12207. a.setY( 1, a.getY( 1 ) * - 1 );
  12208. a.setZ( 0, a.getZ( 0 ) * - 1 );
  12209. a.setW( 0, a.getW( 0 ) * - 1 );
  12210. assert.deepEqual( a.array, expected, "Check all set* calls set the correct values" );
  12211. } );
  12212. QUnit.test( "setXY", ( assert ) => {
  12213. var f32a = new Float32Array( [ 1, 2, 3, 4 ] );
  12214. var a = new BufferAttribute( f32a, 2, false );
  12215. var expected = new Float32Array( [ - 1, - 2, 3, 4 ] );
  12216. a.setXY( 0, - 1, - 2 );
  12217. assert.deepEqual( a.array, expected, "Check for the correct values" );
  12218. } );
  12219. QUnit.test( "setXYZ", ( assert ) => {
  12220. var f32a = new Float32Array( [ 1, 2, 3, 4, 5, 6 ] );
  12221. var a = new BufferAttribute( f32a, 3, false );
  12222. var expected = new Float32Array( [ 1, 2, 3, - 4, - 5, - 6 ] );
  12223. a.setXYZ( 1, - 4, - 5, - 6 );
  12224. assert.deepEqual( a.array, expected, "Check for the correct values" );
  12225. } );
  12226. QUnit.test( "setXYZW", ( assert ) => {
  12227. var f32a = new Float32Array( [ 1, 2, 3, 4 ] );
  12228. var a = new BufferAttribute( f32a, 4, false );
  12229. var expected = new Float32Array( [ - 1, - 2, - 3, - 4 ] );
  12230. a.setXYZW( 0, - 1, - 2, - 3, - 4 );
  12231. assert.deepEqual( a.array, expected, "Check for the correct values" );
  12232. } );
  12233. QUnit.test( "onUpload", ( assert ) => {
  12234. var a = new BufferAttribute();
  12235. var func = function () { };
  12236. a.onUpload( func );
  12237. assert.strictEqual( a.onUploadCallback, func, "Check callback was set properly" );
  12238. } );
  12239. QUnit.test( "clone", ( assert ) => {
  12240. var attr = new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 0.12, - 12 ] ), 2 );
  12241. var attrCopy = attr.clone();
  12242. assert.ok( attr.array.length === attrCopy.array.length, 'attribute was cloned' );
  12243. for ( var i = 0; i < attr.array.length; i ++ ) {
  12244. assert.ok( attr.array[ i ] === attrCopy.array[ i ], 'array item is equal' );
  12245. }
  12246. } );
  12247. // OTHERS
  12248. QUnit.test( "count", ( assert ) => {
  12249. assert.ok(
  12250. new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 5, 6 ] ), 3 ).count === 2,
  12251. 'count is equal to the number of chunks'
  12252. );
  12253. } );
  12254. } );
  12255. QUnit.module.todo( 'Int8BufferAttribute', () => {
  12256. // INHERITANCE
  12257. QUnit.test( "Extending", ( assert ) => {
  12258. assert.ok( false, "everything's gonna be alright" );
  12259. } );
  12260. // INSTANCING
  12261. QUnit.test( "Instancing", ( assert ) => {
  12262. assert.ok( false, "everything's gonna be alright" );
  12263. } );
  12264. } );
  12265. QUnit.module.todo( 'Uint8BufferAttribute', () => {
  12266. // INHERITANCE
  12267. QUnit.test( "Extending", ( assert ) => {
  12268. assert.ok( false, "everything's gonna be alright" );
  12269. } );
  12270. // INSTANCING
  12271. QUnit.test( "Instancing", ( assert ) => {
  12272. assert.ok( false, "everything's gonna be alright" );
  12273. } );
  12274. } );
  12275. QUnit.module.todo( 'Uint8ClampedBufferAttribute', () => {
  12276. // INHERITANCE
  12277. QUnit.test( "Extending", ( assert ) => {
  12278. assert.ok( false, "everything's gonna be alright" );
  12279. } );
  12280. // INSTANCING
  12281. QUnit.test( "Instancing", ( assert ) => {
  12282. assert.ok( false, "everything's gonna be alright" );
  12283. } );
  12284. } );
  12285. QUnit.module.todo( 'Int16BufferAttribute', () => {
  12286. // INHERITANCE
  12287. QUnit.test( "Extending", ( assert ) => {
  12288. assert.ok( false, "everything's gonna be alright" );
  12289. } );
  12290. // INSTANCING
  12291. QUnit.test( "Instancing", ( assert ) => {
  12292. assert.ok( false, "everything's gonna be alright" );
  12293. } );
  12294. } );
  12295. QUnit.module.todo( 'Uint16BufferAttribute', () => {
  12296. // INHERITANCE
  12297. QUnit.test( "Extending", ( assert ) => {
  12298. assert.ok( false, "everything's gonna be alright" );
  12299. } );
  12300. // INSTANCING
  12301. QUnit.test( "Instancing", ( assert ) => {
  12302. assert.ok( false, "everything's gonna be alright" );
  12303. } );
  12304. } );
  12305. QUnit.module.todo( 'Int32BufferAttribute', () => {
  12306. // INHERITANCE
  12307. QUnit.test( "Extending", ( assert ) => {
  12308. assert.ok( false, "everything's gonna be alright" );
  12309. } );
  12310. // INSTANCING
  12311. QUnit.test( "Instancing", ( assert ) => {
  12312. assert.ok( false, "everything's gonna be alright" );
  12313. } );
  12314. } );
  12315. QUnit.module.todo( 'Uint32BufferAttribute', () => {
  12316. // INHERITANCE
  12317. QUnit.test( "Extending", ( assert ) => {
  12318. assert.ok( false, "everything's gonna be alright" );
  12319. } );
  12320. // INSTANCING
  12321. QUnit.test( "Instancing", ( assert ) => {
  12322. assert.ok( false, "everything's gonna be alright" );
  12323. } );
  12324. } );
  12325. QUnit.module.todo( 'Float32BufferAttribute', () => {
  12326. // INHERITANCE
  12327. QUnit.test( "Extending", ( assert ) => {
  12328. assert.ok( false, "everything's gonna be alright" );
  12329. } );
  12330. // INSTANCING
  12331. QUnit.test( "Instancing", ( assert ) => {
  12332. assert.ok( false, "everything's gonna be alright" );
  12333. } );
  12334. } );
  12335. QUnit.module.todo( 'Float64BufferAttribute', () => {
  12336. // INHERITANCE
  12337. QUnit.test( "Extending", ( assert ) => {
  12338. assert.ok( false, "everything's gonna be alright" );
  12339. } );
  12340. // INSTANCING
  12341. QUnit.test( "Instancing", ( assert ) => {
  12342. assert.ok( false, "everything's gonna be alright" );
  12343. } );
  12344. } );
  12345. } );
  12346. /**
  12347. * @author mrdoob / http://mrdoob.com/
  12348. */
  12349. var Cache = {
  12350. enabled: false,
  12351. files: {},
  12352. add: function ( key, file ) {
  12353. if ( this.enabled === false ) return;
  12354. // console.log( 'THREE.Cache', 'Adding key:', key );
  12355. this.files[ key ] = file;
  12356. },
  12357. get: function ( key ) {
  12358. if ( this.enabled === false ) return;
  12359. // console.log( 'THREE.Cache', 'Checking key:', key );
  12360. return this.files[ key ];
  12361. },
  12362. remove: function ( key ) {
  12363. delete this.files[ key ];
  12364. },
  12365. clear: function () {
  12366. this.files = {};
  12367. }
  12368. };
  12369. /**
  12370. * @author mrdoob / http://mrdoob.com/
  12371. */
  12372. function LoadingManager( onLoad, onProgress, onError ) {
  12373. var scope = this;
  12374. var isLoading = false, itemsLoaded = 0, itemsTotal = 0;
  12375. this.onStart = undefined;
  12376. this.onLoad = onLoad;
  12377. this.onProgress = onProgress;
  12378. this.onError = onError;
  12379. this.itemStart = function ( url ) {
  12380. itemsTotal ++;
  12381. if ( isLoading === false ) {
  12382. if ( scope.onStart !== undefined ) {
  12383. scope.onStart( url, itemsLoaded, itemsTotal );
  12384. }
  12385. }
  12386. isLoading = true;
  12387. };
  12388. this.itemEnd = function ( url ) {
  12389. itemsLoaded ++;
  12390. if ( scope.onProgress !== undefined ) {
  12391. scope.onProgress( url, itemsLoaded, itemsTotal );
  12392. }
  12393. if ( itemsLoaded === itemsTotal ) {
  12394. isLoading = false;
  12395. if ( scope.onLoad !== undefined ) {
  12396. scope.onLoad();
  12397. }
  12398. }
  12399. };
  12400. this.itemError = function ( url ) {
  12401. if ( scope.onError !== undefined ) {
  12402. scope.onError( url );
  12403. }
  12404. };
  12405. }
  12406. var DefaultLoadingManager = new LoadingManager();
  12407. /**
  12408. * @author mrdoob / http://mrdoob.com/
  12409. */
  12410. function FileLoader( manager ) {
  12411. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  12412. }
  12413. Object.assign( FileLoader.prototype, {
  12414. load: function ( url, onLoad, onProgress, onError ) {
  12415. if ( url === undefined ) url = '';
  12416. if ( this.path !== undefined ) url = this.path + url;
  12417. var scope = this;
  12418. var cached = Cache.get( url );
  12419. if ( cached !== undefined ) {
  12420. scope.manager.itemStart( url );
  12421. setTimeout( function () {
  12422. if ( onLoad ) onLoad( cached );
  12423. scope.manager.itemEnd( url );
  12424. }, 0 );
  12425. return cached;
  12426. }
  12427. // Check for data: URI
  12428. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  12429. var dataUriRegexResult = url.match( dataUriRegex );
  12430. // Safari can not handle Data URIs through XMLHttpRequest so process manually
  12431. if ( dataUriRegexResult ) {
  12432. var mimeType = dataUriRegexResult[ 1 ];
  12433. var isBase64 = !! dataUriRegexResult[ 2 ];
  12434. var data = dataUriRegexResult[ 3 ];
  12435. data = window.decodeURIComponent( data );
  12436. if ( isBase64 ) data = window.atob( data );
  12437. try {
  12438. var response;
  12439. var responseType = ( this.responseType || '' ).toLowerCase();
  12440. switch ( responseType ) {
  12441. case 'arraybuffer':
  12442. case 'blob':
  12443. var view = new Uint8Array( data.length );
  12444. for ( var i = 0; i < data.length; i ++ ) {
  12445. view[ i ] = data.charCodeAt( i );
  12446. }
  12447. if ( responseType === 'blob' ) {
  12448. response = new Blob( [ view.buffer ], { type: mimeType } );
  12449. } else {
  12450. response = view.buffer;
  12451. }
  12452. break;
  12453. case 'document':
  12454. var parser = new DOMParser();
  12455. response = parser.parseFromString( data, mimeType );
  12456. break;
  12457. case 'json':
  12458. response = JSON.parse( data );
  12459. break;
  12460. default: // 'text' or other
  12461. response = data;
  12462. break;
  12463. }
  12464. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  12465. window.setTimeout( function () {
  12466. if ( onLoad ) onLoad( response );
  12467. scope.manager.itemEnd( url );
  12468. }, 0 );
  12469. } catch ( error ) {
  12470. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  12471. window.setTimeout( function () {
  12472. if ( onError ) onError( error );
  12473. scope.manager.itemEnd( url );
  12474. scope.manager.itemError( url );
  12475. }, 0 );
  12476. }
  12477. } else {
  12478. var request = new XMLHttpRequest();
  12479. request.open( 'GET', url, true );
  12480. request.addEventListener( 'load', function ( event ) {
  12481. var response = event.target.response;
  12482. Cache.add( url, response );
  12483. if ( this.status === 200 ) {
  12484. if ( onLoad ) onLoad( response );
  12485. scope.manager.itemEnd( url );
  12486. } else if ( this.status === 0 ) {
  12487. // Some browsers return HTTP Status 0 when using non-http protocol
  12488. // e.g. 'file://' or 'data://'. Handle as success.
  12489. console.warn( 'THREE.FileLoader: HTTP Status 0 received.' );
  12490. if ( onLoad ) onLoad( response );
  12491. scope.manager.itemEnd( url );
  12492. } else {
  12493. if ( onError ) onError( event );
  12494. scope.manager.itemEnd( url );
  12495. scope.manager.itemError( url );
  12496. }
  12497. }, false );
  12498. if ( onProgress !== undefined ) {
  12499. request.addEventListener( 'progress', function ( event ) {
  12500. onProgress( event );
  12501. }, false );
  12502. }
  12503. request.addEventListener( 'error', function ( event ) {
  12504. if ( onError ) onError( event );
  12505. scope.manager.itemEnd( url );
  12506. scope.manager.itemError( url );
  12507. }, false );
  12508. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  12509. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  12510. if ( request.overrideMimeType ) request.overrideMimeType( this.mimeType !== undefined ? this.mimeType : 'text/plain' );
  12511. for ( var header in this.requestHeader ) {
  12512. request.setRequestHeader( header, this.requestHeader[ header ] );
  12513. }
  12514. request.send( null );
  12515. }
  12516. scope.manager.itemStart( url );
  12517. return request;
  12518. },
  12519. setPath: function ( value ) {
  12520. this.path = value;
  12521. return this;
  12522. },
  12523. setResponseType: function ( value ) {
  12524. this.responseType = value;
  12525. return this;
  12526. },
  12527. setWithCredentials: function ( value ) {
  12528. this.withCredentials = value;
  12529. return this;
  12530. },
  12531. setMimeType: function ( value ) {
  12532. this.mimeType = value;
  12533. return this;
  12534. },
  12535. setRequestHeader: function ( value ) {
  12536. this.requestHeader = value;
  12537. return this;
  12538. }
  12539. } );
  12540. /**
  12541. * @author mrdoob / http://mrdoob.com/
  12542. *
  12543. * parameters = {
  12544. * color: <THREE.Color>,
  12545. * opacity: <float>
  12546. * }
  12547. */
  12548. function ShadowMaterial( parameters ) {
  12549. Material.call( this );
  12550. this.type = 'ShadowMaterial';
  12551. this.color = new Color( 0x000000 );
  12552. this.opacity = 1.0;
  12553. this.lights = true;
  12554. this.transparent = true;
  12555. this.setValues( parameters );
  12556. }
  12557. ShadowMaterial.prototype = Object.create( Material.prototype );
  12558. ShadowMaterial.prototype.constructor = ShadowMaterial;
  12559. ShadowMaterial.prototype.isShadowMaterial = true;
  12560. /**
  12561. * @author alteredq / http://alteredqualia.com/
  12562. *
  12563. * parameters = {
  12564. * color: <hex>,
  12565. * opacity: <float>,
  12566. * map: new THREE.Texture( <Image> ),
  12567. *
  12568. * uvOffset: new THREE.Vector2(),
  12569. * uvScale: new THREE.Vector2()
  12570. * }
  12571. */
  12572. function SpriteMaterial( parameters ) {
  12573. Material.call( this );
  12574. this.type = 'SpriteMaterial';
  12575. this.color = new Color( 0xffffff );
  12576. this.map = null;
  12577. this.rotation = 0;
  12578. this.fog = false;
  12579. this.lights = false;
  12580. this.setValues( parameters );
  12581. }
  12582. SpriteMaterial.prototype = Object.create( Material.prototype );
  12583. SpriteMaterial.prototype.constructor = SpriteMaterial;
  12584. SpriteMaterial.prototype.isSpriteMaterial = true;
  12585. SpriteMaterial.prototype.copy = function ( source ) {
  12586. Material.prototype.copy.call( this, source );
  12587. this.color.copy( source.color );
  12588. this.map = source.map;
  12589. this.rotation = source.rotation;
  12590. return this;
  12591. };
  12592. /**
  12593. * Uniform Utilities
  12594. */
  12595. var UniformsUtils = {
  12596. merge: function ( uniforms ) {
  12597. var merged = {};
  12598. for ( var u = 0; u < uniforms.length; u ++ ) {
  12599. var tmp = this.clone( uniforms[ u ] );
  12600. for ( var p in tmp ) {
  12601. merged[ p ] = tmp[ p ];
  12602. }
  12603. }
  12604. return merged;
  12605. },
  12606. clone: function ( uniforms_src ) {
  12607. var uniforms_dst = {};
  12608. for ( var u in uniforms_src ) {
  12609. uniforms_dst[ u ] = {};
  12610. for ( var p in uniforms_src[ u ] ) {
  12611. var parameter_src = uniforms_src[ u ][ p ];
  12612. if ( parameter_src && ( parameter_src.isColor ||
  12613. parameter_src.isMatrix3 || parameter_src.isMatrix4 ||
  12614. parameter_src.isVector2 || parameter_src.isVector3 || parameter_src.isVector4 ||
  12615. parameter_src.isTexture ) ) {
  12616. uniforms_dst[ u ][ p ] = parameter_src.clone();
  12617. } else if ( Array.isArray( parameter_src ) ) {
  12618. uniforms_dst[ u ][ p ] = parameter_src.slice();
  12619. } else {
  12620. uniforms_dst[ u ][ p ] = parameter_src;
  12621. }
  12622. }
  12623. }
  12624. return uniforms_dst;
  12625. }
  12626. };
  12627. /**
  12628. * @author alteredq / http://alteredqualia.com/
  12629. *
  12630. * parameters = {
  12631. * defines: { "label" : "value" },
  12632. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  12633. *
  12634. * fragmentShader: <string>,
  12635. * vertexShader: <string>,
  12636. *
  12637. * wireframe: <boolean>,
  12638. * wireframeLinewidth: <float>,
  12639. *
  12640. * lights: <bool>,
  12641. *
  12642. * skinning: <bool>,
  12643. * morphTargets: <bool>,
  12644. * morphNormals: <bool>
  12645. * }
  12646. */
  12647. function ShaderMaterial( parameters ) {
  12648. Material.call( this );
  12649. this.type = 'ShaderMaterial';
  12650. this.defines = {};
  12651. this.uniforms = {};
  12652. this.vertexShader = 'void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}';
  12653. this.fragmentShader = 'void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}';
  12654. this.linewidth = 1;
  12655. this.wireframe = false;
  12656. this.wireframeLinewidth = 1;
  12657. this.fog = false; // set to use scene fog
  12658. this.lights = false; // set to use scene lights
  12659. this.clipping = false; // set to use user-defined clipping planes
  12660. this.skinning = false; // set to use skinning attribute streams
  12661. this.morphTargets = false; // set to use morph targets
  12662. this.morphNormals = false; // set to use morph normals
  12663. this.extensions = {
  12664. derivatives: false, // set to use derivatives
  12665. fragDepth: false, // set to use fragment depth values
  12666. drawBuffers: false, // set to use draw buffers
  12667. shaderTextureLOD: false // set to use shader texture LOD
  12668. };
  12669. // When rendered geometry doesn't include these attributes but the material does,
  12670. // use these default values in WebGL. This avoids errors when buffer data is missing.
  12671. this.defaultAttributeValues = {
  12672. 'color': [ 1, 1, 1 ],
  12673. 'uv': [ 0, 0 ],
  12674. 'uv2': [ 0, 0 ]
  12675. };
  12676. this.index0AttributeName = undefined;
  12677. if ( parameters !== undefined ) {
  12678. if ( parameters.attributes !== undefined ) {
  12679. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  12680. }
  12681. this.setValues( parameters );
  12682. }
  12683. }
  12684. ShaderMaterial.prototype = Object.create( Material.prototype );
  12685. ShaderMaterial.prototype.constructor = ShaderMaterial;
  12686. ShaderMaterial.prototype.isShaderMaterial = true;
  12687. ShaderMaterial.prototype.copy = function ( source ) {
  12688. Material.prototype.copy.call( this, source );
  12689. this.fragmentShader = source.fragmentShader;
  12690. this.vertexShader = source.vertexShader;
  12691. this.uniforms = UniformsUtils.clone( source.uniforms );
  12692. this.defines = source.defines;
  12693. this.wireframe = source.wireframe;
  12694. this.wireframeLinewidth = source.wireframeLinewidth;
  12695. this.lights = source.lights;
  12696. this.clipping = source.clipping;
  12697. this.skinning = source.skinning;
  12698. this.morphTargets = source.morphTargets;
  12699. this.morphNormals = source.morphNormals;
  12700. this.extensions = source.extensions;
  12701. return this;
  12702. };
  12703. ShaderMaterial.prototype.toJSON = function ( meta ) {
  12704. var data = Material.prototype.toJSON.call( this, meta );
  12705. data.uniforms = this.uniforms;
  12706. data.vertexShader = this.vertexShader;
  12707. data.fragmentShader = this.fragmentShader;
  12708. return data;
  12709. };
  12710. /**
  12711. * @author mrdoob / http://mrdoob.com/
  12712. */
  12713. function RawShaderMaterial( parameters ) {
  12714. ShaderMaterial.call( this, parameters );
  12715. this.type = 'RawShaderMaterial';
  12716. }
  12717. RawShaderMaterial.prototype = Object.create( ShaderMaterial.prototype );
  12718. RawShaderMaterial.prototype.constructor = RawShaderMaterial;
  12719. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  12720. /**
  12721. * @author mrdoob / http://mrdoob.com/
  12722. * @author alteredq / http://alteredqualia.com/
  12723. *
  12724. * parameters = {
  12725. * color: <hex>,
  12726. * opacity: <float>,
  12727. * map: new THREE.Texture( <Image> ),
  12728. *
  12729. * size: <float>,
  12730. * sizeAttenuation: <bool>
  12731. * }
  12732. */
  12733. function PointsMaterial( parameters ) {
  12734. Material.call( this );
  12735. this.type = 'PointsMaterial';
  12736. this.color = new Color( 0xffffff );
  12737. this.map = null;
  12738. this.size = 1;
  12739. this.sizeAttenuation = true;
  12740. this.lights = false;
  12741. this.setValues( parameters );
  12742. }
  12743. PointsMaterial.prototype = Object.create( Material.prototype );
  12744. PointsMaterial.prototype.constructor = PointsMaterial;
  12745. PointsMaterial.prototype.isPointsMaterial = true;
  12746. PointsMaterial.prototype.copy = function ( source ) {
  12747. Material.prototype.copy.call( this, source );
  12748. this.color.copy( source.color );
  12749. this.map = source.map;
  12750. this.size = source.size;
  12751. this.sizeAttenuation = source.sizeAttenuation;
  12752. return this;
  12753. };
  12754. /**
  12755. * @author WestLangley / http://github.com/WestLangley
  12756. *
  12757. * parameters = {
  12758. * color: <hex>,
  12759. * roughness: <float>,
  12760. * metalness: <float>,
  12761. * opacity: <float>,
  12762. *
  12763. * map: new THREE.Texture( <Image> ),
  12764. *
  12765. * lightMap: new THREE.Texture( <Image> ),
  12766. * lightMapIntensity: <float>
  12767. *
  12768. * aoMap: new THREE.Texture( <Image> ),
  12769. * aoMapIntensity: <float>
  12770. *
  12771. * emissive: <hex>,
  12772. * emissiveIntensity: <float>
  12773. * emissiveMap: new THREE.Texture( <Image> ),
  12774. *
  12775. * bumpMap: new THREE.Texture( <Image> ),
  12776. * bumpScale: <float>,
  12777. *
  12778. * normalMap: new THREE.Texture( <Image> ),
  12779. * normalScale: <Vector2>,
  12780. *
  12781. * displacementMap: new THREE.Texture( <Image> ),
  12782. * displacementScale: <float>,
  12783. * displacementBias: <float>,
  12784. *
  12785. * roughnessMap: new THREE.Texture( <Image> ),
  12786. *
  12787. * metalnessMap: new THREE.Texture( <Image> ),
  12788. *
  12789. * alphaMap: new THREE.Texture( <Image> ),
  12790. *
  12791. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  12792. * envMapIntensity: <float>
  12793. *
  12794. * refractionRatio: <float>,
  12795. *
  12796. * wireframe: <boolean>,
  12797. * wireframeLinewidth: <float>,
  12798. *
  12799. * skinning: <bool>,
  12800. * morphTargets: <bool>,
  12801. * morphNormals: <bool>
  12802. * }
  12803. */
  12804. function MeshStandardMaterial( parameters ) {
  12805. Material.call( this );
  12806. this.defines = { 'STANDARD': '' };
  12807. this.type = 'MeshStandardMaterial';
  12808. this.color = new Color( 0xffffff ); // diffuse
  12809. this.roughness = 0.5;
  12810. this.metalness = 0.5;
  12811. this.map = null;
  12812. this.lightMap = null;
  12813. this.lightMapIntensity = 1.0;
  12814. this.aoMap = null;
  12815. this.aoMapIntensity = 1.0;
  12816. this.emissive = new Color( 0x000000 );
  12817. this.emissiveIntensity = 1.0;
  12818. this.emissiveMap = null;
  12819. this.bumpMap = null;
  12820. this.bumpScale = 1;
  12821. this.normalMap = null;
  12822. this.normalScale = new Vector2( 1, 1 );
  12823. this.displacementMap = null;
  12824. this.displacementScale = 1;
  12825. this.displacementBias = 0;
  12826. this.roughnessMap = null;
  12827. this.metalnessMap = null;
  12828. this.alphaMap = null;
  12829. this.envMap = null;
  12830. this.envMapIntensity = 1.0;
  12831. this.refractionRatio = 0.98;
  12832. this.wireframe = false;
  12833. this.wireframeLinewidth = 1;
  12834. this.wireframeLinecap = 'round';
  12835. this.wireframeLinejoin = 'round';
  12836. this.skinning = false;
  12837. this.morphTargets = false;
  12838. this.morphNormals = false;
  12839. this.setValues( parameters );
  12840. }
  12841. MeshStandardMaterial.prototype = Object.create( Material.prototype );
  12842. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  12843. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  12844. MeshStandardMaterial.prototype.copy = function ( source ) {
  12845. Material.prototype.copy.call( this, source );
  12846. this.defines = { 'STANDARD': '' };
  12847. this.color.copy( source.color );
  12848. this.roughness = source.roughness;
  12849. this.metalness = source.metalness;
  12850. this.map = source.map;
  12851. this.lightMap = source.lightMap;
  12852. this.lightMapIntensity = source.lightMapIntensity;
  12853. this.aoMap = source.aoMap;
  12854. this.aoMapIntensity = source.aoMapIntensity;
  12855. this.emissive.copy( source.emissive );
  12856. this.emissiveMap = source.emissiveMap;
  12857. this.emissiveIntensity = source.emissiveIntensity;
  12858. this.bumpMap = source.bumpMap;
  12859. this.bumpScale = source.bumpScale;
  12860. this.normalMap = source.normalMap;
  12861. this.normalScale.copy( source.normalScale );
  12862. this.displacementMap = source.displacementMap;
  12863. this.displacementScale = source.displacementScale;
  12864. this.displacementBias = source.displacementBias;
  12865. this.roughnessMap = source.roughnessMap;
  12866. this.metalnessMap = source.metalnessMap;
  12867. this.alphaMap = source.alphaMap;
  12868. this.envMap = source.envMap;
  12869. this.envMapIntensity = source.envMapIntensity;
  12870. this.refractionRatio = source.refractionRatio;
  12871. this.wireframe = source.wireframe;
  12872. this.wireframeLinewidth = source.wireframeLinewidth;
  12873. this.wireframeLinecap = source.wireframeLinecap;
  12874. this.wireframeLinejoin = source.wireframeLinejoin;
  12875. this.skinning = source.skinning;
  12876. this.morphTargets = source.morphTargets;
  12877. this.morphNormals = source.morphNormals;
  12878. return this;
  12879. };
  12880. /**
  12881. * @author WestLangley / http://github.com/WestLangley
  12882. *
  12883. * parameters = {
  12884. * reflectivity: <float>
  12885. * }
  12886. */
  12887. function MeshPhysicalMaterial( parameters ) {
  12888. MeshStandardMaterial.call( this );
  12889. this.defines = { 'PHYSICAL': '' };
  12890. this.type = 'MeshPhysicalMaterial';
  12891. this.reflectivity = 0.5; // maps to F0 = 0.04
  12892. this.clearCoat = 0.0;
  12893. this.clearCoatRoughness = 0.0;
  12894. this.setValues( parameters );
  12895. }
  12896. MeshPhysicalMaterial.prototype = Object.create( MeshStandardMaterial.prototype );
  12897. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  12898. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  12899. MeshPhysicalMaterial.prototype.copy = function ( source ) {
  12900. MeshStandardMaterial.prototype.copy.call( this, source );
  12901. this.defines = { 'PHYSICAL': '' };
  12902. this.reflectivity = source.reflectivity;
  12903. this.clearCoat = source.clearCoat;
  12904. this.clearCoatRoughness = source.clearCoatRoughness;
  12905. return this;
  12906. };
  12907. /**
  12908. * @author mrdoob / http://mrdoob.com/
  12909. * @author alteredq / http://alteredqualia.com/
  12910. *
  12911. * parameters = {
  12912. * color: <hex>,
  12913. * specular: <hex>,
  12914. * shininess: <float>,
  12915. * opacity: <float>,
  12916. *
  12917. * map: new THREE.Texture( <Image> ),
  12918. *
  12919. * lightMap: new THREE.Texture( <Image> ),
  12920. * lightMapIntensity: <float>
  12921. *
  12922. * aoMap: new THREE.Texture( <Image> ),
  12923. * aoMapIntensity: <float>
  12924. *
  12925. * emissive: <hex>,
  12926. * emissiveIntensity: <float>
  12927. * emissiveMap: new THREE.Texture( <Image> ),
  12928. *
  12929. * bumpMap: new THREE.Texture( <Image> ),
  12930. * bumpScale: <float>,
  12931. *
  12932. * normalMap: new THREE.Texture( <Image> ),
  12933. * normalScale: <Vector2>,
  12934. *
  12935. * displacementMap: new THREE.Texture( <Image> ),
  12936. * displacementScale: <float>,
  12937. * displacementBias: <float>,
  12938. *
  12939. * specularMap: new THREE.Texture( <Image> ),
  12940. *
  12941. * alphaMap: new THREE.Texture( <Image> ),
  12942. *
  12943. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  12944. * combine: THREE.Multiply,
  12945. * reflectivity: <float>,
  12946. * refractionRatio: <float>,
  12947. *
  12948. * wireframe: <boolean>,
  12949. * wireframeLinewidth: <float>,
  12950. *
  12951. * skinning: <bool>,
  12952. * morphTargets: <bool>,
  12953. * morphNormals: <bool>
  12954. * }
  12955. */
  12956. function MeshPhongMaterial( parameters ) {
  12957. Material.call( this );
  12958. this.type = 'MeshPhongMaterial';
  12959. this.color = new Color( 0xffffff ); // diffuse
  12960. this.specular = new Color( 0x111111 );
  12961. this.shininess = 30;
  12962. this.map = null;
  12963. this.lightMap = null;
  12964. this.lightMapIntensity = 1.0;
  12965. this.aoMap = null;
  12966. this.aoMapIntensity = 1.0;
  12967. this.emissive = new Color( 0x000000 );
  12968. this.emissiveIntensity = 1.0;
  12969. this.emissiveMap = null;
  12970. this.bumpMap = null;
  12971. this.bumpScale = 1;
  12972. this.normalMap = null;
  12973. this.normalScale = new Vector2( 1, 1 );
  12974. this.displacementMap = null;
  12975. this.displacementScale = 1;
  12976. this.displacementBias = 0;
  12977. this.specularMap = null;
  12978. this.alphaMap = null;
  12979. this.envMap = null;
  12980. this.combine = MultiplyOperation;
  12981. this.reflectivity = 1;
  12982. this.refractionRatio = 0.98;
  12983. this.wireframe = false;
  12984. this.wireframeLinewidth = 1;
  12985. this.wireframeLinecap = 'round';
  12986. this.wireframeLinejoin = 'round';
  12987. this.skinning = false;
  12988. this.morphTargets = false;
  12989. this.morphNormals = false;
  12990. this.setValues( parameters );
  12991. }
  12992. MeshPhongMaterial.prototype = Object.create( Material.prototype );
  12993. MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
  12994. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  12995. MeshPhongMaterial.prototype.copy = function ( source ) {
  12996. Material.prototype.copy.call( this, source );
  12997. this.color.copy( source.color );
  12998. this.specular.copy( source.specular );
  12999. this.shininess = source.shininess;
  13000. this.map = source.map;
  13001. this.lightMap = source.lightMap;
  13002. this.lightMapIntensity = source.lightMapIntensity;
  13003. this.aoMap = source.aoMap;
  13004. this.aoMapIntensity = source.aoMapIntensity;
  13005. this.emissive.copy( source.emissive );
  13006. this.emissiveMap = source.emissiveMap;
  13007. this.emissiveIntensity = source.emissiveIntensity;
  13008. this.bumpMap = source.bumpMap;
  13009. this.bumpScale = source.bumpScale;
  13010. this.normalMap = source.normalMap;
  13011. this.normalScale.copy( source.normalScale );
  13012. this.displacementMap = source.displacementMap;
  13013. this.displacementScale = source.displacementScale;
  13014. this.displacementBias = source.displacementBias;
  13015. this.specularMap = source.specularMap;
  13016. this.alphaMap = source.alphaMap;
  13017. this.envMap = source.envMap;
  13018. this.combine = source.combine;
  13019. this.reflectivity = source.reflectivity;
  13020. this.refractionRatio = source.refractionRatio;
  13021. this.wireframe = source.wireframe;
  13022. this.wireframeLinewidth = source.wireframeLinewidth;
  13023. this.wireframeLinecap = source.wireframeLinecap;
  13024. this.wireframeLinejoin = source.wireframeLinejoin;
  13025. this.skinning = source.skinning;
  13026. this.morphTargets = source.morphTargets;
  13027. this.morphNormals = source.morphNormals;
  13028. return this;
  13029. };
  13030. /**
  13031. * @author takahirox / http://github.com/takahirox
  13032. *
  13033. * parameters = {
  13034. * gradientMap: new THREE.Texture( <Image> )
  13035. * }
  13036. */
  13037. function MeshToonMaterial( parameters ) {
  13038. MeshPhongMaterial.call( this );
  13039. this.defines = { 'TOON': '' };
  13040. this.type = 'MeshToonMaterial';
  13041. this.gradientMap = null;
  13042. this.setValues( parameters );
  13043. }
  13044. MeshToonMaterial.prototype = Object.create( MeshPhongMaterial.prototype );
  13045. MeshToonMaterial.prototype.constructor = MeshToonMaterial;
  13046. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  13047. MeshToonMaterial.prototype.copy = function ( source ) {
  13048. MeshPhongMaterial.prototype.copy.call( this, source );
  13049. this.gradientMap = source.gradientMap;
  13050. return this;
  13051. };
  13052. /**
  13053. * @author mrdoob / http://mrdoob.com/
  13054. * @author WestLangley / http://github.com/WestLangley
  13055. *
  13056. * parameters = {
  13057. * opacity: <float>,
  13058. *
  13059. * bumpMap: new THREE.Texture( <Image> ),
  13060. * bumpScale: <float>,
  13061. *
  13062. * normalMap: new THREE.Texture( <Image> ),
  13063. * normalScale: <Vector2>,
  13064. *
  13065. * displacementMap: new THREE.Texture( <Image> ),
  13066. * displacementScale: <float>,
  13067. * displacementBias: <float>,
  13068. *
  13069. * wireframe: <boolean>,
  13070. * wireframeLinewidth: <float>
  13071. *
  13072. * skinning: <bool>,
  13073. * morphTargets: <bool>,
  13074. * morphNormals: <bool>
  13075. * }
  13076. */
  13077. function MeshNormalMaterial( parameters ) {
  13078. Material.call( this );
  13079. this.type = 'MeshNormalMaterial';
  13080. this.bumpMap = null;
  13081. this.bumpScale = 1;
  13082. this.normalMap = null;
  13083. this.normalScale = new Vector2( 1, 1 );
  13084. this.displacementMap = null;
  13085. this.displacementScale = 1;
  13086. this.displacementBias = 0;
  13087. this.wireframe = false;
  13088. this.wireframeLinewidth = 1;
  13089. this.fog = false;
  13090. this.lights = false;
  13091. this.skinning = false;
  13092. this.morphTargets = false;
  13093. this.morphNormals = false;
  13094. this.setValues( parameters );
  13095. }
  13096. MeshNormalMaterial.prototype = Object.create( Material.prototype );
  13097. MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
  13098. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  13099. MeshNormalMaterial.prototype.copy = function ( source ) {
  13100. Material.prototype.copy.call( this, source );
  13101. this.bumpMap = source.bumpMap;
  13102. this.bumpScale = source.bumpScale;
  13103. this.normalMap = source.normalMap;
  13104. this.normalScale.copy( source.normalScale );
  13105. this.displacementMap = source.displacementMap;
  13106. this.displacementScale = source.displacementScale;
  13107. this.displacementBias = source.displacementBias;
  13108. this.wireframe = source.wireframe;
  13109. this.wireframeLinewidth = source.wireframeLinewidth;
  13110. this.skinning = source.skinning;
  13111. this.morphTargets = source.morphTargets;
  13112. this.morphNormals = source.morphNormals;
  13113. return this;
  13114. };
  13115. /**
  13116. * @author mrdoob / http://mrdoob.com/
  13117. * @author alteredq / http://alteredqualia.com/
  13118. *
  13119. * parameters = {
  13120. * color: <hex>,
  13121. * opacity: <float>,
  13122. *
  13123. * map: new THREE.Texture( <Image> ),
  13124. *
  13125. * lightMap: new THREE.Texture( <Image> ),
  13126. * lightMapIntensity: <float>
  13127. *
  13128. * aoMap: new THREE.Texture( <Image> ),
  13129. * aoMapIntensity: <float>
  13130. *
  13131. * emissive: <hex>,
  13132. * emissiveIntensity: <float>
  13133. * emissiveMap: new THREE.Texture( <Image> ),
  13134. *
  13135. * specularMap: new THREE.Texture( <Image> ),
  13136. *
  13137. * alphaMap: new THREE.Texture( <Image> ),
  13138. *
  13139. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  13140. * combine: THREE.Multiply,
  13141. * reflectivity: <float>,
  13142. * refractionRatio: <float>,
  13143. *
  13144. * wireframe: <boolean>,
  13145. * wireframeLinewidth: <float>,
  13146. *
  13147. * skinning: <bool>,
  13148. * morphTargets: <bool>,
  13149. * morphNormals: <bool>
  13150. * }
  13151. */
  13152. function MeshLambertMaterial( parameters ) {
  13153. Material.call( this );
  13154. this.type = 'MeshLambertMaterial';
  13155. this.color = new Color( 0xffffff ); // diffuse
  13156. this.map = null;
  13157. this.lightMap = null;
  13158. this.lightMapIntensity = 1.0;
  13159. this.aoMap = null;
  13160. this.aoMapIntensity = 1.0;
  13161. this.emissive = new Color( 0x000000 );
  13162. this.emissiveIntensity = 1.0;
  13163. this.emissiveMap = null;
  13164. this.specularMap = null;
  13165. this.alphaMap = null;
  13166. this.envMap = null;
  13167. this.combine = MultiplyOperation;
  13168. this.reflectivity = 1;
  13169. this.refractionRatio = 0.98;
  13170. this.wireframe = false;
  13171. this.wireframeLinewidth = 1;
  13172. this.wireframeLinecap = 'round';
  13173. this.wireframeLinejoin = 'round';
  13174. this.skinning = false;
  13175. this.morphTargets = false;
  13176. this.morphNormals = false;
  13177. this.setValues( parameters );
  13178. }
  13179. MeshLambertMaterial.prototype = Object.create( Material.prototype );
  13180. MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
  13181. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  13182. MeshLambertMaterial.prototype.copy = function ( source ) {
  13183. Material.prototype.copy.call( this, source );
  13184. this.color.copy( source.color );
  13185. this.map = source.map;
  13186. this.lightMap = source.lightMap;
  13187. this.lightMapIntensity = source.lightMapIntensity;
  13188. this.aoMap = source.aoMap;
  13189. this.aoMapIntensity = source.aoMapIntensity;
  13190. this.emissive.copy( source.emissive );
  13191. this.emissiveMap = source.emissiveMap;
  13192. this.emissiveIntensity = source.emissiveIntensity;
  13193. this.specularMap = source.specularMap;
  13194. this.alphaMap = source.alphaMap;
  13195. this.envMap = source.envMap;
  13196. this.combine = source.combine;
  13197. this.reflectivity = source.reflectivity;
  13198. this.refractionRatio = source.refractionRatio;
  13199. this.wireframe = source.wireframe;
  13200. this.wireframeLinewidth = source.wireframeLinewidth;
  13201. this.wireframeLinecap = source.wireframeLinecap;
  13202. this.wireframeLinejoin = source.wireframeLinejoin;
  13203. this.skinning = source.skinning;
  13204. this.morphTargets = source.morphTargets;
  13205. this.morphNormals = source.morphNormals;
  13206. return this;
  13207. };
  13208. /**
  13209. * @author mrdoob / http://mrdoob.com/
  13210. * @author alteredq / http://alteredqualia.com/
  13211. * @author bhouston / https://clara.io
  13212. * @author WestLangley / http://github.com/WestLangley
  13213. *
  13214. * parameters = {
  13215. *
  13216. * opacity: <float>,
  13217. *
  13218. * map: new THREE.Texture( <Image> ),
  13219. *
  13220. * alphaMap: new THREE.Texture( <Image> ),
  13221. *
  13222. * displacementMap: new THREE.Texture( <Image> ),
  13223. * displacementScale: <float>,
  13224. * displacementBias: <float>,
  13225. *
  13226. * wireframe: <boolean>,
  13227. * wireframeLinewidth: <float>
  13228. * }
  13229. */
  13230. function MeshDepthMaterial( parameters ) {
  13231. Material.call( this );
  13232. this.type = 'MeshDepthMaterial';
  13233. this.depthPacking = BasicDepthPacking;
  13234. this.skinning = false;
  13235. this.morphTargets = false;
  13236. this.map = null;
  13237. this.alphaMap = null;
  13238. this.displacementMap = null;
  13239. this.displacementScale = 1;
  13240. this.displacementBias = 0;
  13241. this.wireframe = false;
  13242. this.wireframeLinewidth = 1;
  13243. this.fog = false;
  13244. this.lights = false;
  13245. this.setValues( parameters );
  13246. }
  13247. MeshDepthMaterial.prototype = Object.create( Material.prototype );
  13248. MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
  13249. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  13250. MeshDepthMaterial.prototype.copy = function ( source ) {
  13251. Material.prototype.copy.call( this, source );
  13252. this.depthPacking = source.depthPacking;
  13253. this.skinning = source.skinning;
  13254. this.morphTargets = source.morphTargets;
  13255. this.map = source.map;
  13256. this.alphaMap = source.alphaMap;
  13257. this.displacementMap = source.displacementMap;
  13258. this.displacementScale = source.displacementScale;
  13259. this.displacementBias = source.displacementBias;
  13260. this.wireframe = source.wireframe;
  13261. this.wireframeLinewidth = source.wireframeLinewidth;
  13262. return this;
  13263. };
  13264. /**
  13265. * @author WestLangley / http://github.com/WestLangley
  13266. *
  13267. * parameters = {
  13268. *
  13269. * referencePosition: <float>,
  13270. * nearDistance: <float>,
  13271. * farDistance: <float>,
  13272. *
  13273. * skinning: <bool>,
  13274. * morphTargets: <bool>,
  13275. *
  13276. * map: new THREE.Texture( <Image> ),
  13277. *
  13278. * alphaMap: new THREE.Texture( <Image> ),
  13279. *
  13280. * displacementMap: new THREE.Texture( <Image> ),
  13281. * displacementScale: <float>,
  13282. * displacementBias: <float>
  13283. *
  13284. * }
  13285. */
  13286. function MeshDistanceMaterial( parameters ) {
  13287. Material.call( this );
  13288. this.type = 'MeshDistanceMaterial';
  13289. this.referencePosition = new Vector3();
  13290. this.nearDistance = 1;
  13291. this.farDistance = 1000;
  13292. this.skinning = false;
  13293. this.morphTargets = false;
  13294. this.map = null;
  13295. this.alphaMap = null;
  13296. this.displacementMap = null;
  13297. this.displacementScale = 1;
  13298. this.displacementBias = 0;
  13299. this.fog = false;
  13300. this.lights = false;
  13301. this.setValues( parameters );
  13302. }
  13303. MeshDistanceMaterial.prototype = Object.create( Material.prototype );
  13304. MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial;
  13305. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  13306. MeshDistanceMaterial.prototype.copy = function ( source ) {
  13307. Material.prototype.copy.call( this, source );
  13308. this.referencePosition.copy( source.referencePosition );
  13309. this.nearDistance = source.nearDistance;
  13310. this.farDistance = source.farDistance;
  13311. this.skinning = source.skinning;
  13312. this.morphTargets = source.morphTargets;
  13313. this.map = source.map;
  13314. this.alphaMap = source.alphaMap;
  13315. this.displacementMap = source.displacementMap;
  13316. this.displacementScale = source.displacementScale;
  13317. this.displacementBias = source.displacementBias;
  13318. return this;
  13319. };
  13320. /**
  13321. * @author mrdoob / http://mrdoob.com/
  13322. * @author alteredq / http://alteredqualia.com/
  13323. *
  13324. * parameters = {
  13325. * color: <hex>,
  13326. * opacity: <float>,
  13327. *
  13328. * linewidth: <float>,
  13329. * linecap: "round",
  13330. * linejoin: "round"
  13331. * }
  13332. */
  13333. function LineBasicMaterial( parameters ) {
  13334. Material.call( this );
  13335. this.type = 'LineBasicMaterial';
  13336. this.color = new Color( 0xffffff );
  13337. this.linewidth = 1;
  13338. this.linecap = 'round';
  13339. this.linejoin = 'round';
  13340. this.lights = false;
  13341. this.setValues( parameters );
  13342. }
  13343. LineBasicMaterial.prototype = Object.create( Material.prototype );
  13344. LineBasicMaterial.prototype.constructor = LineBasicMaterial;
  13345. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  13346. LineBasicMaterial.prototype.copy = function ( source ) {
  13347. Material.prototype.copy.call( this, source );
  13348. this.color.copy( source.color );
  13349. this.linewidth = source.linewidth;
  13350. this.linecap = source.linecap;
  13351. this.linejoin = source.linejoin;
  13352. return this;
  13353. };
  13354. /**
  13355. * @author alteredq / http://alteredqualia.com/
  13356. *
  13357. * parameters = {
  13358. * color: <hex>,
  13359. * opacity: <float>,
  13360. *
  13361. * linewidth: <float>,
  13362. *
  13363. * scale: <float>,
  13364. * dashSize: <float>,
  13365. * gapSize: <float>
  13366. * }
  13367. */
  13368. function LineDashedMaterial( parameters ) {
  13369. LineBasicMaterial.call( this );
  13370. this.type = 'LineDashedMaterial';
  13371. this.scale = 1;
  13372. this.dashSize = 3;
  13373. this.gapSize = 1;
  13374. this.setValues( parameters );
  13375. }
  13376. LineDashedMaterial.prototype = Object.create( LineBasicMaterial.prototype );
  13377. LineDashedMaterial.prototype.constructor = LineDashedMaterial;
  13378. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  13379. LineDashedMaterial.prototype.copy = function ( source ) {
  13380. LineBasicMaterial.prototype.copy.call( this, source );
  13381. this.scale = source.scale;
  13382. this.dashSize = source.dashSize;
  13383. this.gapSize = source.gapSize;
  13384. return this;
  13385. };
  13386. var Materials = Object.freeze({
  13387. ShadowMaterial: ShadowMaterial,
  13388. SpriteMaterial: SpriteMaterial,
  13389. RawShaderMaterial: RawShaderMaterial,
  13390. ShaderMaterial: ShaderMaterial,
  13391. PointsMaterial: PointsMaterial,
  13392. MeshPhysicalMaterial: MeshPhysicalMaterial,
  13393. MeshStandardMaterial: MeshStandardMaterial,
  13394. MeshPhongMaterial: MeshPhongMaterial,
  13395. MeshToonMaterial: MeshToonMaterial,
  13396. MeshNormalMaterial: MeshNormalMaterial,
  13397. MeshLambertMaterial: MeshLambertMaterial,
  13398. MeshDepthMaterial: MeshDepthMaterial,
  13399. MeshDistanceMaterial: MeshDistanceMaterial,
  13400. MeshBasicMaterial: MeshBasicMaterial,
  13401. LineDashedMaterial: LineDashedMaterial,
  13402. LineBasicMaterial: LineBasicMaterial,
  13403. Material: Material
  13404. });
  13405. /**
  13406. * @author mrdoob / http://mrdoob.com/
  13407. */
  13408. function MaterialLoader( manager ) {
  13409. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  13410. this.textures = {};
  13411. }
  13412. Object.assign( MaterialLoader.prototype, {
  13413. load: function ( url, onLoad, onProgress, onError ) {
  13414. var scope = this;
  13415. var loader = new FileLoader( scope.manager );
  13416. loader.load( url, function ( text ) {
  13417. onLoad( scope.parse( JSON.parse( text ) ) );
  13418. }, onProgress, onError );
  13419. },
  13420. setTextures: function ( value ) {
  13421. this.textures = value;
  13422. },
  13423. parse: function ( json ) {
  13424. var textures = this.textures;
  13425. function getTexture( name ) {
  13426. if ( textures[ name ] === undefined ) {
  13427. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  13428. }
  13429. return textures[ name ];
  13430. }
  13431. var material = new Materials[ json.type ]();
  13432. if ( json.uuid !== undefined ) material.uuid = json.uuid;
  13433. if ( json.name !== undefined ) material.name = json.name;
  13434. if ( json.color !== undefined ) material.color.setHex( json.color );
  13435. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  13436. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  13437. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  13438. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  13439. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  13440. if ( json.clearCoat !== undefined ) material.clearCoat = json.clearCoat;
  13441. if ( json.clearCoatRoughness !== undefined ) material.clearCoatRoughness = json.clearCoatRoughness;
  13442. if ( json.uniforms !== undefined ) material.uniforms = json.uniforms;
  13443. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  13444. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  13445. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  13446. if ( json.fog !== undefined ) material.fog = json.fog;
  13447. if ( json.flatShading !== undefined ) material.flatShading = json.flatShading;
  13448. if ( json.blending !== undefined ) material.blending = json.blending;
  13449. if ( json.side !== undefined ) material.side = json.side;
  13450. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  13451. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  13452. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  13453. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  13454. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  13455. if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
  13456. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  13457. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  13458. if ( json.wireframeLinecap !== undefined ) material.wireframeLinecap = json.wireframeLinecap;
  13459. if ( json.wireframeLinejoin !== undefined ) material.wireframeLinejoin = json.wireframeLinejoin;
  13460. if ( json.rotation !== undefined ) material.rotation = json.rotation;
  13461. if ( json.linewidth !== 1 ) material.linewidth = json.linewidth;
  13462. if ( json.dashSize !== undefined ) material.dashSize = json.dashSize;
  13463. if ( json.gapSize !== undefined ) material.gapSize = json.gapSize;
  13464. if ( json.scale !== undefined ) material.scale = json.scale;
  13465. if ( json.skinning !== undefined ) material.skinning = json.skinning;
  13466. if ( json.morphTargets !== undefined ) material.morphTargets = json.morphTargets;
  13467. if ( json.dithering !== undefined ) material.dithering = json.dithering;
  13468. if ( json.visible !== undefined ) material.visible = json.visible;
  13469. if ( json.userData !== undefined ) material.userData = json.userData;
  13470. // Deprecated
  13471. if ( json.shading !== undefined ) material.flatShading = json.shading === 1; // THREE.FlatShading
  13472. // for PointsMaterial
  13473. if ( json.size !== undefined ) material.size = json.size;
  13474. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  13475. // maps
  13476. if ( json.map !== undefined ) material.map = getTexture( json.map );
  13477. if ( json.alphaMap !== undefined ) {
  13478. material.alphaMap = getTexture( json.alphaMap );
  13479. material.transparent = true;
  13480. }
  13481. if ( json.bumpMap !== undefined ) material.bumpMap = getTexture( json.bumpMap );
  13482. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  13483. if ( json.normalMap !== undefined ) material.normalMap = getTexture( json.normalMap );
  13484. if ( json.normalScale !== undefined ) {
  13485. var normalScale = json.normalScale;
  13486. if ( Array.isArray( normalScale ) === false ) {
  13487. // Blender exporter used to export a scalar. See #7459
  13488. normalScale = [ normalScale, normalScale ];
  13489. }
  13490. material.normalScale = new Vector2().fromArray( normalScale );
  13491. }
  13492. if ( json.displacementMap !== undefined ) material.displacementMap = getTexture( json.displacementMap );
  13493. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  13494. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  13495. if ( json.roughnessMap !== undefined ) material.roughnessMap = getTexture( json.roughnessMap );
  13496. if ( json.metalnessMap !== undefined ) material.metalnessMap = getTexture( json.metalnessMap );
  13497. if ( json.emissiveMap !== undefined ) material.emissiveMap = getTexture( json.emissiveMap );
  13498. if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity;
  13499. if ( json.specularMap !== undefined ) material.specularMap = getTexture( json.specularMap );
  13500. if ( json.envMap !== undefined ) material.envMap = getTexture( json.envMap );
  13501. if ( json.reflectivity !== undefined ) material.reflectivity = json.reflectivity;
  13502. if ( json.lightMap !== undefined ) material.lightMap = getTexture( json.lightMap );
  13503. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  13504. if ( json.aoMap !== undefined ) material.aoMap = getTexture( json.aoMap );
  13505. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  13506. if ( json.gradientMap !== undefined ) material.gradientMap = getTexture( json.gradientMap );
  13507. return material;
  13508. }
  13509. } );
  13510. /**
  13511. * @author mrdoob / http://mrdoob.com/
  13512. */
  13513. function ImageLoader( manager ) {
  13514. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  13515. }
  13516. Object.assign( ImageLoader.prototype, {
  13517. crossOrigin: 'Anonymous',
  13518. load: function ( url, onLoad, onProgress, onError ) {
  13519. if ( url === undefined ) url = '';
  13520. if ( this.path !== undefined ) url = this.path + url;
  13521. var scope = this;
  13522. var cached = Cache.get( url );
  13523. if ( cached !== undefined ) {
  13524. scope.manager.itemStart( url );
  13525. setTimeout( function () {
  13526. if ( onLoad ) onLoad( cached );
  13527. scope.manager.itemEnd( url );
  13528. }, 0 );
  13529. return cached;
  13530. }
  13531. var image = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'img' );
  13532. image.addEventListener( 'load', function () {
  13533. Cache.add( url, this );
  13534. if ( onLoad ) onLoad( this );
  13535. scope.manager.itemEnd( url );
  13536. }, false );
  13537. /*
  13538. image.addEventListener( 'progress', function ( event ) {
  13539. if ( onProgress ) onProgress( event );
  13540. }, false );
  13541. */
  13542. image.addEventListener( 'error', function ( event ) {
  13543. if ( onError ) onError( event );
  13544. scope.manager.itemEnd( url );
  13545. scope.manager.itemError( url );
  13546. }, false );
  13547. if ( url.substr( 0, 5 ) !== 'data:' ) {
  13548. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  13549. }
  13550. scope.manager.itemStart( url );
  13551. image.src = url;
  13552. return image;
  13553. },
  13554. setCrossOrigin: function ( value ) {
  13555. this.crossOrigin = value;
  13556. return this;
  13557. },
  13558. setPath: function ( value ) {
  13559. this.path = value;
  13560. return this;
  13561. }
  13562. } );
  13563. /**
  13564. * @author mrdoob / http://mrdoob.com/
  13565. */
  13566. function TextureLoader( manager ) {
  13567. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  13568. }
  13569. Object.assign( TextureLoader.prototype, {
  13570. crossOrigin: 'Anonymous',
  13571. load: function ( url, onLoad, onProgress, onError ) {
  13572. var loader = new ImageLoader( this.manager );
  13573. loader.setCrossOrigin( this.crossOrigin );
  13574. loader.setPath( this.path );
  13575. var texture = new Texture();
  13576. texture.image = loader.load( url, function () {
  13577. // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  13578. var isJPEG = url.search( /\.(jpg|jpeg)$/ ) > 0 || url.search( /^data\:image\/jpeg/ ) === 0;
  13579. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  13580. texture.needsUpdate = true;
  13581. if ( onLoad !== undefined ) {
  13582. onLoad( texture );
  13583. }
  13584. }, onProgress, onError );
  13585. return texture;
  13586. },
  13587. setCrossOrigin: function ( value ) {
  13588. this.crossOrigin = value;
  13589. return this;
  13590. },
  13591. setPath: function ( value ) {
  13592. this.path = value;
  13593. return this;
  13594. }
  13595. } );
  13596. /**
  13597. * @author alteredq / http://alteredqualia.com/
  13598. */
  13599. function Loader() {
  13600. this.onLoadStart = function () {};
  13601. this.onLoadProgress = function () {};
  13602. this.onLoadComplete = function () {};
  13603. }
  13604. Loader.Handlers = {
  13605. handlers: [],
  13606. add: function ( regex, loader ) {
  13607. this.handlers.push( regex, loader );
  13608. },
  13609. get: function ( file ) {
  13610. var handlers = this.handlers;
  13611. for ( var i = 0, l = handlers.length; i < l; i += 2 ) {
  13612. var regex = handlers[ i ];
  13613. var loader = handlers[ i + 1 ];
  13614. if ( regex.test( file ) ) {
  13615. return loader;
  13616. }
  13617. }
  13618. return null;
  13619. }
  13620. };
  13621. Object.assign( Loader.prototype, {
  13622. crossOrigin: undefined,
  13623. extractUrlBase: function ( url ) {
  13624. var parts = url.split( '/' );
  13625. if ( parts.length === 1 ) return './';
  13626. parts.pop();
  13627. return parts.join( '/' ) + '/';
  13628. },
  13629. initMaterials: function ( materials, texturePath, crossOrigin ) {
  13630. var array = [];
  13631. for ( var i = 0; i < materials.length; ++ i ) {
  13632. array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
  13633. }
  13634. return array;
  13635. },
  13636. createMaterial: ( function () {
  13637. var BlendingMode = {
  13638. NoBlending: NoBlending,
  13639. NormalBlending: NormalBlending,
  13640. AdditiveBlending: AdditiveBlending,
  13641. SubtractiveBlending: SubtractiveBlending,
  13642. MultiplyBlending: MultiplyBlending,
  13643. CustomBlending: CustomBlending
  13644. };
  13645. var color = new Color();
  13646. var textureLoader = new TextureLoader();
  13647. var materialLoader = new MaterialLoader();
  13648. return function createMaterial( m, texturePath, crossOrigin ) {
  13649. // convert from old material format
  13650. var textures = {};
  13651. function loadTexture( path, repeat, offset, wrap, anisotropy ) {
  13652. var fullPath = texturePath + path;
  13653. var loader = Loader.Handlers.get( fullPath );
  13654. var texture;
  13655. if ( loader !== null ) {
  13656. texture = loader.load( fullPath );
  13657. } else {
  13658. textureLoader.setCrossOrigin( crossOrigin );
  13659. texture = textureLoader.load( fullPath );
  13660. }
  13661. if ( repeat !== undefined ) {
  13662. texture.repeat.fromArray( repeat );
  13663. if ( repeat[ 0 ] !== 1 ) texture.wrapS = RepeatWrapping;
  13664. if ( repeat[ 1 ] !== 1 ) texture.wrapT = RepeatWrapping;
  13665. }
  13666. if ( offset !== undefined ) {
  13667. texture.offset.fromArray( offset );
  13668. }
  13669. if ( wrap !== undefined ) {
  13670. if ( wrap[ 0 ] === 'repeat' ) texture.wrapS = RepeatWrapping;
  13671. if ( wrap[ 0 ] === 'mirror' ) texture.wrapS = MirroredRepeatWrapping;
  13672. if ( wrap[ 1 ] === 'repeat' ) texture.wrapT = RepeatWrapping;
  13673. if ( wrap[ 1 ] === 'mirror' ) texture.wrapT = MirroredRepeatWrapping;
  13674. }
  13675. if ( anisotropy !== undefined ) {
  13676. texture.anisotropy = anisotropy;
  13677. }
  13678. var uuid = _Math.generateUUID();
  13679. textures[ uuid ] = texture;
  13680. return uuid;
  13681. }
  13682. //
  13683. var json = {
  13684. uuid: _Math.generateUUID(),
  13685. type: 'MeshLambertMaterial'
  13686. };
  13687. for ( var name in m ) {
  13688. var value = m[ name ];
  13689. switch ( name ) {
  13690. case 'DbgColor':
  13691. case 'DbgIndex':
  13692. case 'opticalDensity':
  13693. case 'illumination':
  13694. break;
  13695. case 'DbgName':
  13696. json.name = value;
  13697. break;
  13698. case 'blending':
  13699. json.blending = BlendingMode[ value ];
  13700. break;
  13701. case 'colorAmbient':
  13702. case 'mapAmbient':
  13703. console.warn( 'THREE.Loader.createMaterial:', name, 'is no longer supported.' );
  13704. break;
  13705. case 'colorDiffuse':
  13706. json.color = color.fromArray( value ).getHex();
  13707. break;
  13708. case 'colorSpecular':
  13709. json.specular = color.fromArray( value ).getHex();
  13710. break;
  13711. case 'colorEmissive':
  13712. json.emissive = color.fromArray( value ).getHex();
  13713. break;
  13714. case 'specularCoef':
  13715. json.shininess = value;
  13716. break;
  13717. case 'shading':
  13718. if ( value.toLowerCase() === 'basic' ) json.type = 'MeshBasicMaterial';
  13719. if ( value.toLowerCase() === 'phong' ) json.type = 'MeshPhongMaterial';
  13720. if ( value.toLowerCase() === 'standard' ) json.type = 'MeshStandardMaterial';
  13721. break;
  13722. case 'mapDiffuse':
  13723. json.map = loadTexture( value, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  13724. break;
  13725. case 'mapDiffuseRepeat':
  13726. case 'mapDiffuseOffset':
  13727. case 'mapDiffuseWrap':
  13728. case 'mapDiffuseAnisotropy':
  13729. break;
  13730. case 'mapEmissive':
  13731. json.emissiveMap = loadTexture( value, m.mapEmissiveRepeat, m.mapEmissiveOffset, m.mapEmissiveWrap, m.mapEmissiveAnisotropy );
  13732. break;
  13733. case 'mapEmissiveRepeat':
  13734. case 'mapEmissiveOffset':
  13735. case 'mapEmissiveWrap':
  13736. case 'mapEmissiveAnisotropy':
  13737. break;
  13738. case 'mapLight':
  13739. json.lightMap = loadTexture( value, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  13740. break;
  13741. case 'mapLightRepeat':
  13742. case 'mapLightOffset':
  13743. case 'mapLightWrap':
  13744. case 'mapLightAnisotropy':
  13745. break;
  13746. case 'mapAO':
  13747. json.aoMap = loadTexture( value, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  13748. break;
  13749. case 'mapAORepeat':
  13750. case 'mapAOOffset':
  13751. case 'mapAOWrap':
  13752. case 'mapAOAnisotropy':
  13753. break;
  13754. case 'mapBump':
  13755. json.bumpMap = loadTexture( value, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  13756. break;
  13757. case 'mapBumpScale':
  13758. json.bumpScale = value;
  13759. break;
  13760. case 'mapBumpRepeat':
  13761. case 'mapBumpOffset':
  13762. case 'mapBumpWrap':
  13763. case 'mapBumpAnisotropy':
  13764. break;
  13765. case 'mapNormal':
  13766. json.normalMap = loadTexture( value, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  13767. break;
  13768. case 'mapNormalFactor':
  13769. json.normalScale = [ value, value ];
  13770. break;
  13771. case 'mapNormalRepeat':
  13772. case 'mapNormalOffset':
  13773. case 'mapNormalWrap':
  13774. case 'mapNormalAnisotropy':
  13775. break;
  13776. case 'mapSpecular':
  13777. json.specularMap = loadTexture( value, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  13778. break;
  13779. case 'mapSpecularRepeat':
  13780. case 'mapSpecularOffset':
  13781. case 'mapSpecularWrap':
  13782. case 'mapSpecularAnisotropy':
  13783. break;
  13784. case 'mapMetalness':
  13785. json.metalnessMap = loadTexture( value, m.mapMetalnessRepeat, m.mapMetalnessOffset, m.mapMetalnessWrap, m.mapMetalnessAnisotropy );
  13786. break;
  13787. case 'mapMetalnessRepeat':
  13788. case 'mapMetalnessOffset':
  13789. case 'mapMetalnessWrap':
  13790. case 'mapMetalnessAnisotropy':
  13791. break;
  13792. case 'mapRoughness':
  13793. json.roughnessMap = loadTexture( value, m.mapRoughnessRepeat, m.mapRoughnessOffset, m.mapRoughnessWrap, m.mapRoughnessAnisotropy );
  13794. break;
  13795. case 'mapRoughnessRepeat':
  13796. case 'mapRoughnessOffset':
  13797. case 'mapRoughnessWrap':
  13798. case 'mapRoughnessAnisotropy':
  13799. break;
  13800. case 'mapAlpha':
  13801. json.alphaMap = loadTexture( value, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  13802. break;
  13803. case 'mapAlphaRepeat':
  13804. case 'mapAlphaOffset':
  13805. case 'mapAlphaWrap':
  13806. case 'mapAlphaAnisotropy':
  13807. break;
  13808. case 'flipSided':
  13809. json.side = BackSide;
  13810. break;
  13811. case 'doubleSided':
  13812. json.side = DoubleSide;
  13813. break;
  13814. case 'transparency':
  13815. console.warn( 'THREE.Loader.createMaterial: transparency has been renamed to opacity' );
  13816. json.opacity = value;
  13817. break;
  13818. case 'depthTest':
  13819. case 'depthWrite':
  13820. case 'colorWrite':
  13821. case 'opacity':
  13822. case 'reflectivity':
  13823. case 'transparent':
  13824. case 'visible':
  13825. case 'wireframe':
  13826. json[ name ] = value;
  13827. break;
  13828. case 'vertexColors':
  13829. if ( value === true ) json.vertexColors = VertexColors;
  13830. if ( value === 'face' ) json.vertexColors = FaceColors;
  13831. break;
  13832. default:
  13833. console.error( 'THREE.Loader.createMaterial: Unsupported', name, value );
  13834. break;
  13835. }
  13836. }
  13837. if ( json.type === 'MeshBasicMaterial' ) delete json.emissive;
  13838. if ( json.type !== 'MeshPhongMaterial' ) delete json.specular;
  13839. if ( json.opacity < 1 ) json.transparent = true;
  13840. materialLoader.setTextures( textures );
  13841. return materialLoader.parse( json );
  13842. };
  13843. } )()
  13844. } );
  13845. /**
  13846. * @author mrdoob / http://mrdoob.com/
  13847. * @author alteredq / http://alteredqualia.com/
  13848. */
  13849. function JSONLoader( manager ) {
  13850. if ( typeof manager === 'boolean' ) {
  13851. console.warn( 'THREE.JSONLoader: showStatus parameter has been removed from constructor.' );
  13852. manager = undefined;
  13853. }
  13854. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  13855. this.withCredentials = false;
  13856. }
  13857. Object.assign( JSONLoader.prototype, {
  13858. load: function ( url, onLoad, onProgress, onError ) {
  13859. var scope = this;
  13860. var texturePath = this.texturePath && ( typeof this.texturePath === "string" ) ? this.texturePath : Loader.prototype.extractUrlBase( url );
  13861. var loader = new FileLoader( this.manager );
  13862. loader.setWithCredentials( this.withCredentials );
  13863. loader.load( url, function ( text ) {
  13864. var json = JSON.parse( text );
  13865. var metadata = json.metadata;
  13866. if ( metadata !== undefined ) {
  13867. var type = metadata.type;
  13868. if ( type !== undefined ) {
  13869. if ( type.toLowerCase() === 'object' ) {
  13870. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.ObjectLoader instead.' );
  13871. return;
  13872. }
  13873. if ( type.toLowerCase() === 'scene' ) {
  13874. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.SceneLoader instead.' );
  13875. return;
  13876. }
  13877. }
  13878. }
  13879. var object = scope.parse( json, texturePath );
  13880. onLoad( object.geometry, object.materials );
  13881. }, onProgress, onError );
  13882. },
  13883. setTexturePath: function ( value ) {
  13884. this.texturePath = value;
  13885. },
  13886. parse: ( function () {
  13887. function parseModel( json, geometry ) {
  13888. function isBitSet( value, position ) {
  13889. return value & ( 1 << position );
  13890. }
  13891. var i, j, fi,
  13892. offset, zLength,
  13893. colorIndex, normalIndex, uvIndex, materialIndex,
  13894. type,
  13895. isQuad,
  13896. hasMaterial,
  13897. hasFaceVertexUv,
  13898. hasFaceNormal, hasFaceVertexNormal,
  13899. hasFaceColor, hasFaceVertexColor,
  13900. vertex, face, faceA, faceB, hex, normal,
  13901. uvLayer, uv, u, v,
  13902. faces = json.faces,
  13903. vertices = json.vertices,
  13904. normals = json.normals,
  13905. colors = json.colors,
  13906. scale = json.scale,
  13907. nUvLayers = 0;
  13908. if ( json.uvs !== undefined ) {
  13909. // disregard empty arrays
  13910. for ( i = 0; i < json.uvs.length; i ++ ) {
  13911. if ( json.uvs[ i ].length ) nUvLayers ++;
  13912. }
  13913. for ( i = 0; i < nUvLayers; i ++ ) {
  13914. geometry.faceVertexUvs[ i ] = [];
  13915. }
  13916. }
  13917. offset = 0;
  13918. zLength = vertices.length;
  13919. while ( offset < zLength ) {
  13920. vertex = new Vector3();
  13921. vertex.x = vertices[ offset ++ ] * scale;
  13922. vertex.y = vertices[ offset ++ ] * scale;
  13923. vertex.z = vertices[ offset ++ ] * scale;
  13924. geometry.vertices.push( vertex );
  13925. }
  13926. offset = 0;
  13927. zLength = faces.length;
  13928. while ( offset < zLength ) {
  13929. type = faces[ offset ++ ];
  13930. isQuad = isBitSet( type, 0 );
  13931. hasMaterial = isBitSet( type, 1 );
  13932. hasFaceVertexUv = isBitSet( type, 3 );
  13933. hasFaceNormal = isBitSet( type, 4 );
  13934. hasFaceVertexNormal = isBitSet( type, 5 );
  13935. hasFaceColor = isBitSet( type, 6 );
  13936. hasFaceVertexColor = isBitSet( type, 7 );
  13937. // console.log("type", type, "bits", isQuad, hasMaterial, hasFaceVertexUv, hasFaceNormal, hasFaceVertexNormal, hasFaceColor, hasFaceVertexColor);
  13938. if ( isQuad ) {
  13939. faceA = new Face3();
  13940. faceA.a = faces[ offset ];
  13941. faceA.b = faces[ offset + 1 ];
  13942. faceA.c = faces[ offset + 3 ];
  13943. faceB = new Face3();
  13944. faceB.a = faces[ offset + 1 ];
  13945. faceB.b = faces[ offset + 2 ];
  13946. faceB.c = faces[ offset + 3 ];
  13947. offset += 4;
  13948. if ( hasMaterial ) {
  13949. materialIndex = faces[ offset ++ ];
  13950. faceA.materialIndex = materialIndex;
  13951. faceB.materialIndex = materialIndex;
  13952. }
  13953. // to get face <=> uv index correspondence
  13954. fi = geometry.faces.length;
  13955. if ( hasFaceVertexUv ) {
  13956. for ( i = 0; i < nUvLayers; i ++ ) {
  13957. uvLayer = json.uvs[ i ];
  13958. geometry.faceVertexUvs[ i ][ fi ] = [];
  13959. geometry.faceVertexUvs[ i ][ fi + 1 ] = [];
  13960. for ( j = 0; j < 4; j ++ ) {
  13961. uvIndex = faces[ offset ++ ];
  13962. u = uvLayer[ uvIndex * 2 ];
  13963. v = uvLayer[ uvIndex * 2 + 1 ];
  13964. uv = new Vector2( u, v );
  13965. if ( j !== 2 ) geometry.faceVertexUvs[ i ][ fi ].push( uv );
  13966. if ( j !== 0 ) geometry.faceVertexUvs[ i ][ fi + 1 ].push( uv );
  13967. }
  13968. }
  13969. }
  13970. if ( hasFaceNormal ) {
  13971. normalIndex = faces[ offset ++ ] * 3;
  13972. faceA.normal.set(
  13973. normals[ normalIndex ++ ],
  13974. normals[ normalIndex ++ ],
  13975. normals[ normalIndex ]
  13976. );
  13977. faceB.normal.copy( faceA.normal );
  13978. }
  13979. if ( hasFaceVertexNormal ) {
  13980. for ( i = 0; i < 4; i ++ ) {
  13981. normalIndex = faces[ offset ++ ] * 3;
  13982. normal = new Vector3(
  13983. normals[ normalIndex ++ ],
  13984. normals[ normalIndex ++ ],
  13985. normals[ normalIndex ]
  13986. );
  13987. if ( i !== 2 ) faceA.vertexNormals.push( normal );
  13988. if ( i !== 0 ) faceB.vertexNormals.push( normal );
  13989. }
  13990. }
  13991. if ( hasFaceColor ) {
  13992. colorIndex = faces[ offset ++ ];
  13993. hex = colors[ colorIndex ];
  13994. faceA.color.setHex( hex );
  13995. faceB.color.setHex( hex );
  13996. }
  13997. if ( hasFaceVertexColor ) {
  13998. for ( i = 0; i < 4; i ++ ) {
  13999. colorIndex = faces[ offset ++ ];
  14000. hex = colors[ colorIndex ];
  14001. if ( i !== 2 ) faceA.vertexColors.push( new Color( hex ) );
  14002. if ( i !== 0 ) faceB.vertexColors.push( new Color( hex ) );
  14003. }
  14004. }
  14005. geometry.faces.push( faceA );
  14006. geometry.faces.push( faceB );
  14007. } else {
  14008. face = new Face3();
  14009. face.a = faces[ offset ++ ];
  14010. face.b = faces[ offset ++ ];
  14011. face.c = faces[ offset ++ ];
  14012. if ( hasMaterial ) {
  14013. materialIndex = faces[ offset ++ ];
  14014. face.materialIndex = materialIndex;
  14015. }
  14016. // to get face <=> uv index correspondence
  14017. fi = geometry.faces.length;
  14018. if ( hasFaceVertexUv ) {
  14019. for ( i = 0; i < nUvLayers; i ++ ) {
  14020. uvLayer = json.uvs[ i ];
  14021. geometry.faceVertexUvs[ i ][ fi ] = [];
  14022. for ( j = 0; j < 3; j ++ ) {
  14023. uvIndex = faces[ offset ++ ];
  14024. u = uvLayer[ uvIndex * 2 ];
  14025. v = uvLayer[ uvIndex * 2 + 1 ];
  14026. uv = new Vector2( u, v );
  14027. geometry.faceVertexUvs[ i ][ fi ].push( uv );
  14028. }
  14029. }
  14030. }
  14031. if ( hasFaceNormal ) {
  14032. normalIndex = faces[ offset ++ ] * 3;
  14033. face.normal.set(
  14034. normals[ normalIndex ++ ],
  14035. normals[ normalIndex ++ ],
  14036. normals[ normalIndex ]
  14037. );
  14038. }
  14039. if ( hasFaceVertexNormal ) {
  14040. for ( i = 0; i < 3; i ++ ) {
  14041. normalIndex = faces[ offset ++ ] * 3;
  14042. normal = new Vector3(
  14043. normals[ normalIndex ++ ],
  14044. normals[ normalIndex ++ ],
  14045. normals[ normalIndex ]
  14046. );
  14047. face.vertexNormals.push( normal );
  14048. }
  14049. }
  14050. if ( hasFaceColor ) {
  14051. colorIndex = faces[ offset ++ ];
  14052. face.color.setHex( colors[ colorIndex ] );
  14053. }
  14054. if ( hasFaceVertexColor ) {
  14055. for ( i = 0; i < 3; i ++ ) {
  14056. colorIndex = faces[ offset ++ ];
  14057. face.vertexColors.push( new Color( colors[ colorIndex ] ) );
  14058. }
  14059. }
  14060. geometry.faces.push( face );
  14061. }
  14062. }
  14063. }
  14064. function parseSkin( json, geometry ) {
  14065. var influencesPerVertex = ( json.influencesPerVertex !== undefined ) ? json.influencesPerVertex : 2;
  14066. if ( json.skinWeights ) {
  14067. for ( var i = 0, l = json.skinWeights.length; i < l; i += influencesPerVertex ) {
  14068. var x = json.skinWeights[ i ];
  14069. var y = ( influencesPerVertex > 1 ) ? json.skinWeights[ i + 1 ] : 0;
  14070. var z = ( influencesPerVertex > 2 ) ? json.skinWeights[ i + 2 ] : 0;
  14071. var w = ( influencesPerVertex > 3 ) ? json.skinWeights[ i + 3 ] : 0;
  14072. geometry.skinWeights.push( new Vector4( x, y, z, w ) );
  14073. }
  14074. }
  14075. if ( json.skinIndices ) {
  14076. for ( var i = 0, l = json.skinIndices.length; i < l; i += influencesPerVertex ) {
  14077. var a = json.skinIndices[ i ];
  14078. var b = ( influencesPerVertex > 1 ) ? json.skinIndices[ i + 1 ] : 0;
  14079. var c = ( influencesPerVertex > 2 ) ? json.skinIndices[ i + 2 ] : 0;
  14080. var d = ( influencesPerVertex > 3 ) ? json.skinIndices[ i + 3 ] : 0;
  14081. geometry.skinIndices.push( new Vector4( a, b, c, d ) );
  14082. }
  14083. }
  14084. geometry.bones = json.bones;
  14085. if ( geometry.bones && geometry.bones.length > 0 && ( geometry.skinWeights.length !== geometry.skinIndices.length || geometry.skinIndices.length !== geometry.vertices.length ) ) {
  14086. console.warn( 'When skinning, number of vertices (' + geometry.vertices.length + '), skinIndices (' +
  14087. geometry.skinIndices.length + '), and skinWeights (' + geometry.skinWeights.length + ') should match.' );
  14088. }
  14089. }
  14090. function parseMorphing( json, geometry ) {
  14091. var scale = json.scale;
  14092. if ( json.morphTargets !== undefined ) {
  14093. for ( var i = 0, l = json.morphTargets.length; i < l; i ++ ) {
  14094. geometry.morphTargets[ i ] = {};
  14095. geometry.morphTargets[ i ].name = json.morphTargets[ i ].name;
  14096. geometry.morphTargets[ i ].vertices = [];
  14097. var dstVertices = geometry.morphTargets[ i ].vertices;
  14098. var srcVertices = json.morphTargets[ i ].vertices;
  14099. for ( var v = 0, vl = srcVertices.length; v < vl; v += 3 ) {
  14100. var vertex = new Vector3();
  14101. vertex.x = srcVertices[ v ] * scale;
  14102. vertex.y = srcVertices[ v + 1 ] * scale;
  14103. vertex.z = srcVertices[ v + 2 ] * scale;
  14104. dstVertices.push( vertex );
  14105. }
  14106. }
  14107. }
  14108. if ( json.morphColors !== undefined && json.morphColors.length > 0 ) {
  14109. console.warn( 'THREE.JSONLoader: "morphColors" no longer supported. Using them as face colors.' );
  14110. var faces = geometry.faces;
  14111. var morphColors = json.morphColors[ 0 ].colors;
  14112. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  14113. faces[ i ].color.fromArray( morphColors, i * 3 );
  14114. }
  14115. }
  14116. }
  14117. function parseAnimations( json, geometry ) {
  14118. var outputAnimations = [];
  14119. // parse old style Bone/Hierarchy animations
  14120. var animations = [];
  14121. if ( json.animation !== undefined ) {
  14122. animations.push( json.animation );
  14123. }
  14124. if ( json.animations !== undefined ) {
  14125. if ( json.animations.length ) {
  14126. animations = animations.concat( json.animations );
  14127. } else {
  14128. animations.push( json.animations );
  14129. }
  14130. }
  14131. for ( var i = 0; i < animations.length; i ++ ) {
  14132. var clip = AnimationClip.parseAnimation( animations[ i ], geometry.bones );
  14133. if ( clip ) outputAnimations.push( clip );
  14134. }
  14135. // parse implicit morph animations
  14136. if ( geometry.morphTargets ) {
  14137. // TODO: Figure out what an appropraite FPS is for morph target animations -- defaulting to 10, but really it is completely arbitrary.
  14138. var morphAnimationClips = AnimationClip.CreateClipsFromMorphTargetSequences( geometry.morphTargets, 10 );
  14139. outputAnimations = outputAnimations.concat( morphAnimationClips );
  14140. }
  14141. if ( outputAnimations.length > 0 ) geometry.animations = outputAnimations;
  14142. }
  14143. return function ( json, texturePath ) {
  14144. if ( json.data !== undefined ) {
  14145. // Geometry 4.0 spec
  14146. json = json.data;
  14147. }
  14148. if ( json.scale !== undefined ) {
  14149. json.scale = 1.0 / json.scale;
  14150. } else {
  14151. json.scale = 1.0;
  14152. }
  14153. var geometry = new Geometry();
  14154. parseModel( json, geometry );
  14155. parseSkin( json, geometry );
  14156. parseMorphing( json, geometry );
  14157. parseAnimations( json, geometry );
  14158. geometry.computeFaceNormals();
  14159. geometry.computeBoundingSphere();
  14160. if ( json.materials === undefined || json.materials.length === 0 ) {
  14161. return { geometry: geometry };
  14162. } else {
  14163. var materials = Loader.prototype.initMaterials( json.materials, texturePath, this.crossOrigin );
  14164. return { geometry: geometry, materials: materials };
  14165. }
  14166. };
  14167. } )()
  14168. } );
  14169. /**
  14170. * @author mrdoob / http://mrdoob.com/
  14171. */
  14172. function Line( geometry, material, mode ) {
  14173. if ( mode === 1 ) {
  14174. console.warn( 'THREE.Line: parameter THREE.LinePieces no longer supported. Created THREE.LineSegments instead.' );
  14175. return new LineSegments( geometry, material );
  14176. }
  14177. Object3D.call( this );
  14178. this.type = 'Line';
  14179. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  14180. this.material = material !== undefined ? material : new LineBasicMaterial( { color: Math.random() * 0xffffff } );
  14181. }
  14182. Line.prototype = Object.assign( Object.create( Object3D.prototype ), {
  14183. constructor: Line,
  14184. isLine: true,
  14185. raycast: ( function () {
  14186. var inverseMatrix = new Matrix4();
  14187. var ray = new Ray();
  14188. var sphere = new Sphere();
  14189. return function raycast( raycaster, intersects ) {
  14190. var precision = raycaster.linePrecision;
  14191. var precisionSq = precision * precision;
  14192. var geometry = this.geometry;
  14193. var matrixWorld = this.matrixWorld;
  14194. // Checking boundingSphere distance to ray
  14195. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  14196. sphere.copy( geometry.boundingSphere );
  14197. sphere.applyMatrix4( matrixWorld );
  14198. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  14199. //
  14200. inverseMatrix.getInverse( matrixWorld );
  14201. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  14202. var vStart = new Vector3();
  14203. var vEnd = new Vector3();
  14204. var interSegment = new Vector3();
  14205. var interRay = new Vector3();
  14206. var step = ( this && this.isLineSegments ) ? 2 : 1;
  14207. if ( geometry.isBufferGeometry ) {
  14208. var index = geometry.index;
  14209. var attributes = geometry.attributes;
  14210. var positions = attributes.position.array;
  14211. if ( index !== null ) {
  14212. var indices = index.array;
  14213. for ( var i = 0, l = indices.length - 1; i < l; i += step ) {
  14214. var a = indices[ i ];
  14215. var b = indices[ i + 1 ];
  14216. vStart.fromArray( positions, a * 3 );
  14217. vEnd.fromArray( positions, b * 3 );
  14218. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  14219. if ( distSq > precisionSq ) continue;
  14220. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  14221. var distance = raycaster.ray.origin.distanceTo( interRay );
  14222. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  14223. intersects.push( {
  14224. distance: distance,
  14225. // What do we want? intersection point on the ray or on the segment??
  14226. // point: raycaster.ray.at( distance ),
  14227. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  14228. index: i,
  14229. face: null,
  14230. faceIndex: null,
  14231. object: this
  14232. } );
  14233. }
  14234. } else {
  14235. for ( var i = 0, l = positions.length / 3 - 1; i < l; i += step ) {
  14236. vStart.fromArray( positions, 3 * i );
  14237. vEnd.fromArray( positions, 3 * i + 3 );
  14238. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  14239. if ( distSq > precisionSq ) continue;
  14240. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  14241. var distance = raycaster.ray.origin.distanceTo( interRay );
  14242. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  14243. intersects.push( {
  14244. distance: distance,
  14245. // What do we want? intersection point on the ray or on the segment??
  14246. // point: raycaster.ray.at( distance ),
  14247. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  14248. index: i,
  14249. face: null,
  14250. faceIndex: null,
  14251. object: this
  14252. } );
  14253. }
  14254. }
  14255. } else if ( geometry.isGeometry ) {
  14256. var vertices = geometry.vertices;
  14257. var nbVertices = vertices.length;
  14258. for ( var i = 0; i < nbVertices - 1; i += step ) {
  14259. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  14260. if ( distSq > precisionSq ) continue;
  14261. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  14262. var distance = raycaster.ray.origin.distanceTo( interRay );
  14263. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  14264. intersects.push( {
  14265. distance: distance,
  14266. // What do we want? intersection point on the ray or on the segment??
  14267. // point: raycaster.ray.at( distance ),
  14268. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  14269. index: i,
  14270. face: null,
  14271. faceIndex: null,
  14272. object: this
  14273. } );
  14274. }
  14275. }
  14276. };
  14277. }() ),
  14278. clone: function () {
  14279. return new this.constructor( this.geometry, this.material ).copy( this );
  14280. }
  14281. } );
  14282. /**
  14283. * @author mrdoob / http://mrdoob.com/
  14284. */
  14285. function LineSegments( geometry, material ) {
  14286. Line.call( this, geometry, material );
  14287. this.type = 'LineSegments';
  14288. }
  14289. LineSegments.prototype = Object.assign( Object.create( Line.prototype ), {
  14290. constructor: LineSegments,
  14291. isLineSegments: true
  14292. } );
  14293. /**
  14294. * @author bhouston / http://exocortex.com
  14295. */
  14296. const x = 2;
  14297. const y = 3;
  14298. const z = 4;
  14299. const w = 5;
  14300. const negInf2 = new Vector2( - Infinity, - Infinity );
  14301. const posInf2 = new Vector2( Infinity, Infinity );
  14302. const zero2 = new Vector2();
  14303. const one2 = new Vector2( 1, 1 );
  14304. const two2 = new Vector2( 2, 2 );
  14305. const negInf3 = new Vector3( - Infinity, - Infinity, - Infinity );
  14306. const posInf3 = new Vector3( Infinity, Infinity, Infinity );
  14307. const zero3 = new Vector3();
  14308. const one3 = new Vector3( 1, 1, 1 );
  14309. const two3 = new Vector3( 2, 2, 2 );
  14310. const eps = 0.0001;
  14311. /**
  14312. * @author simonThiele / https://github.com/simonThiele
  14313. * @author TristanVALCKE / https://github.com/Itee
  14314. */
  14315. /* global QUnit */
  14316. var DegToRad = Math.PI / 180;
  14317. function bufferAttributeEquals( a, b, tolerance ) {
  14318. tolerance = tolerance || 0.0001;
  14319. if ( a.count !== b.count || a.itemSize !== b.itemSize ) {
  14320. return false;
  14321. }
  14322. for ( var i = 0, il = a.count * a.itemSize; i < il; i ++ ) {
  14323. var delta = a[ i ] - b[ i ];
  14324. if ( delta > tolerance ) {
  14325. return false;
  14326. }
  14327. }
  14328. return true;
  14329. }
  14330. function getBBForVertices( vertices ) {
  14331. var geometry = new BufferGeometry();
  14332. geometry.addAttribute( "position", new BufferAttribute( new Float32Array( vertices ), 3 ) );
  14333. geometry.computeBoundingBox();
  14334. return geometry.boundingBox;
  14335. }
  14336. function getBSForVertices( vertices ) {
  14337. var geometry = new BufferGeometry();
  14338. geometry.addAttribute( "position", new BufferAttribute( new Float32Array( vertices ), 3 ) );
  14339. geometry.computeBoundingSphere();
  14340. return geometry.boundingSphere;
  14341. }
  14342. function getNormalsForVertices( vertices, assert ) {
  14343. var geometry = new BufferGeometry();
  14344. geometry.addAttribute( "position", new BufferAttribute( new Float32Array( vertices ), 3 ) );
  14345. geometry.computeVertexNormals();
  14346. assert.ok( geometry.attributes.normal !== undefined, "normal attribute was created" );
  14347. return geometry.attributes.normal.array;
  14348. }
  14349. function comparePositions( pos, v ) {
  14350. return (
  14351. pos[ 0 ] === v[ 0 ].x && pos[ 1 ] === v[ 0 ].y && pos[ 2 ] === v[ 0 ].z &&
  14352. pos[ 3 ] === v[ 1 ].x && pos[ 4 ] === v[ 1 ].y && pos[ 5 ] === v[ 1 ].z &&
  14353. pos[ 6 ] === v[ 2 ].x && pos[ 7 ] === v[ 2 ].y && pos[ 8 ] === v[ 2 ].z
  14354. );
  14355. }
  14356. function compareColors( col, c ) {
  14357. return (
  14358. col[ 0 ] === c[ 0 ].r && col[ 1 ] === c[ 0 ].g && col[ 2 ] === c[ 0 ].b &&
  14359. col[ 3 ] === c[ 1 ].r && col[ 4 ] === c[ 1 ].g && col[ 5 ] === c[ 1 ].b &&
  14360. col[ 6 ] === c[ 2 ].r && col[ 7 ] === c[ 2 ].g && col[ 8 ] === c[ 2 ].b
  14361. );
  14362. }
  14363. function compareUvs( uvs, u ) {
  14364. return (
  14365. uvs[ 0 ] === u[ 0 ].x && uvs[ 1 ] === u[ 0 ].y &&
  14366. uvs[ 2 ] === u[ 1 ].x && uvs[ 3 ] === u[ 1 ].y &&
  14367. uvs[ 4 ] === u[ 2 ].x && uvs[ 5 ] === u[ 2 ].y
  14368. );
  14369. }
  14370. QUnit.module( 'Core', () => {
  14371. QUnit.module.todo( 'BufferGeometry', () => {
  14372. // INHERITANCE
  14373. QUnit.test( "Extending", ( assert ) => {
  14374. assert.ok( false, "everything's gonna be alright" );
  14375. } );
  14376. // INSTANCING
  14377. QUnit.test( "Instancing", ( assert ) => {
  14378. assert.ok( false, "everything's gonna be alright" );
  14379. } );
  14380. // PUBLIC STUFF
  14381. QUnit.test( "isBufferGeometry", ( assert ) => {
  14382. assert.ok( false, "everything's gonna be alright" );
  14383. } );
  14384. QUnit.test( "setIndex/getIndex", ( assert ) => {
  14385. var a = new BufferGeometry();
  14386. var uint16 = [ 1, 2, 3 ];
  14387. var uint32 = [ 65535, 65536, 65537 ];
  14388. var str = "foo";
  14389. a.setIndex( uint16 );
  14390. assert.ok( a.getIndex() instanceof Uint16BufferAttribute, "Index has the right type" );
  14391. assert.deepEqual( a.getIndex().array, new Uint16Array( uint16 ), "Small index gets stored correctly" );
  14392. a.setIndex( uint32 );
  14393. assert.ok( a.getIndex() instanceof Uint32BufferAttribute, "Index has the right type" );
  14394. assert.deepEqual( a.getIndex().array, new Uint32Array( uint32 ), "Large index gets stored correctly" );
  14395. a.setIndex( str );
  14396. assert.strictEqual( a.getIndex(), str, "Weird index gets stored correctly" );
  14397. } );
  14398. QUnit.test( "getAttribute", ( assert ) => {
  14399. assert.ok( false, "everything's gonna be alright" );
  14400. } );
  14401. QUnit.test( "add / delete Attribute", ( assert ) => {
  14402. var geometry = new BufferGeometry();
  14403. var attributeName = "position";
  14404. assert.ok( geometry.attributes[ attributeName ] === undefined, 'no attribute defined' );
  14405. geometry.addAttribute( attributeName, new BufferAttribute( new Float32Array( [ 1, 2, 3 ], 1 ) ) );
  14406. assert.ok( geometry.attributes[ attributeName ] !== undefined, 'attribute is defined' );
  14407. geometry.removeAttribute( attributeName );
  14408. assert.ok( geometry.attributes[ attributeName ] === undefined, 'no attribute defined' );
  14409. } );
  14410. QUnit.test( "addGroup", ( assert ) => {
  14411. var a = new BufferGeometry();
  14412. var expected = [
  14413. {
  14414. start: 0,
  14415. count: 1,
  14416. materialIndex: 0
  14417. },
  14418. {
  14419. start: 1,
  14420. count: 2,
  14421. materialIndex: 2
  14422. }
  14423. ];
  14424. a.addGroup( 0, 1, 0 );
  14425. a.addGroup( 1, 2, 2 );
  14426. assert.deepEqual( a.groups, expected, "Check groups were stored correctly and in order" );
  14427. a.clearGroups();
  14428. assert.strictEqual( a.groups.length, 0, "Check groups were deleted correctly" );
  14429. } );
  14430. QUnit.test( "clearGroups", ( assert ) => {
  14431. assert.ok( false, "everything's gonna be alright" );
  14432. } );
  14433. QUnit.test( "setDrawRange", ( assert ) => {
  14434. var a = new BufferGeometry();
  14435. a.setDrawRange( 1.0, 7 );
  14436. assert.deepEqual( a.drawRange, {
  14437. start: 1,
  14438. count: 7
  14439. }, "Check draw range was stored correctly" );
  14440. } );
  14441. QUnit.test( "applyMatrix", ( assert ) => {
  14442. var geometry = new BufferGeometry();
  14443. geometry.addAttribute( "position", new BufferAttribute( new Float32Array( 6 ), 3 ) );
  14444. var matrix = new Matrix4().set(
  14445. 1, 0, 0, 1.5,
  14446. 0, 1, 0, - 2,
  14447. 0, 0, 1, 3,
  14448. 0, 0, 0, 1
  14449. );
  14450. geometry.applyMatrix( matrix );
  14451. var position = geometry.attributes.position.array;
  14452. var m = matrix.elements;
  14453. assert.ok( position[ 0 ] === m[ 12 ] && position[ 1 ] === m[ 13 ] && position[ 2 ] === m[ 14 ], "position was extracted from matrix" );
  14454. assert.ok( position[ 3 ] === m[ 12 ] && position[ 4 ] === m[ 13 ] && position[ 5 ] === m[ 14 ], "position was extracted from matrix twice" );
  14455. assert.ok( geometry.attributes.position.version === 1, "version was increased during update" );
  14456. } );
  14457. QUnit.test( "rotateX/Y/Z", ( assert ) => {
  14458. var geometry = new BufferGeometry();
  14459. geometry.addAttribute( "position", new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 5, 6 ] ), 3 ) );
  14460. var pos = geometry.attributes.position.array;
  14461. geometry.rotateX( 180 * DegToRad );
  14462. // object was rotated around x so all items should be flipped but the x ones
  14463. assert.ok( pos[ 0 ] === 1 && pos[ 1 ] === - 2 && pos[ 2 ] === - 3 &&
  14464. pos[ 3 ] === 4 && pos[ 4 ] === - 5 && pos[ 5 ] === - 6, "vertices were rotated around x by 180 degrees" );
  14465. geometry.rotateY( 180 * DegToRad );
  14466. // vertices were rotated around y so all items should be flipped again but the y ones
  14467. assert.ok( pos[ 0 ] === - 1 && pos[ 1 ] === - 2 && pos[ 2 ] === 3 &&
  14468. pos[ 3 ] === - 4 && pos[ 4 ] === - 5 && pos[ 5 ] === 6, "vertices were rotated around y by 180 degrees" );
  14469. geometry.rotateZ( 180 * DegToRad );
  14470. // vertices were rotated around z so all items should be flipped again but the z ones
  14471. assert.ok( pos[ 0 ] === 1 && pos[ 1 ] === 2 && pos[ 2 ] === 3 &&
  14472. pos[ 3 ] === 4 && pos[ 4 ] === 5 && pos[ 5 ] === 6, "vertices were rotated around z by 180 degrees" );
  14473. } );
  14474. QUnit.test( "translate", ( assert ) => {
  14475. var geometry = new BufferGeometry();
  14476. geometry.addAttribute( "position", new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 5, 6 ] ), 3 ) );
  14477. var pos = geometry.attributes.position.array;
  14478. geometry.translate( 10, 20, 30 );
  14479. assert.ok( pos[ 0 ] === 11 && pos[ 1 ] === 22 && pos[ 2 ] === 33 &&
  14480. pos[ 3 ] === 14 && pos[ 4 ] === 25 && pos[ 5 ] === 36, "vertices were translated" );
  14481. } );
  14482. QUnit.test( "scale", ( assert ) => {
  14483. var geometry = new BufferGeometry();
  14484. geometry.addAttribute( "position", new BufferAttribute( new Float32Array( [ - 1, - 1, - 1, 2, 2, 2 ] ), 3 ) );
  14485. var pos = geometry.attributes.position.array;
  14486. geometry.scale( 1, 2, 3 );
  14487. assert.ok( pos[ 0 ] === - 1 && pos[ 1 ] === - 2 && pos[ 2 ] === - 3 &&
  14488. pos[ 3 ] === 2 && pos[ 4 ] === 4 && pos[ 5 ] === 6, "vertices were scaled" );
  14489. } );
  14490. QUnit.test( "lookAt", ( assert ) => {
  14491. var a = new BufferGeometry();
  14492. var vertices = new Float32Array( [
  14493. - 1.0, - 1.0, 1.0,
  14494. 1.0, - 1.0, 1.0,
  14495. 1.0, 1.0, 1.0,
  14496. 1.0, 1.0, 1.0,
  14497. - 1.0, 1.0, 1.0,
  14498. - 1.0, - 1.0, 1.0
  14499. ] );
  14500. a.addAttribute( 'position', new BufferAttribute( vertices, 3 ) );
  14501. var sqrt = Math.sqrt( 2 );
  14502. var expected = new Float32Array( [
  14503. 1, 0, - sqrt,
  14504. - 1, 0, - sqrt,
  14505. - 1, sqrt, 0,
  14506. - 1, sqrt, 0,
  14507. 1, sqrt, 0,
  14508. 1, 0, - sqrt
  14509. ] );
  14510. a.lookAt( new Vector3( 0, 1, - 1 ) );
  14511. assert.ok( bufferAttributeEquals( a.attributes.position.array, expected ), "Rotation is correct" );
  14512. } );
  14513. QUnit.test( "center", ( assert ) => {
  14514. var geometry = new BufferGeometry();
  14515. geometry.addAttribute( "position", new BufferAttribute( new Float32Array( [
  14516. - 1, - 1, - 1,
  14517. 1, 1, 1,
  14518. 4, 4, 4
  14519. ] ), 3 ) );
  14520. geometry.center();
  14521. var pos = geometry.attributes.position.array;
  14522. // the boundingBox should go from (-1, -1, -1) to (4, 4, 4) so it has a size of (5, 5, 5)
  14523. // after centering it the vertices should be placed between (-2.5, -2.5, -2.5) and (2.5, 2.5, 2.5)
  14524. assert.ok( pos[ 0 ] === - 2.5 && pos[ 1 ] === - 2.5 && pos[ 2 ] === - 2.5 &&
  14525. pos[ 3 ] === - 0.5 && pos[ 4 ] === - 0.5 && pos[ 5 ] === - 0.5 &&
  14526. pos[ 6 ] === 2.5 && pos[ 7 ] === 2.5 && pos[ 8 ] === 2.5, "vertices were replaced by boundingBox dimensions" );
  14527. } );
  14528. QUnit.test( "setFromObject", ( assert ) => {
  14529. var lineGeo = new Geometry();
  14530. lineGeo.vertices.push(
  14531. new Vector3( - 10, 0, 0 ),
  14532. new Vector3( 0, 10, 0 ),
  14533. new Vector3( 10, 0, 0 )
  14534. );
  14535. lineGeo.colors.push(
  14536. new Color( 1, 0, 0 ),
  14537. new Color( 0, 1, 0 ),
  14538. new Color( 0, 0, 1 )
  14539. );
  14540. var line = new LineSegments( lineGeo, null );
  14541. var geometry = new BufferGeometry().setFromObject( line );
  14542. var pos = geometry.attributes.position.array;
  14543. var col = geometry.attributes.color.array;
  14544. var v = lineGeo.vertices;
  14545. var c = lineGeo.colors;
  14546. assert.ok(
  14547. // position exists
  14548. pos !== undefined &&
  14549. // vertex arrays have the same size
  14550. v.length * 3 === pos.length &&
  14551. // there are three complete vertices (each vertex contains three values)
  14552. geometry.attributes.position.count === 3 &&
  14553. // check if both arrays contains the same data
  14554. pos[ 0 ] === v[ 0 ].x && pos[ 1 ] === v[ 0 ].y && pos[ 2 ] === v[ 0 ].z &&
  14555. pos[ 3 ] === v[ 1 ].x && pos[ 4 ] === v[ 1 ].y && pos[ 5 ] === v[ 1 ].z &&
  14556. pos[ 6 ] === v[ 2 ].x && pos[ 7 ] === v[ 2 ].y && pos[ 8 ] === v[ 2 ].z
  14557. , "positions are equal" );
  14558. assert.ok(
  14559. // color exists
  14560. col !== undefined &&
  14561. // color arrays have the same size
  14562. c.length * 3 === col.length &&
  14563. // there are three complete colors (each color contains three values)
  14564. geometry.attributes.color.count === 3 &&
  14565. // check if both arrays contains the same data
  14566. col[ 0 ] === c[ 0 ].r && col[ 1 ] === c[ 0 ].g && col[ 2 ] === c[ 0 ].b &&
  14567. col[ 3 ] === c[ 1 ].r && col[ 4 ] === c[ 1 ].g && col[ 5 ] === c[ 1 ].b &&
  14568. col[ 6 ] === c[ 2 ].r && col[ 7 ] === c[ 2 ].g && col[ 8 ] === c[ 2 ].b
  14569. , "colors are equal" );
  14570. } );
  14571. QUnit.test( "setFromObject (more)", ( assert ) => {
  14572. var lineGeo = new Geometry();
  14573. lineGeo.vertices.push(
  14574. new Vector3( - 10, 0, 0 ),
  14575. new Vector3( 0, 10, 0 ),
  14576. new Vector3( 10, 0, 0 )
  14577. );
  14578. lineGeo.colors.push(
  14579. new Color( 1, 0, 0 ),
  14580. new Color( 0, 1, 0 ),
  14581. new Color( 0, 0, 1 )
  14582. );
  14583. lineGeo.computeBoundingBox();
  14584. lineGeo.computeBoundingSphere();
  14585. var line = new LineSegments( lineGeo );
  14586. var geometry = new BufferGeometry().setFromObject( line );
  14587. assert.ok( geometry.boundingBox.equals( lineGeo.boundingBox ), "BoundingBox was set correctly" );
  14588. assert.ok( geometry.boundingSphere.equals( lineGeo.boundingSphere ), "BoundingSphere was set correctly" );
  14589. var pos = geometry.attributes.position.array;
  14590. var col = geometry.attributes.color.array;
  14591. var v = lineGeo.vertices;
  14592. var c = lineGeo.colors;
  14593. // adapted from setFromObject QUnit.test (way up)
  14594. assert.notStrictEqual( pos, undefined, "Position attribute exists" );
  14595. assert.strictEqual( v.length * 3, pos.length, "Vertex arrays have the same size" );
  14596. assert.strictEqual( geometry.attributes.position.count, 3, "Correct number of vertices" );
  14597. assert.ok( comparePositions( pos, v ), "Positions are identical" );
  14598. assert.notStrictEqual( col, undefined, "Color attribute exists" );
  14599. assert.strictEqual( c.length * 3, col.length, "Color arrays have the same size" );
  14600. assert.strictEqual( geometry.attributes.color.count, 3, "Correct number of colors" );
  14601. assert.ok( compareColors( col, c ), "Colors are identical" );
  14602. // setFromObject with a Mesh as object
  14603. lineGeo.faces.push( new Face3( 0, 1, 2 ) );
  14604. var lineMesh = new Mesh( lineGeo );
  14605. var geometry = new BufferGeometry().setFromObject( lineMesh );
  14606. // no colors
  14607. var pos = geometry.attributes.position.array;
  14608. var v = lineGeo.vertices;
  14609. assert.notStrictEqual( pos, undefined, "Mesh: position attribute exists" );
  14610. assert.strictEqual( v.length * 3, pos.length, "Mesh: vertex arrays have the same size" );
  14611. assert.strictEqual( geometry.attributes.position.count, 3, "Mesh: correct number of vertices" );
  14612. assert.ok( comparePositions( pos, v ), "Mesh: positions are identical" );
  14613. } );
  14614. QUnit.test( "updateFromObject", ( assert ) => {
  14615. var geo = new Geometry();
  14616. geo.vertices.push(
  14617. new Vector3( - 10, 0, 0 ),
  14618. new Vector3( 0, 10, 0 ),
  14619. new Vector3( 10, 0, 0 )
  14620. );
  14621. geo.faces.push( new Face3( 0, 1, 2 ) );
  14622. geo.faces[ 0 ].vertexColors.push(
  14623. new Color( 1, 0, 0 ),
  14624. new Color( 0, 1, 0 ),
  14625. new Color( 0, 0, 1 )
  14626. );
  14627. geo.faceVertexUvs[ 0 ] = [
  14628. [
  14629. new Vector2( 0, 0 ),
  14630. new Vector2( 1, 0 ),
  14631. new Vector2( 1, 1 )
  14632. ]
  14633. ];
  14634. geo.computeFaceNormals();
  14635. geo.computeVertexNormals();
  14636. geo.verticesNeedUpdate = true;
  14637. geo.normalsNeedUpdate = true;
  14638. geo.colorsNeedUpdate = true;
  14639. geo.uvsNeedUpdate = true;
  14640. geo.groupsNeedUpdate = true;
  14641. var mesh = new Mesh( geo );
  14642. var geometry = new BufferGeometry();
  14643. geometry.updateFromObject( mesh ); // first call to create the underlying structure (DirectGeometry)
  14644. geometry.updateFromObject( mesh ); // second time to actually go thru the motions and update
  14645. var pos = geometry.attributes.position.array;
  14646. var col = geometry.attributes.color.array;
  14647. var norm = geometry.attributes.normal.array;
  14648. var uvs = geometry.attributes.uv.array;
  14649. var v = geo.vertices;
  14650. var c = geo.faces[ 0 ].vertexColors;
  14651. var n = geo.faces[ 0 ].vertexNormals;
  14652. var u = geo.faceVertexUvs[ 0 ][ 0 ];
  14653. assert.notStrictEqual( pos, undefined, "Position attribute exists" );
  14654. assert.strictEqual( v.length * 3, pos.length, "Both arrays have the same size" );
  14655. assert.strictEqual( geometry.attributes.position.count, v.length, "Correct number of vertices" );
  14656. assert.ok( comparePositions( pos, v ), "Positions are identical" );
  14657. assert.notStrictEqual( col, undefined, "Color attribute exists" );
  14658. assert.strictEqual( c.length * 3, col.length, "Both arrays have the same size" );
  14659. assert.strictEqual( geometry.attributes.color.count, c.length, "Correct number of colors" );
  14660. assert.ok( compareColors( col, c ), "Colors are identical" );
  14661. assert.notStrictEqual( norm, undefined, "Normal attribute exists" );
  14662. assert.strictEqual( n.length * 3, norm.length, "Both arrays have the same size" );
  14663. assert.strictEqual( geometry.attributes.normal.count, n.length, "Correct number of normals" );
  14664. assert.ok( comparePositions( norm, n ), "Normals are identical" );
  14665. assert.notStrictEqual( uvs, undefined, "UV attribute exists" );
  14666. assert.strictEqual( u.length * 2, uvs.length, "Both arrays have the same size" );
  14667. assert.strictEqual( geometry.attributes.uv.count, u.length, "Correct number of UV coordinates" );
  14668. assert.ok( compareUvs( uvs, u ), "UVs are identical" );
  14669. } );
  14670. QUnit.test( "fromGeometry/fromDirectGeometry", ( assert ) => {
  14671. var a = new BufferGeometry();
  14672. // BoxGeometry is a bit too simple but works fine in a pinch
  14673. // var b = new BoxGeometry( 1, 1, 1 );
  14674. // b.mergeVertices();
  14675. // b.computeVertexNormals();
  14676. // b.computeBoundingBox();
  14677. // b.computeBoundingSphere();
  14678. var asyncDone = assert.async(); // tell QUnit we're done with asserts
  14679. var loader = new JSONLoader();
  14680. loader.load( "../../examples/models/skinned/simple/simple.js", function ( modelGeometry ) {
  14681. a.fromGeometry( modelGeometry );
  14682. var attr;
  14683. var geometry = new DirectGeometry().fromGeometry( modelGeometry );
  14684. var positions = new Float32Array( geometry.vertices.length * 3 );
  14685. attr = new BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices );
  14686. assert.ok( bufferAttributeEquals( a.attributes.position, attr ), "Vertices are identical" );
  14687. if ( geometry.normals.length > 0 ) {
  14688. var normals = new Float32Array( geometry.normals.length * 3 );
  14689. attr = new BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals );
  14690. assert.ok( bufferAttributeEquals( a.attributes.normal, attr ), "Normals are identical" );
  14691. }
  14692. if ( geometry.colors.length > 0 ) {
  14693. var colors = new Float32Array( geometry.colors.length * 3 );
  14694. attr = new BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors );
  14695. assert.ok( bufferAttributeEquals( a.attributes.color, attr ), "Colors are identical" );
  14696. }
  14697. if ( geometry.uvs.length > 0 ) {
  14698. var uvs = new Float32Array( geometry.uvs.length * 2 );
  14699. attr = new BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs );
  14700. assert.ok( bufferAttributeEquals( a.attributes.uv, attr ), "UVs are identical" );
  14701. }
  14702. if ( geometry.uvs2.length > 0 ) {
  14703. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  14704. attr = new BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 );
  14705. assert.ok( bufferAttributeEquals( a.attributes.uv2, attr ), "UV2s are identical" );
  14706. }
  14707. if ( geometry.indices.length > 0 ) {
  14708. var TypeArray = arrayMax( geometry.indices ) > 65535 ? Uint32Array : Uint16Array;
  14709. var indices = new TypeArray( geometry.indices.length * 3 );
  14710. attr = new BufferAttribute( indices, 1 ).copyIndicesArray( geometry.indices );
  14711. assert.ok( bufferAttributeEquals( a.indices, attr ), "Indices are identical" );
  14712. }
  14713. // groups
  14714. assert.deepEqual( a.groups, geometry.groups, "Groups are identical" );
  14715. // morphs
  14716. if ( geometry.morphTargets !== undefined ) {
  14717. for ( var name in geometry.morphTargets ) {
  14718. var morphTargets = geometry.morphTargets[ name ];
  14719. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  14720. var morphTarget = morphTargets[ i ];
  14721. attr = new Float32BufferAttribute( morphTarget.length * 3, 3 );
  14722. attr.copyVector3sArray( morphTarget );
  14723. assert.ok(
  14724. bufferAttributeEquals( a.morphAttributes[ name ][ i ], attr ),
  14725. "MorphTargets #" + i + " are identical"
  14726. );
  14727. }
  14728. }
  14729. }
  14730. // skinning
  14731. if ( geometry.skinIndices.length > 0 ) {
  14732. attr = new Float32BufferAttribute( geometry.skinIndices.length * 4, 4 );
  14733. attr.copyVector4sArray( geometry.skinIndices );
  14734. assert.ok( bufferAttributeEquals( a.attributes.skinIndex, attr ), "SkinIndices are identical" );
  14735. }
  14736. if ( geometry.skinWeights.length > 0 ) {
  14737. attr = new Float32BufferAttribute( geometry.skinWeights.length * 4, 4 );
  14738. attr.copyVector4sArray( geometry.skinWeights );
  14739. assert.ok( bufferAttributeEquals( a.attributes.skinWeight, attr ), "SkinWeights are identical" );
  14740. }
  14741. // TODO
  14742. // DirectGeometry doesn't actually copy boundingSphere and boundingBox yet,
  14743. // so they're always null
  14744. if ( geometry.boundingSphere !== null ) {
  14745. assert.ok( a.boundingSphere.equals( geometry.boundingSphere ), "BoundingSphere is identical" );
  14746. }
  14747. if ( geometry.boundingBox !== null ) {
  14748. assert.ok( a.boundingBox.equals( geometry.boundingBox ), "BoundingBox is identical" );
  14749. }
  14750. asyncDone();
  14751. } );
  14752. } );
  14753. QUnit.test( "computeBoundingBox", ( assert ) => {
  14754. var bb = getBBForVertices( [ - 1, - 2, - 3, 13, - 2, - 3.5, - 1, - 20, 0, - 4, 5, 6 ] );
  14755. assert.ok( bb.min.x === - 4 && bb.min.y === - 20 && bb.min.z === - 3.5, "min values are set correctly" );
  14756. assert.ok( bb.max.x === 13 && bb.max.y === 5 && bb.max.z === 6, "max values are set correctly" );
  14757. var bb = getBBForVertices( [ - 1, - 1, - 1 ] );
  14758. 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" );
  14759. 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" );
  14760. } );
  14761. QUnit.test( "computeBoundingSphere", ( assert ) => {
  14762. var bs = getBSForVertices( [ - 10, 0, 0, 10, 0, 0 ] );
  14763. assert.ok( bs.radius === ( 10 + 10 ) / 2, "radius is equal to deltaMinMax / 2" );
  14764. assert.ok( bs.center.x === 0 && bs.center.y === 0 && bs.center.y === 0, "bounding sphere is at ( 0, 0, 0 )" );
  14765. var bs = getBSForVertices( [ - 5, 11, - 3, 5, - 11, 3 ] );
  14766. var radius = new Vector3( 5, 11, 3 ).length();
  14767. assert.ok( bs.radius === radius, "radius is equal to directionLength" );
  14768. assert.ok( bs.center.x === 0 && bs.center.y === 0 && bs.center.y === 0, "bounding sphere is at ( 0, 0, 0 )" );
  14769. } );
  14770. QUnit.test( "computeFaceNormals", ( assert ) => {
  14771. assert.ok( false, "everything's gonna be alright" );
  14772. } );
  14773. QUnit.test( "computeVertexNormals", ( assert ) => {
  14774. // get normals for a counter clockwise created triangle
  14775. var normals = getNormalsForVertices( [ - 1, 0, 0, 1, 0, 0, 0, 1, 0 ], assert );
  14776. assert.ok( normals[ 0 ] === 0 && normals[ 1 ] === 0 && normals[ 2 ] === 1,
  14777. "first normal is pointing to screen since the the triangle was created counter clockwise" );
  14778. assert.ok( normals[ 3 ] === 0 && normals[ 4 ] === 0 && normals[ 5 ] === 1,
  14779. "second normal is pointing to screen since the the triangle was created counter clockwise" );
  14780. assert.ok( normals[ 6 ] === 0 && normals[ 7 ] === 0 && normals[ 8 ] === 1,
  14781. "third normal is pointing to screen since the the triangle was created counter clockwise" );
  14782. // get normals for a clockwise created triangle
  14783. var normals = getNormalsForVertices( [ 1, 0, 0, - 1, 0, 0, 0, 1, 0 ], assert );
  14784. assert.ok( normals[ 0 ] === 0 && normals[ 1 ] === 0 && normals[ 2 ] === - 1,
  14785. "first normal is pointing to screen since the the triangle was created clockwise" );
  14786. assert.ok( normals[ 3 ] === 0 && normals[ 4 ] === 0 && normals[ 5 ] === - 1,
  14787. "second normal is pointing to screen since the the triangle was created clockwise" );
  14788. assert.ok( normals[ 6 ] === 0 && normals[ 7 ] === 0 && normals[ 8 ] === - 1,
  14789. "third normal is pointing to screen since the the triangle was created clockwise" );
  14790. var normals = getNormalsForVertices( [ 0, 0, 1, 0, 0, - 1, 1, 1, 0 ], assert );
  14791. // the triangle is rotated by 45 degrees to the right so the normals of the three vertices
  14792. // should point to (1, -1, 0).normalized(). The simplest solution is to check against a normalized
  14793. // vector (1, -1, 0) but you will get calculation errors because of floating calculations so another
  14794. // valid technique is to create a vector which stands in 90 degrees to the normals and calculate the
  14795. // dot product which is the cos of the angle between them. This should be < floating calculation error
  14796. // which can be taken from Number.EPSILON
  14797. var direction = new Vector3( 1, 1, 0 ).normalize(); // a vector which should have 90 degrees difference to normals
  14798. var difference = direction.dot( new Vector3( normals[ 0 ], normals[ 1 ], normals[ 2 ] ) );
  14799. assert.ok( difference < Number.EPSILON, "normal is equal to reference vector" );
  14800. // get normals for a line should be NAN because you need min a triangle to calculate normals
  14801. var normals = getNormalsForVertices( [ 1, 0, 0, - 1, 0, 0 ], assert );
  14802. for ( var i = 0; i < normals.length; i ++ ) {
  14803. assert.ok( ! normals[ i ], "normals can't be calculated which is good" );
  14804. }
  14805. } );
  14806. QUnit.test( "computeVertexNormals (indexed)", ( assert ) => {
  14807. var sqrt = 0.5 * Math.sqrt( 2 );
  14808. var normal = new BufferAttribute( new Float32Array( [
  14809. - 1, 0, 0, - 1, 0, 0, - 1, 0, 0,
  14810. sqrt, sqrt, 0, sqrt, sqrt, 0, sqrt, sqrt, 0,
  14811. - 1, 0, 0
  14812. ] ), 3 );
  14813. var position = new BufferAttribute( new Float32Array( [
  14814. 0.5, 0.5, 0.5, 0.5, 0.5, - 0.5, 0.5, - 0.5, 0.5,
  14815. 0.5, - 0.5, - 0.5, - 0.5, 0.5, - 0.5, - 0.5, 0.5, 0.5,
  14816. - 0.5, - 0.5, - 0.5
  14817. ] ), 3 );
  14818. var index = new BufferAttribute( new Uint16Array( [
  14819. 0, 2, 1, 2, 3, 1, 4, 6, 5, 6, 7, 5
  14820. ] ), 1 );
  14821. var a = new BufferGeometry();
  14822. a.addAttribute( "position", position );
  14823. a.computeVertexNormals();
  14824. assert.ok(
  14825. bufferAttributeEquals( normal, a.getAttribute( "normal" ) ),
  14826. "Regular geometry: first computed normals are correct"
  14827. );
  14828. // a second time to see if the existing normals get properly deleted
  14829. a.computeVertexNormals();
  14830. assert.ok(
  14831. bufferAttributeEquals( normal, a.getAttribute( "normal" ) ),
  14832. "Regular geometry: second computed normals are correct"
  14833. );
  14834. // indexed geometry
  14835. var a = new BufferGeometry();
  14836. a.addAttribute( "position", position );
  14837. a.setIndex( index );
  14838. a.computeVertexNormals();
  14839. assert.ok( bufferAttributeEquals( normal, a.getAttribute( "normal" ) ), "Indexed geometry: computed normals are correct" );
  14840. } );
  14841. QUnit.test( "merge", ( assert ) => {
  14842. var geometry1 = new BufferGeometry();
  14843. geometry1.addAttribute( "attrName", new BufferAttribute( new Float32Array( [ 1, 2, 3, 0, 0, 0 ] ), 3 ) );
  14844. var geometry2 = new BufferGeometry();
  14845. geometry2.addAttribute( "attrName", new BufferAttribute( new Float32Array( [ 4, 5, 6 ] ), 3 ) );
  14846. var attr = geometry1.attributes.attrName.array;
  14847. geometry1.merge( geometry2, 1 );
  14848. // merged array should be 1, 2, 3, 4, 5, 6
  14849. for ( var i = 0; i < attr.length; i ++ ) {
  14850. assert.ok( attr[ i ] === i + 1, "" );
  14851. }
  14852. geometry1.merge( geometry2 );
  14853. assert.ok( attr[ 0 ] === 4 && attr[ 1 ] === 5 && attr[ 2 ] === 6, "copied the 3 attributes without offset" );
  14854. } );
  14855. QUnit.test( "normalizeNormals", ( assert ) => {
  14856. assert.ok( false, "everything's gonna be alright" );
  14857. } );
  14858. QUnit.test( "toNonIndexed", ( assert ) => {
  14859. var geometry = new BufferGeometry();
  14860. var vertices = new Float32Array( [
  14861. 0.5, 0.5, 0.5, 0.5, 0.5, - 0.5, 0.5, - 0.5, 0.5, 0.5, - 0.5, - 0.5
  14862. ] );
  14863. var index = new BufferAttribute( new Uint16Array( [ 0, 2, 1, 2, 3, 1 ] ) );
  14864. var expected = new Float32Array( [
  14865. 0.5, 0.5, 0.5, 0.5, - 0.5, 0.5, 0.5, 0.5, - 0.5,
  14866. 0.5, - 0.5, 0.5, 0.5, - 0.5, - 0.5, 0.5, 0.5, - 0.5
  14867. ] );
  14868. geometry.addAttribute( 'position', new BufferAttribute( vertices, 3 ) );
  14869. geometry.setIndex( index );
  14870. var nonIndexed = geometry.toNonIndexed();
  14871. assert.deepEqual( nonIndexed.getAttribute( "position" ).array, expected, "Expected vertices" );
  14872. } );
  14873. QUnit.test( "toJSON", ( assert ) => {
  14874. var index = new BufferAttribute( new Uint16Array( [ 0, 1, 2, 3 ] ), 1 );
  14875. var attribute1 = new BufferAttribute( new Uint16Array( [ 1, 3, 5, 7 ] ), 1 );
  14876. var a = new BufferGeometry();
  14877. a.name = "JSONQUnit.test";
  14878. // a.parameters = { "placeholder": 0 };
  14879. a.addAttribute( "attribute1", attribute1 );
  14880. a.setIndex( index );
  14881. a.addGroup( 0, 1, 2 );
  14882. a.boundingSphere = new Sphere( new Vector3( x, y, z ), 0.5 );
  14883. var j = a.toJSON();
  14884. var gold = {
  14885. "metadata": {
  14886. "version": 4.5,
  14887. "type": "BufferGeometry",
  14888. "generator": "BufferGeometry.toJSON"
  14889. },
  14890. "uuid": a.uuid,
  14891. "type": "BufferGeometry",
  14892. "name": "JSONQUnit.test",
  14893. "data": {
  14894. "attributes": {
  14895. "attribute1": {
  14896. "itemSize": 1,
  14897. "type": "Uint16Array",
  14898. "array": [ 1, 3, 5, 7 ],
  14899. "normalized": false
  14900. }
  14901. },
  14902. "index": {
  14903. "type": "Uint16Array",
  14904. "array": [ 0, 1, 2, 3 ]
  14905. },
  14906. "groups": [
  14907. {
  14908. "start": 0,
  14909. "count": 1,
  14910. "materialIndex": 2
  14911. }
  14912. ],
  14913. "boundingSphere": {
  14914. "center": [ 2, 3, 4 ],
  14915. "radius": 0.5
  14916. }
  14917. }
  14918. };
  14919. assert.deepEqual( j, gold, "Generated JSON is as expected" );
  14920. } );
  14921. QUnit.test( "clone", ( assert ) => {
  14922. var a = new BufferGeometry();
  14923. a.addAttribute( "attribute1", new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 5, 6 ] ), 3 ) );
  14924. a.addAttribute( "attribute2", new BufferAttribute( new Float32Array( [ 0, 1, 3, 5, 6 ] ), 1 ) );
  14925. a.addGroup( 0, 1, 2 );
  14926. a.computeBoundingBox();
  14927. a.computeBoundingSphere();
  14928. a.setDrawRange( 0, 1 );
  14929. var b = a.clone();
  14930. assert.notEqual( a, b, "A new object was created" );
  14931. assert.notEqual( a.id, b.id, "New object has a different GUID" );
  14932. assert.strictEqual(
  14933. Object.keys( a.attributes ).count, Object.keys( b.attributes ).count,
  14934. "Both objects have the same amount of attributes"
  14935. );
  14936. assert.ok(
  14937. bufferAttributeEquals( a.getAttribute( "attribute1" ), b.getAttribute( "attribute1" ) ),
  14938. "First attributes buffer is identical"
  14939. );
  14940. assert.ok(
  14941. bufferAttributeEquals( a.getAttribute( "attribute2" ), b.getAttribute( "attribute2" ) ),
  14942. "Second attributes buffer is identical"
  14943. );
  14944. assert.deepEqual( a.groups, b.groups, "Groups are identical" );
  14945. assert.ok( a.boundingBox.equals( b.boundingBox ), "BoundingBoxes are equal" );
  14946. assert.ok( a.boundingSphere.equals( b.boundingSphere ), "BoundingSpheres are equal" );
  14947. assert.strictEqual( a.drawRange.start, b.drawRange.start, "DrawRange start is identical" );
  14948. assert.strictEqual( a.drawRange.count, b.drawRange.count, "DrawRange count is identical" );
  14949. } );
  14950. QUnit.test( "copy", ( assert ) => {
  14951. var geometry = new BufferGeometry();
  14952. geometry.addAttribute( "attrName", new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 5, 6 ] ), 3 ) );
  14953. geometry.addAttribute( "attrName2", new BufferAttribute( new Float32Array( [ 0, 1, 3, 5, 6 ] ), 1 ) );
  14954. var copy = new BufferGeometry().copy( geometry );
  14955. assert.ok( copy !== geometry && geometry.id !== copy.id, "new object was created" );
  14956. Object.keys( geometry.attributes ).forEach( function ( key ) {
  14957. var attribute = geometry.attributes[ key ];
  14958. assert.ok( attribute !== undefined, "all attributes where copied" );
  14959. for ( var i = 0; i < attribute.array.length; i ++ ) {
  14960. assert.ok( attribute.array[ i ] === copy.attributes[ key ].array[ i ], "values of the attribute are equal" );
  14961. }
  14962. } );
  14963. } );
  14964. QUnit.test( "dispose", ( assert ) => {
  14965. assert.ok( false, "everything's gonna be alright" );
  14966. } );
  14967. } );
  14968. } );
  14969. /**
  14970. * @author alteredq / http://alteredqualia.com/
  14971. */
  14972. function Clock( autoStart ) {
  14973. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  14974. this.startTime = 0;
  14975. this.oldTime = 0;
  14976. this.elapsedTime = 0;
  14977. this.running = false;
  14978. }
  14979. Object.assign( Clock.prototype, {
  14980. start: function () {
  14981. this.startTime = ( typeof performance === 'undefined' ? Date : performance ).now(); // see #10732
  14982. this.oldTime = this.startTime;
  14983. this.elapsedTime = 0;
  14984. this.running = true;
  14985. },
  14986. stop: function () {
  14987. this.getElapsedTime();
  14988. this.running = false;
  14989. this.autoStart = false;
  14990. },
  14991. getElapsedTime: function () {
  14992. this.getDelta();
  14993. return this.elapsedTime;
  14994. },
  14995. getDelta: function () {
  14996. var diff = 0;
  14997. if ( this.autoStart && ! this.running ) {
  14998. this.start();
  14999. return 0;
  15000. }
  15001. if ( this.running ) {
  15002. var newTime = ( typeof performance === 'undefined' ? Date : performance ).now();
  15003. diff = ( newTime - this.oldTime ) / 1000;
  15004. this.oldTime = newTime;
  15005. this.elapsedTime += diff;
  15006. }
  15007. return diff;
  15008. }
  15009. } );
  15010. /**
  15011. * @author simonThiele / https://github.com/simonThiele
  15012. * @author TristanVALCKE / https://github.com/Itee
  15013. */
  15014. /* global QUnit */
  15015. QUnit.module( 'Core', () => {
  15016. QUnit.module.todo( 'Clock', () => {
  15017. function mockPerformance() {
  15018. self.performance = {
  15019. deltaTime: 0,
  15020. next: function ( delta ) {
  15021. this.deltaTime += delta;
  15022. },
  15023. now: function () {
  15024. return this.deltaTime;
  15025. }
  15026. };
  15027. }
  15028. // INSTANCING
  15029. QUnit.test( "Instancing", ( assert ) => {
  15030. assert.ok( false, "everything's gonna be alright" );
  15031. } );
  15032. // PUBLIC STUFF
  15033. QUnit.test( "start", ( assert ) => {
  15034. assert.ok( false, "everything's gonna be alright" );
  15035. } );
  15036. QUnit.test( "stop", ( assert ) => {
  15037. assert.ok( false, "everything's gonna be alright" );
  15038. } );
  15039. QUnit.test( "getElapsedTime", ( assert ) => {
  15040. assert.ok( false, "everything's gonna be alright" );
  15041. } );
  15042. QUnit.test( "getDelta", ( assert ) => {
  15043. assert.ok( false, "everything's gonna be alright" );
  15044. } );
  15045. // OTHERS
  15046. QUnit.test( "clock with performance", ( assert ) => {
  15047. mockPerformance();
  15048. var clock = new Clock( false );
  15049. clock.start();
  15050. self.performance.next( 123 );
  15051. assert.numEqual( clock.getElapsedTime(), 0.123, "okay" );
  15052. self.performance.next( 100 );
  15053. assert.numEqual( clock.getElapsedTime(), 0.223, "okay" );
  15054. clock.stop();
  15055. self.performance.next( 1000 );
  15056. assert.numEqual( clock.getElapsedTime(), 0.223, "don't update time if the clock was stopped" );
  15057. } );
  15058. } );
  15059. } );
  15060. /**
  15061. * @author moraxy / https://github.com/moraxy
  15062. * @author TristanVALCKE / https://github.com/Itee
  15063. */
  15064. /* global QUnit */
  15065. QUnit.module( 'Core', () => {
  15066. QUnit.module.todo( 'DirectGeometry', () => {
  15067. // INSTANCING
  15068. QUnit.test( "Instancing", ( assert ) => {
  15069. assert.ok( false, "everything's gonna be alright" );
  15070. } );
  15071. // PUBLIC STUFF
  15072. QUnit.test( "computeGroups", ( assert ) => {
  15073. var a = new DirectGeometry();
  15074. var b = new Geometry();
  15075. var expected = [
  15076. { start: 0, materialIndex: 0, count: 3 },
  15077. { start: 3, materialIndex: 1, count: 3 },
  15078. { start: 6, materialIndex: 2, count: 6 }
  15079. ];
  15080. // we only care for materialIndex
  15081. b.faces.push(
  15082. new Face3( 0, 0, 0, undefined, undefined, 0 ),
  15083. new Face3( 0, 0, 0, undefined, undefined, 1 ),
  15084. new Face3( 0, 0, 0, undefined, undefined, 2 ),
  15085. new Face3( 0, 0, 0, undefined, undefined, 2 )
  15086. );
  15087. a.computeGroups( b );
  15088. assert.deepEqual( a.groups, expected, "Groups are as expected" );
  15089. } );
  15090. QUnit.test( "fromGeometry", ( assert ) => {
  15091. var a = new DirectGeometry();
  15092. var asyncDone = assert.async(); // tell QUnit when we're done with async stuff
  15093. var loader = new JSONLoader();
  15094. loader.load( "../../examples/models/skinned/simple/simple.js", function ( geometry ) {
  15095. a.fromGeometry( geometry );
  15096. var tmp = new DirectGeometry();
  15097. tmp.computeGroups( geometry );
  15098. assert.deepEqual( a.groups, tmp.groups, "Check groups" );
  15099. var morphTargets = geometry.morphTargets;
  15100. var morphTargetsLength = morphTargets.length;
  15101. var morphTargetsPosition;
  15102. if ( morphTargetsLength > 0 ) {
  15103. morphTargetsPosition = [];
  15104. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  15105. morphTargetsPosition[ i ] = [];
  15106. }
  15107. morphTargets.position = morphTargetsPosition;
  15108. }
  15109. var morphNormals = geometry.morphNormals;
  15110. var morphNormalsLength = morphNormals.length;
  15111. var morphTargetsNormal;
  15112. if ( morphNormalsLength > 0 ) {
  15113. morphTargetsNormal = [];
  15114. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  15115. morphTargetsNormal[ i ] = [];
  15116. }
  15117. morphTargets.normal = morphTargetsNormal;
  15118. }
  15119. var vertices = [];
  15120. var normals = [];
  15121. var colors = [];
  15122. var uvs = [];
  15123. var uvs2 = [];
  15124. var skinIndices = [];
  15125. var skinWeights = [];
  15126. var hasFaceVertexUv = geometry.faceVertexUvs[ 0 ] && geometry.faceVertexUvs[ 0 ].length > 0;
  15127. var hasFaceVertexUv2 = geometry.faceVertexUvs[ 1 ] && geometry.faceVertexUvs[ 1 ].length > 0;
  15128. var hasSkinIndices = geometry.skinIndices.length === geometry.vertices.length;
  15129. var hasSkinWeights = geometry.skinWeights.length === geometry.vertices.length;
  15130. for ( var i = 0; i < geometry.faces.length; i ++ ) {
  15131. var face = geometry.faces[ i ];
  15132. vertices.push(
  15133. geometry.vertices[ face.a ],
  15134. geometry.vertices[ face.b ],
  15135. geometry.vertices[ face.c ]
  15136. );
  15137. var vertexNormals = face.vertexNormals;
  15138. if ( vertexNormals.length === 3 ) {
  15139. normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  15140. } else {
  15141. normals.push( face.normal, face.normal, face.normal );
  15142. }
  15143. var vertexColors = face.vertexColors;
  15144. if ( vertexColors.length === 3 ) {
  15145. colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  15146. } else {
  15147. colors.push( face.color, face.color, face.color );
  15148. }
  15149. if ( hasFaceVertexUv === true ) {
  15150. var vertexUvs = geometry.faceVertexUvs[ 0 ][ i ];
  15151. if ( vertexUvs !== undefined ) {
  15152. uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  15153. } else {
  15154. uvs.push( new Vector2(), new Vector2(), new Vector2() );
  15155. }
  15156. }
  15157. if ( hasFaceVertexUv2 === true ) {
  15158. var vertexUvs = geometry.faceVertexUvs[ 1 ][ i ];
  15159. if ( vertexUvs !== undefined ) {
  15160. uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  15161. } else {
  15162. uvs2.push( new Vector2(), new Vector2(), new Vector2() );
  15163. }
  15164. }
  15165. // morphs
  15166. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  15167. var morphTarget = morphTargets[ j ].vertices;
  15168. morphTargetsPosition[ j ].push(
  15169. morphTarget[ face.a ],
  15170. morphTarget[ face.b ],
  15171. morphTarget[ face.c ]
  15172. );
  15173. }
  15174. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  15175. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  15176. morphTargetsNormal[ j ].push( morphNormal.a, morphNormal.b, morphNormal.c );
  15177. }
  15178. // skins
  15179. if ( hasSkinIndices ) {
  15180. skinIndices.push(
  15181. geometry.skinIndices[ face.a ],
  15182. geometry.skinIndices[ face.b ],
  15183. geometry.skinIndices[ face.c ]
  15184. );
  15185. }
  15186. if ( hasSkinWeights ) {
  15187. skinWeights.push(
  15188. geometry.skinWeights[ face.a ],
  15189. geometry.skinWeights[ face.b ],
  15190. geometry.skinWeights[ face.c ]
  15191. );
  15192. }
  15193. }
  15194. assert.deepEqual( a.vertices, vertices, "Vertices are identical" );
  15195. assert.deepEqual( a.normals, normals, "Normals are identical" );
  15196. assert.deepEqual( a.colors, colors, "Colors are identical" );
  15197. assert.deepEqual( a.uvs, uvs, "UV coordinates are identical" );
  15198. assert.deepEqual( a.uvs2, uvs2, "UV(2) coordinates are identical" );
  15199. assert.deepEqual( a.skinIndices, skinIndices, "SkinIndices are identical" );
  15200. assert.deepEqual( a.skinWeights, skinWeights, "SkinWeights are identical" );
  15201. assert.deepEqual( a.morphTargetsPosition, morphTargetsPosition, "MorphTargets (Position) are identical" );
  15202. assert.deepEqual( a.morphTargetsNormal, morphTargetsNormal, "MorphTargets (Normals) are identical" );
  15203. asyncDone();
  15204. } );
  15205. } );
  15206. } );
  15207. } );
  15208. /**
  15209. * @author simonThiele / https://github.com/simonThiele
  15210. * @author TristanVALCKE / https://github.com/Itee
  15211. */
  15212. /* global QUnit */
  15213. QUnit.module( 'Core', () => {
  15214. QUnit.module.todo( 'EventDispatcher', () => {
  15215. // INSTANCING
  15216. QUnit.test( "Instancing", ( assert ) => {
  15217. assert.ok( false, "everything's gonna be alright" );
  15218. } );
  15219. // PUBLIC STUFF
  15220. QUnit.test( "addEventListener", ( assert ) => {
  15221. var eventDispatcher = new EventDispatcher();
  15222. var listener = {};
  15223. eventDispatcher.addEventListener( 'anyType', listener );
  15224. assert.ok( eventDispatcher._listeners.anyType.length === 1, "listener with unknown type was added" );
  15225. assert.ok( eventDispatcher._listeners.anyType[ 0 ] === listener, "listener with unknown type was added" );
  15226. eventDispatcher.addEventListener( 'anyType', listener );
  15227. assert.ok( eventDispatcher._listeners.anyType.length === 1, "can't add one listener twice to same type" );
  15228. assert.ok( eventDispatcher._listeners.anyType[ 0 ] === listener, "listener is still there" );
  15229. } );
  15230. QUnit.test( "hasEventListener", ( assert ) => {
  15231. var eventDispatcher = new EventDispatcher();
  15232. var listener = {};
  15233. eventDispatcher.addEventListener( 'anyType', listener );
  15234. assert.ok( eventDispatcher.hasEventListener( 'anyType', listener ), "listener was found" );
  15235. assert.ok( ! eventDispatcher.hasEventListener( 'anotherType', listener ), "listener was not found which is good" );
  15236. } );
  15237. QUnit.test( "removeEventListener", ( assert ) => {
  15238. var eventDispatcher = new EventDispatcher();
  15239. var listener = {};
  15240. assert.ok( eventDispatcher._listeners === undefined, "there are no listeners by default" );
  15241. eventDispatcher.addEventListener( 'anyType', listener );
  15242. assert.ok( Object.keys( eventDispatcher._listeners ).length === 1 &&
  15243. eventDispatcher._listeners.anyType.length === 1, "if a listener was added, there is a new key" );
  15244. eventDispatcher.removeEventListener( 'anyType', listener );
  15245. assert.ok( eventDispatcher._listeners.anyType.length === 0, "listener was deleted" );
  15246. eventDispatcher.removeEventListener( 'unknownType', listener );
  15247. assert.ok( eventDispatcher._listeners.unknownType === undefined, "unknown types will be ignored" );
  15248. eventDispatcher.removeEventListener( 'anyType', undefined );
  15249. assert.ok( eventDispatcher._listeners.anyType.length === 0, "undefined listeners are ignored" );
  15250. } );
  15251. QUnit.test( "dispatchEvent", ( assert ) => {
  15252. var eventDispatcher = new EventDispatcher();
  15253. var callCount = 0;
  15254. var listener = function () {
  15255. callCount ++;
  15256. };
  15257. eventDispatcher.addEventListener( 'anyType', listener );
  15258. assert.ok( callCount === 0, "no event, no call" );
  15259. eventDispatcher.dispatchEvent( { type: 'anyType' } );
  15260. assert.ok( callCount === 1, "one event, one call" );
  15261. eventDispatcher.dispatchEvent( { type: 'anyType' } );
  15262. assert.ok( callCount === 2, "two events, two calls" );
  15263. } );
  15264. } );
  15265. } );
  15266. /**
  15267. * @author simonThiele / https://github.com/simonThiele
  15268. * @author TristanVALCKE / https://github.com/Itee
  15269. */
  15270. /* global QUnit */
  15271. QUnit.module( 'Core', () => {
  15272. QUnit.module.todo( 'Face3', () => {
  15273. // INSTANCING
  15274. QUnit.test( "Instancing", ( assert ) => {
  15275. assert.ok( false, "everything's gonna be alright" );
  15276. } );
  15277. // PUBLIC STUFF
  15278. QUnit.test( "copy", ( assert ) => {
  15279. var instance = new Face3( 0, 1, 2, new Vector3( 0, 1, 0 ), new Color( 0.25, 0.5, 0.75 ), 2 );
  15280. var copiedInstance = instance.copy( instance );
  15281. checkCopy( copiedInstance, assert );
  15282. checkVertexAndColors( copiedInstance, assert );
  15283. } );
  15284. QUnit.test( "copy (more)", ( assert ) => {
  15285. var instance = new Face3( 0, 1, 2,
  15286. [ new Vector3( 0, 1, 0 ), new Vector3( 1, 0, 1 ) ],
  15287. [ new Color( 0.25, 0.5, 0.75 ), new Color( 1, 0, 0.4 ) ],
  15288. 2 );
  15289. var copiedInstance = instance.copy( instance );
  15290. checkCopy( copiedInstance, assert );
  15291. checkVertexAndColorArrays( copiedInstance, assert );
  15292. } );
  15293. QUnit.test( "clone", ( assert ) => {
  15294. var instance = new Face3( 0, 1, 2, new Vector3( 0, 1, 0 ), new Color( 0.25, 0.5, 0.75 ), 2 );
  15295. var copiedInstance = instance.clone();
  15296. checkCopy( copiedInstance, assert );
  15297. checkVertexAndColors( copiedInstance, assert );
  15298. } );
  15299. function checkCopy( copiedInstance, assert ) {
  15300. assert.ok( copiedInstance instanceof Face3, "copy created the correct type" );
  15301. assert.ok(
  15302. copiedInstance.a === 0 &&
  15303. copiedInstance.b === 1 &&
  15304. copiedInstance.c === 2 &&
  15305. copiedInstance.materialIndex === 2
  15306. , "properties where copied" );
  15307. }
  15308. function checkVertexAndColors( copiedInstance, assert ) {
  15309. assert.ok(
  15310. copiedInstance.normal.x === 0 && copiedInstance.normal.y === 1 && copiedInstance.normal.z === 0 &&
  15311. copiedInstance.color.r === 0.25 && copiedInstance.color.g === 0.5 && copiedInstance.color.b === 0.75
  15312. , "properties where copied" );
  15313. }
  15314. function checkVertexAndColorArrays( copiedInstance, assert ) {
  15315. assert.ok(
  15316. copiedInstance.vertexNormals[ 0 ].x === 0 && copiedInstance.vertexNormals[ 0 ].y === 1 && copiedInstance.vertexNormals[ 0 ].z === 0 &&
  15317. copiedInstance.vertexNormals[ 1 ].x === 1 && copiedInstance.vertexNormals[ 1 ].y === 0 && copiedInstance.vertexNormals[ 1 ].z === 1 &&
  15318. copiedInstance.vertexColors[ 0 ].r === 0.25 && copiedInstance.vertexColors[ 0 ].g === 0.5 && copiedInstance.vertexColors[ 0 ].b === 0.75 &&
  15319. copiedInstance.vertexColors[ 1 ].r === 1 && copiedInstance.vertexColors[ 1 ].g === 0 && copiedInstance.vertexColors[ 1 ].b === 0.4
  15320. , "properties where copied" );
  15321. }
  15322. } );
  15323. } );
  15324. /**
  15325. * @author clockworkgeek / https://github.com/clockworkgeek
  15326. * @author timothypratley / https://github.com/timothypratley
  15327. * @author WestLangley / http://github.com/WestLangley
  15328. * @author Mugen87 / https://github.com/Mugen87
  15329. */
  15330. // PolyhedronGeometry
  15331. function PolyhedronGeometry( vertices, indices, radius, detail ) {
  15332. Geometry.call( this );
  15333. this.type = 'PolyhedronGeometry';
  15334. this.parameters = {
  15335. vertices: vertices,
  15336. indices: indices,
  15337. radius: radius,
  15338. detail: detail
  15339. };
  15340. this.fromBufferGeometry( new PolyhedronBufferGeometry( vertices, indices, radius, detail ) );
  15341. this.mergeVertices();
  15342. }
  15343. PolyhedronGeometry.prototype = Object.create( Geometry.prototype );
  15344. PolyhedronGeometry.prototype.constructor = PolyhedronGeometry;
  15345. // PolyhedronBufferGeometry
  15346. function PolyhedronBufferGeometry( vertices, indices, radius, detail ) {
  15347. BufferGeometry.call( this );
  15348. this.type = 'PolyhedronBufferGeometry';
  15349. this.parameters = {
  15350. vertices: vertices,
  15351. indices: indices,
  15352. radius: radius,
  15353. detail: detail
  15354. };
  15355. radius = radius || 1;
  15356. detail = detail || 0;
  15357. // default buffer data
  15358. var vertexBuffer = [];
  15359. var uvBuffer = [];
  15360. // the subdivision creates the vertex buffer data
  15361. subdivide( detail );
  15362. // all vertices should lie on a conceptual sphere with a given radius
  15363. appplyRadius( radius );
  15364. // finally, create the uv data
  15365. generateUVs();
  15366. // build non-indexed geometry
  15367. this.addAttribute( 'position', new Float32BufferAttribute( vertexBuffer, 3 ) );
  15368. this.addAttribute( 'normal', new Float32BufferAttribute( vertexBuffer.slice(), 3 ) );
  15369. this.addAttribute( 'uv', new Float32BufferAttribute( uvBuffer, 2 ) );
  15370. if ( detail === 0 ) {
  15371. this.computeVertexNormals(); // flat normals
  15372. } else {
  15373. this.normalizeNormals(); // smooth normals
  15374. }
  15375. // helper functions
  15376. function subdivide( detail ) {
  15377. var a = new Vector3();
  15378. var b = new Vector3();
  15379. var c = new Vector3();
  15380. // iterate over all faces and apply a subdivison with the given detail value
  15381. for ( var i = 0; i < indices.length; i += 3 ) {
  15382. // get the vertices of the face
  15383. getVertexByIndex( indices[ i + 0 ], a );
  15384. getVertexByIndex( indices[ i + 1 ], b );
  15385. getVertexByIndex( indices[ i + 2 ], c );
  15386. // perform subdivision
  15387. subdivideFace( a, b, c, detail );
  15388. }
  15389. }
  15390. function subdivideFace( a, b, c, detail ) {
  15391. var cols = Math.pow( 2, detail );
  15392. // we use this multidimensional array as a data structure for creating the subdivision
  15393. var v = [];
  15394. var i, j;
  15395. // construct all of the vertices for this subdivision
  15396. for ( i = 0; i <= cols; i ++ ) {
  15397. v[ i ] = [];
  15398. var aj = a.clone().lerp( c, i / cols );
  15399. var bj = b.clone().lerp( c, i / cols );
  15400. var rows = cols - i;
  15401. for ( j = 0; j <= rows; j ++ ) {
  15402. if ( j === 0 && i === cols ) {
  15403. v[ i ][ j ] = aj;
  15404. } else {
  15405. v[ i ][ j ] = aj.clone().lerp( bj, j / rows );
  15406. }
  15407. }
  15408. }
  15409. // construct all of the faces
  15410. for ( i = 0; i < cols; i ++ ) {
  15411. for ( j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  15412. var k = Math.floor( j / 2 );
  15413. if ( j % 2 === 0 ) {
  15414. pushVertex( v[ i ][ k + 1 ] );
  15415. pushVertex( v[ i + 1 ][ k ] );
  15416. pushVertex( v[ i ][ k ] );
  15417. } else {
  15418. pushVertex( v[ i ][ k + 1 ] );
  15419. pushVertex( v[ i + 1 ][ k + 1 ] );
  15420. pushVertex( v[ i + 1 ][ k ] );
  15421. }
  15422. }
  15423. }
  15424. }
  15425. function appplyRadius( radius ) {
  15426. var vertex = new Vector3();
  15427. // iterate over the entire buffer and apply the radius to each vertex
  15428. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  15429. vertex.x = vertexBuffer[ i + 0 ];
  15430. vertex.y = vertexBuffer[ i + 1 ];
  15431. vertex.z = vertexBuffer[ i + 2 ];
  15432. vertex.normalize().multiplyScalar( radius );
  15433. vertexBuffer[ i + 0 ] = vertex.x;
  15434. vertexBuffer[ i + 1 ] = vertex.y;
  15435. vertexBuffer[ i + 2 ] = vertex.z;
  15436. }
  15437. }
  15438. function generateUVs() {
  15439. var vertex = new Vector3();
  15440. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  15441. vertex.x = vertexBuffer[ i + 0 ];
  15442. vertex.y = vertexBuffer[ i + 1 ];
  15443. vertex.z = vertexBuffer[ i + 2 ];
  15444. var u = azimuth( vertex ) / 2 / Math.PI + 0.5;
  15445. var v = inclination( vertex ) / Math.PI + 0.5;
  15446. uvBuffer.push( u, 1 - v );
  15447. }
  15448. correctUVs();
  15449. correctSeam();
  15450. }
  15451. function correctSeam() {
  15452. // handle case when face straddles the seam, see #3269
  15453. for ( var i = 0; i < uvBuffer.length; i += 6 ) {
  15454. // uv data of a single face
  15455. var x0 = uvBuffer[ i + 0 ];
  15456. var x1 = uvBuffer[ i + 2 ];
  15457. var x2 = uvBuffer[ i + 4 ];
  15458. var max = Math.max( x0, x1, x2 );
  15459. var min = Math.min( x0, x1, x2 );
  15460. // 0.9 is somewhat arbitrary
  15461. if ( max > 0.9 && min < 0.1 ) {
  15462. if ( x0 < 0.2 ) uvBuffer[ i + 0 ] += 1;
  15463. if ( x1 < 0.2 ) uvBuffer[ i + 2 ] += 1;
  15464. if ( x2 < 0.2 ) uvBuffer[ i + 4 ] += 1;
  15465. }
  15466. }
  15467. }
  15468. function pushVertex( vertex ) {
  15469. vertexBuffer.push( vertex.x, vertex.y, vertex.z );
  15470. }
  15471. function getVertexByIndex( index, vertex ) {
  15472. var stride = index * 3;
  15473. vertex.x = vertices[ stride + 0 ];
  15474. vertex.y = vertices[ stride + 1 ];
  15475. vertex.z = vertices[ stride + 2 ];
  15476. }
  15477. function correctUVs() {
  15478. var a = new Vector3();
  15479. var b = new Vector3();
  15480. var c = new Vector3();
  15481. var centroid = new Vector3();
  15482. var uvA = new Vector2();
  15483. var uvB = new Vector2();
  15484. var uvC = new Vector2();
  15485. for ( var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6 ) {
  15486. a.set( vertexBuffer[ i + 0 ], vertexBuffer[ i + 1 ], vertexBuffer[ i + 2 ] );
  15487. b.set( vertexBuffer[ i + 3 ], vertexBuffer[ i + 4 ], vertexBuffer[ i + 5 ] );
  15488. c.set( vertexBuffer[ i + 6 ], vertexBuffer[ i + 7 ], vertexBuffer[ i + 8 ] );
  15489. uvA.set( uvBuffer[ j + 0 ], uvBuffer[ j + 1 ] );
  15490. uvB.set( uvBuffer[ j + 2 ], uvBuffer[ j + 3 ] );
  15491. uvC.set( uvBuffer[ j + 4 ], uvBuffer[ j + 5 ] );
  15492. centroid.copy( a ).add( b ).add( c ).divideScalar( 3 );
  15493. var azi = azimuth( centroid );
  15494. correctUV( uvA, j + 0, a, azi );
  15495. correctUV( uvB, j + 2, b, azi );
  15496. correctUV( uvC, j + 4, c, azi );
  15497. }
  15498. }
  15499. function correctUV( uv, stride, vector, azimuth ) {
  15500. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) {
  15501. uvBuffer[ stride ] = uv.x - 1;
  15502. }
  15503. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) {
  15504. uvBuffer[ stride ] = azimuth / 2 / Math.PI + 0.5;
  15505. }
  15506. }
  15507. // Angle around the Y axis, counter-clockwise when looking from above.
  15508. function azimuth( vector ) {
  15509. return Math.atan2( vector.z, - vector.x );
  15510. }
  15511. // Angle above the XZ plane.
  15512. function inclination( vector ) {
  15513. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  15514. }
  15515. }
  15516. PolyhedronBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  15517. PolyhedronBufferGeometry.prototype.constructor = PolyhedronBufferGeometry;
  15518. /**
  15519. * @author Abe Pazos / https://hamoid.com
  15520. * @author Mugen87 / https://github.com/Mugen87
  15521. */
  15522. // DodecahedronGeometry
  15523. function DodecahedronGeometry( radius, detail ) {
  15524. Geometry.call( this );
  15525. this.type = 'DodecahedronGeometry';
  15526. this.parameters = {
  15527. radius: radius,
  15528. detail: detail
  15529. };
  15530. this.fromBufferGeometry( new DodecahedronBufferGeometry( radius, detail ) );
  15531. this.mergeVertices();
  15532. }
  15533. DodecahedronGeometry.prototype = Object.create( Geometry.prototype );
  15534. DodecahedronGeometry.prototype.constructor = DodecahedronGeometry;
  15535. // DodecahedronBufferGeometry
  15536. function DodecahedronBufferGeometry( radius, detail ) {
  15537. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  15538. var r = 1 / t;
  15539. var vertices = [
  15540. // (±1, ±1, ±1)
  15541. - 1, - 1, - 1, - 1, - 1, 1,
  15542. - 1, 1, - 1, - 1, 1, 1,
  15543. 1, - 1, - 1, 1, - 1, 1,
  15544. 1, 1, - 1, 1, 1, 1,
  15545. // (0, ±1/φ, ±φ)
  15546. 0, - r, - t, 0, - r, t,
  15547. 0, r, - t, 0, r, t,
  15548. // (±1/φ, ±φ, 0)
  15549. - r, - t, 0, - r, t, 0,
  15550. r, - t, 0, r, t, 0,
  15551. // (±φ, 0, ±1/φ)
  15552. - t, 0, - r, t, 0, - r,
  15553. - t, 0, r, t, 0, r
  15554. ];
  15555. var indices = [
  15556. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  15557. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  15558. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  15559. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  15560. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  15561. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  15562. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  15563. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  15564. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  15565. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  15566. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  15567. 1, 12, 14, 1, 14, 5, 1, 5, 9
  15568. ];
  15569. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  15570. this.type = 'DodecahedronBufferGeometry';
  15571. this.parameters = {
  15572. radius: radius,
  15573. detail: detail
  15574. };
  15575. }
  15576. DodecahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  15577. DodecahedronBufferGeometry.prototype.constructor = DodecahedronBufferGeometry;
  15578. /**
  15579. * @author simonThiele / https://github.com/simonThiele
  15580. */
  15581. /* global QUnit */
  15582. function getGeometryByParams( x1, y1, z1, x2, y2, z2, x3, y3, z3 ) {
  15583. var geometry = new Geometry();
  15584. // a triangle
  15585. geometry.vertices = [
  15586. new Vector3( x1, y1, z1 ),
  15587. new Vector3( x2, y2, z2 ),
  15588. new Vector3( x3, y3, z3 )
  15589. ];
  15590. return geometry;
  15591. }
  15592. function getGeometry() {
  15593. return getGeometryByParams( - 0.5, 0, 0, 0.5, 0, 0, 0, 1, 0 );
  15594. }
  15595. QUnit.module( 'Core', () => {
  15596. QUnit.module.todo( 'Geometry', () => {
  15597. // INHERITANCE
  15598. QUnit.test( "Extending", ( assert ) => {
  15599. assert.ok( false, "everything's gonna be alright" );
  15600. } );
  15601. // INSTANCING
  15602. QUnit.test( "Instancing", ( assert ) => {
  15603. assert.ok( false, "everything's gonna be alright" );
  15604. } );
  15605. // PUBLIC STUFF
  15606. QUnit.test( "isGeometry", ( assert ) => {
  15607. assert.ok( false, "everything's gonna be alright" );
  15608. } );
  15609. QUnit.test( "applyMatrix", ( assert ) => {
  15610. var geometry = getGeometry();
  15611. geometry.faces.push( new Face3( 0, 1, 2 ) );
  15612. var m = new Matrix4();
  15613. var expectedVerts = [
  15614. new Vector3( 1.5, 3, 4 ),
  15615. new Vector3( 2.5, 3, 4 ),
  15616. new Vector3( 2, 3, 5 )
  15617. ];
  15618. var v0, v1, v2;
  15619. m.makeRotationX( Math.PI / 2 );
  15620. m.setPosition( new Vector3( x, y, z ) );
  15621. geometry.applyMatrix( m );
  15622. v0 = geometry.vertices[ 0 ];
  15623. v1 = geometry.vertices[ 1 ];
  15624. v2 = geometry.vertices[ 2 ];
  15625. assert.ok(
  15626. Math.abs( v0.x - expectedVerts[ 0 ].x ) <= eps &&
  15627. Math.abs( v0.y - expectedVerts[ 0 ].y ) <= eps &&
  15628. Math.abs( v0.z - expectedVerts[ 0 ].z ) <= eps,
  15629. "First vertex is as expected"
  15630. );
  15631. assert.ok(
  15632. Math.abs( v1.x - expectedVerts[ 1 ].x ) <= eps &&
  15633. Math.abs( v1.y - expectedVerts[ 1 ].y ) <= eps &&
  15634. Math.abs( v1.z - expectedVerts[ 1 ].z ) <= eps,
  15635. "Second vertex is as expected"
  15636. );
  15637. assert.ok(
  15638. Math.abs( v2.x - expectedVerts[ 2 ].x ) <= eps &&
  15639. Math.abs( v2.y - expectedVerts[ 2 ].y ) <= eps &&
  15640. Math.abs( v2.z - expectedVerts[ 2 ].z ) <= eps,
  15641. "Third vertex is as expected"
  15642. );
  15643. } );
  15644. QUnit.test( "rotateX", ( assert ) => {
  15645. var geometry = getGeometry();
  15646. var matrix = new Matrix4();
  15647. matrix.makeRotationX( Math.PI / 2 ); // 90 degree
  15648. geometry.applyMatrix( matrix );
  15649. var v0 = geometry.vertices[ 0 ], v1 = geometry.vertices[ 1 ], v2 = geometry.vertices[ 2 ];
  15650. assert.ok( v0.x === - 0.5 && v0.y === 0 && v0.z === 0, "first vertex was rotated" );
  15651. assert.ok( v1.x === 0.5 && v1.y === 0 && v1.z === 0, "second vertex was rotated" );
  15652. assert.ok( v2.x === 0 && v2.y < Number.EPSILON && v2.z === 1, "third vertex was rotated" );
  15653. } );
  15654. QUnit.test( "rotateY", ( assert ) => {
  15655. var geometry = getGeometry();
  15656. var matrix = new Matrix4();
  15657. matrix.makeRotationY( Math.PI ); // 180 degrees
  15658. geometry.applyMatrix( matrix );
  15659. var v0 = geometry.vertices[ 0 ], v1 = geometry.vertices[ 1 ], v2 = geometry.vertices[ 2 ];
  15660. assert.ok( v0.x === 0.5 && v0.y === 0 && v0.z < Number.EPSILON, "first vertex was rotated" );
  15661. assert.ok( v1.x === - 0.5 && v1.y === 0 && v1.z < Number.EPSILON, "second vertex was rotated" );
  15662. assert.ok( v2.x === 0 && v2.y === 1 && v2.z === 0, "third vertex was rotated" );
  15663. } );
  15664. QUnit.test( "rotateZ", ( assert ) => {
  15665. var geometry = getGeometry();
  15666. var matrix = new Matrix4();
  15667. matrix.makeRotationZ( Math.PI / 2 * 3 ); // 270 degrees
  15668. geometry.applyMatrix( matrix );
  15669. var v0 = geometry.vertices[ 0 ], v1 = geometry.vertices[ 1 ], v2 = geometry.vertices[ 2 ];
  15670. assert.ok( v0.x < Number.EPSILON && v0.y === 0.5 && v0.z === 0, "first vertex was rotated" );
  15671. assert.ok( v1.x < Number.EPSILON && v1.y === - 0.5 && v1.z === 0, "second vertex was rotated" );
  15672. assert.ok( v2.x === 1 && v2.y < Number.EPSILON && v2.z === 0, "third vertex was rotated" );
  15673. } );
  15674. QUnit.test( "translate", ( assert ) => {
  15675. var a = getGeometry();
  15676. var expected = [
  15677. new Vector3( - 2.5, 3, - 4 ),
  15678. new Vector3( - 1.5, 3, - 4 ),
  15679. new Vector3( - 2, 4, - 4 )
  15680. ];
  15681. var v;
  15682. a.translate( - x, y, - z );
  15683. for ( var i = 0; i < a.vertices.length; i ++ ) {
  15684. v = a.vertices[ i ];
  15685. assert.ok(
  15686. Math.abs( v.x - expected[ i ].x ) <= eps &&
  15687. Math.abs( v.y - expected[ i ].y ) <= eps &&
  15688. Math.abs( v.z - expected[ i ].z ) <= eps,
  15689. "Vertex #" + i + " was translated as expected"
  15690. );
  15691. }
  15692. } );
  15693. QUnit.test( "scale", ( assert ) => {
  15694. var a = getGeometry();
  15695. var expected = [
  15696. new Vector3( - 1, 0, 0 ),
  15697. new Vector3( 1, 0, 0 ),
  15698. new Vector3( 0, 3, 0 )
  15699. ];
  15700. var v;
  15701. a.scale( 2, 3, 4 );
  15702. for ( var i = 0; i < a.vertices.length; i ++ ) {
  15703. v = a.vertices[ i ];
  15704. assert.ok(
  15705. Math.abs( v.x - expected[ i ].x ) <= eps &&
  15706. Math.abs( v.y - expected[ i ].y ) <= eps &&
  15707. Math.abs( v.z - expected[ i ].z ) <= eps,
  15708. "Vertex #" + i + " was scaled as expected"
  15709. );
  15710. }
  15711. } );
  15712. QUnit.test( "lookAt", ( assert ) => {
  15713. var a = getGeometry();
  15714. var expected = [
  15715. new Vector3( - 0.5, 0, 0 ),
  15716. new Vector3( 0.5, 0, 0 ),
  15717. new Vector3( 0, 0.5 * Math.sqrt( 2 ), 0.5 * Math.sqrt( 2 ) )
  15718. ];
  15719. a.lookAt( new Vector3( 0, - 1, 1 ) );
  15720. for ( var i = 0; i < a.vertices.length; i ++ ) {
  15721. var v = a.vertices[ i ];
  15722. assert.ok(
  15723. Math.abs( v.x - expected[ i ].x ) <= eps &&
  15724. Math.abs( v.y - expected[ i ].y ) <= eps &&
  15725. Math.abs( v.z - expected[ i ].z ) <= eps,
  15726. "Vertex #" + i + " was adjusted as expected"
  15727. );
  15728. }
  15729. } );
  15730. QUnit.test( "fromBufferGeometry", ( assert ) => {
  15731. var bufferGeometry = new BufferGeometry();
  15732. bufferGeometry.addAttribute( 'position', new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ] ), 3 ) );
  15733. bufferGeometry.addAttribute( 'color', new BufferAttribute( new Float32Array( [ 0, 0, 0, 0.5, 0.5, 0.5, 1, 1, 1 ] ), 3 ) );
  15734. bufferGeometry.addAttribute( 'normal', new BufferAttribute( new Float32Array( [ 0, 1, 0, 1, 0, 1, 1, 1, 0 ] ), 3 ) );
  15735. bufferGeometry.addAttribute( 'uv', new BufferAttribute( new Float32Array( [ 0, 0, 0, 1, 1, 1 ] ), 2 ) );
  15736. bufferGeometry.addAttribute( 'uv2', new BufferAttribute( new Float32Array( [ 0, 0, 0, 1, 1, 1 ] ), 2 ) );
  15737. var geometry = new Geometry().fromBufferGeometry( bufferGeometry );
  15738. var colors = geometry.colors;
  15739. assert.ok(
  15740. colors[ 0 ].r === 0 && colors[ 0 ].g === 0 && colors[ 0 ].b === 0 &&
  15741. colors[ 1 ].r === 0.5 && colors[ 1 ].g === 0.5 && colors[ 1 ].b === 0.5 &&
  15742. colors[ 2 ].r === 1 && colors[ 2 ].g === 1 && colors[ 2 ].b === 1
  15743. , "colors were created well" );
  15744. var vertices = geometry.vertices;
  15745. assert.ok(
  15746. vertices[ 0 ].x === 1 && vertices[ 0 ].y === 2 && vertices[ 0 ].z === 3 &&
  15747. vertices[ 1 ].x === 4 && vertices[ 1 ].y === 5 && vertices[ 1 ].z === 6 &&
  15748. vertices[ 2 ].x === 7 && vertices[ 2 ].y === 8 && vertices[ 2 ].z === 9
  15749. , "vertices were created well" );
  15750. var vNormals = geometry.faces[ 0 ].vertexNormals;
  15751. assert.ok(
  15752. vNormals[ 0 ].x === 0 && vNormals[ 0 ].y === 1 && vNormals[ 0 ].z === 0 &&
  15753. vNormals[ 1 ].x === 1 && vNormals[ 1 ].y === 0 && vNormals[ 1 ].z === 1 &&
  15754. vNormals[ 2 ].x === 1 && vNormals[ 2 ].y === 1 && vNormals[ 2 ].z === 0
  15755. , "vertex normals were created well" );
  15756. } );
  15757. QUnit.test( "center", ( assert ) => {
  15758. assert.ok( false, "everything's gonna be alright" );
  15759. } );
  15760. QUnit.test( "normalize", ( assert ) => {
  15761. var geometry = getGeometry();
  15762. geometry.computeLineDistances();
  15763. var distances = geometry.lineDistances;
  15764. assert.ok( distances[ 0 ] === 0, "distance to the 1st point is 0" );
  15765. assert.ok( distances[ 1 ] === 1 + distances[ 0 ], "distance from the 1st to the 2nd is sqrt(2nd - 1st) + distance - 1" );
  15766. 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" );
  15767. } );
  15768. QUnit.test( "normalize (actual)", ( assert ) => {
  15769. var a = getGeometry();
  15770. var sqrt = 0.5 * Math.sqrt( 2 );
  15771. var expected = [
  15772. new Vector3( - sqrt, - sqrt, 0 ),
  15773. new Vector3( sqrt, - sqrt, 0 ),
  15774. new Vector3( 0, sqrt, 0 )
  15775. ];
  15776. var v;
  15777. a.normalize();
  15778. for ( var i = 0; i < a.vertices.length; i ++ ) {
  15779. v = a.vertices[ i ];
  15780. assert.ok(
  15781. Math.abs( v.x - expected[ i ].x ) <= eps &&
  15782. Math.abs( v.y - expected[ i ].y ) <= eps &&
  15783. Math.abs( v.z - expected[ i ].z ) <= eps,
  15784. "Vertex #" + i + " was normalized as expected"
  15785. );
  15786. }
  15787. } );
  15788. QUnit.test( "computeFaceNormals", ( assert ) => {
  15789. assert.ok( false, "everything's gonna be alright" );
  15790. } );
  15791. QUnit.test( "computeVertexNormals", ( assert ) => {
  15792. assert.ok( false, "everything's gonna be alright" );
  15793. } );
  15794. QUnit.test( "computeFlatVertexNormals", ( assert ) => {
  15795. assert.ok( false, "everything's gonna be alright" );
  15796. } );
  15797. QUnit.test( "computeMorphNormals", ( assert ) => {
  15798. assert.ok( false, "everything's gonna be alright" );
  15799. } );
  15800. QUnit.test( "computeLineDistances", ( assert ) => {
  15801. assert.ok( false, "everything's gonna be alright" );
  15802. } );
  15803. QUnit.test( "computeBoundingBox", ( assert ) => {
  15804. var a = new DodecahedronGeometry();
  15805. a.computeBoundingBox();
  15806. assert.strictEqual( a.boundingBox.isEmpty(), false, "Bounding box isn't empty" );
  15807. var allIn = true;
  15808. for ( var i = 0; i < a.vertices.length; i ++ ) {
  15809. if ( ! a.boundingBox.containsPoint( a.vertices[ i ] ) ) {
  15810. allIn = false;
  15811. }
  15812. }
  15813. assert.strictEqual( allIn, true, "All vertices are inside the box" );
  15814. } );
  15815. QUnit.test( "computeBoundingSphere", ( assert ) => {
  15816. var a = new DodecahedronGeometry();
  15817. a.computeBoundingSphere();
  15818. var allIn = true;
  15819. for ( var i = 0; i < a.vertices.length; i ++ ) {
  15820. if ( ! a.boundingSphere.containsPoint( a.vertices[ i ] ) ) {
  15821. allIn = false;
  15822. }
  15823. }
  15824. assert.strictEqual( allIn, true, "All vertices are inside the bounding sphere" );
  15825. } );
  15826. QUnit.test( "merge", ( assert ) => {
  15827. assert.ok( false, "everything's gonna be alright" );
  15828. } );
  15829. QUnit.test( "mergeMesh", ( assert ) => {
  15830. assert.ok( false, "everything's gonna be alright" );
  15831. } );
  15832. QUnit.test( "mergeVertices", ( assert ) => {
  15833. var a = new Geometry();
  15834. var b = new BoxBufferGeometry( 1, 1, 1 );
  15835. var verts, faces, removed;
  15836. a.fromBufferGeometry( b );
  15837. removed = a.mergeVertices();
  15838. verts = a.vertices.length;
  15839. faces = a.faces.length;
  15840. assert.strictEqual( removed, 16, "Removed the expected number of vertices" );
  15841. assert.strictEqual( verts, 8, "Minimum number of vertices remaining" );
  15842. assert.strictEqual( faces, 12, "Minimum number of faces remaining" );
  15843. } );
  15844. QUnit.test( "sortFacesByMaterialIndex", ( assert ) => {
  15845. var box = new BoxBufferGeometry( 1, 1, 1 );
  15846. var a = new Geometry().fromBufferGeometry( box );
  15847. var expected = [ 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 ];
  15848. a.faces.reverse(); // a bit too simple probably, still missing stuff like checking new UVs
  15849. a.sortFacesByMaterialIndex();
  15850. var indices = [];
  15851. for ( var i = 0; i < a.faces.length; i ++ ) {
  15852. indices.push( a.faces[ i ].materialIndex );
  15853. }
  15854. assert.deepEqual( indices, expected, "Faces in correct order" );
  15855. } );
  15856. QUnit.test( "toJSON", ( assert ) => {
  15857. var a = getGeometry();
  15858. var gold = {
  15859. "metadata": {
  15860. "version": 4.5,
  15861. "type": "Geometry",
  15862. "generator": "Geometry.toJSON"
  15863. },
  15864. "uuid": null,
  15865. "type": "Geometry",
  15866. "data": {
  15867. "vertices": [ - 0.5, 0, 0, 0.5, 0, 0, 0, 1, 0 ],
  15868. "normals": [ 0, 0, 1 ],
  15869. "faces": [ 50, 0, 1, 2, 0, 0, 0, 0, 0 ]
  15870. }
  15871. };
  15872. var json;
  15873. a.faces.push( new Face3( 0, 1, 2 ) );
  15874. a.computeFaceNormals();
  15875. a.computeVertexNormals();
  15876. json = a.toJSON();
  15877. json.uuid = null;
  15878. assert.deepEqual( json, gold, "Generated JSON is as expected" );
  15879. } );
  15880. QUnit.test( "clone", ( assert ) => {
  15881. assert.ok( false, "everything's gonna be alright" );
  15882. } );
  15883. QUnit.test( "copy", ( assert ) => {
  15884. assert.ok( false, "everything's gonna be alright" );
  15885. } );
  15886. QUnit.test( "dispose", ( assert ) => {
  15887. assert.ok( false, "everything's gonna be alright" );
  15888. } );
  15889. } );
  15890. } );
  15891. /**
  15892. * @author benaadams / https://twitter.com/ben_a_adams
  15893. */
  15894. function InstancedBufferAttribute( array, itemSize, meshPerAttribute ) {
  15895. BufferAttribute.call( this, array, itemSize );
  15896. this.meshPerAttribute = meshPerAttribute || 1;
  15897. }
  15898. InstancedBufferAttribute.prototype = Object.assign( Object.create( BufferAttribute.prototype ), {
  15899. constructor: InstancedBufferAttribute,
  15900. isInstancedBufferAttribute: true,
  15901. copy: function ( source ) {
  15902. BufferAttribute.prototype.copy.call( this, source );
  15903. this.meshPerAttribute = source.meshPerAttribute;
  15904. return this;
  15905. }
  15906. } );
  15907. /**
  15908. * @author simonThiele / https://github.com/simonThiele
  15909. */
  15910. /* global QUnit */
  15911. QUnit.module( 'Core', () => {
  15912. QUnit.module.todo( 'InstancedBufferAttribute', () => {
  15913. // INHERITANCE
  15914. QUnit.test( "Extending", ( assert ) => {
  15915. assert.ok( false, "everything's gonna be alright" );
  15916. } );
  15917. // INSTANCING
  15918. QUnit.test( "Instancing", ( assert ) => {
  15919. var instance = new InstancedBufferAttribute( new Float32Array( 10 ), 2 );
  15920. assert.ok( instance.meshPerAttribute === 1, "ok" );
  15921. var instance = new InstancedBufferAttribute( new Float32Array( 10 ), 2, 123 );
  15922. assert.ok( instance.meshPerAttribute === 123, "ok" );
  15923. } );
  15924. // PUBLIC STUFF
  15925. QUnit.test( "copy", ( assert ) => {
  15926. var array = new Float32Array( [ 1, 2, 3, 7, 8, 9 ] );
  15927. var instance = new InstancedBufferAttribute( array, 2, 123 );
  15928. var copiedInstance = instance.copy( instance );
  15929. assert.ok( copiedInstance instanceof InstancedBufferAttribute, "the clone has the correct type" );
  15930. assert.ok( copiedInstance.itemSize === 2, "itemSize was copied" );
  15931. assert.ok( copiedInstance.meshPerAttribute === 123, "meshPerAttribute was copied" );
  15932. for ( var i = 0; i < array.length; i ++ ) {
  15933. assert.ok( copiedInstance.array[ i ] === array[ i ], "array was copied" );
  15934. }
  15935. } );
  15936. } );
  15937. } );
  15938. /**
  15939. * @author benaadams / https://twitter.com/ben_a_adams
  15940. */
  15941. function InstancedBufferGeometry() {
  15942. BufferGeometry.call( this );
  15943. this.type = 'InstancedBufferGeometry';
  15944. this.maxInstancedCount = undefined;
  15945. }
  15946. InstancedBufferGeometry.prototype = Object.assign( Object.create( BufferGeometry.prototype ), {
  15947. constructor: InstancedBufferGeometry,
  15948. isInstancedBufferGeometry: true,
  15949. copy: function ( source ) {
  15950. BufferGeometry.prototype.copy.call( this, source );
  15951. this.maxInstancedCount = source.maxInstancedCount;
  15952. return this;
  15953. },
  15954. clone: function () {
  15955. return new this.constructor().copy( this );
  15956. }
  15957. } );
  15958. /**
  15959. * @author simonThiele / https://github.com/simonThiele
  15960. */
  15961. /* global QUnit */
  15962. QUnit.module( 'Core', () => {
  15963. QUnit.module.todo( 'InstancedBufferGeometry', () => {
  15964. function createClonableMock() {
  15965. return {
  15966. callCount: 0,
  15967. clone: function () {
  15968. this.callCount ++;
  15969. return this;
  15970. }
  15971. };
  15972. }
  15973. // INHERITANCE
  15974. QUnit.test( "Extending", ( assert ) => {
  15975. assert.ok( false, "everything's gonna be alright" );
  15976. } );
  15977. // INSTANCING
  15978. QUnit.test( "Instancing", ( assert ) => {
  15979. assert.ok( false, "everything's gonna be alright" );
  15980. } );
  15981. // PUBLIC STUFF
  15982. QUnit.test( "copy", ( assert ) => {
  15983. var instanceMock1 = {};
  15984. var instanceMock2 = {};
  15985. var indexMock = createClonableMock();
  15986. var defaultAttribute1 = new BufferAttribute( new Float32Array( [ 1 ] ) );
  15987. var defaultAttribute2 = new BufferAttribute( new Float32Array( [ 2 ] ) );
  15988. var instance = new InstancedBufferGeometry();
  15989. instance.addGroup( 0, 10, instanceMock1 );
  15990. instance.addGroup( 10, 5, instanceMock2 );
  15991. instance.setIndex( indexMock );
  15992. instance.addAttribute( 'defaultAttribute1', defaultAttribute1 );
  15993. instance.addAttribute( 'defaultAttribute2', defaultAttribute2 );
  15994. var copiedInstance = new InstancedBufferGeometry().copy( instance );
  15995. assert.ok( copiedInstance instanceof InstancedBufferGeometry, "the clone has the correct type" );
  15996. assert.equal( copiedInstance.index, indexMock, "index was copied" );
  15997. assert.equal( copiedInstance.index.callCount, 1, "index.clone was called once" );
  15998. assert.ok( copiedInstance.attributes[ 'defaultAttribute1' ] instanceof BufferAttribute, "attribute was created" );
  15999. assert.deepEqual( copiedInstance.attributes[ 'defaultAttribute1' ].array, defaultAttribute1.array, "attribute was copied" );
  16000. assert.deepEqual( copiedInstance.attributes[ 'defaultAttribute2' ].array, defaultAttribute2.array, "attribute was copied" );
  16001. assert.equal( copiedInstance.groups[ 0 ].start, 0, "group was copied" );
  16002. assert.equal( copiedInstance.groups[ 0 ].count, 10, "group was copied" );
  16003. assert.equal( copiedInstance.groups[ 0 ].materialIndex, instanceMock1, "group was copied" );
  16004. assert.equal( copiedInstance.groups[ 1 ].start, 10, "group was copied" );
  16005. assert.equal( copiedInstance.groups[ 1 ].count, 5, "group was copied" );
  16006. assert.equal( copiedInstance.groups[ 1 ].materialIndex, instanceMock2, "group was copied" );
  16007. } );
  16008. QUnit.test( "clone", ( assert ) => {
  16009. assert.ok( false, "everything's gonna be alright" );
  16010. } );
  16011. } );
  16012. } );
  16013. /**
  16014. * @author benaadams / https://twitter.com/ben_a_adams
  16015. */
  16016. function InterleavedBuffer( array, stride ) {
  16017. this.uuid = _Math.generateUUID();
  16018. this.array = array;
  16019. this.stride = stride;
  16020. this.count = array !== undefined ? array.length / stride : 0;
  16021. this.dynamic = false;
  16022. this.updateRange = { offset: 0, count: - 1 };
  16023. this.onUploadCallback = function () {};
  16024. this.version = 0;
  16025. }
  16026. Object.defineProperty( InterleavedBuffer.prototype, 'needsUpdate', {
  16027. set: function ( value ) {
  16028. if ( value === true ) this.version ++;
  16029. }
  16030. } );
  16031. Object.assign( InterleavedBuffer.prototype, {
  16032. isInterleavedBuffer: true,
  16033. setArray: function ( array ) {
  16034. if ( Array.isArray( array ) ) {
  16035. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  16036. }
  16037. this.count = array !== undefined ? array.length / this.stride : 0;
  16038. this.array = array;
  16039. },
  16040. setDynamic: function ( value ) {
  16041. this.dynamic = value;
  16042. return this;
  16043. },
  16044. copy: function ( source ) {
  16045. this.array = new source.array.constructor( source.array );
  16046. this.count = source.count;
  16047. this.stride = source.stride;
  16048. this.dynamic = source.dynamic;
  16049. return this;
  16050. },
  16051. copyAt: function ( index1, attribute, index2 ) {
  16052. index1 *= this.stride;
  16053. index2 *= attribute.stride;
  16054. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  16055. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  16056. }
  16057. return this;
  16058. },
  16059. set: function ( value, offset ) {
  16060. if ( offset === undefined ) offset = 0;
  16061. this.array.set( value, offset );
  16062. return this;
  16063. },
  16064. clone: function () {
  16065. return new this.constructor().copy( this );
  16066. },
  16067. onUpload: function ( callback ) {
  16068. this.onUploadCallback = callback;
  16069. return this;
  16070. }
  16071. } );
  16072. /**
  16073. * @author benaadams / https://twitter.com/ben_a_adams
  16074. */
  16075. function InstancedInterleavedBuffer( array, stride, meshPerAttribute ) {
  16076. InterleavedBuffer.call( this, array, stride );
  16077. this.meshPerAttribute = meshPerAttribute || 1;
  16078. }
  16079. InstancedInterleavedBuffer.prototype = Object.assign( Object.create( InterleavedBuffer.prototype ), {
  16080. constructor: InstancedInterleavedBuffer,
  16081. isInstancedInterleavedBuffer: true,
  16082. copy: function ( source ) {
  16083. InterleavedBuffer.prototype.copy.call( this, source );
  16084. this.meshPerAttribute = source.meshPerAttribute;
  16085. return this;
  16086. }
  16087. } );
  16088. /**
  16089. * @author simonThiele / https://github.com/simonThiele
  16090. */
  16091. /* global QUnit */
  16092. QUnit.module( 'Core', () => {
  16093. QUnit.module.todo( 'InstancedInterleavedBuffer', () => {
  16094. // INHERITANCE
  16095. QUnit.test( "Extending", ( assert ) => {
  16096. assert.ok( false, "everything's gonna be alright" );
  16097. } );
  16098. // INSTANCING
  16099. QUnit.test( "Instancing", ( assert ) => {
  16100. var array = new Float32Array( [ 1, 2, 3, 7, 8, 9 ] );
  16101. var instance = new InstancedInterleavedBuffer( array, 3 );
  16102. assert.ok( instance.meshPerAttribute === 1, "ok" );
  16103. } );
  16104. // PUBLIC STUFF
  16105. QUnit.test( "isInstancedInterleavedBuffer", ( assert ) => {
  16106. assert.ok( false, "everything's gonna be alright" );
  16107. } );
  16108. QUnit.test( "copy", ( assert ) => {
  16109. var array = new Float32Array( [ 1, 2, 3, 7, 8, 9 ] );
  16110. var instance = new InstancedInterleavedBuffer( array, 3 );
  16111. var copiedInstance = instance.copy( instance );
  16112. assert.ok( copiedInstance.meshPerAttribute === 1, "additional attribute was copied" );
  16113. } );
  16114. } );
  16115. } );
  16116. /**
  16117. * @author simonThiele / https://github.com/simonThiele
  16118. */
  16119. /* global QUnit */
  16120. QUnit.module( 'Core', () => {
  16121. QUnit.module.todo( 'InterleavedBuffer', () => {
  16122. function checkInstanceAgainstCopy( instance, copiedInstance, assert ) {
  16123. assert.ok( copiedInstance instanceof InterleavedBuffer, "the clone has the correct type" );
  16124. for ( var i = 0; i < instance.array.length; i ++ ) {
  16125. assert.ok( copiedInstance.array[ i ] === instance.array[ i ], "array was copied" );
  16126. }
  16127. assert.ok( copiedInstance.stride === instance.stride, "stride was copied" );
  16128. assert.ok( copiedInstance.dynamic === true, "dynamic was copied" );
  16129. }
  16130. // INSTANCING
  16131. QUnit.test( "Instancing", ( assert ) => {
  16132. assert.ok( false, "everything's gonna be alright" );
  16133. } );
  16134. // PROPERTIES
  16135. QUnit.test( "needsUpdate", ( assert ) => {
  16136. var a = new InterleavedBuffer( new Float32Array( [ 1, 2, 3, 4 ], 2 ) );
  16137. a.needsUpdate = true;
  16138. assert.strictEqual( a.version, 1, "Check version increased" );
  16139. } );
  16140. // PUBLIC STUFF
  16141. QUnit.test( "isInterleavedBuffer", ( assert ) => {
  16142. assert.ok( false, "everything's gonna be alright" );
  16143. } );
  16144. QUnit.test( "setArray", ( assert ) => {
  16145. var f32a = new Float32Array( [ 1, 2, 3, 4 ] );
  16146. var f32b = new Float32Array( [] );
  16147. var a = new InterleavedBuffer( f32a, 2, false );
  16148. a.setArray( f32a );
  16149. assert.strictEqual( a.count, 2, "Check item count for non-empty array" );
  16150. assert.strictEqual( a.array, f32a, "Check array itself" );
  16151. a.setArray( f32b );
  16152. assert.strictEqual( a.count, 0, "Check item count for empty array" );
  16153. assert.strictEqual( a.array, f32b, "Check array itself" );
  16154. assert.throws(
  16155. function () {
  16156. a.setArray( [ 1, 2, 3, 4 ] );
  16157. },
  16158. /array should be a Typed Array/,
  16159. "Calling setArray with a non-typed array throws Error"
  16160. );
  16161. } );
  16162. QUnit.test( "setDynamic", ( assert ) => {
  16163. assert.ok( false, "everything's gonna be alright" );
  16164. } );
  16165. QUnit.test( "copy", ( assert ) => {
  16166. var array = new Float32Array( [ 1, 2, 3, 7, 8, 9 ] );
  16167. var instance = new InterleavedBuffer( array, 3 );
  16168. instance.setDynamic( true );
  16169. checkInstanceAgainstCopy( instance, instance.copy( instance ), assert );
  16170. } );
  16171. QUnit.test( "copyAt", ( assert ) => {
  16172. var a = new InterleavedBuffer( new Float32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ] ), 3 );
  16173. var b = new InterleavedBuffer( new Float32Array( 9 ), 3 );
  16174. var expected = new Float32Array( [ 4, 5, 6, 7, 8, 9, 1, 2, 3 ] );
  16175. b.copyAt( 1, a, 2 );
  16176. b.copyAt( 0, a, 1 );
  16177. b.copyAt( 2, a, 0 );
  16178. assert.deepEqual( b.array, expected, "Check the right values were replaced" );
  16179. } );
  16180. QUnit.test( "set", ( assert ) => {
  16181. var instance = new InterleavedBuffer( new Float32Array( [ 1, 2, 3, 7, 8, 9 ] ), 3 );
  16182. instance.set( [ 0, - 1 ] );
  16183. assert.ok( instance.array[ 0 ] === 0 && instance.array[ 1 ] === - 1, "replace at first by default" );
  16184. } );
  16185. QUnit.test( "clone", ( assert ) => {
  16186. var array = new Float32Array( [ 1, 2, 3, 7, 8, 9 ] );
  16187. var instance = new InterleavedBuffer( array, 3 );
  16188. instance.setDynamic( true );
  16189. checkInstanceAgainstCopy( instance, instance.clone(), assert );
  16190. } );
  16191. QUnit.test( "onUpload", ( assert ) => {
  16192. var a = new InterleavedBuffer();
  16193. var func = function () { };
  16194. a.onUpload( func );
  16195. assert.strictEqual( a.onUploadCallback, func, "Check callback was set properly" );
  16196. } );
  16197. // OTHERS
  16198. QUnit.test( "count", ( assert ) => {
  16199. var instance = new InterleavedBuffer( new Float32Array( [ 1, 2, 3, 7, 8, 9 ] ), 3 );
  16200. assert.equal( instance.count, 2, "count is calculated via array length / stride" );
  16201. } );
  16202. } );
  16203. } );
  16204. /**
  16205. * @author benaadams / https://twitter.com/ben_a_adams
  16206. */
  16207. function InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, normalized ) {
  16208. this.uuid = _Math.generateUUID();
  16209. this.data = interleavedBuffer;
  16210. this.itemSize = itemSize;
  16211. this.offset = offset;
  16212. this.normalized = normalized === true;
  16213. }
  16214. Object.defineProperties( InterleavedBufferAttribute.prototype, {
  16215. count: {
  16216. get: function () {
  16217. return this.data.count;
  16218. }
  16219. },
  16220. array: {
  16221. get: function () {
  16222. return this.data.array;
  16223. }
  16224. }
  16225. } );
  16226. Object.assign( InterleavedBufferAttribute.prototype, {
  16227. isInterleavedBufferAttribute: true,
  16228. setX: function ( index, x ) {
  16229. this.data.array[ index * this.data.stride + this.offset ] = x;
  16230. return this;
  16231. },
  16232. setY: function ( index, y ) {
  16233. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  16234. return this;
  16235. },
  16236. setZ: function ( index, z ) {
  16237. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  16238. return this;
  16239. },
  16240. setW: function ( index, w ) {
  16241. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  16242. return this;
  16243. },
  16244. getX: function ( index ) {
  16245. return this.data.array[ index * this.data.stride + this.offset ];
  16246. },
  16247. getY: function ( index ) {
  16248. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  16249. },
  16250. getZ: function ( index ) {
  16251. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  16252. },
  16253. getW: function ( index ) {
  16254. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  16255. },
  16256. setXY: function ( index, x, y ) {
  16257. index = index * this.data.stride + this.offset;
  16258. this.data.array[ index + 0 ] = x;
  16259. this.data.array[ index + 1 ] = y;
  16260. return this;
  16261. },
  16262. setXYZ: function ( index, x, y, z ) {
  16263. index = index * this.data.stride + this.offset;
  16264. this.data.array[ index + 0 ] = x;
  16265. this.data.array[ index + 1 ] = y;
  16266. this.data.array[ index + 2 ] = z;
  16267. return this;
  16268. },
  16269. setXYZW: function ( index, x, y, z, w ) {
  16270. index = index * this.data.stride + this.offset;
  16271. this.data.array[ index + 0 ] = x;
  16272. this.data.array[ index + 1 ] = y;
  16273. this.data.array[ index + 2 ] = z;
  16274. this.data.array[ index + 3 ] = w;
  16275. return this;
  16276. }
  16277. } );
  16278. /**
  16279. * @author simonThiele / https://github.com/simonThiele
  16280. * @author TristanVALCKE / https://github.com/Itee
  16281. */
  16282. /* global QUnit */
  16283. QUnit.module( 'Core', () => {
  16284. QUnit.module.todo( 'InterleavedBufferAttribute', () => {
  16285. // INSTANCING
  16286. QUnit.test( "Instancing", ( assert ) => {
  16287. assert.ok( false, "everything's gonna be alright" );
  16288. } );
  16289. // PROPERTIES
  16290. QUnit.test( "count", ( assert ) => {
  16291. var buffer = new InterleavedBuffer( new Float32Array( [ 1, 2, 3, 7, 8, 9 ] ), 3 );
  16292. var instance = new InterleavedBufferAttribute( buffer, 2, 0 );
  16293. assert.ok( instance.count === 2, "count is calculated via array length / stride" );
  16294. } );
  16295. QUnit.test( "array", ( assert ) => {
  16296. assert.ok( false, "everything's gonna be alright" );
  16297. } );
  16298. // PUBLIC STUFF
  16299. // setY, setZ and setW are calculated in the same way so not QUnit.testing this
  16300. // TODO: ( you can't be sure that will be the case in future, or a mistake was introduce in one off them ! )
  16301. QUnit.test( "setX", ( assert ) => {
  16302. var buffer = new InterleavedBuffer( new Float32Array( [ 1, 2, 3, 7, 8, 9 ] ), 3 );
  16303. var instance = new InterleavedBufferAttribute( buffer, 2, 0 );
  16304. instance.setX( 0, 123 );
  16305. instance.setX( 1, 321 );
  16306. assert.ok( instance.data.array[ 0 ] === 123 &&
  16307. instance.data.array[ 3 ] === 321, "x was calculated correct based on index and default offset" );
  16308. var buffer = new InterleavedBuffer( new Float32Array( [ 1, 2, 3, 7, 8, 9 ] ), 3 );
  16309. var instance = new InterleavedBufferAttribute( buffer, 2, 1 );
  16310. instance.setX( 0, 123 );
  16311. instance.setX( 1, 321 );
  16312. // the offset was defined as 1, so go one step futher in the array
  16313. assert.ok( instance.data.array[ 1 ] === 123 &&
  16314. instance.data.array[ 4 ] === 321, "x was calculated correct based on index and default offset" );
  16315. } );
  16316. QUnit.test( "setY", ( assert ) => {
  16317. assert.ok( false, "everything's gonna be alright" );
  16318. } );
  16319. QUnit.test( "setZ", ( assert ) => {
  16320. assert.ok( false, "everything's gonna be alright" );
  16321. } );
  16322. QUnit.test( "setW", ( assert ) => {
  16323. assert.ok( false, "everything's gonna be alright" );
  16324. } );
  16325. QUnit.test( "getX", ( assert ) => {
  16326. assert.ok( false, "everything's gonna be alright" );
  16327. } );
  16328. QUnit.test( "getY", ( assert ) => {
  16329. assert.ok( false, "everything's gonna be alright" );
  16330. } );
  16331. QUnit.test( "getZ", ( assert ) => {
  16332. assert.ok( false, "everything's gonna be alright" );
  16333. } );
  16334. QUnit.test( "getW", ( assert ) => {
  16335. assert.ok( false, "everything's gonna be alright" );
  16336. } );
  16337. QUnit.test( "setXY", ( assert ) => {
  16338. assert.ok( false, "everything's gonna be alright" );
  16339. } );
  16340. QUnit.test( "setXYZ", ( assert ) => {
  16341. assert.ok( false, "everything's gonna be alright" );
  16342. } );
  16343. QUnit.test( "setXYZW", ( assert ) => {
  16344. assert.ok( false, "everything's gonna be alright" );
  16345. } );
  16346. } );
  16347. } );
  16348. /**
  16349. * @author moraxy / https://github.com/moraxy
  16350. */
  16351. /* global QUnit */
  16352. QUnit.module( 'Core', () => {
  16353. QUnit.module.todo( 'Layers', () => {
  16354. // INSTANCING
  16355. QUnit.test( "Instancing", ( assert ) => {
  16356. assert.ok( false, "everything's gonna be alright" );
  16357. } );
  16358. // PUBLIC STUFF
  16359. QUnit.test( "set", ( assert ) => {
  16360. var a = new Layers();
  16361. a.set( 0 );
  16362. assert.strictEqual( a.mask, 1, "Set channel 0" );
  16363. a.set( 1 );
  16364. assert.strictEqual( a.mask, 2, "Set channel 1" );
  16365. a.set( 2 );
  16366. assert.strictEqual( a.mask, 4, "Set channel 2" );
  16367. } );
  16368. QUnit.test( "enable", ( assert ) => {
  16369. var a = new Layers();
  16370. a.set( 0 );
  16371. a.enable( 0 );
  16372. assert.strictEqual( a.mask, 1, "Enable channel 0 with mask 0" );
  16373. a.set( 0 );
  16374. a.enable( 1 );
  16375. assert.strictEqual( a.mask, 3, "Enable channel 1 with mask 0" );
  16376. a.set( 1 );
  16377. a.enable( 0 );
  16378. assert.strictEqual( a.mask, 3, "Enable channel 0 with mask 1" );
  16379. a.set( 1 );
  16380. a.enable( 1 );
  16381. assert.strictEqual( a.mask, 2, "Enable channel 1 with mask 1" );
  16382. } );
  16383. QUnit.test( "toggle", ( assert ) => {
  16384. var a = new Layers();
  16385. a.set( 0 );
  16386. a.toggle( 0 );
  16387. assert.strictEqual( a.mask, 0, "Toggle channel 0 with mask 0" );
  16388. a.set( 0 );
  16389. a.toggle( 1 );
  16390. assert.strictEqual( a.mask, 3, "Toggle channel 1 with mask 0" );
  16391. a.set( 1 );
  16392. a.toggle( 0 );
  16393. assert.strictEqual( a.mask, 3, "Toggle channel 0 with mask 1" );
  16394. a.set( 1 );
  16395. a.toggle( 1 );
  16396. assert.strictEqual( a.mask, 0, "Toggle channel 1 with mask 1" );
  16397. } );
  16398. QUnit.test( "disable", ( assert ) => {
  16399. var a = new Layers();
  16400. a.set( 0 );
  16401. a.disable( 0 );
  16402. assert.strictEqual( a.mask, 0, "Disable channel 0 with mask 0" );
  16403. a.set( 0 );
  16404. a.disable( 1 );
  16405. assert.strictEqual( a.mask, 1, "Disable channel 1 with mask 0" );
  16406. a.set( 1 );
  16407. a.disable( 0 );
  16408. assert.strictEqual( a.mask, 2, "Disable channel 0 with mask 1" );
  16409. a.set( 1 );
  16410. a.disable( 1 );
  16411. assert.strictEqual( a.mask, 0, "Disable channel 1 with mask 1" );
  16412. } );
  16413. QUnit.test( "test", ( assert ) => {
  16414. var a = new Layers();
  16415. var b = new Layers();
  16416. assert.ok( a.test( b ), "Start out true" );
  16417. a.set( 1 );
  16418. assert.notOk( a.test( b ), "Set channel 1 in a and fail the QUnit.test" );
  16419. b.toggle( 1 );
  16420. assert.ok( a.test( b ), "Toggle channel 1 in b and pass again" );
  16421. } );
  16422. } );
  16423. } );
  16424. /**
  16425. * @author simonThiele / https://github.com/simonThiele
  16426. * @author TristanVALCKE / https://github.com/Itee
  16427. */
  16428. /* global QUnit */
  16429. QUnit.module( 'Core', () => {
  16430. QUnit.module.todo( 'Object3D', () => {
  16431. var RadToDeg = 180 / Math.PI;
  16432. var eulerEquals = function ( a, b, tolerance ) {
  16433. tolerance = tolerance || 0.0001;
  16434. if ( a.order != b.order ) {
  16435. return false;
  16436. }
  16437. return (
  16438. Math.abs( a.x - b.x ) <= tolerance &&
  16439. Math.abs( a.y - b.y ) <= tolerance &&
  16440. Math.abs( a.z - b.z ) <= tolerance
  16441. );
  16442. };
  16443. // INHERITANCE
  16444. QUnit.test( "Extending", ( assert ) => {
  16445. assert.ok( false, "everything's gonna be alright" );
  16446. } );
  16447. // INSTANCING
  16448. QUnit.test( "Instancing", ( assert ) => {
  16449. assert.ok( false, "everything's gonna be alright" );
  16450. } );
  16451. // STATIC STUFF
  16452. QUnit.test( "DefaultUp", ( assert ) => {
  16453. assert.ok( false, "everything's gonna be alright" );
  16454. } );
  16455. QUnit.test( "DefaultMatrixAutoUpdate", ( assert ) => {
  16456. assert.ok( false, "everything's gonna be alright" );
  16457. } );
  16458. // PUBLIC STUFF
  16459. QUnit.test( "isObject3D", ( assert ) => {
  16460. assert.ok( false, "everything's gonna be alright" );
  16461. } );
  16462. QUnit.test( "onBeforeRender", ( assert ) => {
  16463. assert.ok( false, "everything's gonna be alright" );
  16464. } );
  16465. QUnit.test( "onAfterRender", ( assert ) => {
  16466. assert.ok( false, "everything's gonna be alright" );
  16467. } );
  16468. QUnit.test( "applyMatrix", ( assert ) => {
  16469. var a = new Object3D();
  16470. var m = new Matrix4();
  16471. var expectedPos = new Vector3( x, y, z );
  16472. var expectedQuat = new Quaternion( 0.5 * Math.sqrt( 2 ), 0, 0, 0.5 * Math.sqrt( 2 ) );
  16473. m.makeRotationX( Math.PI / 2 );
  16474. m.setPosition( new Vector3( x, y, z ) );
  16475. a.applyMatrix( m );
  16476. assert.deepEqual( a.position, expectedPos, "Position has the expected values" );
  16477. assert.ok(
  16478. Math.abs( a.quaternion.x - expectedQuat.x ) <= eps &&
  16479. Math.abs( a.quaternion.y - expectedQuat.y ) <= eps &&
  16480. Math.abs( a.quaternion.z - expectedQuat.z ) <= eps,
  16481. "Quaternion has the expected values"
  16482. );
  16483. } );
  16484. QUnit.test( "applyQuaternion", ( assert ) => {
  16485. var a = new Object3D();
  16486. var sqrt = 0.5 * Math.sqrt( 2 );
  16487. var quat = new Quaternion( 0, sqrt, 0, sqrt );
  16488. var expected = new Quaternion( sqrt / 2, sqrt / 2, 0, 0 );
  16489. a.quaternion.set( 0.25, 0.25, 0.25, 0.25 );
  16490. a.applyQuaternion( quat );
  16491. assert.ok(
  16492. Math.abs( a.quaternion.x - expected.x ) <= eps &&
  16493. Math.abs( a.quaternion.y - expected.y ) <= eps &&
  16494. Math.abs( a.quaternion.z - expected.z ) <= eps,
  16495. "Quaternion has the expected values"
  16496. );
  16497. } );
  16498. QUnit.test( "setRotationFromAxisAngle", ( assert ) => {
  16499. var a = new Object3D();
  16500. var axis = new Vector3( 0, 1, 0 );
  16501. var angle = Math.PI;
  16502. var expected = new Euler( - Math.PI, 0, - Math.PI );
  16503. a.setRotationFromAxisAngle( axis, angle );
  16504. assert.ok( eulerEquals( a.getWorldRotation(), expected ), "Correct values after rotation" );
  16505. axis.set( 1, 0, 0 );
  16506. var angle = 0;
  16507. expected.set( 0, 0, 0 );
  16508. a.setRotationFromAxisAngle( axis, angle );
  16509. assert.ok( eulerEquals( a.getWorldRotation(), expected ), "Correct values after zeroing" );
  16510. } );
  16511. QUnit.test( "setRotationFromEuler", ( assert ) => {
  16512. var a = new Object3D();
  16513. var rotation = new Euler( ( 45 / RadToDeg ), 0, Math.PI );
  16514. var expected = rotation.clone(); // bit obvious
  16515. a.setRotationFromEuler( rotation );
  16516. assert.ok( eulerEquals( a.getWorldRotation(), expected ), "Correct values after rotation" );
  16517. } );
  16518. QUnit.test( "setRotationFromMatrix", ( assert ) => {
  16519. var a = new Object3D();
  16520. var m = new Matrix4();
  16521. var eye = new Vector3( 0, 0, 0 );
  16522. var target = new Vector3( 0, 1, - 1 );
  16523. var up = new Vector3( 0, 1, 0 );
  16524. m.lookAt( eye, target, up );
  16525. a.setRotationFromMatrix( m );
  16526. assert.numEqual( a.getWorldRotation().x * RadToDeg, 45, "Correct rotation angle" );
  16527. } );
  16528. QUnit.test( "setRotationFromQuaternion", ( assert ) => {
  16529. var a = new Object3D();
  16530. var rotation = new Quaternion().setFromEuler( new Euler( Math.PI, 0, - Math.PI ) );
  16531. var expected = new Euler( Math.PI, 0, - Math.PI );
  16532. a.setRotationFromQuaternion( rotation );
  16533. assert.ok( eulerEquals( a.getWorldRotation(), expected ), "Correct values after rotation" );
  16534. } );
  16535. QUnit.test( "rotateOnAxis", ( assert ) => {
  16536. assert.ok( false, "everything's gonna be alright" );
  16537. } );
  16538. QUnit.test( "rotateOnWorldAxis", ( assert ) => {
  16539. assert.ok( false, "everything's gonna be alright" );
  16540. } );
  16541. QUnit.test( "rotateX", ( assert ) => {
  16542. var obj = new Object3D();
  16543. var angleInRad = 1.562;
  16544. obj.rotateX( angleInRad );
  16545. assert.numEqual( obj.rotation.x, angleInRad, "x is equal" );
  16546. } );
  16547. QUnit.test( "rotateY", ( assert ) => {
  16548. var obj = new Object3D();
  16549. var angleInRad = - 0.346;
  16550. obj.rotateY( angleInRad );
  16551. assert.numEqual( obj.rotation.y, angleInRad, "y is equal" );
  16552. } );
  16553. QUnit.test( "rotateZ", ( assert ) => {
  16554. var obj = new Object3D();
  16555. var angleInRad = 1;
  16556. obj.rotateZ( angleInRad );
  16557. assert.numEqual( obj.rotation.z, angleInRad, "z is equal" );
  16558. } );
  16559. QUnit.test( "translateOnAxis", ( assert ) => {
  16560. var obj = new Object3D();
  16561. obj.translateOnAxis( new Vector3( 1, 0, 0 ), 1 );
  16562. obj.translateOnAxis( new Vector3( 0, 1, 0 ), 1.23 );
  16563. obj.translateOnAxis( new Vector3( 0, 0, 1 ), - 4.56 );
  16564. assert.propEqual( obj.position, {
  16565. x: 1,
  16566. y: 1.23,
  16567. z: - 4.56
  16568. } );
  16569. } );
  16570. QUnit.test( "translateX", ( assert ) => {
  16571. var obj = new Object3D();
  16572. obj.translateX( 1.234 );
  16573. assert.numEqual( obj.position.x, 1.234, "x is equal" );
  16574. } );
  16575. QUnit.test( "translateY", ( assert ) => {
  16576. var obj = new Object3D();
  16577. obj.translateY( 1.234 );
  16578. assert.numEqual( obj.position.y, 1.234, "y is equal" );
  16579. } );
  16580. QUnit.test( "translateZ", ( assert ) => {
  16581. var obj = new Object3D();
  16582. obj.translateZ( 1.234 );
  16583. assert.numEqual( obj.position.z, 1.234, "z is equal" );
  16584. } );
  16585. QUnit.test( "localToWorld", ( assert ) => {
  16586. assert.ok( false, "everything's gonna be alright" );
  16587. } );
  16588. QUnit.test( "worldToLocal", ( assert ) => {
  16589. assert.ok( false, "everything's gonna be alright" );
  16590. } );
  16591. QUnit.test( "lookAt", ( assert ) => {
  16592. var obj = new Object3D();
  16593. obj.lookAt( new Vector3( 0, - 1, 1 ) );
  16594. assert.numEqual( obj.rotation.x * RadToDeg, 45, "x is equal" );
  16595. } );
  16596. QUnit.test( "add/remove", ( assert ) => {
  16597. var a = new Object3D();
  16598. var child1 = new Object3D();
  16599. var child2 = new Object3D();
  16600. assert.strictEqual( a.children.length, 0, "Starts with no children" );
  16601. a.add( child1 );
  16602. assert.strictEqual( a.children.length, 1, "The first child was added" );
  16603. assert.strictEqual( a.children[ 0 ], child1, "It's the right one" );
  16604. a.add( child2 );
  16605. assert.strictEqual( a.children.length, 2, "The second child was added" );
  16606. assert.strictEqual( a.children[ 1 ], child2, "It's the right one" );
  16607. assert.strictEqual( a.children[ 0 ], child1, "The first one is still there" );
  16608. a.remove( child1 );
  16609. assert.strictEqual( a.children.length, 1, "The first child was removed" );
  16610. assert.strictEqual( a.children[ 0 ], child2, "The second one is still there" );
  16611. a.add( child1 );
  16612. a.remove( child1, child2 );
  16613. assert.strictEqual( a.children.length, 0, "Both children were removed at once" );
  16614. child1.add( child2 );
  16615. assert.strictEqual( child1.children.length, 1, "The second child was added to the first one" );
  16616. a.add( child2 );
  16617. assert.strictEqual( a.children.length, 1, "The second one was added to the parent (no remove)" );
  16618. assert.strictEqual( a.children[ 0 ], child2, "The second one is now the parent's child again" );
  16619. assert.strictEqual( child1.children.length, 0, "The first one no longer has any children" );
  16620. } );
  16621. QUnit.test( "getObjectById/getObjectByName/getObjectByProperty", ( assert ) => {
  16622. var parent = new Object3D();
  16623. var childName = new Object3D();
  16624. var childId = new Object3D(); // id = parent.id + 2
  16625. var childNothing = new Object3D();
  16626. parent.prop = true;
  16627. childName.name = "foo";
  16628. parent.add( childName, childId, childNothing );
  16629. assert.strictEqual( parent.getObjectByProperty( 'prop', true ), parent, "Get parent by its own property" );
  16630. assert.strictEqual( parent.getObjectByName( "foo" ), childName, "Get child by name" );
  16631. assert.strictEqual( parent.getObjectById( parent.id + 2 ), childId, "Get child by Id" );
  16632. assert.strictEqual(
  16633. parent.getObjectByProperty( 'no-property', 'no-value' ), undefined,
  16634. "Unknown property results in undefined"
  16635. );
  16636. } );
  16637. QUnit.test( "getWorldPosition", ( assert ) => {
  16638. var a = new Object3D();
  16639. var b = new Object3D();
  16640. var expectedSingle = new Vector3( x, y, z );
  16641. var expectedParent = new Vector3( x, y, 0 );
  16642. var expectedChild = new Vector3( x, y, 7 + ( z - z ) );
  16643. a.translateX( x );
  16644. a.translateY( y );
  16645. a.translateZ( z );
  16646. assert.deepEqual(
  16647. a.getWorldPosition(), expectedSingle,
  16648. "WorldPosition as expected for single object"
  16649. );
  16650. // translate child and then parent
  16651. b.translateZ( 7 );
  16652. a.add( b );
  16653. a.translateZ( - z );
  16654. assert.deepEqual( a.getWorldPosition(), expectedParent, "WorldPosition as expected for parent" );
  16655. assert.deepEqual( b.getWorldPosition(), expectedChild, "WorldPosition as expected for child" );
  16656. } );
  16657. QUnit.test( "getWorldQuaternion", ( assert ) => {
  16658. assert.ok( false, "everything's gonna be alright" );
  16659. } );
  16660. QUnit.test( "getWorldRotation", ( assert ) => {
  16661. var obj = new Object3D();
  16662. obj.lookAt( new Vector3( 0, - 1, 1 ) );
  16663. assert.numEqual( obj.getWorldRotation().x * RadToDeg, 45, "x is equal" );
  16664. obj.lookAt( new Vector3( 1, 0, 0 ) );
  16665. assert.numEqual( obj.getWorldRotation().y * RadToDeg, 90, "y is equal" );
  16666. } );
  16667. QUnit.test( "getWorldScale", ( assert ) => {
  16668. var a = new Object3D();
  16669. var m = new Matrix4().makeScale( x, y, z );
  16670. var expected = new Vector3( x, y, z );
  16671. a.applyMatrix( m );
  16672. assert.deepEqual( a.getWorldScale(), expected, "WorldScale as expected" );
  16673. } );
  16674. QUnit.test( "getWorldDirection", ( assert ) => {
  16675. var a = new Object3D();
  16676. var expected = new Vector3( 0, - 0.5 * Math.sqrt( 2 ), 0.5 * Math.sqrt( 2 ) );
  16677. var dir;
  16678. a.lookAt( new Vector3( 0, - 1, 1 ) );
  16679. dir = a.getWorldDirection();
  16680. assert.ok(
  16681. Math.abs( dir.x - expected.x ) <= eps &&
  16682. Math.abs( dir.y - expected.y ) <= eps &&
  16683. Math.abs( dir.z - expected.z ) <= eps,
  16684. "Direction has the expected values"
  16685. );
  16686. } );
  16687. QUnit.test( "raycast", ( assert ) => {
  16688. assert.ok( false, "everything's gonna be alright" );
  16689. } );
  16690. QUnit.test( "traverse/traverseVisible/traverseAncestors", ( assert ) => {
  16691. var a = new Object3D();
  16692. var b = new Object3D();
  16693. var c = new Object3D();
  16694. var d = new Object3D();
  16695. var names = [];
  16696. var expectedNormal = [ "parent", "child", "childchild 1", "childchild 2" ];
  16697. var expectedVisible = [ "parent", "child", "childchild 2" ];
  16698. var expectedAncestors = [ "child", "parent" ];
  16699. a.name = "parent";
  16700. b.name = "child";
  16701. c.name = "childchild 1";
  16702. c.visible = false;
  16703. d.name = "childchild 2";
  16704. b.add( c );
  16705. b.add( d );
  16706. a.add( b );
  16707. a.traverse( function ( obj ) {
  16708. names.push( obj.name );
  16709. } );
  16710. assert.deepEqual( names, expectedNormal, "Traversed objects in expected order" );
  16711. var names = [];
  16712. a.traverseVisible( function ( obj ) {
  16713. names.push( obj.name );
  16714. } );
  16715. assert.deepEqual( names, expectedVisible, "Traversed visible objects in expected order" );
  16716. var names = [];
  16717. c.traverseAncestors( function ( obj ) {
  16718. names.push( obj.name );
  16719. } );
  16720. assert.deepEqual( names, expectedAncestors, "Traversed ancestors in expected order" );
  16721. } );
  16722. QUnit.test( "updateMatrix", ( assert ) => {
  16723. assert.ok( false, "everything's gonna be alright" );
  16724. } );
  16725. QUnit.test( "updateMatrixWorld", ( assert ) => {
  16726. assert.ok( false, "everything's gonna be alright" );
  16727. } );
  16728. QUnit.test( "toJSON", ( assert ) => {
  16729. var a = new Object3D();
  16730. var child = new Object3D();
  16731. var childChild = new Object3D();
  16732. a.name = "a's name";
  16733. a.matrix.set( 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 );
  16734. a.visible = false;
  16735. a.castShadow = true;
  16736. a.receiveShadow = true;
  16737. a.userData[ "foo" ] = "bar";
  16738. child.uuid = "5D4E9AE8-DA61-4912-A575-71A5BE3D72CD";
  16739. childChild.uuid = "B43854B3-E970-4E85-BD41-AAF8D7BFA189";
  16740. child.add( childChild );
  16741. a.add( child );
  16742. var gold = {
  16743. "metadata": {
  16744. "version": 4.5,
  16745. "type": "Object",
  16746. "generator": "Object3D.toJSON"
  16747. },
  16748. "object": {
  16749. "uuid": "0A1E4F43-CB5B-4097-8F82-DC2969C0B8C2",
  16750. "type": "Object3D",
  16751. "name": "a's name",
  16752. "castShadow": true,
  16753. "receiveShadow": true,
  16754. "visible": false,
  16755. "userData": { "foo": "bar" },
  16756. "matrix": [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ],
  16757. "children": [
  16758. {
  16759. "uuid": "5D4E9AE8-DA61-4912-A575-71A5BE3D72CD",
  16760. "type": "Object3D",
  16761. "matrix": [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ],
  16762. "children": [
  16763. {
  16764. "uuid": "B43854B3-E970-4E85-BD41-AAF8D7BFA189",
  16765. "type": "Object3D",
  16766. "matrix": [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]
  16767. }
  16768. ]
  16769. }
  16770. ]
  16771. }
  16772. };
  16773. // hacks
  16774. var out = a.toJSON();
  16775. out.object.uuid = "0A1E4F43-CB5B-4097-8F82-DC2969C0B8C2";
  16776. assert.deepEqual( out, gold, "JSON is as expected" );
  16777. } );
  16778. QUnit.test( "clone", ( assert ) => {
  16779. var a;
  16780. var b = new Object3D();
  16781. assert.strictEqual( a, undefined, "Undefined pre-clone()" );
  16782. a = b.clone();
  16783. assert.notStrictEqual( a, b, "Defined but seperate instances post-clone()" );
  16784. a.uuid = b.uuid;
  16785. assert.deepEqual( a, b, "But identical properties" );
  16786. } );
  16787. QUnit.test( "copy", ( assert ) => {
  16788. var a = new Object3D();
  16789. var b = new Object3D();
  16790. var child = new Object3D();
  16791. var childChild = new Object3D();
  16792. a.name = "original";
  16793. b.name = "to-be-copied";
  16794. b.position.set( x, y, z );
  16795. b.quaternion.set( x, y, z, w );
  16796. b.scale.set( 2, 3, 4 );
  16797. // bogus QUnit.test values
  16798. b.matrix.set( 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 );
  16799. b.matrixWorld.set( 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 );
  16800. b.matrixAutoUpdate = false;
  16801. b.matrixWorldNeedsUpdate = true;
  16802. b.layers.mask = 2;
  16803. b.visible = false;
  16804. b.castShadow = true;
  16805. b.receiveShadow = true;
  16806. b.frustumCulled = false;
  16807. b.renderOrder = 1;
  16808. b.userData[ "foo" ] = "bar";
  16809. child.add( childChild );
  16810. b.add( child );
  16811. assert.notDeepEqual( a, b, "Objects are not equal pre-copy()" );
  16812. a.copy( b, true );
  16813. // check they're all unique instances
  16814. assert.ok(
  16815. a.uuid !== b.uuid &&
  16816. a.children[ 0 ].uuid !== b.children[ 0 ].uuid &&
  16817. a.children[ 0 ].children[ 0 ].uuid !== b.children[ 0 ].children[ 0 ].uuid,
  16818. "UUIDs are all different"
  16819. );
  16820. // and now fix that
  16821. a.uuid = b.uuid;
  16822. a.children[ 0 ].uuid = b.children[ 0 ].uuid;
  16823. a.children[ 0 ].children[ 0 ].uuid = b.children[ 0 ].children[ 0 ].uuid;
  16824. assert.deepEqual( a, b, "Objects are equal post-copy()" );
  16825. } );
  16826. } );
  16827. } );
  16828. /**
  16829. * @author mrdoob / http://mrdoob.com/
  16830. * @author bhouston / http://clara.io/
  16831. * @author stephomi / http://stephaneginier.com/
  16832. */
  16833. function Raycaster( origin, direction, near, far ) {
  16834. this.ray = new Ray( origin, direction );
  16835. // direction is assumed to be normalized (for accurate distance calculations)
  16836. this.near = near || 0;
  16837. this.far = far || Infinity;
  16838. this.params = {
  16839. Mesh: {},
  16840. Line: {},
  16841. LOD: {},
  16842. Points: { threshold: 1 },
  16843. Sprite: {}
  16844. };
  16845. Object.defineProperties( this.params, {
  16846. PointCloud: {
  16847. get: function () {
  16848. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  16849. return this.Points;
  16850. }
  16851. }
  16852. } );
  16853. }
  16854. function ascSort( a, b ) {
  16855. return a.distance - b.distance;
  16856. }
  16857. function intersectObject( object, raycaster, intersects, recursive ) {
  16858. if ( object.visible === false ) return;
  16859. object.raycast( raycaster, intersects );
  16860. if ( recursive === true ) {
  16861. var children = object.children;
  16862. for ( var i = 0, l = children.length; i < l; i ++ ) {
  16863. intersectObject( children[ i ], raycaster, intersects, true );
  16864. }
  16865. }
  16866. }
  16867. Object.assign( Raycaster.prototype, {
  16868. linePrecision: 1,
  16869. set: function ( origin, direction ) {
  16870. // direction is assumed to be normalized (for accurate distance calculations)
  16871. this.ray.set( origin, direction );
  16872. },
  16873. setFromCamera: function ( coords, camera ) {
  16874. if ( ( camera && camera.isPerspectiveCamera ) ) {
  16875. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  16876. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  16877. } else if ( ( camera && camera.isOrthographicCamera ) ) {
  16878. this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
  16879. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  16880. } else {
  16881. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  16882. }
  16883. },
  16884. intersectObject: function ( object, recursive ) {
  16885. var intersects = [];
  16886. intersectObject( object, this, intersects, recursive );
  16887. intersects.sort( ascSort );
  16888. return intersects;
  16889. },
  16890. intersectObjects: function ( objects, recursive ) {
  16891. var intersects = [];
  16892. if ( Array.isArray( objects ) === false ) {
  16893. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  16894. return intersects;
  16895. }
  16896. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  16897. intersectObject( objects[ i ], this, intersects, recursive );
  16898. }
  16899. intersects.sort( ascSort );
  16900. return intersects;
  16901. }
  16902. } );
  16903. /**
  16904. * @author mrdoob / http://mrdoob.com/
  16905. * @author benaadams / https://twitter.com/ben_a_adams
  16906. * @author Mugen87 / https://github.com/Mugen87
  16907. */
  16908. // SphereGeometry
  16909. function SphereGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  16910. Geometry.call( this );
  16911. this.type = 'SphereGeometry';
  16912. this.parameters = {
  16913. radius: radius,
  16914. widthSegments: widthSegments,
  16915. heightSegments: heightSegments,
  16916. phiStart: phiStart,
  16917. phiLength: phiLength,
  16918. thetaStart: thetaStart,
  16919. thetaLength: thetaLength
  16920. };
  16921. this.fromBufferGeometry( new SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
  16922. this.mergeVertices();
  16923. }
  16924. SphereGeometry.prototype = Object.create( Geometry.prototype );
  16925. SphereGeometry.prototype.constructor = SphereGeometry;
  16926. // SphereBufferGeometry
  16927. function SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  16928. BufferGeometry.call( this );
  16929. this.type = 'SphereBufferGeometry';
  16930. this.parameters = {
  16931. radius: radius,
  16932. widthSegments: widthSegments,
  16933. heightSegments: heightSegments,
  16934. phiStart: phiStart,
  16935. phiLength: phiLength,
  16936. thetaStart: thetaStart,
  16937. thetaLength: thetaLength
  16938. };
  16939. radius = radius || 50;
  16940. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  16941. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  16942. phiStart = phiStart !== undefined ? phiStart : 0;
  16943. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  16944. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  16945. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  16946. var thetaEnd = thetaStart + thetaLength;
  16947. var ix, iy;
  16948. var index = 0;
  16949. var grid = [];
  16950. var vertex = new Vector3();
  16951. var normal = new Vector3();
  16952. // buffers
  16953. var indices = [];
  16954. var vertices = [];
  16955. var normals = [];
  16956. var uvs = [];
  16957. // generate vertices, normals and uvs
  16958. for ( iy = 0; iy <= heightSegments; iy ++ ) {
  16959. var verticesRow = [];
  16960. var v = iy / heightSegments;
  16961. for ( ix = 0; ix <= widthSegments; ix ++ ) {
  16962. var u = ix / widthSegments;
  16963. // vertex
  16964. vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  16965. vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
  16966. vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  16967. vertices.push( vertex.x, vertex.y, vertex.z );
  16968. // normal
  16969. normal.set( vertex.x, vertex.y, vertex.z ).normalize();
  16970. normals.push( normal.x, normal.y, normal.z );
  16971. // uv
  16972. uvs.push( u, 1 - v );
  16973. verticesRow.push( index ++ );
  16974. }
  16975. grid.push( verticesRow );
  16976. }
  16977. // indices
  16978. for ( iy = 0; iy < heightSegments; iy ++ ) {
  16979. for ( ix = 0; ix < widthSegments; ix ++ ) {
  16980. var a = grid[ iy ][ ix + 1 ];
  16981. var b = grid[ iy ][ ix ];
  16982. var c = grid[ iy + 1 ][ ix ];
  16983. var d = grid[ iy + 1 ][ ix + 1 ];
  16984. if ( iy !== 0 || thetaStart > 0 ) indices.push( a, b, d );
  16985. if ( iy !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( b, c, d );
  16986. }
  16987. }
  16988. // build geometry
  16989. this.setIndex( indices );
  16990. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16991. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16992. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16993. }
  16994. SphereBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16995. SphereBufferGeometry.prototype.constructor = SphereBufferGeometry;
  16996. /**
  16997. * @author simonThiele / https://github.com/simonThiele
  16998. */
  16999. /* global QUnit */
  17000. function checkRayDirectionAgainstReferenceVector( rayDirection, refVector, assert ) {
  17001. assert.ok( refVector.x - rayDirection.x <= Number.EPSILON && refVector.y - rayDirection.y <= Number.EPSILON && refVector.z - rayDirection.z <= Number.EPSILON, "camera is pointing to" +
  17002. " the same direction as expected" );
  17003. }
  17004. function getRaycaster() {
  17005. return new Raycaster(
  17006. new Vector3( 0, 0, 0 ),
  17007. new Vector3( 0, 0, - 1 ),
  17008. 1,
  17009. 100
  17010. );
  17011. }
  17012. function getObjectsToCheck() {
  17013. var objects = [];
  17014. var sphere1 = getSphere();
  17015. sphere1.position.set( 0, 0, - 10 );
  17016. sphere1.name = 1;
  17017. objects.push( sphere1 );
  17018. var sphere11 = getSphere();
  17019. sphere11.position.set( 0, 0, 1 );
  17020. sphere11.name = 11;
  17021. sphere1.add( sphere11 );
  17022. var sphere12 = getSphere();
  17023. sphere12.position.set( 0, 0, - 1 );
  17024. sphere12.name = 12;
  17025. sphere1.add( sphere12 );
  17026. var sphere2 = getSphere();
  17027. sphere2.position.set( - 5, 0, - 5 );
  17028. sphere2.name = 2;
  17029. objects.push( sphere2 );
  17030. for ( var i = 0; i < objects.length; i ++ ) {
  17031. objects[ i ].updateMatrixWorld();
  17032. }
  17033. return objects;
  17034. }
  17035. function getSphere() {
  17036. return new Mesh( new SphereGeometry( 1, 100, 100 ) );
  17037. }
  17038. QUnit.module( 'Core', () => {
  17039. QUnit.module.todo( 'Raycaster', () => {
  17040. // INSTANCING
  17041. QUnit.test( "Instancing", ( assert ) => {
  17042. assert.ok( false, "everything's gonna be alright" );
  17043. } );
  17044. // PUBLIC STUFF
  17045. QUnit.test( "linePrecision", ( assert ) => {
  17046. assert.ok( false, "everything's gonna be alright" );
  17047. } );
  17048. QUnit.test( "set", ( assert ) => {
  17049. var origin = new Vector3( 0, 0, 0 );
  17050. var direction = new Vector3( 0, 0, - 1 );
  17051. var a = new Raycaster( origin.clone(), direction.clone() );
  17052. assert.deepEqual( a.ray.origin, origin, "Origin is correct" );
  17053. assert.deepEqual( a.ray.direction, direction, "Direction is correct" );
  17054. origin.set( 1, 1, 1 );
  17055. direction.set( - 1, 0, 0 );
  17056. a.set( origin, direction );
  17057. assert.deepEqual( a.ray.origin, origin, "Origin was set correctly" );
  17058. assert.deepEqual( a.ray.direction, direction, "Direction was set correctly" );
  17059. } );
  17060. QUnit.test( "setFromCamera (Perspective)", ( assert ) => {
  17061. var raycaster = new Raycaster();
  17062. var rayDirection = raycaster.ray.direction;
  17063. var camera = new PerspectiveCamera( 90, 1, 1, 1000 );
  17064. raycaster.setFromCamera( {
  17065. x: 0,
  17066. y: 0
  17067. }, camera );
  17068. assert.ok( rayDirection.x === 0, rayDirection.y === 0, rayDirection.z === - 1,
  17069. "camera is looking straight to -z and so does the ray in the middle of the screen" );
  17070. var step = 0.1;
  17071. for ( var x = - 1; x <= 1; x += step ) {
  17072. for ( var y = - 1; y <= 1; y += step ) {
  17073. raycaster.setFromCamera( {
  17074. x,
  17075. y
  17076. }, camera );
  17077. var refVector = new Vector3( x, y, - 1 ).normalize();
  17078. checkRayDirectionAgainstReferenceVector( rayDirection, refVector, assert );
  17079. }
  17080. }
  17081. } );
  17082. QUnit.test( "setFromCamera (Orthographic)", ( assert ) => {
  17083. var raycaster = new Raycaster();
  17084. var rayOrigin = raycaster.ray.origin;
  17085. var rayDirection = raycaster.ray.direction;
  17086. var camera = new OrthographicCamera( - 1, 1, 1, - 1, 0, 1000 );
  17087. var expectedOrigin = new Vector3( 0, 0, 0 );
  17088. var expectedDirection = new Vector3( 0, 0, - 1 );
  17089. raycaster.setFromCamera( {
  17090. x: 0,
  17091. y: 0
  17092. }, camera );
  17093. assert.deepEqual( rayOrigin, expectedOrigin, "Ray origin has the right coordinates" );
  17094. assert.deepEqual( rayDirection, expectedDirection, "Camera and Ray are pointing towards -z" );
  17095. } );
  17096. QUnit.test( "intersectObject", ( assert ) => {
  17097. var raycaster = getRaycaster();
  17098. var objectsToCheck = getObjectsToCheck();
  17099. assert.ok( raycaster.intersectObject( objectsToCheck[ 0 ] ).length === 1,
  17100. "no recursive search should lead to one hit" );
  17101. assert.ok( raycaster.intersectObject( objectsToCheck[ 0 ], true ).length === 3,
  17102. "recursive search should lead to three hits" );
  17103. var intersections = raycaster.intersectObject( objectsToCheck[ 0 ], true );
  17104. for ( var i = 0; i < intersections.length - 1; i ++ ) {
  17105. assert.ok( intersections[ i ].distance <= intersections[ i + 1 ].distance, "intersections are sorted" );
  17106. }
  17107. } );
  17108. QUnit.test( "intersectObjects", ( assert ) => {
  17109. var raycaster = getRaycaster();
  17110. var objectsToCheck = getObjectsToCheck();
  17111. assert.ok( raycaster.intersectObjects( objectsToCheck ).length === 1,
  17112. "no recursive search should lead to one hit" );
  17113. assert.ok( raycaster.intersectObjects( objectsToCheck, true ).length === 3,
  17114. "recursive search should lead to three hits" );
  17115. var intersections = raycaster.intersectObjects( objectsToCheck, true );
  17116. for ( var i = 0; i < intersections.length - 1; i ++ ) {
  17117. assert.ok( intersections[ i ].distance <= intersections[ i + 1 ].distance, "intersections are sorted" );
  17118. }
  17119. } );
  17120. } );
  17121. } );
  17122. /**
  17123. * @author mrdoob / http://mrdoob.com/
  17124. */
  17125. function Uniform( value ) {
  17126. if ( typeof value === 'string' ) {
  17127. console.warn( 'THREE.Uniform: Type parameter is no longer needed.' );
  17128. value = arguments[ 1 ];
  17129. }
  17130. this.value = value;
  17131. }
  17132. Uniform.prototype.clone = function () {
  17133. return new Uniform( this.value.clone === undefined ? this.value : this.value.clone() );
  17134. };
  17135. /**
  17136. * @author moraxy / https://github.com/moraxy
  17137. */
  17138. /* global QUnit */
  17139. QUnit.module( 'Core', () => {
  17140. QUnit.module.todo( 'Uniform', () => {
  17141. // INSTANCING
  17142. QUnit.test( "Instancing", ( assert ) => {
  17143. var a;
  17144. var b = new Vector3( x, y, z );
  17145. a = new Uniform( 5 );
  17146. assert.strictEqual( a.value, 5, "New constructor works with simple values" );
  17147. a = new Uniform( b );
  17148. assert.ok( a.value.equals( b ), "New constructor works with complex values" );
  17149. } );
  17150. // PUBLIC STUFF
  17151. QUnit.test( "clone", ( assert ) => {
  17152. var a = new Uniform( 23 );
  17153. var b = a.clone();
  17154. assert.strictEqual( b.value, a.value, "clone() with simple values works" );
  17155. var a = new Uniform( new Vector3( 1, 2, 3 ) );
  17156. var b = a.clone();
  17157. assert.ok( b.value.equals( a.value ), "clone() with complex values works" );
  17158. } );
  17159. } );
  17160. } );
  17161. /**
  17162. * @author mrdoob / http://mrdoob.com/
  17163. */
  17164. function Group() {
  17165. Object3D.call( this );
  17166. this.type = 'Group';
  17167. }
  17168. Group.prototype = Object.assign( Object.create( Object3D.prototype ), {
  17169. constructor: Group
  17170. } );
  17171. /**
  17172. * @author TristanVALCKE / https://github.com/Itee
  17173. */
  17174. /* global QUnit */
  17175. QUnit.module.todo( 'Extras', () => {
  17176. QUnit.module.todo( 'SceneUtils', () => {
  17177. // PUBLIC STUFF
  17178. QUnit.test( "createMultiMaterialObject", ( assert ) => {
  17179. assert.ok( false, "everything's gonna be alright" );
  17180. } );
  17181. QUnit.test( "detach", ( assert ) => {
  17182. assert.ok( false, "everything's gonna be alright" );
  17183. } );
  17184. QUnit.test( "attach", ( assert ) => {
  17185. assert.ok( false, "everything's gonna be alright" );
  17186. } );
  17187. } );
  17188. } );
  17189. /**
  17190. * @author zz85 / http://www.lab4games.net/zz85/blog
  17191. */
  17192. var ShapeUtils = {
  17193. // calculate area of the contour polygon
  17194. area: function ( contour ) {
  17195. var n = contour.length;
  17196. var a = 0.0;
  17197. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  17198. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  17199. }
  17200. return a * 0.5;
  17201. },
  17202. triangulate: ( function () {
  17203. /**
  17204. * This code is a quick port of code written in C++ which was submitted to
  17205. * flipcode.com by John W. Ratcliff // July 22, 2000
  17206. * See original code and more information here:
  17207. * http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml
  17208. *
  17209. * ported to actionscript by Zevan Rosser
  17210. * www.actionsnippet.com
  17211. *
  17212. * ported to javascript by Joshua Koo
  17213. * http://www.lab4games.net/zz85/blog
  17214. *
  17215. */
  17216. function snip( contour, u, v, w, n, verts ) {
  17217. var p;
  17218. var ax, ay, bx, by;
  17219. var cx, cy, px, py;
  17220. ax = contour[ verts[ u ] ].x;
  17221. ay = contour[ verts[ u ] ].y;
  17222. bx = contour[ verts[ v ] ].x;
  17223. by = contour[ verts[ v ] ].y;
  17224. cx = contour[ verts[ w ] ].x;
  17225. cy = contour[ verts[ w ] ].y;
  17226. if ( ( bx - ax ) * ( cy - ay ) - ( by - ay ) * ( cx - ax ) <= 0 ) return false;
  17227. var aX, aY, bX, bY, cX, cY;
  17228. var apx, apy, bpx, bpy, cpx, cpy;
  17229. var cCROSSap, bCROSScp, aCROSSbp;
  17230. aX = cx - bx; aY = cy - by;
  17231. bX = ax - cx; bY = ay - cy;
  17232. cX = bx - ax; cY = by - ay;
  17233. for ( p = 0; p < n; p ++ ) {
  17234. px = contour[ verts[ p ] ].x;
  17235. py = contour[ verts[ p ] ].y;
  17236. if ( ( ( px === ax ) && ( py === ay ) ) ||
  17237. ( ( px === bx ) && ( py === by ) ) ||
  17238. ( ( px === cx ) && ( py === cy ) ) ) continue;
  17239. apx = px - ax; apy = py - ay;
  17240. bpx = px - bx; bpy = py - by;
  17241. cpx = px - cx; cpy = py - cy;
  17242. // see if p is inside triangle abc
  17243. aCROSSbp = aX * bpy - aY * bpx;
  17244. cCROSSap = cX * apy - cY * apx;
  17245. bCROSScp = bX * cpy - bY * cpx;
  17246. if ( ( aCROSSbp >= - Number.EPSILON ) && ( bCROSScp >= - Number.EPSILON ) && ( cCROSSap >= - Number.EPSILON ) ) return false;
  17247. }
  17248. return true;
  17249. }
  17250. // takes in an contour array and returns
  17251. return function triangulate( contour, indices ) {
  17252. var n = contour.length;
  17253. if ( n < 3 ) return null;
  17254. var result = [],
  17255. verts = [],
  17256. vertIndices = [];
  17257. /* we want a counter-clockwise polygon in verts */
  17258. var u, v, w;
  17259. if ( ShapeUtils.area( contour ) > 0.0 ) {
  17260. for ( v = 0; v < n; v ++ ) verts[ v ] = v;
  17261. } else {
  17262. for ( v = 0; v < n; v ++ ) verts[ v ] = ( n - 1 ) - v;
  17263. }
  17264. var nv = n;
  17265. /* remove nv - 2 vertices, creating 1 triangle every time */
  17266. var count = 2 * nv; /* error detection */
  17267. for ( v = nv - 1; nv > 2; ) {
  17268. /* if we loop, it is probably a non-simple polygon */
  17269. if ( ( count -- ) <= 0 ) {
  17270. //** Triangulate: ERROR - probable bad polygon!
  17271. //throw ( "Warning, unable to triangulate polygon!" );
  17272. //return null;
  17273. // Sometimes warning is fine, especially polygons are triangulated in reverse.
  17274. console.warn( 'THREE.ShapeUtils: Unable to triangulate polygon! in triangulate()' );
  17275. if ( indices ) return vertIndices;
  17276. return result;
  17277. }
  17278. /* three consecutive vertices in current polygon, <u,v,w> */
  17279. u = v; if ( nv <= u ) u = 0; /* previous */
  17280. v = u + 1; if ( nv <= v ) v = 0; /* new v */
  17281. w = v + 1; if ( nv <= w ) w = 0; /* next */
  17282. if ( snip( contour, u, v, w, nv, verts ) ) {
  17283. var a, b, c, s, t;
  17284. /* true names of the vertices */
  17285. a = verts[ u ];
  17286. b = verts[ v ];
  17287. c = verts[ w ];
  17288. /* output Triangle */
  17289. result.push( [ contour[ a ],
  17290. contour[ b ],
  17291. contour[ c ] ] );
  17292. vertIndices.push( [ verts[ u ], verts[ v ], verts[ w ] ] );
  17293. /* remove v from the remaining polygon */
  17294. for ( s = v, t = v + 1; t < nv; s ++, t ++ ) {
  17295. verts[ s ] = verts[ t ];
  17296. }
  17297. nv --;
  17298. /* reset error detection counter */
  17299. count = 2 * nv;
  17300. }
  17301. }
  17302. if ( indices ) return vertIndices;
  17303. return result;
  17304. };
  17305. } )(),
  17306. triangulateShape: function ( contour, holes ) {
  17307. function removeDupEndPts( points ) {
  17308. var l = points.length;
  17309. if ( l > 2 && points[ l - 1 ].equals( points[ 0 ] ) ) {
  17310. points.pop();
  17311. }
  17312. }
  17313. removeDupEndPts( contour );
  17314. holes.forEach( removeDupEndPts );
  17315. function point_in_segment_2D_colin( inSegPt1, inSegPt2, inOtherPt ) {
  17316. // inOtherPt needs to be collinear to the inSegment
  17317. if ( inSegPt1.x !== inSegPt2.x ) {
  17318. if ( inSegPt1.x < inSegPt2.x ) {
  17319. return ( ( inSegPt1.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt2.x ) );
  17320. } else {
  17321. return ( ( inSegPt2.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt1.x ) );
  17322. }
  17323. } else {
  17324. if ( inSegPt1.y < inSegPt2.y ) {
  17325. return ( ( inSegPt1.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt2.y ) );
  17326. } else {
  17327. return ( ( inSegPt2.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt1.y ) );
  17328. }
  17329. }
  17330. }
  17331. function intersect_segments_2D( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1, inSeg2Pt2, inExcludeAdjacentSegs ) {
  17332. var seg1dx = inSeg1Pt2.x - inSeg1Pt1.x, seg1dy = inSeg1Pt2.y - inSeg1Pt1.y;
  17333. var seg2dx = inSeg2Pt2.x - inSeg2Pt1.x, seg2dy = inSeg2Pt2.y - inSeg2Pt1.y;
  17334. var seg1seg2dx = inSeg1Pt1.x - inSeg2Pt1.x;
  17335. var seg1seg2dy = inSeg1Pt1.y - inSeg2Pt1.y;
  17336. var limit = seg1dy * seg2dx - seg1dx * seg2dy;
  17337. var perpSeg1 = seg1dy * seg1seg2dx - seg1dx * seg1seg2dy;
  17338. if ( Math.abs( limit ) > Number.EPSILON ) {
  17339. // not parallel
  17340. var perpSeg2;
  17341. if ( limit > 0 ) {
  17342. if ( ( perpSeg1 < 0 ) || ( perpSeg1 > limit ) ) return [];
  17343. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  17344. if ( ( perpSeg2 < 0 ) || ( perpSeg2 > limit ) ) return [];
  17345. } else {
  17346. if ( ( perpSeg1 > 0 ) || ( perpSeg1 < limit ) ) return [];
  17347. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  17348. if ( ( perpSeg2 > 0 ) || ( perpSeg2 < limit ) ) return [];
  17349. }
  17350. // i.e. to reduce rounding errors
  17351. // intersection at endpoint of segment#1?
  17352. if ( perpSeg2 === 0 ) {
  17353. if ( ( inExcludeAdjacentSegs ) &&
  17354. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  17355. return [ inSeg1Pt1 ];
  17356. }
  17357. if ( perpSeg2 === limit ) {
  17358. if ( ( inExcludeAdjacentSegs ) &&
  17359. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  17360. return [ inSeg1Pt2 ];
  17361. }
  17362. // intersection at endpoint of segment#2?
  17363. if ( perpSeg1 === 0 ) return [ inSeg2Pt1 ];
  17364. if ( perpSeg1 === limit ) return [ inSeg2Pt2 ];
  17365. // return real intersection point
  17366. var factorSeg1 = perpSeg2 / limit;
  17367. return [ { x: inSeg1Pt1.x + factorSeg1 * seg1dx, y: inSeg1Pt1.y + factorSeg1 * seg1dy } ];
  17368. } else {
  17369. // parallel or collinear
  17370. if ( ( perpSeg1 !== 0 ) ||
  17371. ( seg2dy * seg1seg2dx !== seg2dx * seg1seg2dy ) ) return [];
  17372. // they are collinear or degenerate
  17373. var seg1Pt = ( ( seg1dx === 0 ) && ( seg1dy === 0 ) ); // segment1 is just a point?
  17374. var seg2Pt = ( ( seg2dx === 0 ) && ( seg2dy === 0 ) ); // segment2 is just a point?
  17375. // both segments are points
  17376. if ( seg1Pt && seg2Pt ) {
  17377. if ( ( inSeg1Pt1.x !== inSeg2Pt1.x ) ||
  17378. ( inSeg1Pt1.y !== inSeg2Pt1.y ) ) return []; // they are distinct points
  17379. return [ inSeg1Pt1 ]; // they are the same point
  17380. }
  17381. // segment#1 is a single point
  17382. if ( seg1Pt ) {
  17383. if ( ! point_in_segment_2D_colin( inSeg2Pt1, inSeg2Pt2, inSeg1Pt1 ) ) return []; // but not in segment#2
  17384. return [ inSeg1Pt1 ];
  17385. }
  17386. // segment#2 is a single point
  17387. if ( seg2Pt ) {
  17388. if ( ! point_in_segment_2D_colin( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1 ) ) return []; // but not in segment#1
  17389. return [ inSeg2Pt1 ];
  17390. }
  17391. // they are collinear segments, which might overlap
  17392. var seg1min, seg1max, seg1minVal, seg1maxVal;
  17393. var seg2min, seg2max, seg2minVal, seg2maxVal;
  17394. if ( seg1dx !== 0 ) {
  17395. // the segments are NOT on a vertical line
  17396. if ( inSeg1Pt1.x < inSeg1Pt2.x ) {
  17397. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.x;
  17398. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.x;
  17399. } else {
  17400. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.x;
  17401. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.x;
  17402. }
  17403. if ( inSeg2Pt1.x < inSeg2Pt2.x ) {
  17404. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.x;
  17405. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.x;
  17406. } else {
  17407. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.x;
  17408. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.x;
  17409. }
  17410. } else {
  17411. // the segments are on a vertical line
  17412. if ( inSeg1Pt1.y < inSeg1Pt2.y ) {
  17413. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.y;
  17414. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.y;
  17415. } else {
  17416. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.y;
  17417. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.y;
  17418. }
  17419. if ( inSeg2Pt1.y < inSeg2Pt2.y ) {
  17420. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.y;
  17421. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.y;
  17422. } else {
  17423. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.y;
  17424. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.y;
  17425. }
  17426. }
  17427. if ( seg1minVal <= seg2minVal ) {
  17428. if ( seg1maxVal < seg2minVal ) return [];
  17429. if ( seg1maxVal === seg2minVal ) {
  17430. if ( inExcludeAdjacentSegs ) return [];
  17431. return [ seg2min ];
  17432. }
  17433. if ( seg1maxVal <= seg2maxVal ) return [ seg2min, seg1max ];
  17434. return [ seg2min, seg2max ];
  17435. } else {
  17436. if ( seg1minVal > seg2maxVal ) return [];
  17437. if ( seg1minVal === seg2maxVal ) {
  17438. if ( inExcludeAdjacentSegs ) return [];
  17439. return [ seg1min ];
  17440. }
  17441. if ( seg1maxVal <= seg2maxVal ) return [ seg1min, seg1max ];
  17442. return [ seg1min, seg2max ];
  17443. }
  17444. }
  17445. }
  17446. function isPointInsideAngle( inVertex, inLegFromPt, inLegToPt, inOtherPt ) {
  17447. // The order of legs is important
  17448. // translation of all points, so that Vertex is at (0,0)
  17449. var legFromPtX = inLegFromPt.x - inVertex.x, legFromPtY = inLegFromPt.y - inVertex.y;
  17450. var legToPtX = inLegToPt.x - inVertex.x, legToPtY = inLegToPt.y - inVertex.y;
  17451. var otherPtX = inOtherPt.x - inVertex.x, otherPtY = inOtherPt.y - inVertex.y;
  17452. // main angle >0: < 180 deg.; 0: 180 deg.; <0: > 180 deg.
  17453. var from2toAngle = legFromPtX * legToPtY - legFromPtY * legToPtX;
  17454. var from2otherAngle = legFromPtX * otherPtY - legFromPtY * otherPtX;
  17455. if ( Math.abs( from2toAngle ) > Number.EPSILON ) {
  17456. // angle != 180 deg.
  17457. var other2toAngle = otherPtX * legToPtY - otherPtY * legToPtX;
  17458. // console.log( "from2to: " + from2toAngle + ", from2other: " + from2otherAngle + ", other2to: " + other2toAngle );
  17459. if ( from2toAngle > 0 ) {
  17460. // main angle < 180 deg.
  17461. return ( ( from2otherAngle >= 0 ) && ( other2toAngle >= 0 ) );
  17462. } else {
  17463. // main angle > 180 deg.
  17464. return ( ( from2otherAngle >= 0 ) || ( other2toAngle >= 0 ) );
  17465. }
  17466. } else {
  17467. // angle == 180 deg.
  17468. // console.log( "from2to: 180 deg., from2other: " + from2otherAngle );
  17469. return ( from2otherAngle > 0 );
  17470. }
  17471. }
  17472. function removeHoles( contour, holes ) {
  17473. var shape = contour.concat(); // work on this shape
  17474. var hole;
  17475. function isCutLineInsideAngles( inShapeIdx, inHoleIdx ) {
  17476. // Check if hole point lies within angle around shape point
  17477. var lastShapeIdx = shape.length - 1;
  17478. var prevShapeIdx = inShapeIdx - 1;
  17479. if ( prevShapeIdx < 0 ) prevShapeIdx = lastShapeIdx;
  17480. var nextShapeIdx = inShapeIdx + 1;
  17481. if ( nextShapeIdx > lastShapeIdx ) nextShapeIdx = 0;
  17482. var insideAngle = isPointInsideAngle( shape[ inShapeIdx ], shape[ prevShapeIdx ], shape[ nextShapeIdx ], hole[ inHoleIdx ] );
  17483. if ( ! insideAngle ) {
  17484. // console.log( "Vertex (Shape): " + inShapeIdx + ", Point: " + hole[inHoleIdx].x + "/" + hole[inHoleIdx].y );
  17485. return false;
  17486. }
  17487. // Check if shape point lies within angle around hole point
  17488. var lastHoleIdx = hole.length - 1;
  17489. var prevHoleIdx = inHoleIdx - 1;
  17490. if ( prevHoleIdx < 0 ) prevHoleIdx = lastHoleIdx;
  17491. var nextHoleIdx = inHoleIdx + 1;
  17492. if ( nextHoleIdx > lastHoleIdx ) nextHoleIdx = 0;
  17493. insideAngle = isPointInsideAngle( hole[ inHoleIdx ], hole[ prevHoleIdx ], hole[ nextHoleIdx ], shape[ inShapeIdx ] );
  17494. if ( ! insideAngle ) {
  17495. // console.log( "Vertex (Hole): " + inHoleIdx + ", Point: " + shape[inShapeIdx].x + "/" + shape[inShapeIdx].y );
  17496. return false;
  17497. }
  17498. return true;
  17499. }
  17500. function intersectsShapeEdge( inShapePt, inHolePt ) {
  17501. // checks for intersections with shape edges
  17502. var sIdx, nextIdx, intersection;
  17503. for ( sIdx = 0; sIdx < shape.length; sIdx ++ ) {
  17504. nextIdx = sIdx + 1; nextIdx %= shape.length;
  17505. intersection = intersect_segments_2D( inShapePt, inHolePt, shape[ sIdx ], shape[ nextIdx ], true );
  17506. if ( intersection.length > 0 ) return true;
  17507. }
  17508. return false;
  17509. }
  17510. var indepHoles = [];
  17511. function intersectsHoleEdge( inShapePt, inHolePt ) {
  17512. // checks for intersections with hole edges
  17513. var ihIdx, chkHole,
  17514. hIdx, nextIdx, intersection;
  17515. for ( ihIdx = 0; ihIdx < indepHoles.length; ihIdx ++ ) {
  17516. chkHole = holes[ indepHoles[ ihIdx ] ];
  17517. for ( hIdx = 0; hIdx < chkHole.length; hIdx ++ ) {
  17518. nextIdx = hIdx + 1; nextIdx %= chkHole.length;
  17519. intersection = intersect_segments_2D( inShapePt, inHolePt, chkHole[ hIdx ], chkHole[ nextIdx ], true );
  17520. if ( intersection.length > 0 ) return true;
  17521. }
  17522. }
  17523. return false;
  17524. }
  17525. var holeIndex, shapeIndex,
  17526. shapePt, holePt,
  17527. holeIdx, cutKey, failedCuts = [],
  17528. tmpShape1, tmpShape2,
  17529. tmpHole1, tmpHole2;
  17530. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  17531. indepHoles.push( h );
  17532. }
  17533. var minShapeIndex = 0;
  17534. var counter = indepHoles.length * 2;
  17535. while ( indepHoles.length > 0 ) {
  17536. counter --;
  17537. if ( counter < 0 ) {
  17538. console.log( 'THREE.ShapeUtils: Infinite Loop! Holes left:" + indepHoles.length + ", Probably Hole outside Shape!' );
  17539. break;
  17540. }
  17541. // search for shape-vertex and hole-vertex,
  17542. // which can be connected without intersections
  17543. for ( shapeIndex = minShapeIndex; shapeIndex < shape.length; shapeIndex ++ ) {
  17544. shapePt = shape[ shapeIndex ];
  17545. holeIndex = - 1;
  17546. // search for hole which can be reached without intersections
  17547. for ( var h = 0; h < indepHoles.length; h ++ ) {
  17548. holeIdx = indepHoles[ h ];
  17549. // prevent multiple checks
  17550. cutKey = shapePt.x + ':' + shapePt.y + ':' + holeIdx;
  17551. if ( failedCuts[ cutKey ] !== undefined ) continue;
  17552. hole = holes[ holeIdx ];
  17553. for ( var h2 = 0; h2 < hole.length; h2 ++ ) {
  17554. holePt = hole[ h2 ];
  17555. if ( ! isCutLineInsideAngles( shapeIndex, h2 ) ) continue;
  17556. if ( intersectsShapeEdge( shapePt, holePt ) ) continue;
  17557. if ( intersectsHoleEdge( shapePt, holePt ) ) continue;
  17558. holeIndex = h2;
  17559. indepHoles.splice( h, 1 );
  17560. tmpShape1 = shape.slice( 0, shapeIndex + 1 );
  17561. tmpShape2 = shape.slice( shapeIndex );
  17562. tmpHole1 = hole.slice( holeIndex );
  17563. tmpHole2 = hole.slice( 0, holeIndex + 1 );
  17564. shape = tmpShape1.concat( tmpHole1 ).concat( tmpHole2 ).concat( tmpShape2 );
  17565. minShapeIndex = shapeIndex;
  17566. // Debug only, to show the selected cuts
  17567. // glob_CutLines.push( [ shapePt, holePt ] );
  17568. break;
  17569. }
  17570. if ( holeIndex >= 0 ) break; // hole-vertex found
  17571. failedCuts[ cutKey ] = true; // remember failure
  17572. }
  17573. if ( holeIndex >= 0 ) break; // hole-vertex found
  17574. }
  17575. }
  17576. return shape; /* shape with no holes */
  17577. }
  17578. var i, il, f, face,
  17579. key, index,
  17580. allPointsMap = {};
  17581. // 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.
  17582. var allpoints = contour.concat();
  17583. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  17584. Array.prototype.push.apply( allpoints, holes[ h ] );
  17585. }
  17586. //console.log( "allpoints",allpoints, allpoints.length );
  17587. // prepare all points map
  17588. for ( i = 0, il = allpoints.length; i < il; i ++ ) {
  17589. key = allpoints[ i ].x + ':' + allpoints[ i ].y;
  17590. if ( allPointsMap[ key ] !== undefined ) {
  17591. console.warn( 'THREE.ShapeUtils: Duplicate point', key, i );
  17592. }
  17593. allPointsMap[ key ] = i;
  17594. }
  17595. // remove holes by cutting paths to holes and adding them to the shape
  17596. var shapeWithoutHoles = removeHoles( contour, holes );
  17597. var triangles = ShapeUtils.triangulate( shapeWithoutHoles, false ); // True returns indices for points of spooled shape
  17598. //console.log( "triangles",triangles, triangles.length );
  17599. // check all face vertices against all points map
  17600. for ( i = 0, il = triangles.length; i < il; i ++ ) {
  17601. face = triangles[ i ];
  17602. for ( f = 0; f < 3; f ++ ) {
  17603. key = face[ f ].x + ':' + face[ f ].y;
  17604. index = allPointsMap[ key ];
  17605. if ( index !== undefined ) {
  17606. face[ f ] = index;
  17607. }
  17608. }
  17609. }
  17610. return triangles.concat();
  17611. },
  17612. isClockWise: function ( pts ) {
  17613. return ShapeUtils.area( pts ) < 0;
  17614. }
  17615. };
  17616. /**
  17617. * @author TristanVALCKE / https://github.com/Itee
  17618. */
  17619. /* global QUnit */
  17620. QUnit.module( 'Extras', () => {
  17621. QUnit.module.todo( 'ShapeUtils', () => {
  17622. // PUBLIC STUFF
  17623. QUnit.test( "area", ( assert ) => {
  17624. assert.ok( false, "everything's gonna be alright" );
  17625. } );
  17626. QUnit.test( "triangulate", ( assert ) => {
  17627. assert.ok( false, "everything's gonna be alright" );
  17628. } );
  17629. QUnit.test( "triangulateShape", ( assert ) => {
  17630. assert.ok( false, "everything's gonna be alright" );
  17631. } );
  17632. QUnit.test( "isClockWise", ( assert ) => {
  17633. assert.ok( false, "everything's gonna be alright" );
  17634. } );
  17635. } );
  17636. } );
  17637. /**
  17638. * @author zz85 / http://www.lab4games.net/zz85/blog
  17639. * Extensible curve object
  17640. *
  17641. * Some common of curve methods:
  17642. * .getPoint( t, optionalTarget ), .getTangent( t )
  17643. * .getPointAt( u, optionalTarget ), .getTangentAt( u )
  17644. * .getPoints(), .getSpacedPoints()
  17645. * .getLength()
  17646. * .updateArcLengths()
  17647. *
  17648. * This following curves inherit from THREE.Curve:
  17649. *
  17650. * -- 2D curves --
  17651. * THREE.ArcCurve
  17652. * THREE.CubicBezierCurve
  17653. * THREE.EllipseCurve
  17654. * THREE.LineCurve
  17655. * THREE.QuadraticBezierCurve
  17656. * THREE.SplineCurve
  17657. *
  17658. * -- 3D curves --
  17659. * THREE.CatmullRomCurve3
  17660. * THREE.CubicBezierCurve3
  17661. * THREE.LineCurve3
  17662. * THREE.QuadraticBezierCurve3
  17663. *
  17664. * A series of curves can be represented as a THREE.CurvePath.
  17665. *
  17666. **/
  17667. /**************************************************************
  17668. * Abstract Curve base class
  17669. **************************************************************/
  17670. function Curve() {
  17671. this.arcLengthDivisions = 200;
  17672. }
  17673. Object.assign( Curve.prototype, {
  17674. // Virtual base class method to overwrite and implement in subclasses
  17675. // - t [0 .. 1]
  17676. getPoint: function ( /* t, optionalTarget */ ) {
  17677. console.warn( 'THREE.Curve: .getPoint() not implemented.' );
  17678. return null;
  17679. },
  17680. // Get point at relative position in curve according to arc length
  17681. // - u [0 .. 1]
  17682. getPointAt: function ( u, optionalTarget ) {
  17683. var t = this.getUtoTmapping( u );
  17684. return this.getPoint( t, optionalTarget );
  17685. },
  17686. // Get sequence of points using getPoint( t )
  17687. getPoints: function ( divisions ) {
  17688. if ( divisions === undefined ) divisions = 5;
  17689. var points = [];
  17690. for ( var d = 0; d <= divisions; d ++ ) {
  17691. points.push( this.getPoint( d / divisions ) );
  17692. }
  17693. return points;
  17694. },
  17695. // Get sequence of points using getPointAt( u )
  17696. getSpacedPoints: function ( divisions ) {
  17697. if ( divisions === undefined ) divisions = 5;
  17698. var points = [];
  17699. for ( var d = 0; d <= divisions; d ++ ) {
  17700. points.push( this.getPointAt( d / divisions ) );
  17701. }
  17702. return points;
  17703. },
  17704. // Get total curve arc length
  17705. getLength: function () {
  17706. var lengths = this.getLengths();
  17707. return lengths[ lengths.length - 1 ];
  17708. },
  17709. // Get list of cumulative segment lengths
  17710. getLengths: function ( divisions ) {
  17711. if ( divisions === undefined ) divisions = this.arcLengthDivisions;
  17712. if ( this.cacheArcLengths &&
  17713. ( this.cacheArcLengths.length === divisions + 1 ) &&
  17714. ! this.needsUpdate ) {
  17715. return this.cacheArcLengths;
  17716. }
  17717. this.needsUpdate = false;
  17718. var cache = [];
  17719. var current, last = this.getPoint( 0 );
  17720. var p, sum = 0;
  17721. cache.push( 0 );
  17722. for ( p = 1; p <= divisions; p ++ ) {
  17723. current = this.getPoint( p / divisions );
  17724. sum += current.distanceTo( last );
  17725. cache.push( sum );
  17726. last = current;
  17727. }
  17728. this.cacheArcLengths = cache;
  17729. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  17730. },
  17731. updateArcLengths: function () {
  17732. this.needsUpdate = true;
  17733. this.getLengths();
  17734. },
  17735. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  17736. getUtoTmapping: function ( u, distance ) {
  17737. var arcLengths = this.getLengths();
  17738. var i = 0, il = arcLengths.length;
  17739. var targetArcLength; // The targeted u distance value to get
  17740. if ( distance ) {
  17741. targetArcLength = distance;
  17742. } else {
  17743. targetArcLength = u * arcLengths[ il - 1 ];
  17744. }
  17745. // binary search for the index with largest value smaller than target u distance
  17746. var low = 0, high = il - 1, comparison;
  17747. while ( low <= high ) {
  17748. 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
  17749. comparison = arcLengths[ i ] - targetArcLength;
  17750. if ( comparison < 0 ) {
  17751. low = i + 1;
  17752. } else if ( comparison > 0 ) {
  17753. high = i - 1;
  17754. } else {
  17755. high = i;
  17756. break;
  17757. // DONE
  17758. }
  17759. }
  17760. i = high;
  17761. if ( arcLengths[ i ] === targetArcLength ) {
  17762. return i / ( il - 1 );
  17763. }
  17764. // we could get finer grain at lengths, or use simple interpolation between two points
  17765. var lengthBefore = arcLengths[ i ];
  17766. var lengthAfter = arcLengths[ i + 1 ];
  17767. var segmentLength = lengthAfter - lengthBefore;
  17768. // determine where we are between the 'before' and 'after' points
  17769. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  17770. // add that fractional amount to t
  17771. var t = ( i + segmentFraction ) / ( il - 1 );
  17772. return t;
  17773. },
  17774. // Returns a unit vector tangent at t
  17775. // In case any sub curve does not implement its tangent derivation,
  17776. // 2 points a small delta apart will be used to find its gradient
  17777. // which seems to give a reasonable approximation
  17778. getTangent: function ( t ) {
  17779. var delta = 0.0001;
  17780. var t1 = t - delta;
  17781. var t2 = t + delta;
  17782. // Capping in case of danger
  17783. if ( t1 < 0 ) t1 = 0;
  17784. if ( t2 > 1 ) t2 = 1;
  17785. var pt1 = this.getPoint( t1 );
  17786. var pt2 = this.getPoint( t2 );
  17787. var vec = pt2.clone().sub( pt1 );
  17788. return vec.normalize();
  17789. },
  17790. getTangentAt: function ( u ) {
  17791. var t = this.getUtoTmapping( u );
  17792. return this.getTangent( t );
  17793. },
  17794. computeFrenetFrames: function ( segments, closed ) {
  17795. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  17796. var normal = new Vector3();
  17797. var tangents = [];
  17798. var normals = [];
  17799. var binormals = [];
  17800. var vec = new Vector3();
  17801. var mat = new Matrix4();
  17802. var i, u, theta;
  17803. // compute the tangent vectors for each segment on the curve
  17804. for ( i = 0; i <= segments; i ++ ) {
  17805. u = i / segments;
  17806. tangents[ i ] = this.getTangentAt( u );
  17807. tangents[ i ].normalize();
  17808. }
  17809. // select an initial normal vector perpendicular to the first tangent vector,
  17810. // and in the direction of the minimum tangent xyz component
  17811. normals[ 0 ] = new Vector3();
  17812. binormals[ 0 ] = new Vector3();
  17813. var min = Number.MAX_VALUE;
  17814. var tx = Math.abs( tangents[ 0 ].x );
  17815. var ty = Math.abs( tangents[ 0 ].y );
  17816. var tz = Math.abs( tangents[ 0 ].z );
  17817. if ( tx <= min ) {
  17818. min = tx;
  17819. normal.set( 1, 0, 0 );
  17820. }
  17821. if ( ty <= min ) {
  17822. min = ty;
  17823. normal.set( 0, 1, 0 );
  17824. }
  17825. if ( tz <= min ) {
  17826. normal.set( 0, 0, 1 );
  17827. }
  17828. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  17829. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  17830. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  17831. // compute the slowly-varying normal and binormal vectors for each segment on the curve
  17832. for ( i = 1; i <= segments; i ++ ) {
  17833. normals[ i ] = normals[ i - 1 ].clone();
  17834. binormals[ i ] = binormals[ i - 1 ].clone();
  17835. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  17836. if ( vec.length() > Number.EPSILON ) {
  17837. vec.normalize();
  17838. theta = Math.acos( _Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  17839. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  17840. }
  17841. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  17842. }
  17843. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  17844. if ( closed === true ) {
  17845. theta = Math.acos( _Math.clamp( normals[ 0 ].dot( normals[ segments ] ), - 1, 1 ) );
  17846. theta /= segments;
  17847. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ segments ] ) ) > 0 ) {
  17848. theta = - theta;
  17849. }
  17850. for ( i = 1; i <= segments; i ++ ) {
  17851. // twist a little...
  17852. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  17853. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  17854. }
  17855. }
  17856. return {
  17857. tangents: tangents,
  17858. normals: normals,
  17859. binormals: binormals
  17860. };
  17861. }
  17862. } );
  17863. /**
  17864. * @author TristanVALCKE / https://github.com/Itee
  17865. */
  17866. /* global QUnit */
  17867. QUnit.module( 'Extras', () => {
  17868. QUnit.module( 'Core', () => {
  17869. QUnit.module.todo( 'Curve', () => {
  17870. // INSTANCING
  17871. QUnit.test( "Instancing", ( assert ) => {
  17872. assert.ok( false, "everything's gonna be alright" );
  17873. } );
  17874. // PUBLIC STUFF
  17875. QUnit.test( "getPoint", ( assert ) => {
  17876. assert.ok( false, "everything's gonna be alright" );
  17877. } );
  17878. QUnit.test( "getPointAt", ( assert ) => {
  17879. assert.ok( false, "everything's gonna be alright" );
  17880. } );
  17881. QUnit.test( "getPoints", ( assert ) => {
  17882. assert.ok( false, "everything's gonna be alright" );
  17883. } );
  17884. QUnit.test( "getSpacedPoints", ( assert ) => {
  17885. assert.ok( false, "everything's gonna be alright" );
  17886. } );
  17887. QUnit.test( "getLength", ( assert ) => {
  17888. assert.ok( false, "everything's gonna be alright" );
  17889. } );
  17890. QUnit.test( "getLengths", ( assert ) => {
  17891. assert.ok( false, "everything's gonna be alright" );
  17892. } );
  17893. QUnit.test( "updateArcLengths", ( assert ) => {
  17894. assert.ok( false, "everything's gonna be alright" );
  17895. } );
  17896. QUnit.test( "getUtoTmapping", ( assert ) => {
  17897. assert.ok( false, "everything's gonna be alright" );
  17898. } );
  17899. QUnit.test( "getTangent", ( assert ) => {
  17900. assert.ok( false, "everything's gonna be alright" );
  17901. } );
  17902. QUnit.test( "getTangentAt", ( assert ) => {
  17903. assert.ok( false, "everything's gonna be alright" );
  17904. } );
  17905. QUnit.test( "computeFrenetFrames", ( assert ) => {
  17906. assert.ok( false, "everything's gonna be alright" );
  17907. } );
  17908. } );
  17909. } );
  17910. } );
  17911. function LineCurve( v1, v2 ) {
  17912. Curve.call( this );
  17913. this.v1 = v1;
  17914. this.v2 = v2;
  17915. }
  17916. LineCurve.prototype = Object.create( Curve.prototype );
  17917. LineCurve.prototype.constructor = LineCurve;
  17918. LineCurve.prototype.isLineCurve = true;
  17919. LineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  17920. var point = optionalTarget || new Vector2();
  17921. if ( t === 1 ) {
  17922. point.copy( this.v2 );
  17923. } else {
  17924. point.copy( this.v2 ).sub( this.v1 );
  17925. point.multiplyScalar( t ).add( this.v1 );
  17926. }
  17927. return point;
  17928. };
  17929. // Line curve is linear, so we can overwrite default getPointAt
  17930. LineCurve.prototype.getPointAt = function ( u, optionalTarget ) {
  17931. return this.getPoint( u, optionalTarget );
  17932. };
  17933. LineCurve.prototype.getTangent = function ( /* t */ ) {
  17934. var tangent = this.v2.clone().sub( this.v1 );
  17935. return tangent.normalize();
  17936. };
  17937. /**
  17938. * @author zz85 / http://www.lab4games.net/zz85/blog
  17939. *
  17940. **/
  17941. /**************************************************************
  17942. * Curved Path - a curve path is simply a array of connected
  17943. * curves, but retains the api of a curve
  17944. **************************************************************/
  17945. function CurvePath() {
  17946. Curve.call( this );
  17947. this.curves = [];
  17948. this.autoClose = false; // Automatically closes the path
  17949. }
  17950. CurvePath.prototype = Object.assign( Object.create( Curve.prototype ), {
  17951. constructor: CurvePath,
  17952. add: function ( curve ) {
  17953. this.curves.push( curve );
  17954. },
  17955. closePath: function () {
  17956. // Add a line curve if start and end of lines are not connected
  17957. var startPoint = this.curves[ 0 ].getPoint( 0 );
  17958. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  17959. if ( ! startPoint.equals( endPoint ) ) {
  17960. this.curves.push( new LineCurve( endPoint, startPoint ) );
  17961. }
  17962. },
  17963. // To get accurate point with reference to
  17964. // entire path distance at time t,
  17965. // following has to be done:
  17966. // 1. Length of each sub path have to be known
  17967. // 2. Locate and identify type of curve
  17968. // 3. Get t for the curve
  17969. // 4. Return curve.getPointAt(t')
  17970. getPoint: function ( t ) {
  17971. var d = t * this.getLength();
  17972. var curveLengths = this.getCurveLengths();
  17973. var i = 0;
  17974. // To think about boundaries points.
  17975. while ( i < curveLengths.length ) {
  17976. if ( curveLengths[ i ] >= d ) {
  17977. var diff = curveLengths[ i ] - d;
  17978. var curve = this.curves[ i ];
  17979. var segmentLength = curve.getLength();
  17980. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  17981. return curve.getPointAt( u );
  17982. }
  17983. i ++;
  17984. }
  17985. return null;
  17986. // loop where sum != 0, sum > d , sum+1 <d
  17987. },
  17988. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  17989. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  17990. // getPoint() depends on getLength
  17991. getLength: function () {
  17992. var lens = this.getCurveLengths();
  17993. return lens[ lens.length - 1 ];
  17994. },
  17995. // cacheLengths must be recalculated.
  17996. updateArcLengths: function () {
  17997. this.needsUpdate = true;
  17998. this.cacheLengths = null;
  17999. this.getCurveLengths();
  18000. },
  18001. // Compute lengths and cache them
  18002. // We cannot overwrite getLengths() because UtoT mapping uses it.
  18003. getCurveLengths: function () {
  18004. // We use cache values if curves and cache array are same length
  18005. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  18006. return this.cacheLengths;
  18007. }
  18008. // Get length of sub-curve
  18009. // Push sums into cached array
  18010. var lengths = [], sums = 0;
  18011. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  18012. sums += this.curves[ i ].getLength();
  18013. lengths.push( sums );
  18014. }
  18015. this.cacheLengths = lengths;
  18016. return lengths;
  18017. },
  18018. getSpacedPoints: function ( divisions ) {
  18019. if ( divisions === undefined ) divisions = 40;
  18020. var points = [];
  18021. for ( var i = 0; i <= divisions; i ++ ) {
  18022. points.push( this.getPoint( i / divisions ) );
  18023. }
  18024. if ( this.autoClose ) {
  18025. points.push( points[ 0 ] );
  18026. }
  18027. return points;
  18028. },
  18029. getPoints: function ( divisions ) {
  18030. divisions = divisions || 12;
  18031. var points = [], last;
  18032. for ( var i = 0, curves = this.curves; i < curves.length; i ++ ) {
  18033. var curve = curves[ i ];
  18034. var resolution = ( curve && curve.isEllipseCurve ) ? divisions * 2
  18035. : ( curve && curve.isLineCurve ) ? 1
  18036. : ( curve && curve.isSplineCurve ) ? divisions * curve.points.length
  18037. : divisions;
  18038. var pts = curve.getPoints( resolution );
  18039. for ( var j = 0; j < pts.length; j ++ ) {
  18040. var point = pts[ j ];
  18041. if ( last && last.equals( point ) ) continue; // ensures no consecutive points are duplicates
  18042. points.push( point );
  18043. last = point;
  18044. }
  18045. }
  18046. if ( this.autoClose && points.length > 1 && ! points[ points.length - 1 ].equals( points[ 0 ] ) ) {
  18047. points.push( points[ 0 ] );
  18048. }
  18049. return points;
  18050. },
  18051. /**************************************************************
  18052. * Create Geometries Helpers
  18053. **************************************************************/
  18054. /// Generate geometry from path points (for Line or Points objects)
  18055. createPointsGeometry: function ( divisions ) {
  18056. var pts = this.getPoints( divisions );
  18057. return this.createGeometry( pts );
  18058. },
  18059. // Generate geometry from equidistant sampling along the path
  18060. createSpacedPointsGeometry: function ( divisions ) {
  18061. var pts = this.getSpacedPoints( divisions );
  18062. return this.createGeometry( pts );
  18063. },
  18064. createGeometry: function ( points ) {
  18065. var geometry = new Geometry();
  18066. for ( var i = 0, l = points.length; i < l; i ++ ) {
  18067. var point = points[ i ];
  18068. geometry.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  18069. }
  18070. return geometry;
  18071. }
  18072. } );
  18073. /**
  18074. * @author TristanVALCKE / https://github.com/Itee
  18075. */
  18076. /* global QUnit */
  18077. QUnit.module( 'Extras', () => {
  18078. QUnit.module( 'Core', () => {
  18079. QUnit.module.todo( 'CurvePath', () => {
  18080. // INHERITANCE
  18081. QUnit.test( "Extending", ( assert ) => {
  18082. assert.ok( false, "everything's gonna be alright" );
  18083. } );
  18084. // INSTANCING
  18085. QUnit.test( "Instancing", ( assert ) => {
  18086. assert.ok( false, "everything's gonna be alright" );
  18087. } );
  18088. // PUBLIC STUFF
  18089. QUnit.test( "add", ( assert ) => {
  18090. assert.ok( false, "everything's gonna be alright" );
  18091. } );
  18092. QUnit.test( "closePath", ( assert ) => {
  18093. assert.ok( false, "everything's gonna be alright" );
  18094. } );
  18095. QUnit.test( "getPoint", ( assert ) => {
  18096. assert.ok( false, "everything's gonna be alright" );
  18097. } );
  18098. QUnit.test( "getLength", ( assert ) => {
  18099. assert.ok( false, "everything's gonna be alright" );
  18100. } );
  18101. QUnit.test( "updateArcLengths", ( assert ) => {
  18102. assert.ok( false, "everything's gonna be alright" );
  18103. } );
  18104. QUnit.test( "getCurveLengths", ( assert ) => {
  18105. assert.ok( false, "everything's gonna be alright" );
  18106. } );
  18107. QUnit.test( "getSpacedPoints", ( assert ) => {
  18108. assert.ok( false, "everything's gonna be alright" );
  18109. } );
  18110. QUnit.test( "getPoints", ( assert ) => {
  18111. assert.ok( false, "everything's gonna be alright" );
  18112. } );
  18113. QUnit.test( "createPointsGeometry", ( assert ) => {
  18114. assert.ok( false, "everything's gonna be alright" );
  18115. } );
  18116. QUnit.test( "createSpacedPointsGeometry", ( assert ) => {
  18117. assert.ok( false, "everything's gonna be alright" );
  18118. } );
  18119. QUnit.test( "createGeometry", ( assert ) => {
  18120. assert.ok( false, "everything's gonna be alright" );
  18121. } );
  18122. } );
  18123. } );
  18124. } );
  18125. /**
  18126. * @author zz85 / http://www.lab4games.net/zz85/blog
  18127. *
  18128. * Bezier Curves formulas obtained from
  18129. * http://en.wikipedia.org/wiki/Bézier_curve
  18130. */
  18131. function CatmullRom( t, p0, p1, p2, p3 ) {
  18132. var v0 = ( p2 - p0 ) * 0.5;
  18133. var v1 = ( p3 - p1 ) * 0.5;
  18134. var t2 = t * t;
  18135. var t3 = t * t2;
  18136. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  18137. }
  18138. //
  18139. function QuadraticBezierP0( t, p ) {
  18140. var k = 1 - t;
  18141. return k * k * p;
  18142. }
  18143. function QuadraticBezierP1( t, p ) {
  18144. return 2 * ( 1 - t ) * t * p;
  18145. }
  18146. function QuadraticBezierP2( t, p ) {
  18147. return t * t * p;
  18148. }
  18149. function QuadraticBezier( t, p0, p1, p2 ) {
  18150. return QuadraticBezierP0( t, p0 ) + QuadraticBezierP1( t, p1 ) +
  18151. QuadraticBezierP2( t, p2 );
  18152. }
  18153. //
  18154. function CubicBezierP0( t, p ) {
  18155. var k = 1 - t;
  18156. return k * k * k * p;
  18157. }
  18158. function CubicBezierP1( t, p ) {
  18159. var k = 1 - t;
  18160. return 3 * k * k * t * p;
  18161. }
  18162. function CubicBezierP2( t, p ) {
  18163. return 3 * ( 1 - t ) * t * t * p;
  18164. }
  18165. function CubicBezierP3( t, p ) {
  18166. return t * t * t * p;
  18167. }
  18168. function CubicBezier( t, p0, p1, p2, p3 ) {
  18169. return CubicBezierP0( t, p0 ) + CubicBezierP1( t, p1 ) + CubicBezierP2( t, p2 ) +
  18170. CubicBezierP3( t, p3 );
  18171. }
  18172. function EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  18173. Curve.call( this );
  18174. this.aX = aX;
  18175. this.aY = aY;
  18176. this.xRadius = xRadius;
  18177. this.yRadius = yRadius;
  18178. this.aStartAngle = aStartAngle;
  18179. this.aEndAngle = aEndAngle;
  18180. this.aClockwise = aClockwise;
  18181. this.aRotation = aRotation || 0;
  18182. }
  18183. EllipseCurve.prototype = Object.create( Curve.prototype );
  18184. EllipseCurve.prototype.constructor = EllipseCurve;
  18185. EllipseCurve.prototype.isEllipseCurve = true;
  18186. EllipseCurve.prototype.getPoint = function ( t, optionalTarget ) {
  18187. var point = optionalTarget || new Vector2();
  18188. var twoPi = Math.PI * 2;
  18189. var deltaAngle = this.aEndAngle - this.aStartAngle;
  18190. var samePoints = Math.abs( deltaAngle ) < Number.EPSILON;
  18191. // ensures that deltaAngle is 0 .. 2 PI
  18192. while ( deltaAngle < 0 ) deltaAngle += twoPi;
  18193. while ( deltaAngle > twoPi ) deltaAngle -= twoPi;
  18194. if ( deltaAngle < Number.EPSILON ) {
  18195. if ( samePoints ) {
  18196. deltaAngle = 0;
  18197. } else {
  18198. deltaAngle = twoPi;
  18199. }
  18200. }
  18201. if ( this.aClockwise === true && ! samePoints ) {
  18202. if ( deltaAngle === twoPi ) {
  18203. deltaAngle = - twoPi;
  18204. } else {
  18205. deltaAngle = deltaAngle - twoPi;
  18206. }
  18207. }
  18208. var angle = this.aStartAngle + t * deltaAngle;
  18209. var x = this.aX + this.xRadius * Math.cos( angle );
  18210. var y = this.aY + this.yRadius * Math.sin( angle );
  18211. if ( this.aRotation !== 0 ) {
  18212. var cos = Math.cos( this.aRotation );
  18213. var sin = Math.sin( this.aRotation );
  18214. var tx = x - this.aX;
  18215. var ty = y - this.aY;
  18216. // Rotate the point about the center of the ellipse.
  18217. x = tx * cos - ty * sin + this.aX;
  18218. y = tx * sin + ty * cos + this.aY;
  18219. }
  18220. return point.set( x, y );
  18221. };
  18222. function SplineCurve( points /* array of Vector2 */ ) {
  18223. Curve.call( this );
  18224. this.points = ( points === undefined ) ? [] : points;
  18225. }
  18226. SplineCurve.prototype = Object.create( Curve.prototype );
  18227. SplineCurve.prototype.constructor = SplineCurve;
  18228. SplineCurve.prototype.isSplineCurve = true;
  18229. SplineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  18230. var point = optionalTarget || new Vector2();
  18231. var points = this.points;
  18232. var p = ( points.length - 1 ) * t;
  18233. var intPoint = Math.floor( p );
  18234. var weight = p - intPoint;
  18235. var p0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  18236. var p1 = points[ intPoint ];
  18237. var p2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  18238. var p3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  18239. point.set(
  18240. CatmullRom( weight, p0.x, p1.x, p2.x, p3.x ),
  18241. CatmullRom( weight, p0.y, p1.y, p2.y, p3.y )
  18242. );
  18243. return point;
  18244. };
  18245. function CubicBezierCurve( v0, v1, v2, v3 ) {
  18246. Curve.call( this );
  18247. this.v0 = v0;
  18248. this.v1 = v1;
  18249. this.v2 = v2;
  18250. this.v3 = v3;
  18251. }
  18252. CubicBezierCurve.prototype = Object.create( Curve.prototype );
  18253. CubicBezierCurve.prototype.constructor = CubicBezierCurve;
  18254. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  18255. CubicBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  18256. var point = optionalTarget || new Vector2();
  18257. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  18258. point.set(
  18259. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  18260. CubicBezier( t, v0.y, v1.y, v2.y, v3.y )
  18261. );
  18262. return point;
  18263. };
  18264. function QuadraticBezierCurve( v0, v1, v2 ) {
  18265. Curve.call( this );
  18266. this.v0 = v0;
  18267. this.v1 = v1;
  18268. this.v2 = v2;
  18269. }
  18270. QuadraticBezierCurve.prototype = Object.create( Curve.prototype );
  18271. QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
  18272. QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
  18273. QuadraticBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  18274. var point = optionalTarget || new Vector2();
  18275. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  18276. point.set(
  18277. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  18278. QuadraticBezier( t, v0.y, v1.y, v2.y )
  18279. );
  18280. return point;
  18281. };
  18282. var PathPrototype = Object.assign( Object.create( CurvePath.prototype ), {
  18283. fromPoints: function ( vectors ) {
  18284. this.moveTo( vectors[ 0 ].x, vectors[ 0 ].y );
  18285. for ( var i = 1, l = vectors.length; i < l; i ++ ) {
  18286. this.lineTo( vectors[ i ].x, vectors[ i ].y );
  18287. }
  18288. },
  18289. moveTo: function ( x, y ) {
  18290. this.currentPoint.set( x, y ); // TODO consider referencing vectors instead of copying?
  18291. },
  18292. lineTo: function ( x, y ) {
  18293. var curve = new LineCurve( this.currentPoint.clone(), new Vector2( x, y ) );
  18294. this.curves.push( curve );
  18295. this.currentPoint.set( x, y );
  18296. },
  18297. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  18298. var curve = new QuadraticBezierCurve(
  18299. this.currentPoint.clone(),
  18300. new Vector2( aCPx, aCPy ),
  18301. new Vector2( aX, aY )
  18302. );
  18303. this.curves.push( curve );
  18304. this.currentPoint.set( aX, aY );
  18305. },
  18306. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  18307. var curve = new CubicBezierCurve(
  18308. this.currentPoint.clone(),
  18309. new Vector2( aCP1x, aCP1y ),
  18310. new Vector2( aCP2x, aCP2y ),
  18311. new Vector2( aX, aY )
  18312. );
  18313. this.curves.push( curve );
  18314. this.currentPoint.set( aX, aY );
  18315. },
  18316. splineThru: function ( pts /*Array of Vector*/ ) {
  18317. var npts = [ this.currentPoint.clone() ].concat( pts );
  18318. var curve = new SplineCurve( npts );
  18319. this.curves.push( curve );
  18320. this.currentPoint.copy( pts[ pts.length - 1 ] );
  18321. },
  18322. arc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  18323. var x0 = this.currentPoint.x;
  18324. var y0 = this.currentPoint.y;
  18325. this.absarc( aX + x0, aY + y0, aRadius,
  18326. aStartAngle, aEndAngle, aClockwise );
  18327. },
  18328. absarc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  18329. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  18330. },
  18331. ellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  18332. var x0 = this.currentPoint.x;
  18333. var y0 = this.currentPoint.y;
  18334. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  18335. },
  18336. absellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  18337. var curve = new EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  18338. if ( this.curves.length > 0 ) {
  18339. // if a previous curve is present, attempt to join
  18340. var firstPoint = curve.getPoint( 0 );
  18341. if ( ! firstPoint.equals( this.currentPoint ) ) {
  18342. this.lineTo( firstPoint.x, firstPoint.y );
  18343. }
  18344. }
  18345. this.curves.push( curve );
  18346. var lastPoint = curve.getPoint( 1 );
  18347. this.currentPoint.copy( lastPoint );
  18348. }
  18349. } );
  18350. /**
  18351. * @author zz85 / http://www.lab4games.net/zz85/blog
  18352. * Creates free form 2d path using series of points, lines or curves.
  18353. **/
  18354. function Path( points ) {
  18355. CurvePath.call( this );
  18356. this.currentPoint = new Vector2();
  18357. if ( points ) {
  18358. this.fromPoints( points );
  18359. }
  18360. }
  18361. Path.prototype = PathPrototype;
  18362. PathPrototype.constructor = Path;
  18363. /**
  18364. * @author zz85 / http://www.lab4games.net/zz85/blog
  18365. * Defines a 2d shape plane using paths.
  18366. **/
  18367. // STEP 1 Create a path.
  18368. // STEP 2 Turn path into shape.
  18369. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  18370. // STEP 3a - Extract points from each shape, turn to vertices
  18371. // STEP 3b - Triangulate each shape, add faces.
  18372. function Shape() {
  18373. Path.apply( this, arguments );
  18374. this.holes = [];
  18375. }
  18376. Shape.prototype = Object.assign( Object.create( PathPrototype ), {
  18377. constructor: Shape,
  18378. getPointsHoles: function ( divisions ) {
  18379. var holesPts = [];
  18380. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  18381. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  18382. }
  18383. return holesPts;
  18384. },
  18385. // Get points of shape and holes (keypoints based on segments parameter)
  18386. extractAllPoints: function ( divisions ) {
  18387. return {
  18388. shape: this.getPoints( divisions ),
  18389. holes: this.getPointsHoles( divisions )
  18390. };
  18391. },
  18392. extractPoints: function ( divisions ) {
  18393. return this.extractAllPoints( divisions );
  18394. }
  18395. } );
  18396. /**
  18397. * @author zz85 / http://www.lab4games.net/zz85/blog
  18398. * minimal class for proxing functions to Path. Replaces old "extractSubpaths()"
  18399. **/
  18400. function ShapePath() {
  18401. this.subPaths = [];
  18402. this.currentPath = null;
  18403. }
  18404. Object.assign( ShapePath.prototype, {
  18405. moveTo: function ( x, y ) {
  18406. this.currentPath = new Path();
  18407. this.subPaths.push( this.currentPath );
  18408. this.currentPath.moveTo( x, y );
  18409. },
  18410. lineTo: function ( x, y ) {
  18411. this.currentPath.lineTo( x, y );
  18412. },
  18413. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  18414. this.currentPath.quadraticCurveTo( aCPx, aCPy, aX, aY );
  18415. },
  18416. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  18417. this.currentPath.bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY );
  18418. },
  18419. splineThru: function ( pts ) {
  18420. this.currentPath.splineThru( pts );
  18421. },
  18422. toShapes: function ( isCCW, noHoles ) {
  18423. function toShapesNoHoles( inSubpaths ) {
  18424. var shapes = [];
  18425. for ( var i = 0, l = inSubpaths.length; i < l; i ++ ) {
  18426. var tmpPath = inSubpaths[ i ];
  18427. var tmpShape = new Shape();
  18428. tmpShape.curves = tmpPath.curves;
  18429. shapes.push( tmpShape );
  18430. }
  18431. return shapes;
  18432. }
  18433. function isPointInsidePolygon( inPt, inPolygon ) {
  18434. var polyLen = inPolygon.length;
  18435. // inPt on polygon contour => immediate success or
  18436. // toggling of inside/outside at every single! intersection point of an edge
  18437. // with the horizontal line through inPt, left of inPt
  18438. // not counting lowerY endpoints of edges and whole edges on that line
  18439. var inside = false;
  18440. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  18441. var edgeLowPt = inPolygon[ p ];
  18442. var edgeHighPt = inPolygon[ q ];
  18443. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  18444. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  18445. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  18446. // not parallel
  18447. if ( edgeDy < 0 ) {
  18448. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  18449. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  18450. }
  18451. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  18452. if ( inPt.y === edgeLowPt.y ) {
  18453. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  18454. // continue; // no intersection or edgeLowPt => doesn't count !!!
  18455. } else {
  18456. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  18457. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  18458. if ( perpEdge < 0 ) continue;
  18459. inside = ! inside; // true intersection left of inPt
  18460. }
  18461. } else {
  18462. // parallel or collinear
  18463. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  18464. // edge lies on the same horizontal line as inPt
  18465. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  18466. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  18467. // continue;
  18468. }
  18469. }
  18470. return inside;
  18471. }
  18472. var isClockWise = ShapeUtils.isClockWise;
  18473. var subPaths = this.subPaths;
  18474. if ( subPaths.length === 0 ) return [];
  18475. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  18476. var solid, tmpPath, tmpShape, shapes = [];
  18477. if ( subPaths.length === 1 ) {
  18478. tmpPath = subPaths[ 0 ];
  18479. tmpShape = new Shape();
  18480. tmpShape.curves = tmpPath.curves;
  18481. shapes.push( tmpShape );
  18482. return shapes;
  18483. }
  18484. var holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  18485. holesFirst = isCCW ? ! holesFirst : holesFirst;
  18486. // console.log("Holes first", holesFirst);
  18487. var betterShapeHoles = [];
  18488. var newShapes = [];
  18489. var newShapeHoles = [];
  18490. var mainIdx = 0;
  18491. var tmpPoints;
  18492. newShapes[ mainIdx ] = undefined;
  18493. newShapeHoles[ mainIdx ] = [];
  18494. for ( var i = 0, l = subPaths.length; i < l; i ++ ) {
  18495. tmpPath = subPaths[ i ];
  18496. tmpPoints = tmpPath.getPoints();
  18497. solid = isClockWise( tmpPoints );
  18498. solid = isCCW ? ! solid : solid;
  18499. if ( solid ) {
  18500. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  18501. newShapes[ mainIdx ] = { s: new Shape(), p: tmpPoints };
  18502. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  18503. if ( holesFirst ) mainIdx ++;
  18504. newShapeHoles[ mainIdx ] = [];
  18505. //console.log('cw', i);
  18506. } else {
  18507. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  18508. //console.log('ccw', i);
  18509. }
  18510. }
  18511. // only Holes? -> probably all Shapes with wrong orientation
  18512. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  18513. if ( newShapes.length > 1 ) {
  18514. var ambiguous = false;
  18515. var toChange = [];
  18516. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  18517. betterShapeHoles[ sIdx ] = [];
  18518. }
  18519. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  18520. var sho = newShapeHoles[ sIdx ];
  18521. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  18522. var ho = sho[ hIdx ];
  18523. var hole_unassigned = true;
  18524. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  18525. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  18526. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  18527. if ( hole_unassigned ) {
  18528. hole_unassigned = false;
  18529. betterShapeHoles[ s2Idx ].push( ho );
  18530. } else {
  18531. ambiguous = true;
  18532. }
  18533. }
  18534. }
  18535. if ( hole_unassigned ) {
  18536. betterShapeHoles[ sIdx ].push( ho );
  18537. }
  18538. }
  18539. }
  18540. // console.log("ambiguous: ", ambiguous);
  18541. if ( toChange.length > 0 ) {
  18542. // console.log("to change: ", toChange);
  18543. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  18544. }
  18545. }
  18546. var tmpHoles;
  18547. for ( var i = 0, il = newShapes.length; i < il; i ++ ) {
  18548. tmpShape = newShapes[ i ].s;
  18549. shapes.push( tmpShape );
  18550. tmpHoles = newShapeHoles[ i ];
  18551. for ( var j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  18552. tmpShape.holes.push( tmpHoles[ j ].h );
  18553. }
  18554. }
  18555. //console.log("shape", shapes);
  18556. return shapes;
  18557. }
  18558. } );
  18559. /**
  18560. * @author zz85 / http://www.lab4games.net/zz85/blog
  18561. * @author mrdoob / http://mrdoob.com/
  18562. */
  18563. function Font( data ) {
  18564. this.data = data;
  18565. }
  18566. Object.assign( Font.prototype, {
  18567. isFont: true,
  18568. generateShapes: function ( text, size, divisions ) {
  18569. function createPaths( text ) {
  18570. var chars = String( text ).split( '' );
  18571. var scale = size / data.resolution;
  18572. var line_height = ( data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness ) * scale;
  18573. var offsetX = 0, offsetY = 0;
  18574. var paths = [];
  18575. for ( var i = 0; i < chars.length; i ++ ) {
  18576. var char = chars[ i ];
  18577. if ( char === '\n' ) {
  18578. offsetX = 0;
  18579. offsetY -= line_height;
  18580. } else {
  18581. var ret = createPath( char, scale, offsetX, offsetY );
  18582. offsetX += ret.offsetX;
  18583. paths.push( ret.path );
  18584. }
  18585. }
  18586. return paths;
  18587. }
  18588. function createPath( c, scale, offsetX, offsetY ) {
  18589. var glyph = data.glyphs[ c ] || data.glyphs[ '?' ];
  18590. if ( ! glyph ) return;
  18591. var path = new ShapePath();
  18592. var pts = [];
  18593. var x, y, cpx, cpy, cpx0, cpy0, cpx1, cpy1, cpx2, cpy2, laste;
  18594. if ( glyph.o ) {
  18595. var outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  18596. for ( var i = 0, l = outline.length; i < l; ) {
  18597. var action = outline[ i ++ ];
  18598. switch ( action ) {
  18599. case 'm': // moveTo
  18600. x = outline[ i ++ ] * scale + offsetX;
  18601. y = outline[ i ++ ] * scale + offsetY;
  18602. path.moveTo( x, y );
  18603. break;
  18604. case 'l': // lineTo
  18605. x = outline[ i ++ ] * scale + offsetX;
  18606. y = outline[ i ++ ] * scale + offsetY;
  18607. path.lineTo( x, y );
  18608. break;
  18609. case 'q': // quadraticCurveTo
  18610. cpx = outline[ i ++ ] * scale + offsetX;
  18611. cpy = outline[ i ++ ] * scale + offsetY;
  18612. cpx1 = outline[ i ++ ] * scale + offsetX;
  18613. cpy1 = outline[ i ++ ] * scale + offsetY;
  18614. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  18615. laste = pts[ pts.length - 1 ];
  18616. if ( laste ) {
  18617. cpx0 = laste.x;
  18618. cpy0 = laste.y;
  18619. for ( var i2 = 1; i2 <= divisions; i2 ++ ) {
  18620. var t = i2 / divisions;
  18621. QuadraticBezier( t, cpx0, cpx1, cpx );
  18622. QuadraticBezier( t, cpy0, cpy1, cpy );
  18623. }
  18624. }
  18625. break;
  18626. case 'b': // bezierCurveTo
  18627. cpx = outline[ i ++ ] * scale + offsetX;
  18628. cpy = outline[ i ++ ] * scale + offsetY;
  18629. cpx1 = outline[ i ++ ] * scale + offsetX;
  18630. cpy1 = outline[ i ++ ] * scale + offsetY;
  18631. cpx2 = outline[ i ++ ] * scale + offsetX;
  18632. cpy2 = outline[ i ++ ] * scale + offsetY;
  18633. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  18634. laste = pts[ pts.length - 1 ];
  18635. if ( laste ) {
  18636. cpx0 = laste.x;
  18637. cpy0 = laste.y;
  18638. for ( var i2 = 1; i2 <= divisions; i2 ++ ) {
  18639. var t = i2 / divisions;
  18640. CubicBezier( t, cpx0, cpx1, cpx2, cpx );
  18641. CubicBezier( t, cpy0, cpy1, cpy2, cpy );
  18642. }
  18643. }
  18644. break;
  18645. }
  18646. }
  18647. }
  18648. return { offsetX: glyph.ha * scale, path: path };
  18649. }
  18650. //
  18651. if ( size === undefined ) size = 100;
  18652. if ( divisions === undefined ) divisions = 4;
  18653. var data = this.data;
  18654. var paths = createPaths( text );
  18655. var shapes = [];
  18656. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  18657. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  18658. }
  18659. return shapes;
  18660. }
  18661. } );
  18662. /**
  18663. * @author TristanVALCKE / https://github.com/Itee
  18664. */
  18665. /* global QUnit */
  18666. QUnit.module( 'Extras', () => {
  18667. QUnit.module( 'Core', () => {
  18668. QUnit.module.todo( 'Font', () => {
  18669. // INSTANCING
  18670. QUnit.test( "Instancing", ( assert ) => {
  18671. assert.ok( false, "everything's gonna be alright" );
  18672. } );
  18673. // PUBLIC STUFF
  18674. QUnit.test( "isFont", ( assert ) => {
  18675. assert.ok( false, "everything's gonna be alright" );
  18676. } );
  18677. QUnit.test( "generateShapes", ( assert ) => {
  18678. assert.ok( false, "everything's gonna be alright" );
  18679. } );
  18680. } );
  18681. } );
  18682. } );
  18683. /**
  18684. * @author TristanVALCKE / https://github.com/Itee
  18685. */
  18686. /* global QUnit */
  18687. QUnit.module( 'Extras', () => {
  18688. QUnit.module( 'Core', () => {
  18689. QUnit.module.todo( 'Interpolations', () => {
  18690. // PUBLIC STUFF
  18691. QUnit.test( "CatmullRom", ( assert ) => {
  18692. assert.ok( false, "everything's gonna be alright" );
  18693. } );
  18694. QUnit.test( "QuadraticBezier", ( assert ) => {
  18695. assert.ok( false, "everything's gonna be alright" );
  18696. } );
  18697. QUnit.test( "CubicBezier", ( assert ) => {
  18698. assert.ok( false, "everything's gonna be alright" );
  18699. } );
  18700. } );
  18701. } );
  18702. } );
  18703. /**
  18704. * @author TristanVALCKE / https://github.com/Itee
  18705. */
  18706. /* global QUnit */
  18707. QUnit.module( 'Extras', () => {
  18708. QUnit.module( 'Core', () => {
  18709. QUnit.module.todo( 'Path', () => {
  18710. // INSTANCING
  18711. QUnit.test( "Instancing", ( assert ) => {
  18712. assert.ok( false, "everything's gonna be alright" );
  18713. } );
  18714. } );
  18715. } );
  18716. } );
  18717. /**
  18718. * @author TristanVALCKE / https://github.com/Itee
  18719. */
  18720. /* global QUnit */
  18721. QUnit.module( 'Extras', () => {
  18722. QUnit.module( 'Core', () => {
  18723. QUnit.module.todo( 'PathPrototype', () => {
  18724. // INHERITANCE
  18725. QUnit.test( "Extending", ( assert ) => {
  18726. assert.ok( false, "everything's gonna be alright" );
  18727. } );
  18728. // PUBLIC STUFF
  18729. QUnit.test( "fromPoints", ( assert ) => {
  18730. assert.ok( false, "everything's gonna be alright" );
  18731. } );
  18732. QUnit.test( "moveTo", ( assert ) => {
  18733. assert.ok( false, "everything's gonna be alright" );
  18734. } );
  18735. QUnit.test( "lineTo", ( assert ) => {
  18736. assert.ok( false, "everything's gonna be alright" );
  18737. } );
  18738. QUnit.test( "quadraticCurveTo", ( assert ) => {
  18739. assert.ok( false, "everything's gonna be alright" );
  18740. } );
  18741. QUnit.test( "bezierCurveTo", ( assert ) => {
  18742. assert.ok( false, "everything's gonna be alright" );
  18743. } );
  18744. QUnit.test( "splineThru", ( assert ) => {
  18745. assert.ok( false, "everything's gonna be alright" );
  18746. } );
  18747. QUnit.test( "arc", ( assert ) => {
  18748. assert.ok( false, "everything's gonna be alright" );
  18749. } );
  18750. QUnit.test( "absarc", ( assert ) => {
  18751. assert.ok( false, "everything's gonna be alright" );
  18752. } );
  18753. QUnit.test( "ellipse", ( assert ) => {
  18754. assert.ok( false, "everything's gonna be alright" );
  18755. } );
  18756. QUnit.test( "absellipse", ( assert ) => {
  18757. assert.ok( false, "everything's gonna be alright" );
  18758. } );
  18759. } );
  18760. } );
  18761. } );
  18762. /**
  18763. * @author TristanVALCKE / https://github.com/Itee
  18764. */
  18765. /* global QUnit */
  18766. QUnit.module( 'Extras', () => {
  18767. QUnit.module( 'Core', () => {
  18768. QUnit.module.todo( 'Shape', () => {
  18769. // INHERITANCE
  18770. QUnit.test( "Extending", ( assert ) => {
  18771. assert.ok( false, "everything's gonna be alright" );
  18772. } );
  18773. // INSTANCING
  18774. QUnit.test( "Instancing", ( assert ) => {
  18775. assert.ok( false, "everything's gonna be alright" );
  18776. } );
  18777. // PUBLIC STUFF
  18778. QUnit.test( "getPointsHoles", ( assert ) => {
  18779. assert.ok( false, "everything's gonna be alright" );
  18780. } );
  18781. QUnit.test( "extractAllPoints", ( assert ) => {
  18782. assert.ok( false, "everything's gonna be alright" );
  18783. } );
  18784. QUnit.test( "extractPoints", ( assert ) => {
  18785. assert.ok( false, "everything's gonna be alright" );
  18786. } );
  18787. } );
  18788. } );
  18789. } );
  18790. /**
  18791. * @author TristanVALCKE / https://github.com/Itee
  18792. */
  18793. /* global QUnit */
  18794. QUnit.module( 'Extras', () => {
  18795. QUnit.module( 'Core', () => {
  18796. QUnit.module.todo( 'ShapePath', () => {
  18797. // INSTANCING
  18798. QUnit.test( "Instancing", ( assert ) => {
  18799. assert.ok( false, "everything's gonna be alright" );
  18800. } );
  18801. // PUBLIC STUFF
  18802. QUnit.test( "moveTo", ( assert ) => {
  18803. assert.ok( false, "everything's gonna be alright" );
  18804. } );
  18805. QUnit.test( "lineTo", ( assert ) => {
  18806. assert.ok( false, "everything's gonna be alright" );
  18807. } );
  18808. QUnit.test( "quadraticCurveTo", ( assert ) => {
  18809. assert.ok( false, "everything's gonna be alright" );
  18810. } );
  18811. QUnit.test( "bezierCurveTo", ( assert ) => {
  18812. assert.ok( false, "everything's gonna be alright" );
  18813. } );
  18814. QUnit.test( "splineThru", ( assert ) => {
  18815. assert.ok( false, "everything's gonna be alright" );
  18816. } );
  18817. QUnit.test( "toShapes", ( assert ) => {
  18818. assert.ok( false, "everything's gonna be alright" );
  18819. } );
  18820. } );
  18821. } );
  18822. } );
  18823. /**
  18824. * @author TristanVALCKE / https://github.com/Itee
  18825. */
  18826. /* global QUnit */
  18827. QUnit.module( 'Extras', () => {
  18828. QUnit.module( 'Curves', () => {
  18829. QUnit.module.todo( 'ArcCurve', () => {
  18830. // INHERITANCE
  18831. QUnit.test( "Extending", ( assert ) => {
  18832. assert.ok( false, "everything's gonna be alright" );
  18833. } );
  18834. // INSTANCING
  18835. QUnit.test( "Instancing", ( assert ) => {
  18836. assert.ok( false, "everything's gonna be alright" );
  18837. } );
  18838. // PUBLIC STUFF
  18839. QUnit.test( "isArcCurve", ( assert ) => {
  18840. assert.ok( false, "everything's gonna be alright" );
  18841. } );
  18842. } );
  18843. } );
  18844. } );
  18845. /**
  18846. * @author zz85 https://github.com/zz85
  18847. *
  18848. * Centripetal CatmullRom Curve - which is useful for avoiding
  18849. * cusps and self-intersections in non-uniform catmull rom curves.
  18850. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  18851. *
  18852. * curve.type accepts centripetal(default), chordal and catmullrom
  18853. * curve.tension is used for catmullrom which defaults to 0.5
  18854. */
  18855. /*
  18856. Based on an optimized c++ solution in
  18857. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  18858. - http://ideone.com/NoEbVM
  18859. This CubicPoly class could be used for reusing some variables and calculations,
  18860. but for three.js curve use, it could be possible inlined and flatten into a single function call
  18861. which can be placed in CurveUtils.
  18862. */
  18863. function CubicPoly() {
  18864. var c0 = 0, c1 = 0, c2 = 0, c3 = 0;
  18865. /*
  18866. * Compute coefficients for a cubic polynomial
  18867. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  18868. * such that
  18869. * p(0) = x0, p(1) = x1
  18870. * and
  18871. * p'(0) = t0, p'(1) = t1.
  18872. */
  18873. function init( x0, x1, t0, t1 ) {
  18874. c0 = x0;
  18875. c1 = t0;
  18876. c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  18877. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  18878. }
  18879. return {
  18880. initCatmullRom: function ( x0, x1, x2, x3, tension ) {
  18881. init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  18882. },
  18883. initNonuniformCatmullRom: function ( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  18884. // compute tangents when parameterized in [t1,t2]
  18885. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  18886. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  18887. // rescale tangents for parametrization in [0,1]
  18888. t1 *= dt1;
  18889. t2 *= dt1;
  18890. init( x1, x2, t1, t2 );
  18891. },
  18892. calc: function ( t ) {
  18893. var t2 = t * t;
  18894. var t3 = t2 * t;
  18895. return c0 + c1 * t + c2 * t2 + c3 * t3;
  18896. }
  18897. };
  18898. }
  18899. //
  18900. var tmp = new Vector3();
  18901. var px = new CubicPoly();
  18902. var py = new CubicPoly();
  18903. var pz = new CubicPoly();
  18904. function CatmullRomCurve3( points ) {
  18905. Curve.call( this );
  18906. if ( points.length < 2 ) console.warn( 'THREE.CatmullRomCurve3: Points array needs at least two entries.' );
  18907. this.points = points || [];
  18908. this.closed = false;
  18909. }
  18910. CatmullRomCurve3.prototype = Object.create( Curve.prototype );
  18911. CatmullRomCurve3.prototype.constructor = CatmullRomCurve3;
  18912. CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
  18913. CatmullRomCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  18914. var point = optionalTarget || new Vector3();
  18915. var points = this.points;
  18916. var l = points.length;
  18917. var p = ( l - ( this.closed ? 0 : 1 ) ) * t;
  18918. var intPoint = Math.floor( p );
  18919. var weight = p - intPoint;
  18920. if ( this.closed ) {
  18921. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / points.length ) + 1 ) * points.length;
  18922. } else if ( weight === 0 && intPoint === l - 1 ) {
  18923. intPoint = l - 2;
  18924. weight = 1;
  18925. }
  18926. var p0, p1, p2, p3; // 4 points
  18927. if ( this.closed || intPoint > 0 ) {
  18928. p0 = points[ ( intPoint - 1 ) % l ];
  18929. } else {
  18930. // extrapolate first point
  18931. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  18932. p0 = tmp;
  18933. }
  18934. p1 = points[ intPoint % l ];
  18935. p2 = points[ ( intPoint + 1 ) % l ];
  18936. if ( this.closed || intPoint + 2 < l ) {
  18937. p3 = points[ ( intPoint + 2 ) % l ];
  18938. } else {
  18939. // extrapolate last point
  18940. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
  18941. p3 = tmp;
  18942. }
  18943. if ( this.type === undefined || this.type === 'centripetal' || this.type === 'chordal' ) {
  18944. // init Centripetal / Chordal Catmull-Rom
  18945. var pow = this.type === 'chordal' ? 0.5 : 0.25;
  18946. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  18947. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  18948. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  18949. // safety check for repeated points
  18950. if ( dt1 < 1e-4 ) dt1 = 1.0;
  18951. if ( dt0 < 1e-4 ) dt0 = dt1;
  18952. if ( dt2 < 1e-4 ) dt2 = dt1;
  18953. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  18954. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  18955. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  18956. } else if ( this.type === 'catmullrom' ) {
  18957. var tension = this.tension !== undefined ? this.tension : 0.5;
  18958. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, tension );
  18959. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, tension );
  18960. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, tension );
  18961. }
  18962. point.set(
  18963. px.calc( weight ),
  18964. py.calc( weight ),
  18965. pz.calc( weight )
  18966. );
  18967. return point;
  18968. };
  18969. /**
  18970. * @author zz85 / http://joshuakoo.com
  18971. * @author TristanVALCKE / https://github.com/Itee
  18972. */
  18973. /* global QUnit */
  18974. QUnit.module( 'Extras', () => {
  18975. QUnit.module( 'Curves', () => {
  18976. QUnit.module.todo( 'CatmullRomCurve3', () => {
  18977. /* eslint-disable */
  18978. var positions = [
  18979. new Vector3( - 60, - 100, 60 ),
  18980. new Vector3( - 60, 20, 60 ),
  18981. new Vector3( - 60, 120, 60 ),
  18982. new Vector3( 60, 20, - 60 ),
  18983. new Vector3( 60, - 100, - 60 )
  18984. ];
  18985. /* eslint-enable */
  18986. // INHERITANCE
  18987. QUnit.test( "Extending", ( assert ) => {
  18988. assert.ok( false, "everything's gonna be alright" );
  18989. } );
  18990. // INSTANCING
  18991. QUnit.test( "Instancing", ( assert ) => {
  18992. assert.ok( false, "everything's gonna be alright" );
  18993. } );
  18994. // PUBLIC STUFF
  18995. QUnit.test( "isCatmullRomCurve3", ( assert ) => {
  18996. assert.ok( false, "everything's gonna be alright" );
  18997. } );
  18998. QUnit.test( "getPoint", ( assert ) => {
  18999. assert.ok( false, "everything's gonna be alright" );
  19000. } );
  19001. // OTHERS
  19002. QUnit.test( "catmullrom check", ( assert ) => {
  19003. var curve = new CatmullRomCurve3( positions );
  19004. curve.type = 'catmullrom';
  19005. var expectedPoints = [
  19006. new Vector3( - 60, - 100, 60 ),
  19007. new Vector3( - 60, - 51.04, 60 ),
  19008. new Vector3( - 60, - 2.7199999999999998, 60 ),
  19009. new Vector3( - 61.92, 44.48, 61.92 ),
  19010. new Vector3( - 68.64, 95.36000000000001, 68.64 ),
  19011. new Vector3( - 60, 120, 60 ),
  19012. new Vector3( - 14.880000000000017, 95.36000000000001, 14.880000000000017 ),
  19013. new Vector3( 41.75999999999997, 44.48000000000003, - 41.75999999999997 ),
  19014. new Vector3( 67.68, - 2.720000000000023, - 67.68 ),
  19015. new Vector3( 65.75999999999999, - 51.04000000000001, - 65.75999999999999 ),
  19016. new Vector3( 60, - 100, - 60 )
  19017. ];
  19018. var points = curve.getPoints( 10 );
  19019. assert.equal( points.length, expectedPoints.length, 'correct number of points.' );
  19020. points.forEach( function ( point, i ) {
  19021. assert.numEqual( point.x, expectedPoints[ i ].x, 'points[' + i + '].x' );
  19022. assert.numEqual( point.y, expectedPoints[ i ].y, 'points[' + i + '].y' );
  19023. assert.numEqual( point.z, expectedPoints[ i ].z, 'points[' + i + '].z' );
  19024. } );
  19025. } );
  19026. QUnit.test( "chordal basic check", ( assert ) => {
  19027. var curve = new CatmullRomCurve3( positions );
  19028. curve.type = 'chordal';
  19029. var expectedPoints = [
  19030. new Vector3( - 60, - 100, 60 ),
  19031. new Vector3( - 60, - 52, 60 ),
  19032. new Vector3( - 60, - 4, 60 ),
  19033. new Vector3( - 60.656435889910924, 41.62455386421379, 60.656435889910924 ),
  19034. new Vector3( - 62.95396150459915, 87.31049238896205, 62.95396150459915 ),
  19035. new Vector3( - 60, 120, 60 ),
  19036. new Vector3( - 16.302568199486444, 114.1500463116312, 16.302568199486444 ),
  19037. new Vector3( 42.998098664956586, 54.017050116427455, - 42.998098664956586 ),
  19038. new Vector3( 63.542500175682434, - 1.137153397546383, - 63.542500175682434 ),
  19039. new Vector3( 62.65687513176183, - 49.85286504815978, - 62.65687513176183 ),
  19040. new Vector3( 60.00000000000001, - 100, - 60.00000000000001 )
  19041. ];
  19042. var points = curve.getPoints( 10 );
  19043. assert.equal( points.length, expectedPoints.length, 'correct number of points.' );
  19044. points.forEach( function ( point, i ) {
  19045. assert.numEqual( point.x, expectedPoints[ i ].x, 'points[' + i + '].x' );
  19046. assert.numEqual( point.y, expectedPoints[ i ].y, 'points[' + i + '].y' );
  19047. assert.numEqual( point.z, expectedPoints[ i ].z, 'points[' + i + '].z' );
  19048. } );
  19049. } );
  19050. QUnit.test( "centripetal basic check", ( assert ) => {
  19051. var curve = new CatmullRomCurve3( positions );
  19052. curve.type = 'centripetal';
  19053. var expectedPoints = [
  19054. new Vector3( - 60, - 100, 60 ),
  19055. new Vector3( - 60, - 51.47527724919028, 60 ),
  19056. new Vector3( - 60, - 3.300369665587032, 60 ),
  19057. new Vector3( - 61.13836565863938, 42.86306307781241, 61.13836565863938 ),
  19058. new Vector3( - 65.1226454638772, 90.69743905511538, 65.1226454638772 ),
  19059. new Vector3( - 60, 120, 60 ),
  19060. new Vector3( - 15.620412575504497, 103.10790870179872, 15.620412575504497 ),
  19061. new Vector3( 42.384384731047874, 48.35477686933143, - 42.384384731047874 ),
  19062. new Vector3( 65.25545512241153, - 1.646250966068339, - 65.25545512241153 ),
  19063. new Vector3( 63.94159134180865, - 50.234688224551256, - 63.94159134180865 ),
  19064. new Vector3( 59.99999999999999, - 100, - 59.99999999999999 ),
  19065. ];
  19066. var points = curve.getPoints( 10 );
  19067. assert.equal( points.length, expectedPoints.length, 'correct number of points.' );
  19068. points.forEach( function ( point, i ) {
  19069. assert.numEqual( point.x, expectedPoints[ i ].x, 'points[' + i + '].x' );
  19070. assert.numEqual( point.y, expectedPoints[ i ].y, 'points[' + i + '].y' );
  19071. assert.numEqual( point.z, expectedPoints[ i ].z, 'points[' + i + '].z' );
  19072. } );
  19073. } );
  19074. QUnit.test( "closed catmullrom basic check", ( assert ) => {
  19075. var curve = new CatmullRomCurve3( positions );
  19076. curve.type = 'catmullrom';
  19077. curve.closed = true;
  19078. var expectedPoints = [
  19079. new Vector3( - 60, - 100, 60 ),
  19080. new Vector3( - 67.5, - 46.25, 67.5 ),
  19081. new Vector3( - 60, 20, 60 ),
  19082. new Vector3( - 67.5, 83.75, 67.5 ),
  19083. new Vector3( - 60, 120, 60 ),
  19084. new Vector3( 0, 83.75, 0 ),
  19085. new Vector3( 60, 20, - 60 ),
  19086. new Vector3( 75, - 46.25, - 75 ),
  19087. new Vector3( 60, - 100, - 60 ),
  19088. new Vector3( 0, - 115, 0 ),
  19089. new Vector3( - 60, - 100, 60 ),
  19090. ];
  19091. var points = curve.getPoints( 10 );
  19092. assert.equal( points.length, expectedPoints.length, 'correct number of points.' );
  19093. points.forEach( function ( point, i ) {
  19094. assert.numEqual( point.x, expectedPoints[ i ].x, 'points[' + i + '].x' );
  19095. assert.numEqual( point.y, expectedPoints[ i ].y, 'points[' + i + '].y' );
  19096. assert.numEqual( point.z, expectedPoints[ i ].z, 'points[' + i + '].z' );
  19097. } );
  19098. } );
  19099. //
  19100. // curve.type = 'catmullrom'; only from here on
  19101. //
  19102. QUnit.test( "getLength/getLengths", ( assert ) => {
  19103. var curve = new THREE.CatmullRomCurve3( positions );
  19104. curve.type = 'catmullrom';
  19105. var length = curve.getLength();
  19106. var expectedLength = 551.549686276872;
  19107. assert.numEqual( length, expectedLength, "Correct length of curve" );
  19108. var expectedLengths = [
  19109. 0,
  19110. 120,
  19111. 220,
  19112. 416.9771560359221,
  19113. 536.9771560359221
  19114. ];
  19115. var lengths = curve.getLengths( expectedLengths.length - 1 );
  19116. assert.strictEqual( lengths.length, expectedLengths.length, "Correct number of segments" );
  19117. lengths.forEach( function ( segment, i ) {
  19118. assert.numEqual( segment, expectedLengths[ i ], "segment[" + i + "] correct" );
  19119. } );
  19120. } );
  19121. QUnit.test( "getPointAt", ( assert ) => {
  19122. var curve = new THREE.CatmullRomCurve3( positions );
  19123. curve.type = 'catmullrom';
  19124. var expectedPoints = [
  19125. new THREE.Vector3( - 60, - 100, 60 ),
  19126. new THREE.Vector3( - 64.84177333183106, 64.86956465359813, 64.84177333183106 ),
  19127. new THREE.Vector3( - 28.288507045700854, 104.83101184518996, 28.288507045700854 ),
  19128. new THREE.Vector3( 60, - 100, - 60 )
  19129. ];
  19130. var points = [
  19131. curve.getPointAt( 0 ),
  19132. curve.getPointAt( 0.3 ),
  19133. curve.getPointAt( 0.5 ),
  19134. curve.getPointAt( 1 )
  19135. ];
  19136. assert.deepEqual( points, expectedPoints, "Correct points" );
  19137. } );
  19138. QUnit.test( "getTangent/getTangentAt", ( assert ) => {
  19139. var curve = new THREE.CatmullRomCurve3( positions );
  19140. curve.type = 'catmullrom';
  19141. var expectedTangents = [
  19142. new THREE.Vector3( 0, 1, 0 ),
  19143. new THREE.Vector3( - 0.0001090274561657922, 0.9999999881130137, 0.0001090274561657922 ),
  19144. new THREE.Vector3( 0.7071067811865475, - 2.0930381713877622e-13, - 0.7071067811865475 ),
  19145. new THREE.Vector3( 0.43189437062802816, - 0.7917919583070032, - 0.43189437062802816 ),
  19146. new THREE.Vector3( - 0.00019991333100812723, - 0.9999999600346592, 0.00019991333100812723 )
  19147. ];
  19148. var tangents = [
  19149. curve.getTangent( 0 ),
  19150. curve.getTangent( 0.25 ),
  19151. curve.getTangent( 0.5 ),
  19152. curve.getTangent( 0.75 ),
  19153. curve.getTangent( 1 )
  19154. ];
  19155. expectedTangents.forEach( function ( exp, i ) {
  19156. var tangent = tangents[ i ];
  19157. assert.numEqual( tangent.x, exp.x, "getTangent #" + i + ": x correct" );
  19158. assert.numEqual( tangent.y, exp.y, "getTangent #" + i + ": y correct" );
  19159. } );
  19160. //
  19161. var expectedTangents = [
  19162. new THREE.Vector3( 0, 1, 0 ),
  19163. new THREE.Vector3( - 0.10709018822205997, 0.9884651653817284, 0.10709018822205997 ),
  19164. new THREE.Vector3( 0.6396363672964268, - 0.4262987629159402, - 0.6396363672964268 ),
  19165. new THREE.Vector3( 0.5077298411616501, - 0.6960034603275557, - 0.5077298411616501 ),
  19166. new THREE.Vector3( - 0.00019991333100812723, - 0.9999999600346592, 0.00019991333100812723 )
  19167. ];
  19168. var tangents = [
  19169. curve.getTangentAt( 0 ),
  19170. curve.getTangentAt( 0.25 ),
  19171. curve.getTangentAt( 0.5 ),
  19172. curve.getTangentAt( 0.75 ),
  19173. curve.getTangentAt( 1 )
  19174. ];
  19175. expectedTangents.forEach( function ( exp, i ) {
  19176. var tangent = tangents[ i ];
  19177. assert.numEqual( tangent.x, exp.x, "getTangentAt #" + i + ": x correct" );
  19178. assert.numEqual( tangent.y, exp.y, "getTangentAt #" + i + ": y correct" );
  19179. } );
  19180. } );
  19181. QUnit.test( "computeFrenetFrames", ( assert ) => {
  19182. var curve = new THREE.CatmullRomCurve3( positions );
  19183. curve.type = 'catmullrom';
  19184. var expected = {
  19185. binormals: [
  19186. new THREE.Vector3( - 1, 0, 0 ),
  19187. new THREE.Vector3( - 0.28685061854203, 0.6396363672964267, - 0.7131493814579701 ),
  19188. new THREE.Vector3( - 1.9982670528160395e-8, - 0.0001999133310081272, - 0.9999999800173295 )
  19189. ],
  19190. normals: [
  19191. new THREE.Vector3( 0, 0, - 1 ),
  19192. new THREE.Vector3( - 0.7131493814579699, - 0.6396363672964268, - 0.2868506185420297 ),
  19193. new THREE.Vector3( - 0.9999999800173294, 0.00019991333100810582, - 1.99826701852146e-8 )
  19194. ],
  19195. tangents: [
  19196. new THREE.Vector3( 0, 1, 0 ),
  19197. new THREE.Vector3( 0.6396363672964269, - 0.4262987629159403, - 0.6396363672964269 ),
  19198. new THREE.Vector3( - 0.0001999133310081273, - 0.9999999600346594, 0.0001999133310081273 )
  19199. ]
  19200. };
  19201. var frames = curve.computeFrenetFrames( 2, false );
  19202. Object.keys( expected ).forEach( function ( group, i ) {
  19203. expected[ group ].forEach( function ( vec, j ) {
  19204. assert.numEqual( frames[ group ][ j ].x, vec.x, "Frenet frames [" + i + ", " + j + "].x correct" );
  19205. assert.numEqual( frames[ group ][ j ].y, vec.y, "Frenet frames [" + i + ", " + j + "].y correct" );
  19206. assert.numEqual( frames[ group ][ j ].z, vec.z, "Frenet frames [" + i + ", " + j + "].z correct" );
  19207. } );
  19208. } );
  19209. } );
  19210. QUnit.test( "getUtoTmapping", ( assert ) => {
  19211. var curve = new THREE.CatmullRomCurve3( positions );
  19212. curve.type = 'catmullrom';
  19213. var start = curve.getUtoTmapping( 0, 0 );
  19214. var end = curve.getUtoTmapping( 0, curve.getLength() );
  19215. var somewhere = curve.getUtoTmapping( 0.5, 500 );
  19216. var expectedSomewhere = 0.8964116382083199;
  19217. assert.strictEqual( start, 0, "getUtoTmapping( 0, 0 ) is the starting point" );
  19218. assert.strictEqual( end, 1, "getUtoTmapping( 0, length ) is the ending point" );
  19219. assert.numEqual( somewhere, expectedSomewhere, "getUtoTmapping( 0.5, 500 ) is correct" );
  19220. } );
  19221. QUnit.test( "getSpacedPoints", ( assert ) => {
  19222. var curve = new THREE.CatmullRomCurve3( positions );
  19223. curve.type = 'catmullrom';
  19224. var expectedPoints = [
  19225. new THREE.Vector3( - 60, - 100, 60 ),
  19226. new THREE.Vector3( - 60, 10.311489426555056, 60 ),
  19227. new THREE.Vector3( - 65.05889864636504, 117.99691802595966, 65.05889864636504 ),
  19228. new THREE.Vector3( 6.054276900088592, 78.7153118386369, - 6.054276900088592 ),
  19229. new THREE.Vector3( 64.9991491385602, 8.386980812799566, - 64.9991491385602 ),
  19230. new THREE.Vector3( 60, - 100, - 60 )
  19231. ];
  19232. var points = curve.getSpacedPoints();
  19233. assert.strictEqual( points.length, expectedPoints.length, "Correct number of points" );
  19234. assert.deepEqual( points, expectedPoints, "Correct points calculated" );
  19235. } );
  19236. } );
  19237. } );
  19238. } );
  19239. /**
  19240. * @author TristanVALCKE / https://github.com/Itee
  19241. * @author moraxy / https://github.com/moraxy
  19242. */
  19243. /* global QUnit */
  19244. QUnit.module( 'Extras', () => {
  19245. QUnit.module( 'Curves', () => {
  19246. QUnit.module.todo( 'CubicBezierCurve', ( hooks ) => {
  19247. let curve = undefined;
  19248. hooks.before( function () {
  19249. curve = new CubicBezierCurve(
  19250. new Vector2( - 10, 0 ),
  19251. new Vector2( - 5, 15 ),
  19252. new Vector2( 20, 15 ),
  19253. new Vector2( 10, 0 )
  19254. );
  19255. } );
  19256. // INHERITANCE
  19257. QUnit.test( "Extending", ( assert ) => {
  19258. assert.ok( false, "everything's gonna be alright" );
  19259. } );
  19260. // INSTANCING
  19261. QUnit.test( "Instancing", ( assert ) => {
  19262. assert.ok( false, "everything's gonna be alright" );
  19263. } );
  19264. // PUBLIC STUFF
  19265. QUnit.test( "isCubicBezierCurve", ( assert ) => {
  19266. assert.ok( false, "everything's gonna be alright" );
  19267. } );
  19268. QUnit.test( "getPoint", ( assert ) => {
  19269. assert.ok( false, "everything's gonna be alright" );
  19270. } );
  19271. // OTHERS
  19272. QUnit.test( "Simple curve", ( assert ) => {
  19273. var expectedPoints = [
  19274. new Vector2( - 10, 0 ),
  19275. new Vector2( - 3.359375, 8.4375 ),
  19276. new Vector2( 5.625, 11.25 ),
  19277. new Vector2( 11.796875, 8.4375 ),
  19278. new Vector2( 10, 0 )
  19279. ];
  19280. var points = curve.getPoints( expectedPoints.length - 1 );
  19281. assert.strictEqual( points.length, expectedPoints.length, "Correct number of points" );
  19282. assert.deepEqual( points, expectedPoints, "Correct points calculated" );
  19283. // symmetry
  19284. var curveRev = new CubicBezierCurve(
  19285. curve.v3, curve.v2, curve.v1, curve.v0
  19286. );
  19287. var points = curveRev.getPoints( expectedPoints.length - 1 );
  19288. assert.strictEqual( points.length, expectedPoints.length, "Reversed: Correct number of points" );
  19289. assert.deepEqual( points, expectedPoints.reverse(), "Reversed: Correct points curve" );
  19290. } );
  19291. QUnit.test( "getLength/getLengths", ( assert ) => {
  19292. var length = curve.getLength();
  19293. var expectedLength = 36.64630888504102;
  19294. assert.numEqual( length, expectedLength, "Correct length of curve" );
  19295. var expectedLengths = [
  19296. 0,
  19297. 10.737285813492393,
  19298. 20.15159143794633,
  19299. 26.93408340370825,
  19300. 35.56079575637337
  19301. ];
  19302. var lengths = curve.getLengths( expectedLengths.length - 1 );
  19303. assert.strictEqual( lengths.length, expectedLengths.length, "Correct number of segments" );
  19304. lengths.forEach( function ( segment, i ) {
  19305. assert.numEqual( segment, expectedLengths[ i ], "segment[" + i + "] correct" );
  19306. } );
  19307. } );
  19308. QUnit.test( "getPointAt", ( assert ) => {
  19309. var expectedPoints = [
  19310. new Vector2( - 10, 0 ),
  19311. new Vector2( - 3.3188282598022596, 8.463722639089221 ),
  19312. new Vector2( 3.4718554735926617, 11.07899406116314 ),
  19313. new Vector2( 10, 0 )
  19314. ];
  19315. var points = [
  19316. curve.getPointAt( 0 ),
  19317. curve.getPointAt( 0.3 ),
  19318. curve.getPointAt( 0.5 ),
  19319. curve.getPointAt( 1 )
  19320. ];
  19321. assert.deepEqual( points, expectedPoints, "Correct points" );
  19322. } );
  19323. QUnit.test( "getTangent/getTangentAt", ( assert ) => {
  19324. var expectedTangents = [
  19325. new Vector2( 0.316370061632252, 0.9486358543207215 ),
  19326. new Vector2( 0.838961283088303, 0.5441911111721949 ),
  19327. new Vector2( 1, 0 ),
  19328. new Vector2( 0.47628313192245453, - 0.8792919755383518 ),
  19329. new Vector2( - 0.5546041767829665, - 0.8321142992972107 )
  19330. ];
  19331. var tangents = [
  19332. curve.getTangent( 0 ),
  19333. curve.getTangent( 0.25 ),
  19334. curve.getTangent( 0.5 ),
  19335. curve.getTangent( 0.75 ),
  19336. curve.getTangent( 1 )
  19337. ];
  19338. expectedTangents.forEach( function ( exp, i ) {
  19339. var tangent = tangents[ i ];
  19340. assert.numEqual( tangent.x, exp.x, "getTangent #" + i + ": x correct" );
  19341. assert.numEqual( tangent.y, exp.y, "getTangent #" + i + ": y correct" );
  19342. } );
  19343. //
  19344. var expectedTangents = [
  19345. new Vector2( 0.316370061632252, 0.9486358543207215 ),
  19346. new Vector2( 0.7794223085548987, 0.6264988945935596 ),
  19347. new Vector2( 0.988266153082452, 0.15274164681452052 ),
  19348. new Vector2( 0.5004110404199416, - 0.8657879593906534 ),
  19349. new Vector2( - 0.5546041767829665, - 0.8321142992972107 )
  19350. ];
  19351. var tangents = [
  19352. curve.getTangentAt( 0 ),
  19353. curve.getTangentAt( 0.25 ),
  19354. curve.getTangentAt( 0.5 ),
  19355. curve.getTangentAt( 0.75 ),
  19356. curve.getTangentAt( 1 )
  19357. ];
  19358. expectedTangents.forEach( function ( exp, i ) {
  19359. var tangent = tangents[ i ];
  19360. assert.numEqual( tangent.x, exp.x, "getTangentAt #" + i + ": x correct" );
  19361. assert.numEqual( tangent.y, exp.y, "getTangentAt #" + i + ": y correct" );
  19362. } );
  19363. } );
  19364. QUnit.test( "getUtoTmapping", ( assert ) => {
  19365. var start = curve.getUtoTmapping( 0, 0 );
  19366. var end = curve.getUtoTmapping( 0, curve.getLength() );
  19367. var somewhere = curve.getUtoTmapping( 0.5, 1 );
  19368. var expectedSomewhere = 0.02130029182257093;
  19369. assert.strictEqual( start, 0, "getUtoTmapping( 0, 0 ) is the starting point" );
  19370. assert.strictEqual( end, 1, "getUtoTmapping( 0, length ) is the ending point" );
  19371. assert.numEqual( somewhere, expectedSomewhere, "getUtoTmapping( 0.5, 1 ) is correct" );
  19372. } );
  19373. QUnit.test( "getSpacedPoints", ( assert ) => {
  19374. var expectedPoints = [
  19375. new Vector2( - 10, 0 ),
  19376. new Vector2( - 6.16826457740703, 6.17025727295411 ),
  19377. new Vector2( - 0.058874033259857184, 10.1240558653185 ),
  19378. new Vector2( 7.123523032625162, 11.154913869041575 ),
  19379. new Vector2( 12.301846885754463, 6.808865855469985 ),
  19380. new Vector2( 10, 0 )
  19381. ];
  19382. var points = curve.getSpacedPoints();
  19383. assert.strictEqual( points.length, expectedPoints.length, "Correct number of points" );
  19384. assert.deepEqual( points, expectedPoints, "Correct points calculated" );
  19385. } );
  19386. } );
  19387. } );
  19388. } );
  19389. function CubicBezierCurve3( v0, v1, v2, v3 ) {
  19390. Curve.call( this );
  19391. this.v0 = v0;
  19392. this.v1 = v1;
  19393. this.v2 = v2;
  19394. this.v3 = v3;
  19395. }
  19396. CubicBezierCurve3.prototype = Object.create( Curve.prototype );
  19397. CubicBezierCurve3.prototype.constructor = CubicBezierCurve3;
  19398. CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
  19399. CubicBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  19400. var point = optionalTarget || new Vector3();
  19401. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  19402. point.set(
  19403. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  19404. CubicBezier( t, v0.y, v1.y, v2.y, v3.y ),
  19405. CubicBezier( t, v0.z, v1.z, v2.z, v3.z )
  19406. );
  19407. return point;
  19408. };
  19409. /**
  19410. * @author TristanVALCKE / https://github.com/Itee
  19411. * @author moraxy / https://github.com/moraxy
  19412. */
  19413. /* global QUnit */
  19414. QUnit.module( 'Extras', () => {
  19415. QUnit.module( 'Curves', () => {
  19416. QUnit.module.todo( 'CubicBezierCurve3', ( hooks ) => {
  19417. let curve = undefined;
  19418. hooks.before( function () {
  19419. curve = new CubicBezierCurve3(
  19420. new Vector3( - 10, 0, 2 ),
  19421. new Vector3( - 5, 15, 4 ),
  19422. new Vector3( 20, 15, - 5 ),
  19423. new Vector3( 10, 0, 10 )
  19424. );
  19425. } );
  19426. // INHERITANCE
  19427. QUnit.test( "Extending", ( assert ) => {
  19428. assert.ok( false, "everything's gonna be alright" );
  19429. } );
  19430. // INSTANCING
  19431. QUnit.test( "Instancing", ( assert ) => {
  19432. assert.ok( false, "everything's gonna be alright" );
  19433. } );
  19434. // PUBLIC STUFF
  19435. QUnit.test( "isCubicBezierCurve3", ( assert ) => {
  19436. assert.ok( false, "everything's gonna be alright" );
  19437. } );
  19438. QUnit.test( "getPoint", ( assert ) => {
  19439. assert.ok( false, "everything's gonna be alright" );
  19440. } );
  19441. // OTHERS
  19442. QUnit.test( "Simple curve", ( assert ) => {
  19443. var expectedPoints = [
  19444. new Vector3( - 10, 0, 2 ),
  19445. new Vector3( - 3.359375, 8.4375, 1.984375 ),
  19446. new Vector3( 5.625, 11.25, 1.125 ),
  19447. new Vector3( 11.796875, 8.4375, 2.703125 ),
  19448. new Vector3( 10, 0, 10 )
  19449. ];
  19450. var points = curve.getPoints( expectedPoints.length - 1 );
  19451. assert.strictEqual( points.length, expectedPoints.length, "Correct number of points" );
  19452. assert.deepEqual( points, expectedPoints, "Correct points calculated" );
  19453. // symmetry
  19454. var curveRev = new CubicBezierCurve3(
  19455. curve.v3, curve.v2, curve.v1, curve.v0
  19456. );
  19457. points = curveRev.getPoints( expectedPoints.length - 1 );
  19458. assert.strictEqual( points.length, expectedPoints.length, "Reversed: Correct number of points" );
  19459. assert.deepEqual( points, expectedPoints.reverse(), "Reversed: Correct points curve" );
  19460. } );
  19461. QUnit.test( "getLength/getLengths", ( assert ) => {
  19462. var length = curve.getLength();
  19463. var expectedLength = 39.58103024989427;
  19464. assert.numEqual( length, expectedLength, "Correct length of curve" );
  19465. var expectedLengths = [
  19466. 0,
  19467. 10.73729718231036,
  19468. 20.19074500737662,
  19469. 27.154413277853756,
  19470. 38.453287150114214
  19471. ];
  19472. var lengths = curve.getLengths( expectedLengths.length - 1 );
  19473. assert.strictEqual( lengths.length, expectedLengths.length, "Correct number of segments" );
  19474. lengths.forEach( function ( segment, i ) {
  19475. assert.numEqual( segment, expectedLengths[ i ], "segment[" + i + "] correct" );
  19476. } );
  19477. } );
  19478. QUnit.test( "getPointAt", ( assert ) => {
  19479. var expectedPoints = [
  19480. new Vector3( - 10, 0, 2 ),
  19481. new Vector3( - 2.591880240484318, 8.908333501170798, 1.8953420625251136 ),
  19482. new Vector3( 4.866251460832755, 11.22787914038507, 1.150832855206874 ),
  19483. new Vector3( 10, 0, 10 )
  19484. ];
  19485. var points = [
  19486. curve.getPointAt( 0 ),
  19487. curve.getPointAt( 0.3 ),
  19488. curve.getPointAt( 0.5 ),
  19489. curve.getPointAt( 1 )
  19490. ];
  19491. assert.deepEqual( points, expectedPoints, "Correct points" );
  19492. } );
  19493. QUnit.test( "getTangent/getTangentAt", ( assert ) => {
  19494. var expectedTangents = [
  19495. new Vector3( 0.3138715439944244, 0.9411440474105875, 0.12542940601858074 ),
  19496. new Vector3( 0.8351825262580098, 0.54174002562179, - 0.09480449605683638 ),
  19497. new Vector3( 0.9997531780538501, 0, - 0.02221672728433752 ),
  19498. new Vector3( 0.40693407933981185, - 0.7512629496079668, 0.5196235518317053 ),
  19499. new Vector3( - 0.42632467075185815, - 0.6396469221230213, 0.6396085444448543 )
  19500. ];
  19501. var tangents = [
  19502. curve.getTangent( 0 ),
  19503. curve.getTangent( 0.25 ),
  19504. curve.getTangent( 0.5 ),
  19505. curve.getTangent( 0.75 ),
  19506. curve.getTangent( 1 )
  19507. ];
  19508. expectedTangents.forEach( function ( exp, i ) {
  19509. var tangent = tangents[ i ];
  19510. assert.numEqual( tangent.x, exp.x, "getTangent #" + i + ": x correct" );
  19511. assert.numEqual( tangent.y, exp.y, "getTangent #" + i + ": y correct" );
  19512. } );
  19513. //
  19514. expectedTangents = [
  19515. new Vector3( 0.3138715439944244, 0.9411440474105875, 0.12542940601858074 ),
  19516. new Vector3( 0.8016539573770751, 0.5918626760037707, - 0.08396133262002324 ),
  19517. new Vector3( 0.997337559412928, 0.05740742907719314, - 0.044968652092444425 ),
  19518. new Vector3( 0.1389373097746809, - 0.7882209938358005, 0.5995032016837588 ),
  19519. new Vector3( - 0.42632467075185815, - 0.6396469221230213, 0.6396085444448543 )
  19520. ];
  19521. tangents = [
  19522. curve.getTangentAt( 0 ),
  19523. curve.getTangentAt( 0.25 ),
  19524. curve.getTangentAt( 0.5 ),
  19525. curve.getTangentAt( 0.75 ),
  19526. curve.getTangentAt( 1 )
  19527. ];
  19528. expectedTangents.forEach( function ( exp, i ) {
  19529. var tangent = tangents[ i ];
  19530. assert.numEqual( tangent.x, exp.x, "getTangentAt #" + i + ": x correct" );
  19531. assert.numEqual( tangent.y, exp.y, "getTangentAt #" + i + ": y correct" );
  19532. } );
  19533. } );
  19534. QUnit.test( "getUtoTmapping", ( assert ) => {
  19535. var start = curve.getUtoTmapping( 0, 0 );
  19536. var end = curve.getUtoTmapping( 0, curve.getLength() );
  19537. var somewhere = curve.getUtoTmapping( 0.5, 1 );
  19538. var expectedSomewhere = 0.021163245321323316;
  19539. assert.strictEqual( start, 0, "getUtoTmapping( 0, 0 ) is the starting point" );
  19540. assert.strictEqual( end, 1, "getUtoTmapping( 0, length ) is the ending point" );
  19541. assert.numEqual( somewhere, expectedSomewhere, "getUtoTmapping( 0.5, 1 ) is correct" );
  19542. } );
  19543. QUnit.test( "getSpacedPoints", ( assert ) => {
  19544. var expectedPoints = [
  19545. new Vector3( - 10, 0, 2 ),
  19546. new Vector3( - 5.756524515061918, 6.568020242700483, 2.22116711170301 ),
  19547. new Vector3( 1.0003511895116906, 10.49656064587831, 1.4727101010850698 ),
  19548. new Vector3( 8.767656412295171, 10.784286845278622, 1.2873599519775174 ),
  19549. new Vector3( 12.306772513558396, 5.545103788071547, 4.909948454535794 ),
  19550. new Vector3( 10, 0, 10 )
  19551. ];
  19552. var points = curve.getSpacedPoints();
  19553. assert.strictEqual( points.length, expectedPoints.length, "Correct number of points" );
  19554. assert.deepEqual( points, expectedPoints, "Correct points calculated" );
  19555. } );
  19556. QUnit.test( "computeFrenetFrames", ( assert ) => {
  19557. var expected = {
  19558. binormals: [
  19559. new Vector3( - 0.9486358543207215, 0.316370061632252, - 6.938893903907228e-18 ),
  19560. new Vector3( - 0.05491430765311864, 0.9969838307670049, 0.054842137122173326 ),
  19561. new Vector3( 0.5944656510461876, 0.334836503700931, 0.7310917216844742 )
  19562. ],
  19563. normals: [
  19564. new Vector3( 0.03968210891259515, 0.11898683173537697, - 0.9921025471723304 ),
  19565. new Vector3( - 0.047981365124836806, 0.05222670079466692, - 0.9974819097732357 ),
  19566. new Vector3( 0.6818048583242511, - 0.6919077473246573, - 0.23749906180354932 )
  19567. ],
  19568. tangents: [
  19569. new Vector3( 0.3138715439944244, 0.9411440474105875, 0.12542940601858074 ),
  19570. new Vector3( 0.9973375594129282, 0.05740742907719315, - 0.04496865209244443 ),
  19571. new Vector3( - 0.42632467075185815, - 0.6396469221230213, 0.6396085444448543 )
  19572. ]
  19573. };
  19574. var frames = curve.computeFrenetFrames( 2, false );
  19575. Object.keys( expected ).forEach( function ( group, i ) {
  19576. expected[ group ].forEach( function ( vec, j ) {
  19577. assert.numEqual( frames[ group ][ j ].x, vec.x, "Frenet frames [" + i + ", " + j + "].x correct" );
  19578. assert.numEqual( frames[ group ][ j ].y, vec.y, "Frenet frames [" + i + ", " + j + "].y correct" );
  19579. assert.numEqual( frames[ group ][ j ].z, vec.z, "Frenet frames [" + i + ", " + j + "].z correct" );
  19580. } );
  19581. } );
  19582. } );
  19583. } );
  19584. } );
  19585. } );
  19586. /**
  19587. * @author TristanVALCKE / https://github.com/Itee
  19588. */
  19589. /* global QUnit */
  19590. QUnit.module( 'Extras', () => {
  19591. QUnit.module( 'Curves', () => {
  19592. QUnit.module.todo( 'EllipseCurve', ( hooks ) => {
  19593. let curve = undefined;
  19594. hooks.before( function () {
  19595. curve = new EllipseCurve(
  19596. 0, 0, // ax, aY
  19597. 10, 10, // xRadius, yRadius
  19598. 0, 2 * Math.PI, // aStartAngle, aEndAngle
  19599. false, // aClockwise
  19600. 0 // aRotation
  19601. );
  19602. } );
  19603. // INHERITANCE
  19604. QUnit.test( "Extending", ( assert ) => {
  19605. assert.ok( false, "everything's gonna be alright" );
  19606. } );
  19607. // INSTANCING
  19608. QUnit.test( "Instancing", ( assert ) => {
  19609. assert.ok( false, "everything's gonna be alright" );
  19610. } );
  19611. // PUBLIC STUFF
  19612. QUnit.test( "isEllipseCurve", ( assert ) => {
  19613. assert.ok( false, "everything's gonna be alright" );
  19614. } );
  19615. QUnit.test( "getPoint", ( assert ) => {
  19616. assert.ok( false, "everything's gonna be alright" );
  19617. } );
  19618. // OTHERS
  19619. QUnit.test( "Simple curve", ( assert ) => {
  19620. var expectedPoints = [
  19621. new Vector2( 10, 0 ),
  19622. new Vector2( 0, 10 ),
  19623. new Vector2( - 10, 0 ),
  19624. new Vector2( 0, - 10 ),
  19625. new Vector2( 10, 0 )
  19626. ];
  19627. var points = curve.getPoints( expectedPoints.length - 1 );
  19628. assert.strictEqual( points.length, expectedPoints.length, "Correct number of points" );
  19629. points.forEach( function ( point, i ) {
  19630. assert.numEqual( point.x, expectedPoints[ i ].x, "point[" + i + "].x correct" );
  19631. assert.numEqual( point.y, expectedPoints[ i ].y, "point[" + i + "].y correct" );
  19632. } );
  19633. } );
  19634. QUnit.test( "getLength/getLengths", ( assert ) => {
  19635. var length = curve.getLength();
  19636. var expectedLength = 62.829269247282795;
  19637. assert.numEqual( length, expectedLength, "Correct length of curve" );
  19638. var lengths = curve.getLengths( 5 );
  19639. var expectedLengths = [
  19640. 0,
  19641. 11.755705045849462,
  19642. 23.51141009169892,
  19643. 35.26711513754839,
  19644. 47.02282018339785,
  19645. 58.77852522924731
  19646. ];
  19647. assert.strictEqual( lengths.length, expectedLengths.length, "Correct number of segments" );
  19648. lengths.forEach( function ( segment, i ) {
  19649. assert.numEqual( segment, expectedLengths[ i ], "segment[" + i + "] correct" );
  19650. } );
  19651. } );
  19652. QUnit.test( "getPoint/getPointAt", ( assert ) => {
  19653. var testValues = [ 0, 0.3, 0.5, 0.7, 1 ];
  19654. testValues.forEach( function ( val, i ) {
  19655. var expectedX = Math.cos( val * Math.PI * 2 ) * 10;
  19656. var expectedY = Math.sin( val * Math.PI * 2 ) * 10;
  19657. var p = curve.getPoint( val );
  19658. var a = curve.getPointAt( val );
  19659. assert.numEqual( p.x, expectedX, "getPoint(" + val + ").x correct" );
  19660. assert.numEqual( p.y, expectedY, "getPoint(" + val + ").y correct" );
  19661. assert.numEqual( a.x, expectedX, "getPointAt(" + val + ").x correct" );
  19662. assert.numEqual( a.y, expectedY, "getPointAt(" + val + ").y correct" );
  19663. } );
  19664. } );
  19665. QUnit.test( "getTangent", ( assert ) => {
  19666. var expectedTangents = [
  19667. new Vector2( - 0.000314159260186071, 0.9999999506519786 ),
  19668. new Vector2( - 1, 0 ),
  19669. new Vector2( 0, - 1 ),
  19670. new Vector2( 1, 0 ),
  19671. new Vector2( 0.00031415926018600165, 0.9999999506519784 )
  19672. ];
  19673. var tangents = [
  19674. curve.getTangent( 0 ),
  19675. curve.getTangent( 0.25 ),
  19676. curve.getTangent( 0.5 ),
  19677. curve.getTangent( 0.75 ),
  19678. curve.getTangent( 1 )
  19679. ];
  19680. expectedTangents.forEach( function ( exp, i ) {
  19681. var tangent = tangents[ i ];
  19682. assert.numEqual( tangent.x, exp.x, "getTangent #" + i + ": x correct" );
  19683. assert.numEqual( tangent.y, exp.y, "getTangent #" + i + ": y correct" );
  19684. } );
  19685. } );
  19686. QUnit.test( "getUtoTmapping", ( assert ) => {
  19687. var start = curve.getUtoTmapping( 0, 0 );
  19688. var end = curve.getUtoTmapping( 0, curve.getLength() );
  19689. var somewhere = curve.getUtoTmapping( 0.7, 1 );
  19690. var expectedSomewhere = 0.01591614882650014;
  19691. assert.strictEqual( start, 0, "getUtoTmapping( 0, 0 ) is the starting point" );
  19692. assert.strictEqual( end, 1, "getUtoTmapping( 0, length ) is the ending point" );
  19693. assert.numEqual( somewhere, expectedSomewhere, "getUtoTmapping( 0.7, 1 ) is correct" );
  19694. } );
  19695. QUnit.test( "getSpacedPoints", ( assert ) => {
  19696. var expectedPoints = [
  19697. new Vector2( 10, 0 ),
  19698. new Vector2( 3.0901699437494603, 9.51056516295154 ),
  19699. new Vector2( - 8.090169943749492, 5.877852522924707 ),
  19700. new Vector2( - 8.090169943749459, - 5.877852522924751 ),
  19701. new Vector2( 3.0901699437494807, - 9.510565162951533 ),
  19702. new Vector2( 10, - 2.4492935982947065e-15 )
  19703. ];
  19704. var points = curve.getSpacedPoints();
  19705. assert.strictEqual( points.length, expectedPoints.length, "Correct number of points" );
  19706. expectedPoints.forEach( function ( exp, i ) {
  19707. var point = points[ i ];
  19708. assert.numEqual( point.x, exp.x, "Point #" + i + ": x correct" );
  19709. assert.numEqual( point.y, exp.y, "Point #" + i + ": y correct" );
  19710. } );
  19711. } );
  19712. } );
  19713. } );
  19714. } );
  19715. /**
  19716. * @author TristanVALCKE / https://github.com/Itee
  19717. */
  19718. /* global QUnit */
  19719. QUnit.module( 'Extras', () => {
  19720. QUnit.module( 'Curves', () => {
  19721. QUnit.module.todo( 'LineCurve', ( hooks ) => {
  19722. let _points = undefined;
  19723. let _curve = undefined;
  19724. hooks.before( function () {
  19725. _points = [
  19726. new Vector2( 0, 0 ),
  19727. new Vector2( 10, 10 ),
  19728. new Vector2( - 10, 10 ),
  19729. new Vector2( - 8, 5 )
  19730. ];
  19731. _curve = new LineCurve( _points[ 0 ], _points[ 1 ] );
  19732. } );
  19733. // INHERITANCE
  19734. QUnit.test( "Extending", ( assert ) => {
  19735. assert.ok( false, "everything's gonna be alright" );
  19736. } );
  19737. // INSTANCING
  19738. QUnit.test( "Instancing", ( assert ) => {
  19739. assert.ok( false, "everything's gonna be alright" );
  19740. } );
  19741. // PUBLIC STUFF
  19742. QUnit.test( "isLineCurve", ( assert ) => {
  19743. assert.ok( false, "everything's gonna be alright" );
  19744. } );
  19745. QUnit.test( "getPoint", ( assert ) => {
  19746. assert.ok( false, "everything's gonna be alright" );
  19747. } );
  19748. QUnit.test( "getPointAt", ( assert ) => {
  19749. var curve = new LineCurve( _points[ 0 ], _points[ 3 ] );
  19750. var expectedPoints = [
  19751. new Vector2( 0, 0 ),
  19752. new Vector2( - 2.4, 1.5 ),
  19753. new Vector2( - 4, 2.5 ),
  19754. new Vector2( - 8, 5 )
  19755. ];
  19756. var points = [
  19757. curve.getPointAt( 0 ),
  19758. curve.getPointAt( 0.3 ),
  19759. curve.getPointAt( 0.5 ),
  19760. curve.getPointAt( 1 )
  19761. ];
  19762. assert.deepEqual( points, expectedPoints, "Correct points" );
  19763. } );
  19764. QUnit.test( "getTangent", ( assert ) => {
  19765. var curve = _curve;
  19766. var tangent = curve.getTangent( 0 );
  19767. var expectedTangent = Math.sqrt( 0.5 );
  19768. assert.numEqual( tangent.x, expectedTangent, "tangent.x correct" );
  19769. assert.numEqual( tangent.y, expectedTangent, "tangent.y correct" );
  19770. } );
  19771. // OTHERS
  19772. QUnit.test( "Simple curve", ( assert ) => {
  19773. var curve = _curve;
  19774. var expectedPoints = [
  19775. new Vector2( 0, 0 ),
  19776. new Vector2( 2, 2 ),
  19777. new Vector2( 4, 4 ),
  19778. new Vector2( 6, 6 ),
  19779. new Vector2( 8, 8 ),
  19780. new Vector2( 10, 10 )
  19781. ];
  19782. var points = curve.getPoints();
  19783. assert.deepEqual( points, expectedPoints, "Correct points for first curve" );
  19784. //
  19785. curve = new LineCurve( _points[ 1 ], _points[ 2 ] );
  19786. expectedPoints = [
  19787. new Vector2( 10, 10 ),
  19788. new Vector2( 6, 10 ),
  19789. new Vector2( 2, 10 ),
  19790. new Vector2( - 2, 10 ),
  19791. new Vector2( - 6, 10 ),
  19792. new Vector2( - 10, 10 )
  19793. ];
  19794. points = curve.getPoints();
  19795. assert.deepEqual( points, expectedPoints, "Correct points for second curve" );
  19796. } );
  19797. QUnit.test( "getLength/getLengths", ( assert ) => {
  19798. var curve = _curve;
  19799. var length = curve.getLength();
  19800. var expectedLength = Math.sqrt( 200 );
  19801. assert.numEqual( length, expectedLength, "Correct length of curve" );
  19802. var lengths = curve.getLengths( 5 );
  19803. var expectedLengths = [
  19804. 0.0,
  19805. Math.sqrt( 8 ),
  19806. Math.sqrt( 32 ),
  19807. Math.sqrt( 72 ),
  19808. Math.sqrt( 128 ),
  19809. Math.sqrt( 200 )
  19810. ];
  19811. assert.strictEqual( lengths.length, expectedLengths.length, "Correct number of segments" );
  19812. lengths.forEach( function ( segment, i ) {
  19813. assert.numEqual( segment, expectedLengths[ i ], "segment[" + i + "] correct" );
  19814. } );
  19815. } );
  19816. QUnit.test( "getUtoTmapping", ( assert ) => {
  19817. var curve = _curve;
  19818. var start = curve.getUtoTmapping( 0, 0 );
  19819. var end = curve.getUtoTmapping( 0, curve.getLength() );
  19820. var somewhere = curve.getUtoTmapping( 0.3, 0 );
  19821. assert.strictEqual( start, 0, "getUtoTmapping( 0, 0 ) is the starting point" );
  19822. assert.strictEqual( end, 1, "getUtoTmapping( 0, length ) is the ending point" );
  19823. assert.numEqual( somewhere, 0.3, "getUtoTmapping( 0.3, 0 ) is correct" );
  19824. } );
  19825. QUnit.test( "getSpacedPoints", ( assert ) => {
  19826. var curve = _curve;
  19827. var expectedPoints = [
  19828. new Vector2( 0, 0 ),
  19829. new Vector2( 2.5, 2.5 ),
  19830. new Vector2( 5, 5 ),
  19831. new Vector2( 7.5, 7.5 ),
  19832. new Vector2( 10, 10 )
  19833. ];
  19834. var points = curve.getSpacedPoints( 4 );
  19835. assert.strictEqual( points.length, expectedPoints.length, "Correct number of points" );
  19836. assert.deepEqual( points, expectedPoints, "Correct points calculated" );
  19837. } );
  19838. } );
  19839. } );
  19840. } );
  19841. function LineCurve3( v1, v2 ) {
  19842. Curve.call( this );
  19843. this.v1 = v1;
  19844. this.v2 = v2;
  19845. }
  19846. LineCurve3.prototype = Object.create( Curve.prototype );
  19847. LineCurve3.prototype.constructor = LineCurve3;
  19848. LineCurve3.prototype.isLineCurve3 = true;
  19849. LineCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  19850. var point = optionalTarget || new Vector3();
  19851. if ( t === 1 ) {
  19852. point.copy( this.v2 );
  19853. } else {
  19854. point.copy( this.v2 ).sub( this.v1 );
  19855. point.multiplyScalar( t ).add( this.v1 );
  19856. }
  19857. return point;
  19858. };
  19859. // Line curve is linear, so we can overwrite default getPointAt
  19860. LineCurve3.prototype.getPointAt = function ( u, optionalTarget ) {
  19861. return this.getPoint( u, optionalTarget );
  19862. };
  19863. /**
  19864. * @author TristanVALCKE / https://github.com/Itee
  19865. */
  19866. /* global QUnit */
  19867. QUnit.module( 'Extras', () => {
  19868. QUnit.module( 'Curves', () => {
  19869. QUnit.module.todo( 'LineCurve3', ( hooks ) => {
  19870. let _points = undefined;
  19871. let _curve = undefined;
  19872. hooks.before( function () {
  19873. _points = [
  19874. new Vector3( 0, 0, 0 ),
  19875. new Vector3( 10, 10, 10 ),
  19876. new Vector3( - 10, 10, - 10 ),
  19877. new Vector3( - 8, 5, - 7 )
  19878. ];
  19879. _curve = new LineCurve3( _points[ 0 ], _points[ 1 ] );
  19880. } );
  19881. // INHERITANCE
  19882. QUnit.test( "Extending", ( assert ) => {
  19883. assert.ok( false, "everything's gonna be alright" );
  19884. } );
  19885. // INSTANCING
  19886. QUnit.test( "Instancing", ( assert ) => {
  19887. assert.ok( false, "everything's gonna be alright" );
  19888. } );
  19889. // PUBLIC STUFF
  19890. QUnit.test( "isCatmullRomCurve3", ( assert ) => {
  19891. assert.ok( false, "everything's gonna be alright" );
  19892. } );
  19893. QUnit.test( "getPoint", ( assert ) => {
  19894. assert.ok( false, "everything's gonna be alright" );
  19895. } );
  19896. QUnit.test( "getPointAt", ( assert ) => {
  19897. var curve = new LineCurve3( _points[ 0 ], _points[ 3 ] );
  19898. var expectedPoints = [
  19899. new Vector3( 0, 0, 0 ),
  19900. new Vector3( - 2.4, 1.5, - 2.1 ),
  19901. new Vector3( - 4, 2.5, - 3.5 ),
  19902. new Vector3( - 8, 5, - 7 )
  19903. ];
  19904. var points = [
  19905. curve.getPointAt( 0 ),
  19906. curve.getPointAt( 0.3 ),
  19907. curve.getPointAt( 0.5 ),
  19908. curve.getPointAt( 1 )
  19909. ];
  19910. assert.deepEqual( points, expectedPoints, "Correct getPointAt points" );
  19911. } );
  19912. // OTHERS
  19913. QUnit.test( "Simple curve", ( assert ) => {
  19914. var curve = _curve;
  19915. var expectedPoints = [
  19916. new Vector3( 0, 0, 0 ),
  19917. new Vector3( 2, 2, 2 ),
  19918. new Vector3( 4, 4, 4 ),
  19919. new Vector3( 6, 6, 6 ),
  19920. new Vector3( 8, 8, 8 ),
  19921. new Vector3( 10, 10, 10 )
  19922. ];
  19923. var points = curve.getPoints();
  19924. assert.deepEqual( points, expectedPoints, "Correct points for first curve" );
  19925. //
  19926. curve = new LineCurve3( _points[ 1 ], _points[ 2 ] );
  19927. expectedPoints = [
  19928. new Vector3( 10, 10, 10 ),
  19929. new Vector3( 6, 10, 6 ),
  19930. new Vector3( 2, 10, 2 ),
  19931. new Vector3( - 2, 10, - 2 ),
  19932. new Vector3( - 6, 10, - 6 ),
  19933. new Vector3( - 10, 10, - 10 )
  19934. ];
  19935. points = curve.getPoints();
  19936. assert.deepEqual( points, expectedPoints, "Correct points for second curve" );
  19937. } );
  19938. QUnit.test( "getLength/getLengths", ( assert ) => {
  19939. var curve = _curve;
  19940. var length = curve.getLength();
  19941. var expectedLength = Math.sqrt( 300 );
  19942. assert.numEqual( length, expectedLength, "Correct length of curve" );
  19943. var lengths = curve.getLengths( 5 );
  19944. var expectedLengths = [
  19945. 0.0,
  19946. Math.sqrt( 12 ),
  19947. Math.sqrt( 48 ),
  19948. Math.sqrt( 108 ),
  19949. Math.sqrt( 192 ),
  19950. Math.sqrt( 300 )
  19951. ];
  19952. assert.strictEqual( lengths.length, expectedLengths.length, "Correct number of segments" );
  19953. lengths.forEach( function ( segment, i ) {
  19954. assert.numEqual( segment, expectedLengths[ i ], "segment[" + i + "] correct" );
  19955. } );
  19956. } );
  19957. QUnit.test( "getTangent/getTangentAt", ( assert ) => {
  19958. var curve = _curve;
  19959. var tangent = curve.getTangent( 0.5 );
  19960. var expectedTangent = Math.sqrt( 1 / 3 );
  19961. assert.numEqual( tangent.x, expectedTangent, "tangent.x correct" );
  19962. assert.numEqual( tangent.y, expectedTangent, "tangent.y correct" );
  19963. assert.numEqual( tangent.z, expectedTangent, "tangent.z correct" );
  19964. tangent = curve.getTangentAt( 0.5 );
  19965. assert.numEqual( tangent.x, expectedTangent, "tangentAt.x correct" );
  19966. assert.numEqual( tangent.y, expectedTangent, "tangentAt.y correct" );
  19967. assert.numEqual( tangent.z, expectedTangent, "tangentAt.z correct" );
  19968. } );
  19969. QUnit.test( "computeFrenetFrames", ( assert ) => {
  19970. var curve = _curve;
  19971. var expected = {
  19972. binormals: new Vector3( - 0.5 * Math.sqrt( 2 ), 0.5 * Math.sqrt( 2 ), 0 ),
  19973. normals: new Vector3( Math.sqrt( 1 / 6 ), Math.sqrt( 1 / 6 ), - Math.sqrt( 2 / 3 ) ),
  19974. tangents: new Vector3( Math.sqrt( 1 / 3 ), Math.sqrt( 1 / 3 ), Math.sqrt( 1 / 3 ) )
  19975. };
  19976. var frames = curve.computeFrenetFrames( 1, false );
  19977. for ( var val in expected ) {
  19978. assert.numEqual( frames[ val ][ 0 ].x, expected[ val ].x, "Frenet frames " + val + ".x correct" );
  19979. assert.numEqual( frames[ val ][ 0 ].y, expected[ val ].y, "Frenet frames " + val + ".y correct" );
  19980. assert.numEqual( frames[ val ][ 0 ].z, expected[ val ].z, "Frenet frames " + val + ".z correct" );
  19981. }
  19982. } );
  19983. QUnit.test( "getUtoTmapping", ( assert ) => {
  19984. var curve = _curve;
  19985. var start = curve.getUtoTmapping( 0, 0 );
  19986. var end = curve.getUtoTmapping( 0, curve.getLength() );
  19987. var somewhere = curve.getUtoTmapping( 0.7, 0 );
  19988. assert.strictEqual( start, 0, "getUtoTmapping( 0, 0 ) is the starting point" );
  19989. assert.strictEqual( end, 1, "getUtoTmapping( 0, length ) is the ending point" );
  19990. assert.numEqual( somewhere, 0.7, "getUtoTmapping( 0.7, 0 ) is correct" );
  19991. } );
  19992. QUnit.test( "getSpacedPoints", ( assert ) => {
  19993. var curve = _curve;
  19994. var expectedPoints = [
  19995. new Vector3( 0, 0, 0 ),
  19996. new Vector3( 2.5, 2.5, 2.5 ),
  19997. new Vector3( 5, 5, 5 ),
  19998. new Vector3( 7.5, 7.5, 7.5 ),
  19999. new Vector3( 10, 10, 10 )
  20000. ];
  20001. var points = curve.getSpacedPoints( 4 );
  20002. assert.strictEqual( points.length, expectedPoints.length, "Correct number of points" );
  20003. assert.deepEqual( points, expectedPoints, "Correct points calculated" );
  20004. } );
  20005. } );
  20006. } );
  20007. } );
  20008. /**
  20009. * @author TristanVALCKE / https://github.com/Itee
  20010. */
  20011. /* global QUnit */
  20012. QUnit.module( 'Extras', () => {
  20013. QUnit.module( 'Curves', () => {
  20014. QUnit.module.todo( 'QuadraticBezierCurve', ( hooks ) => {
  20015. let _curve = undefined;
  20016. hooks.before( function () {
  20017. _curve = new QuadraticBezierCurve(
  20018. new Vector2( - 10, 0 ),
  20019. new Vector2( 20, 15 ),
  20020. new Vector2( 10, 0 )
  20021. );
  20022. } );
  20023. // INHERITANCE
  20024. QUnit.test( "Extending", ( assert ) => {
  20025. assert.ok( false, "everything's gonna be alright" );
  20026. } );
  20027. // INSTANCING
  20028. QUnit.test( "Instancing", ( assert ) => {
  20029. assert.ok( false, "everything's gonna be alright" );
  20030. } );
  20031. // PUBLIC STUFF
  20032. QUnit.test( "isQuadraticBezierCurve", ( assert ) => {
  20033. assert.ok( false, "everything's gonna be alright" );
  20034. } );
  20035. QUnit.test( "getPoint", ( assert ) => {
  20036. assert.ok( false, "everything's gonna be alright" );
  20037. } );
  20038. // OTHERS
  20039. QUnit.test( "Simple curve", ( assert ) => {
  20040. var curve = _curve;
  20041. var expectedPoints = [
  20042. new Vector2( - 10, 0 ),
  20043. new Vector2( 2.5, 5.625 ),
  20044. new Vector2( 10, 7.5 ),
  20045. new Vector2( 12.5, 5.625 ),
  20046. new Vector2( 10, 0 )
  20047. ];
  20048. var points = curve.getPoints( expectedPoints.length - 1 );
  20049. assert.strictEqual( points.length, expectedPoints.length, "Correct number of points" );
  20050. assert.deepEqual( points, expectedPoints, "Correct points calculated" );
  20051. // symmetry
  20052. var curveRev = new QuadraticBezierCurve(
  20053. curve.v2, curve.v1, curve.v0
  20054. );
  20055. points = curveRev.getPoints( expectedPoints.length - 1 );
  20056. assert.strictEqual( points.length, expectedPoints.length, "Reversed: Correct number of points" );
  20057. assert.deepEqual( points, expectedPoints.reverse(), "Reversed: Correct points curve" );
  20058. } );
  20059. QUnit.test( "getLength/getLengths", ( assert ) => {
  20060. var curve = _curve;
  20061. var length = curve.getLength();
  20062. var expectedLength = 31.269026549416683;
  20063. assert.numEqual( length, expectedLength, "Correct length of curve" );
  20064. var expectedLengths = [
  20065. 0,
  20066. 13.707320124663317,
  20067. 21.43814317269643,
  20068. 24.56314317269643,
  20069. 30.718679298818998
  20070. ];
  20071. var lengths = curve.getLengths( expectedLengths.length - 1 );
  20072. assert.strictEqual( lengths.length, expectedLengths.length, "Correct number of segments" );
  20073. lengths.forEach( function ( segment, i ) {
  20074. assert.numEqual( segment, expectedLengths[ i ], "segment[" + i + "] correct" );
  20075. } );
  20076. } );
  20077. QUnit.test( "getPointAt", ( assert ) => {
  20078. var curve = _curve;
  20079. var expectedPoints = [
  20080. new Vector2( - 10, 0 ),
  20081. new Vector2( - 1.5127849599387615, 3.993582003773624 ),
  20082. new Vector2( 4.310076165722796, 6.269921971403917 ),
  20083. new Vector2( 10, 0 )
  20084. ];
  20085. var points = [
  20086. curve.getPointAt( 0 ),
  20087. curve.getPointAt( 0.3 ),
  20088. curve.getPointAt( 0.5 ),
  20089. curve.getPointAt( 1 )
  20090. ];
  20091. assert.deepEqual( points, expectedPoints, "Correct points" );
  20092. } );
  20093. QUnit.test( "getTangent/getTangentAt", ( assert ) => {
  20094. var curve = _curve;
  20095. var expectedTangents = [
  20096. new Vector2( 0.89443315420562, 0.44720166888975904 ),
  20097. new Vector2( 0.936329177569021, 0.3511234415884543 ),
  20098. new Vector2( 1, 0 ),
  20099. new Vector2( - 5.921189464667277e-13, - 1 ),
  20100. new Vector2( - 0.5546617882904897, - 0.8320758983472577 )
  20101. ];
  20102. var tangents = [
  20103. curve.getTangent( 0 ),
  20104. curve.getTangent( 0.25 ),
  20105. curve.getTangent( 0.5 ),
  20106. curve.getTangent( 0.75 ),
  20107. curve.getTangent( 1 )
  20108. ];
  20109. expectedTangents.forEach( function ( exp, i ) {
  20110. var tangent = tangents[ i ];
  20111. assert.numEqual( tangent.x, exp.x, "getTangent #" + i + ": x correct" );
  20112. assert.numEqual( tangent.y, exp.y, "getTangent #" + i + ": y correct" );
  20113. } );
  20114. //
  20115. expectedTangents = [
  20116. new Vector2( 0.89443315420562, 0.44720166888975904 ),
  20117. new Vector2( 0.9125211423360805, 0.40902954024086674 ),
  20118. new Vector2( 0.9480289098765387, 0.3181842014278863 ),
  20119. new Vector2( 0.7969127189169473, - 0.6040944615111106 ),
  20120. new Vector2( - 0.5546617882904897, - 0.8320758983472577 )
  20121. ];
  20122. tangents = [
  20123. curve.getTangentAt( 0 ),
  20124. curve.getTangentAt( 0.25 ),
  20125. curve.getTangentAt( 0.5 ),
  20126. curve.getTangentAt( 0.75 ),
  20127. curve.getTangentAt( 1 )
  20128. ];
  20129. expectedTangents.forEach( function ( exp, i ) {
  20130. var tangent = tangents[ i ];
  20131. assert.numEqual( tangent.x, exp.x, "getTangentAt #" + i + ": x correct" );
  20132. assert.numEqual( tangent.y, exp.y, "getTangentAt #" + i + ": y correct" );
  20133. } );
  20134. } );
  20135. QUnit.test( "getUtoTmapping", ( assert ) => {
  20136. var curve = _curve;
  20137. var start = curve.getUtoTmapping( 0, 0 );
  20138. var end = curve.getUtoTmapping( 0, curve.getLength() );
  20139. var somewhere = curve.getUtoTmapping( 0.5, 1 );
  20140. var expectedSomewhere = 0.015073978276116116;
  20141. assert.strictEqual( start, 0, "getUtoTmapping( 0, 0 ) is the starting point" );
  20142. assert.strictEqual( end, 1, "getUtoTmapping( 0, length ) is the ending point" );
  20143. assert.numEqual( somewhere, expectedSomewhere, "getUtoTmapping( 0.5, 1 ) is correct" );
  20144. } );
  20145. QUnit.test( "getSpacedPoints", ( assert ) => {
  20146. var curve = _curve;
  20147. var expectedPoints = [
  20148. new Vector2( - 10, 0 ),
  20149. new Vector2( - 4.366603655406173, 2.715408933540383 ),
  20150. new Vector2( 1.3752241477827831, 5.191972084404416 ),
  20151. new Vector2( 7.312990279153634, 7.136310044848586 ),
  20152. new Vector2( 12.499856644824826, 5.653289188715387 ),
  20153. new Vector2( 10, 0 )
  20154. ];
  20155. var points = curve.getSpacedPoints();
  20156. assert.strictEqual( points.length, expectedPoints.length, "Correct number of points" );
  20157. assert.deepEqual( points, expectedPoints, "Correct points calculated" );
  20158. } );
  20159. } );
  20160. } );
  20161. } );
  20162. function QuadraticBezierCurve3( v0, v1, v2 ) {
  20163. Curve.call( this );
  20164. this.v0 = v0;
  20165. this.v1 = v1;
  20166. this.v2 = v2;
  20167. }
  20168. QuadraticBezierCurve3.prototype = Object.create( Curve.prototype );
  20169. QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3;
  20170. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  20171. QuadraticBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  20172. var point = optionalTarget || new Vector3();
  20173. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  20174. point.set(
  20175. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  20176. QuadraticBezier( t, v0.y, v1.y, v2.y ),
  20177. QuadraticBezier( t, v0.z, v1.z, v2.z )
  20178. );
  20179. return point;
  20180. };
  20181. /**
  20182. * @author TristanVALCKE / https://github.com/Itee
  20183. */
  20184. /* global QUnit */
  20185. QUnit.module( 'Extras', () => {
  20186. QUnit.module( 'Curves', () => {
  20187. QUnit.module.todo( 'QuadraticBezierCurve3', ( hooks ) => {
  20188. let _curve = undefined;
  20189. hooks.before( function () {
  20190. _curve = new QuadraticBezierCurve3(
  20191. new Vector3( - 10, 0, 2 ),
  20192. new Vector3( 20, 15, - 5 ),
  20193. new Vector3( 10, 0, 10 )
  20194. );
  20195. } );
  20196. // INHERITANCE
  20197. QUnit.test( "Extending", ( assert ) => {
  20198. assert.ok( false, "everything's gonna be alright" );
  20199. } );
  20200. // INSTANCING
  20201. QUnit.test( "Instancing", ( assert ) => {
  20202. assert.ok( false, "everything's gonna be alright" );
  20203. } );
  20204. // PUBLIC STUFF
  20205. QUnit.test( "isQuadraticBezierCurve3", ( assert ) => {
  20206. assert.ok( false, "everything's gonna be alright" );
  20207. } );
  20208. QUnit.test( "getPoint", ( assert ) => {
  20209. assert.ok( false, "everything's gonna be alright" );
  20210. } );
  20211. // OTHERS
  20212. QUnit.test( "Simple curve", ( assert ) => {
  20213. var curve = _curve;
  20214. var expectedPoints = [
  20215. new Vector3( - 10, 0, 2 ),
  20216. new Vector3( 2.5, 5.625, - 0.125 ),
  20217. new Vector3( 10, 7.5, 0.5 ),
  20218. new Vector3( 12.5, 5.625, 3.875 ),
  20219. new Vector3( 10, 0, 10 )
  20220. ];
  20221. var points = curve.getPoints( expectedPoints.length - 1 );
  20222. assert.strictEqual( points.length, expectedPoints.length, "Correct number of points" );
  20223. assert.deepEqual( points, expectedPoints, "Correct points calculated" );
  20224. // symmetry
  20225. var curveRev = new QuadraticBezierCurve3(
  20226. curve.v2, curve.v1, curve.v0
  20227. );
  20228. points = curveRev.getPoints( expectedPoints.length - 1 );
  20229. assert.strictEqual( points.length, expectedPoints.length, "Reversed: Correct number of points" );
  20230. assert.deepEqual( points, expectedPoints.reverse(), "Reversed: Correct points curve" );
  20231. } );
  20232. QUnit.test( "getLength/getLengths", ( assert ) => {
  20233. var curve = _curve;
  20234. var length = curve.getLength();
  20235. var expectedLength = 35.47294274967861;
  20236. assert.numEqual( length, expectedLength, "Correct length of curve" );
  20237. var expectedLengths = [
  20238. 0,
  20239. 13.871057998581074,
  20240. 21.62710402732536,
  20241. 26.226696400568883,
  20242. 34.91037361704809
  20243. ];
  20244. var lengths = curve.getLengths( expectedLengths.length - 1 );
  20245. assert.strictEqual( lengths.length, expectedLengths.length, "Correct number of segments" );
  20246. lengths.forEach( function ( segment, i ) {
  20247. assert.numEqual( segment, expectedLengths[ i ], "segment[" + i + "] correct" );
  20248. } );
  20249. } );
  20250. QUnit.test( "getPointAt", ( assert ) => {
  20251. var curve = _curve;
  20252. var expectedPoints = [
  20253. new Vector3( - 10, 0, 2 ),
  20254. new Vector3( - 0.4981634504454243, 4.427089043881476, 0.19308849757196012 ),
  20255. new Vector3( 6.149415812887238, 6.838853310980195, - 0.20278120208668637 ),
  20256. new Vector3( 10, 0, 10 )
  20257. ];
  20258. var points = [
  20259. curve.getPointAt( 0 ),
  20260. curve.getPointAt( 0.3 ),
  20261. curve.getPointAt( 0.5 ),
  20262. curve.getPointAt( 1 )
  20263. ];
  20264. assert.deepEqual( points, expectedPoints, "Correct points" );
  20265. } );
  20266. QUnit.test( "getTangent/getTangentAt", ( assert ) => {
  20267. var curve = _curve;
  20268. var expectedTangents = [
  20269. new Vector3( 0.8755715084258769, 0.4377711603816079, - 0.2042815331129452 ),
  20270. new Vector3( 0.9340289249885844, 0.3502608468707904, - 0.07005216937416067 ),
  20271. new Vector3( 0.9284766908853163, 0, 0.37139067635396156 ),
  20272. new Vector3( - 3.669031233375946e-13, - 0.6196442885791218, 0.7848827655333463 ),
  20273. new Vector3( - 0.4263618889888853, - 0.6396068005601663, 0.6396238584473043 )
  20274. ];
  20275. var tangents = [
  20276. curve.getTangent( 0 ),
  20277. curve.getTangent( 0.25 ),
  20278. curve.getTangent( 0.5 ),
  20279. curve.getTangent( 0.75 ),
  20280. curve.getTangent( 1 )
  20281. ];
  20282. expectedTangents.forEach( function ( exp, i ) {
  20283. var tangent = tangents[ i ];
  20284. assert.numEqual( tangent.x, exp.x, "getTangent #" + i + ": x correct" );
  20285. assert.numEqual( tangent.y, exp.y, "getTangent #" + i + ": y correct" );
  20286. } );
  20287. //
  20288. expectedTangents = [
  20289. new Vector3( 0.8755715084258769, 0.4377711603816079, - 0.2042815331129452 ),
  20290. new Vector3( 0.9060725703490549, 0.3984742932857448, - 0.14230507668907377 ),
  20291. new Vector3( 0.9621604167456882, 0.2688562845452628, 0.044312872940942424 ),
  20292. new Vector3( 0.016586454041780826, - 0.6163270940470614, 0.7873155674098058 ),
  20293. new Vector3( - 0.4263618889888853, - 0.6396068005601663, 0.6396238584473043 )
  20294. ];
  20295. tangents = [
  20296. curve.getTangentAt( 0 ),
  20297. curve.getTangentAt( 0.25 ),
  20298. curve.getTangentAt( 0.5 ),
  20299. curve.getTangentAt( 0.75 ),
  20300. curve.getTangentAt( 1 )
  20301. ];
  20302. expectedTangents.forEach( function ( exp, i ) {
  20303. var tangent = tangents[ i ];
  20304. assert.numEqual( tangent.x, exp.x, "getTangentAt #" + i + ": x correct" );
  20305. assert.numEqual( tangent.y, exp.y, "getTangentAt #" + i + ": y correct" );
  20306. } );
  20307. } );
  20308. QUnit.test( "getUtoTmapping", ( assert ) => {
  20309. var curve = _curve;
  20310. var start = curve.getUtoTmapping( 0, 0 );
  20311. var end = curve.getUtoTmapping( 0, curve.getLength() );
  20312. var somewhere = curve.getUtoTmapping( 0.5, 1 );
  20313. var expectedSomewhere = 0.014760890927167196;
  20314. assert.strictEqual( start, 0, "getUtoTmapping( 0, 0 ) is the starting point" );
  20315. assert.strictEqual( end, 1, "getUtoTmapping( 0, length ) is the ending point" );
  20316. assert.numEqual( somewhere, expectedSomewhere, "getUtoTmapping( 0.5, 1 ) is correct" );
  20317. } );
  20318. QUnit.test( "getSpacedPoints", ( assert ) => {
  20319. var curve = _curve;
  20320. var expectedPoints = [
  20321. new Vector3( - 10, 0, 2 ),
  20322. new Vector3( - 3.712652983516992, 3.015179001762753, 0.6957120710270492 ),
  20323. new Vector3( 2.7830973773262975, 5.730399338061483, - 0.1452668772806931 ),
  20324. new Vector3( 9.575825284074465, 7.48754187603603, 0.3461104039841496 ),
  20325. new Vector3( 12.345199937734154, 4.575759904730531, 5.142117429101656 ),
  20326. new Vector3( 10, 0, 10 )
  20327. ];
  20328. var points = curve.getSpacedPoints();
  20329. assert.strictEqual( points.length, expectedPoints.length, "Correct number of points" );
  20330. assert.deepEqual( points, expectedPoints, "Correct points calculated" );
  20331. } );
  20332. QUnit.test( "computeFrenetFrames", ( assert ) => {
  20333. var curve = _curve;
  20334. var expected = {
  20335. binormals: [
  20336. new Vector3( - 0.447201668889759, 0.8944331542056199, 0 ),
  20337. new Vector3( - 0.2684231751110917, 0.9631753839815436, - 0.01556209353802903 ),
  20338. new Vector3( 0.3459273556592433, 0.53807011680075, 0.7686447905324219 )
  20339. ],
  20340. normals: [
  20341. new Vector3( - 0.18271617600817133, - 0.09135504253146765, - 0.9789121795283909 ),
  20342. new Vector3( 0.046865035058597876, - 0.003078628350883253, - 0.9988964863970807 ),
  20343. new Vector3( 0.8357929194629689, - 0.5489842348221077, 0.008155102228190641 )
  20344. ],
  20345. tangents: [
  20346. new Vector3( 0.8755715084258767, 0.4377711603816078, - 0.20428153311294514 ),
  20347. new Vector3( 0.9621604167456884, 0.26885628454526284, 0.04431287294094243 ),
  20348. new Vector3( - 0.4263618889888853, - 0.6396068005601663, 0.6396238584473043 )
  20349. ]
  20350. };
  20351. var frames = curve.computeFrenetFrames( 2, false );
  20352. Object.keys( expected ).forEach( function ( group, i ) {
  20353. expected[ group ].forEach( function ( vec, j ) {
  20354. assert.numEqual( frames[ group ][ j ].x, vec.x, "Frenet frames [" + i + ", " + j + "].x correct" );
  20355. assert.numEqual( frames[ group ][ j ].y, vec.y, "Frenet frames [" + i + ", " + j + "].y correct" );
  20356. assert.numEqual( frames[ group ][ j ].z, vec.z, "Frenet frames [" + i + ", " + j + "].z correct" );
  20357. } );
  20358. } );
  20359. } );
  20360. } );
  20361. } );
  20362. } );
  20363. /**
  20364. * @author TristanVALCKE / https://github.com/Itee
  20365. */
  20366. /* global QUnit */
  20367. QUnit.module( 'Extras', () => {
  20368. QUnit.module( 'Curves', () => {
  20369. QUnit.module.todo( 'SplineCurve', ( hooks ) => {
  20370. let _curve = undefined;
  20371. hooks.before( function () {
  20372. _curve = new SplineCurve( [
  20373. new Vector2( - 10, 0 ),
  20374. new Vector2( - 5, 5 ),
  20375. new Vector2( 0, 0 ),
  20376. new Vector2( 5, - 5 ),
  20377. new Vector2( 10, 0 )
  20378. ] );
  20379. } );
  20380. // INHERITANCE
  20381. QUnit.test( "Extending", ( assert ) => {
  20382. assert.ok( false, "everything's gonna be alright" );
  20383. } );
  20384. // INSTANCING
  20385. QUnit.test( "Instancing", ( assert ) => {
  20386. assert.ok( false, "everything's gonna be alright" );
  20387. } );
  20388. // PUBLIC STUFF
  20389. QUnit.test( "isSplineCurve", ( assert ) => {
  20390. assert.ok( false, "everything's gonna be alright" );
  20391. } );
  20392. QUnit.test( "getPoint", ( assert ) => {
  20393. assert.ok( false, "everything's gonna be alright" );
  20394. } );
  20395. // OTHERS
  20396. QUnit.test( "Simple curve", ( assert ) => {
  20397. var curve = _curve;
  20398. var expectedPoints = [
  20399. new Vector2( - 10, 0 ),
  20400. new Vector2( - 6.08, 4.56 ),
  20401. new Vector2( - 2, 2.48 ),
  20402. new Vector2( 2, - 2.48 ),
  20403. new Vector2( 6.08, - 4.56 ),
  20404. new Vector2( 10, 0 )
  20405. ];
  20406. var points = curve.getPoints( 5 );
  20407. assert.strictEqual( points.length, expectedPoints.length, "1st: Correct number of points" );
  20408. points.forEach( function ( point, i ) {
  20409. assert.numEqual( point.x, expectedPoints[ i ].x, "points[" + i + "].x" );
  20410. assert.numEqual( point.y, expectedPoints[ i ].y, "points[" + i + "].y" );
  20411. } );
  20412. //
  20413. points = curve.getPoints( 4 );
  20414. assert.deepEqual( points, curve.points, "2nd: Returned points are identical to control points" );
  20415. } );
  20416. QUnit.test( "getLength/getLengths", ( assert ) => {
  20417. var curve = _curve;
  20418. var length = curve.getLength();
  20419. var expectedLength = 28.876950901868135;
  20420. assert.numEqual( length, expectedLength, "Correct length of curve" );
  20421. var expectedLengths = [
  20422. 0.0,
  20423. Math.sqrt( 50 ),
  20424. Math.sqrt( 200 ),
  20425. Math.sqrt( 450 ),
  20426. Math.sqrt( 800 )
  20427. ];
  20428. var lengths = curve.getLengths( 4 );
  20429. assert.deepEqual( lengths, expectedLengths, "Correct segment lengths" );
  20430. } );
  20431. QUnit.test( "getPointAt", ( assert ) => {
  20432. var curve = _curve;
  20433. assert.ok( curve.getPointAt( 0 ).equals( curve.points[ 0 ] ), "PointAt 0.0 correct" );
  20434. assert.ok( curve.getPointAt( 1 ).equals( curve.points[ 4 ] ), "PointAt 1.0 correct" );
  20435. var pointAt = curve.getPointAt( 0.5 );
  20436. assert.numEqual( pointAt.x, 0.0, "PointAt 0.5 x correct" );
  20437. assert.numEqual( pointAt.y, 0.0, "PointAt 0.5 y correct" );
  20438. } );
  20439. QUnit.test( "getTangent", ( assert ) => {
  20440. var curve = _curve;
  20441. var expectedTangent = [
  20442. new Vector2( 0.7068243340243188, 0.7073891155729485 ), // 0
  20443. new Vector2( 0.7069654305325396, - 0.7072481035902046 ), // 0.5
  20444. new Vector2( 0.7068243340245123, 0.7073891155727552 ) // 1
  20445. ];
  20446. var tangents = [
  20447. curve.getTangent( 0 ),
  20448. curve.getTangent( 0.5 ),
  20449. curve.getTangent( 1 )
  20450. ];
  20451. tangents.forEach( function ( tangent, i ) {
  20452. assert.numEqual( tangent.x, expectedTangent[ i ].x, "tangent[" + i + "].x" );
  20453. assert.numEqual( tangent.y, expectedTangent[ i ].y, "tangent[" + i + "].y" );
  20454. } );
  20455. } );
  20456. QUnit.test( "getUtoTmapping", ( assert ) => {
  20457. var curve = _curve;
  20458. var start = curve.getUtoTmapping( 0, 0 );
  20459. var end = curve.getUtoTmapping( 0, curve.getLength() );
  20460. var middle = curve.getUtoTmapping( 0.5, 0 );
  20461. assert.strictEqual( start, 0, "getUtoTmapping( 0, 0 ) is the starting point" );
  20462. assert.strictEqual( end, 1, "getUtoTmapping( 0, length ) is the ending point" );
  20463. assert.numEqual( middle, 0.5, "getUtoTmapping( 0.5, 0 ) is the middle" );
  20464. } );
  20465. QUnit.test( "getSpacedPoints", ( assert ) => {
  20466. var curve = _curve;
  20467. var expectedPoints = [
  20468. new Vector2( - 10, 0 ),
  20469. new Vector2( - 4.996509634683014, 4.999995128640857 ),
  20470. new Vector2( 0, 0 ),
  20471. new Vector2( 4.996509634683006, - 4.999995128640857 ),
  20472. new Vector2( 10, 0 )
  20473. ];
  20474. var points = curve.getSpacedPoints( 4 );
  20475. assert.strictEqual( points.length, expectedPoints.length, "Correct number of points" );
  20476. points.forEach( function ( point, i ) {
  20477. assert.numEqual( point.x, expectedPoints[ i ].x, "points[" + i + "].x" );
  20478. assert.numEqual( point.y, expectedPoints[ i ].y, "points[" + i + "].y" );
  20479. } );
  20480. } );
  20481. } );
  20482. } );
  20483. } );
  20484. /**
  20485. * @author TristanVALCKE / https://github.com/Itee
  20486. */
  20487. /* global QUnit */
  20488. QUnit.module( 'Extras', () => {
  20489. QUnit.module( 'Objects', () => {
  20490. QUnit.module.todo( 'ImmediateRenderObject', () => {
  20491. // INHERITANCE
  20492. QUnit.test( "Extending", ( assert ) => {
  20493. assert.ok( false, "everything's gonna be alright" );
  20494. } );
  20495. // INSTANCING
  20496. QUnit.test( "Instancing", ( assert ) => {
  20497. assert.ok( false, "everything's gonna be alright" );
  20498. } );
  20499. // PUBLIC STUFF
  20500. QUnit.test( "isImmediateRenderObject", ( assert ) => {
  20501. assert.ok( false, "everything's gonna be alright" );
  20502. } );
  20503. } );
  20504. } );
  20505. } );
  20506. /**
  20507. * @author TristanVALCKE / https://github.com/Itee
  20508. * @author Anonymous
  20509. */
  20510. /* global QUnit */
  20511. QUnit.module( 'Geometries', () => {
  20512. QUnit.module.todo( 'BoxGeometry', ( hooks ) => {
  20513. var geometries = undefined;
  20514. hooks.beforeEach( function () {
  20515. const parameters = {
  20516. width: 10,
  20517. height: 20,
  20518. depth: 30,
  20519. widthSegments: 2,
  20520. heightSegments: 3,
  20521. depthSegments: 4
  20522. };
  20523. geometries = [
  20524. new BoxGeometry(),
  20525. new BoxGeometry( parameters.width, parameters.height, parameters.depth ),
  20526. new BoxGeometry( parameters.width, parameters.height, parameters.depth, parameters.widthSegments, parameters.heightSegments, parameters.depthSegments )
  20527. ];
  20528. } );
  20529. // INHERITANCE
  20530. QUnit.test( "Extending", ( assert ) => {
  20531. assert.ok( false, "everything's gonna be alright" );
  20532. } );
  20533. // INSTANCING
  20534. QUnit.test( "Instancing", ( assert ) => {
  20535. assert.ok( false, "everything's gonna be alright" );
  20536. } );
  20537. // OTHERS
  20538. QUnit.test( 'Standard geometry tests', ( assert ) => {
  20539. runStdGeometryTests( assert, geometries );
  20540. } );
  20541. } );
  20542. QUnit.module.todo( 'BoxBufferGeometry', ( hooks ) => {
  20543. var geometries = undefined;
  20544. hooks.beforeEach( function () {
  20545. const parameters = {
  20546. width: 10,
  20547. height: 20,
  20548. depth: 30,
  20549. widthSegments: 2,
  20550. heightSegments: 3,
  20551. depthSegments: 4
  20552. };
  20553. geometries = [
  20554. new BoxBufferGeometry(),
  20555. new BoxBufferGeometry( parameters.width, parameters.height, parameters.depth ),
  20556. new BoxBufferGeometry( parameters.width, parameters.height, parameters.depth, parameters.widthSegments, parameters.heightSegments, parameters.depthSegments )
  20557. ];
  20558. } );
  20559. // INHERITANCE
  20560. QUnit.test( "Extending", ( assert ) => {
  20561. assert.ok( false, "everything's gonna be alright" );
  20562. } );
  20563. // INSTANCING
  20564. QUnit.test( "Instancing", ( assert ) => {
  20565. assert.ok( false, "everything's gonna be alright" );
  20566. } );
  20567. // OTHERS
  20568. QUnit.test( 'Standard geometry tests', ( assert ) => {
  20569. runStdGeometryTests( assert, geometries );
  20570. } );
  20571. } );
  20572. } );
  20573. /**
  20574. * @author benaadams / https://twitter.com/ben_a_adams
  20575. * @author Mugen87 / https://github.com/Mugen87
  20576. * @author hughes
  20577. */
  20578. // CircleGeometry
  20579. function CircleGeometry( radius, segments, thetaStart, thetaLength ) {
  20580. Geometry.call( this );
  20581. this.type = 'CircleGeometry';
  20582. this.parameters = {
  20583. radius: radius,
  20584. segments: segments,
  20585. thetaStart: thetaStart,
  20586. thetaLength: thetaLength
  20587. };
  20588. this.fromBufferGeometry( new CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
  20589. this.mergeVertices();
  20590. }
  20591. CircleGeometry.prototype = Object.create( Geometry.prototype );
  20592. CircleGeometry.prototype.constructor = CircleGeometry;
  20593. // CircleBufferGeometry
  20594. function CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) {
  20595. BufferGeometry.call( this );
  20596. this.type = 'CircleBufferGeometry';
  20597. this.parameters = {
  20598. radius: radius,
  20599. segments: segments,
  20600. thetaStart: thetaStart,
  20601. thetaLength: thetaLength
  20602. };
  20603. radius = radius || 50;
  20604. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  20605. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  20606. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  20607. // buffers
  20608. var indices = [];
  20609. var vertices = [];
  20610. var normals = [];
  20611. var uvs = [];
  20612. // helper variables
  20613. var i, s;
  20614. var vertex = new Vector3();
  20615. var uv = new Vector2();
  20616. // center point
  20617. vertices.push( 0, 0, 0 );
  20618. normals.push( 0, 0, 1 );
  20619. uvs.push( 0.5, 0.5 );
  20620. for ( s = 0, i = 3; s <= segments; s ++, i += 3 ) {
  20621. var segment = thetaStart + s / segments * thetaLength;
  20622. // vertex
  20623. vertex.x = radius * Math.cos( segment );
  20624. vertex.y = radius * Math.sin( segment );
  20625. vertices.push( vertex.x, vertex.y, vertex.z );
  20626. // normal
  20627. normals.push( 0, 0, 1 );
  20628. // uvs
  20629. uv.x = ( vertices[ i ] / radius + 1 ) / 2;
  20630. uv.y = ( vertices[ i + 1 ] / radius + 1 ) / 2;
  20631. uvs.push( uv.x, uv.y );
  20632. }
  20633. // indices
  20634. for ( i = 1; i <= segments; i ++ ) {
  20635. indices.push( i, i + 1, 0 );
  20636. }
  20637. // build geometry
  20638. this.setIndex( indices );
  20639. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  20640. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  20641. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  20642. }
  20643. CircleBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  20644. CircleBufferGeometry.prototype.constructor = CircleBufferGeometry;
  20645. /**
  20646. * @author TristanVALCKE / https://github.com/Itee
  20647. * @author Anonymous
  20648. */
  20649. /* global QUnit */
  20650. QUnit.module( 'Geometries', () => {
  20651. QUnit.module.todo( 'CircleGeometry', ( hooks ) => {
  20652. var geometries = undefined;
  20653. hooks.beforeEach( function () {
  20654. const parameters = {
  20655. radius: 10,
  20656. segments: 20,
  20657. thetaStart: 0.1,
  20658. thetaLength: 0.2
  20659. };
  20660. geometries = [
  20661. new CircleGeometry(),
  20662. new CircleGeometry( parameters.radius ),
  20663. new CircleGeometry( parameters.radius, parameters.segments ),
  20664. new CircleGeometry( parameters.radius, parameters.segments, parameters.thetaStart ),
  20665. new CircleGeometry( parameters.radius, parameters.segments, parameters.thetaStart, parameters.thetaLength ),
  20666. ];
  20667. } );
  20668. // INHERITANCE
  20669. QUnit.test( "Extending", ( assert ) => {
  20670. assert.ok( false, "everything's gonna be alright" );
  20671. } );
  20672. // INSTANCING
  20673. QUnit.test( "Instancing", ( assert ) => {
  20674. assert.ok( false, "everything's gonna be alright" );
  20675. } );
  20676. // OTHERS
  20677. QUnit.test( 'Standard geometry tests', ( assert ) => {
  20678. runStdGeometryTests( assert, geometries );
  20679. } );
  20680. } );
  20681. QUnit.module.todo( 'CircleBufferGeometry', ( hooks ) => {
  20682. var geometries = undefined;
  20683. hooks.beforeEach( function () {
  20684. const parameters = {
  20685. radius: 10,
  20686. segments: 20,
  20687. thetaStart: 0.1,
  20688. thetaLength: 0.2
  20689. };
  20690. geometries = [
  20691. new CircleBufferGeometry(),
  20692. new CircleBufferGeometry( parameters.radius ),
  20693. new CircleBufferGeometry( parameters.radius, parameters.segments ),
  20694. new CircleBufferGeometry( parameters.radius, parameters.segments, parameters.thetaStart ),
  20695. new CircleBufferGeometry( parameters.radius, parameters.segments, parameters.thetaStart, parameters.thetaLength ),
  20696. ];
  20697. } );
  20698. // INHERITANCE
  20699. QUnit.test( "Extending", ( assert ) => {
  20700. assert.ok( false, "everything's gonna be alright" );
  20701. } );
  20702. // INSTANCING
  20703. QUnit.test( "Instancing", ( assert ) => {
  20704. assert.ok( false, "everything's gonna be alright" );
  20705. } );
  20706. // OTHERS
  20707. QUnit.test( 'Standard geometry tests', ( assert ) => {
  20708. runStdGeometryTests( assert, geometries );
  20709. } );
  20710. } );
  20711. } );
  20712. /**
  20713. * @author mrdoob / http://mrdoob.com/
  20714. * @author Mugen87 / https://github.com/Mugen87
  20715. */
  20716. // CylinderGeometry
  20717. function CylinderGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  20718. Geometry.call( this );
  20719. this.type = 'CylinderGeometry';
  20720. this.parameters = {
  20721. radiusTop: radiusTop,
  20722. radiusBottom: radiusBottom,
  20723. height: height,
  20724. radialSegments: radialSegments,
  20725. heightSegments: heightSegments,
  20726. openEnded: openEnded,
  20727. thetaStart: thetaStart,
  20728. thetaLength: thetaLength
  20729. };
  20730. this.fromBufferGeometry( new CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) );
  20731. this.mergeVertices();
  20732. }
  20733. CylinderGeometry.prototype = Object.create( Geometry.prototype );
  20734. CylinderGeometry.prototype.constructor = CylinderGeometry;
  20735. // CylinderBufferGeometry
  20736. function CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  20737. BufferGeometry.call( this );
  20738. this.type = 'CylinderBufferGeometry';
  20739. this.parameters = {
  20740. radiusTop: radiusTop,
  20741. radiusBottom: radiusBottom,
  20742. height: height,
  20743. radialSegments: radialSegments,
  20744. heightSegments: heightSegments,
  20745. openEnded: openEnded,
  20746. thetaStart: thetaStart,
  20747. thetaLength: thetaLength
  20748. };
  20749. var scope = this;
  20750. radiusTop = radiusTop !== undefined ? radiusTop : 20;
  20751. radiusBottom = radiusBottom !== undefined ? radiusBottom : 20;
  20752. height = height !== undefined ? height : 100;
  20753. radialSegments = Math.floor( radialSegments ) || 8;
  20754. heightSegments = Math.floor( heightSegments ) || 1;
  20755. openEnded = openEnded !== undefined ? openEnded : false;
  20756. thetaStart = thetaStart !== undefined ? thetaStart : 0.0;
  20757. thetaLength = thetaLength !== undefined ? thetaLength : 2.0 * Math.PI;
  20758. // buffers
  20759. var indices = [];
  20760. var vertices = [];
  20761. var normals = [];
  20762. var uvs = [];
  20763. // helper variables
  20764. var index = 0;
  20765. var indexArray = [];
  20766. var halfHeight = height / 2;
  20767. var groupStart = 0;
  20768. // generate geometry
  20769. generateTorso();
  20770. if ( openEnded === false ) {
  20771. if ( radiusTop > 0 ) generateCap( true );
  20772. if ( radiusBottom > 0 ) generateCap( false );
  20773. }
  20774. // build geometry
  20775. this.setIndex( indices );
  20776. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  20777. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  20778. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  20779. function generateTorso() {
  20780. var x, y;
  20781. var normal = new Vector3();
  20782. var vertex = new Vector3();
  20783. var groupCount = 0;
  20784. // this will be used to calculate the normal
  20785. var slope = ( radiusBottom - radiusTop ) / height;
  20786. // generate vertices, normals and uvs
  20787. for ( y = 0; y <= heightSegments; y ++ ) {
  20788. var indexRow = [];
  20789. var v = y / heightSegments;
  20790. // calculate the radius of the current row
  20791. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  20792. for ( x = 0; x <= radialSegments; x ++ ) {
  20793. var u = x / radialSegments;
  20794. var theta = u * thetaLength + thetaStart;
  20795. var sinTheta = Math.sin( theta );
  20796. var cosTheta = Math.cos( theta );
  20797. // vertex
  20798. vertex.x = radius * sinTheta;
  20799. vertex.y = - v * height + halfHeight;
  20800. vertex.z = radius * cosTheta;
  20801. vertices.push( vertex.x, vertex.y, vertex.z );
  20802. // normal
  20803. normal.set( sinTheta, slope, cosTheta ).normalize();
  20804. normals.push( normal.x, normal.y, normal.z );
  20805. // uv
  20806. uvs.push( u, 1 - v );
  20807. // save index of vertex in respective row
  20808. indexRow.push( index ++ );
  20809. }
  20810. // now save vertices of the row in our index array
  20811. indexArray.push( indexRow );
  20812. }
  20813. // generate indices
  20814. for ( x = 0; x < radialSegments; x ++ ) {
  20815. for ( y = 0; y < heightSegments; y ++ ) {
  20816. // we use the index array to access the correct indices
  20817. var a = indexArray[ y ][ x ];
  20818. var b = indexArray[ y + 1 ][ x ];
  20819. var c = indexArray[ y + 1 ][ x + 1 ];
  20820. var d = indexArray[ y ][ x + 1 ];
  20821. // faces
  20822. indices.push( a, b, d );
  20823. indices.push( b, c, d );
  20824. // update group counter
  20825. groupCount += 6;
  20826. }
  20827. }
  20828. // add a group to the geometry. this will ensure multi material support
  20829. scope.addGroup( groupStart, groupCount, 0 );
  20830. // calculate new start value for groups
  20831. groupStart += groupCount;
  20832. }
  20833. function generateCap( top ) {
  20834. var x, centerIndexStart, centerIndexEnd;
  20835. var uv = new Vector2();
  20836. var vertex = new Vector3();
  20837. var groupCount = 0;
  20838. var radius = ( top === true ) ? radiusTop : radiusBottom;
  20839. var sign = ( top === true ) ? 1 : - 1;
  20840. // save the index of the first center vertex
  20841. centerIndexStart = index;
  20842. // first we generate the center vertex data of the cap.
  20843. // because the geometry needs one set of uvs per face,
  20844. // we must generate a center vertex per face/segment
  20845. for ( x = 1; x <= radialSegments; x ++ ) {
  20846. // vertex
  20847. vertices.push( 0, halfHeight * sign, 0 );
  20848. // normal
  20849. normals.push( 0, sign, 0 );
  20850. // uv
  20851. uvs.push( 0.5, 0.5 );
  20852. // increase index
  20853. index ++;
  20854. }
  20855. // save the index of the last center vertex
  20856. centerIndexEnd = index;
  20857. // now we generate the surrounding vertices, normals and uvs
  20858. for ( x = 0; x <= radialSegments; x ++ ) {
  20859. var u = x / radialSegments;
  20860. var theta = u * thetaLength + thetaStart;
  20861. var cosTheta = Math.cos( theta );
  20862. var sinTheta = Math.sin( theta );
  20863. // vertex
  20864. vertex.x = radius * sinTheta;
  20865. vertex.y = halfHeight * sign;
  20866. vertex.z = radius * cosTheta;
  20867. vertices.push( vertex.x, vertex.y, vertex.z );
  20868. // normal
  20869. normals.push( 0, sign, 0 );
  20870. // uv
  20871. uv.x = ( cosTheta * 0.5 ) + 0.5;
  20872. uv.y = ( sinTheta * 0.5 * sign ) + 0.5;
  20873. uvs.push( uv.x, uv.y );
  20874. // increase index
  20875. index ++;
  20876. }
  20877. // generate indices
  20878. for ( x = 0; x < radialSegments; x ++ ) {
  20879. var c = centerIndexStart + x;
  20880. var i = centerIndexEnd + x;
  20881. if ( top === true ) {
  20882. // face top
  20883. indices.push( i, i + 1, c );
  20884. } else {
  20885. // face bottom
  20886. indices.push( i + 1, i, c );
  20887. }
  20888. groupCount += 3;
  20889. }
  20890. // add a group to the geometry. this will ensure multi material support
  20891. scope.addGroup( groupStart, groupCount, top === true ? 1 : 2 );
  20892. // calculate new start value for groups
  20893. groupStart += groupCount;
  20894. }
  20895. }
  20896. CylinderBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  20897. CylinderBufferGeometry.prototype.constructor = CylinderBufferGeometry;
  20898. /**
  20899. * @author abelnation / http://github.com/abelnation
  20900. */
  20901. // ConeGeometry
  20902. function ConeGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  20903. CylinderGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  20904. this.type = 'ConeGeometry';
  20905. this.parameters = {
  20906. radius: radius,
  20907. height: height,
  20908. radialSegments: radialSegments,
  20909. heightSegments: heightSegments,
  20910. openEnded: openEnded,
  20911. thetaStart: thetaStart,
  20912. thetaLength: thetaLength
  20913. };
  20914. }
  20915. ConeGeometry.prototype = Object.create( CylinderGeometry.prototype );
  20916. ConeGeometry.prototype.constructor = ConeGeometry;
  20917. // ConeBufferGeometry
  20918. function ConeBufferGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  20919. CylinderBufferGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  20920. this.type = 'ConeBufferGeometry';
  20921. this.parameters = {
  20922. radius: radius,
  20923. height: height,
  20924. radialSegments: radialSegments,
  20925. heightSegments: heightSegments,
  20926. openEnded: openEnded,
  20927. thetaStart: thetaStart,
  20928. thetaLength: thetaLength
  20929. };
  20930. }
  20931. ConeBufferGeometry.prototype = Object.create( CylinderBufferGeometry.prototype );
  20932. ConeBufferGeometry.prototype.constructor = ConeBufferGeometry;
  20933. /**
  20934. * @author TristanVALCKE / https://github.com/Itee
  20935. */
  20936. /* global QUnit */
  20937. QUnit.module( 'Geometries', () => {
  20938. QUnit.module.todo( 'ConeGeometry', ( hooks ) => {
  20939. var geometries = undefined;
  20940. hooks.beforeEach( function () {
  20941. const parameters = {};
  20942. geometries = [
  20943. new ConeGeometry()
  20944. ];
  20945. } );
  20946. // INHERITANCE
  20947. QUnit.test( "Extending", ( assert ) => {
  20948. assert.ok( false, "everything's gonna be alright" );
  20949. } );
  20950. // INSTANCING
  20951. QUnit.test( "Instancing", ( assert ) => {
  20952. assert.ok( false, "everything's gonna be alright" );
  20953. } );
  20954. // OTHERS
  20955. QUnit.test( 'Standard geometry tests', ( assert ) => {
  20956. runStdGeometryTests( assert, geometries );
  20957. } );
  20958. } );
  20959. QUnit.module.todo( 'ConeBufferGeometry', ( hooks ) => {
  20960. var geometries = undefined;
  20961. hooks.beforeEach( function () {
  20962. const parameters = {};
  20963. geometries = [
  20964. new ConeBufferGeometry()
  20965. ];
  20966. } );
  20967. // INHERITANCE
  20968. QUnit.test( "Extending", ( assert ) => {
  20969. assert.ok( false, "everything's gonna be alright" );
  20970. } );
  20971. // INSTANCING
  20972. QUnit.test( "Instancing", ( assert ) => {
  20973. assert.ok( false, "everything's gonna be alright" );
  20974. } );
  20975. // OTHERS
  20976. QUnit.test( 'Standard geometry tests', ( assert ) => {
  20977. runStdGeometryTests( assert, geometries );
  20978. } );
  20979. } );
  20980. } );
  20981. /**
  20982. * @author TristanVALCKE / https://github.com/Itee
  20983. * @author Anonymous
  20984. */
  20985. /* global QUnit */
  20986. QUnit.module( 'Geometries', () => {
  20987. QUnit.module.todo( 'CylinderGeometry', ( hooks ) => {
  20988. var geometries = undefined;
  20989. hooks.beforeEach( function () {
  20990. const parameters = {
  20991. radiusTop: 10,
  20992. radiusBottom: 20,
  20993. height: 30,
  20994. radialSegments: 20,
  20995. heightSegments: 30,
  20996. openEnded: true,
  20997. thetaStart: 0.1,
  20998. thetaLength: 2.0,
  20999. };
  21000. geometries = [
  21001. new CylinderGeometry(),
  21002. new CylinderGeometry( parameters.radiusTop ),
  21003. new CylinderGeometry( parameters.radiusTop, parameters.radiusBottom ),
  21004. new CylinderGeometry( parameters.radiusTop, parameters.radiusBottom, parameters.height ),
  21005. new CylinderGeometry( parameters.radiusTop, parameters.radiusBottom, parameters.height, parameters.radialSegments ),
  21006. new CylinderGeometry( parameters.radiusTop, parameters.radiusBottom, parameters.height, parameters.radialSegments, parameters.heightSegments ),
  21007. new CylinderGeometry( parameters.radiusTop, parameters.radiusBottom, parameters.height, parameters.radialSegments, parameters.heightSegments, parameters.openEnded ),
  21008. new CylinderGeometry( parameters.radiusTop, parameters.radiusBottom, parameters.height, parameters.radialSegments, parameters.heightSegments, parameters.openEnded, parameters.thetaStart ),
  21009. new CylinderGeometry( parameters.radiusTop, parameters.radiusBottom, parameters.height, parameters.radialSegments, parameters.heightSegments, parameters.openEnded, parameters.thetaStart, parameters.thetaLength ),
  21010. ];
  21011. } );
  21012. // INHERITANCE
  21013. QUnit.test( "Extending", ( assert ) => {
  21014. assert.ok( false, "everything's gonna be alright" );
  21015. } );
  21016. // INSTANCING
  21017. QUnit.test( "Instancing", ( assert ) => {
  21018. assert.ok( false, "everything's gonna be alright" );
  21019. } );
  21020. // OTHERS
  21021. QUnit.test( 'Standard geometry tests', ( assert ) => {
  21022. runStdGeometryTests( assert, geometries );
  21023. } );
  21024. } );
  21025. QUnit.module.todo( 'CylinderBufferGeometry', ( hooks ) => {
  21026. var geometries = undefined;
  21027. hooks.beforeEach( function () {
  21028. const parameters = {
  21029. radiusTop: 10,
  21030. radiusBottom: 20,
  21031. height: 30,
  21032. radialSegments: 20,
  21033. heightSegments: 30,
  21034. openEnded: true,
  21035. thetaStart: 0.1,
  21036. thetaLength: 2.0,
  21037. };
  21038. geometries = [
  21039. new CylinderBufferGeometry(),
  21040. new CylinderBufferGeometry( parameters.radiusTop ),
  21041. new CylinderBufferGeometry( parameters.radiusTop, parameters.radiusBottom ),
  21042. new CylinderBufferGeometry( parameters.radiusTop, parameters.radiusBottom, parameters.height ),
  21043. new CylinderBufferGeometry( parameters.radiusTop, parameters.radiusBottom, parameters.height, parameters.radialSegments ),
  21044. new CylinderBufferGeometry( parameters.radiusTop, parameters.radiusBottom, parameters.height, parameters.radialSegments, parameters.heightSegments ),
  21045. new CylinderBufferGeometry( parameters.radiusTop, parameters.radiusBottom, parameters.height, parameters.radialSegments, parameters.heightSegments, parameters.openEnded ),
  21046. new CylinderBufferGeometry( parameters.radiusTop, parameters.radiusBottom, parameters.height, parameters.radialSegments, parameters.heightSegments, parameters.openEnded, parameters.thetaStart ),
  21047. new CylinderBufferGeometry( parameters.radiusTop, parameters.radiusBottom, parameters.height, parameters.radialSegments, parameters.heightSegments, parameters.openEnded, parameters.thetaStart, parameters.thetaLength ),
  21048. ];
  21049. } );
  21050. // INHERITANCE
  21051. QUnit.test( "Extending", ( assert ) => {
  21052. assert.ok( false, "everything's gonna be alright" );
  21053. } );
  21054. // INSTANCING
  21055. QUnit.test( "Instancing", ( assert ) => {
  21056. assert.ok( false, "everything's gonna be alright" );
  21057. } );
  21058. // OTHERS
  21059. QUnit.test( 'Standard geometry tests', ( assert ) => {
  21060. runStdGeometryTests( assert, geometries );
  21061. } );
  21062. } );
  21063. } );
  21064. /**
  21065. * @author TristanVALCKE / https://github.com/Itee
  21066. * @author Anonymous
  21067. */
  21068. /* global QUnit */
  21069. QUnit.module( 'Geometries', () => {
  21070. QUnit.module.todo( 'CircleGeometry', ( hooks ) => {
  21071. var geometries = undefined;
  21072. hooks.beforeEach( function () {
  21073. const parameters = {
  21074. radius: 10,
  21075. detail: undefined
  21076. };
  21077. geometries = [
  21078. new DodecahedronGeometry(),
  21079. new DodecahedronGeometry( parameters.radius ),
  21080. new DodecahedronGeometry( parameters.radius, parameters.detail ),
  21081. ];
  21082. } );
  21083. // INHERITANCE
  21084. QUnit.test( "Extending", ( assert ) => {
  21085. assert.ok( false, "everything's gonna be alright" );
  21086. } );
  21087. // INSTANCING
  21088. QUnit.test( "Instancing", ( assert ) => {
  21089. assert.ok( false, "everything's gonna be alright" );
  21090. } );
  21091. // OTHERS
  21092. QUnit.test( 'Standard geometry tests', ( assert ) => {
  21093. runStdGeometryTests( assert, geometries );
  21094. } );
  21095. } );
  21096. QUnit.module.todo( 'CircleBufferGeometry', ( hooks ) => {
  21097. var geometries = undefined;
  21098. hooks.beforeEach( function () {
  21099. const parameters = {
  21100. radius: 10,
  21101. detail: undefined
  21102. };
  21103. geometries = [
  21104. new DodecahedronBufferGeometry(),
  21105. new DodecahedronBufferGeometry( parameters.radius ),
  21106. new DodecahedronBufferGeometry( parameters.radius, parameters.detail ),
  21107. ];
  21108. } );
  21109. // INHERITANCE
  21110. QUnit.test( "Extending", ( assert ) => {
  21111. assert.ok( false, "everything's gonna be alright" );
  21112. } );
  21113. // INSTANCING
  21114. QUnit.test( "Instancing", ( assert ) => {
  21115. assert.ok( false, "everything's gonna be alright" );
  21116. } );
  21117. // OTHERS
  21118. QUnit.test( 'Standard geometry tests', ( assert ) => {
  21119. runStdGeometryTests( assert, geometries );
  21120. } );
  21121. } );
  21122. } );
  21123. /**
  21124. * @author WestLangley / http://github.com/WestLangley
  21125. * @author Mugen87 / https://github.com/Mugen87
  21126. */
  21127. function EdgesGeometry( geometry, thresholdAngle ) {
  21128. BufferGeometry.call( this );
  21129. this.type = 'EdgesGeometry';
  21130. this.parameters = {
  21131. thresholdAngle: thresholdAngle
  21132. };
  21133. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  21134. // buffer
  21135. var vertices = [];
  21136. // helper variables
  21137. var thresholdDot = Math.cos( _Math.DEG2RAD * thresholdAngle );
  21138. var edge = [ 0, 0 ], edges = {}, edge1, edge2;
  21139. var key, keys = [ 'a', 'b', 'c' ];
  21140. // prepare source geometry
  21141. var geometry2;
  21142. if ( geometry.isBufferGeometry ) {
  21143. geometry2 = new Geometry();
  21144. geometry2.fromBufferGeometry( geometry );
  21145. } else {
  21146. geometry2 = geometry.clone();
  21147. }
  21148. geometry2.mergeVertices();
  21149. geometry2.computeFaceNormals();
  21150. var sourceVertices = geometry2.vertices;
  21151. var faces = geometry2.faces;
  21152. // now create a data structure where each entry represents an edge with its adjoining faces
  21153. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  21154. var face = faces[ i ];
  21155. for ( var j = 0; j < 3; j ++ ) {
  21156. edge1 = face[ keys[ j ] ];
  21157. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  21158. edge[ 0 ] = Math.min( edge1, edge2 );
  21159. edge[ 1 ] = Math.max( edge1, edge2 );
  21160. key = edge[ 0 ] + ',' + edge[ 1 ];
  21161. if ( edges[ key ] === undefined ) {
  21162. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ], face1: i, face2: undefined };
  21163. } else {
  21164. edges[ key ].face2 = i;
  21165. }
  21166. }
  21167. }
  21168. // generate vertices
  21169. for ( key in edges ) {
  21170. var e = edges[ key ];
  21171. // an edge is only rendered if the angle (in degrees) between the face normals of the adjoining faces exceeds this value. default = 1 degree.
  21172. if ( e.face2 === undefined || faces[ e.face1 ].normal.dot( faces[ e.face2 ].normal ) <= thresholdDot ) {
  21173. var vertex = sourceVertices[ e.index1 ];
  21174. vertices.push( vertex.x, vertex.y, vertex.z );
  21175. vertex = sourceVertices[ e.index2 ];
  21176. vertices.push( vertex.x, vertex.y, vertex.z );
  21177. }
  21178. }
  21179. // build geometry
  21180. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  21181. }
  21182. EdgesGeometry.prototype = Object.create( BufferGeometry.prototype );
  21183. EdgesGeometry.prototype.constructor = EdgesGeometry;
  21184. /**
  21185. * @author mrdoob / http://mrdoob.com/
  21186. */
  21187. function Scene() {
  21188. Object3D.call( this );
  21189. this.type = 'Scene';
  21190. this.background = null;
  21191. this.fog = null;
  21192. this.overrideMaterial = null;
  21193. this.autoUpdate = true; // checked by the renderer
  21194. }
  21195. Scene.prototype = Object.assign( Object.create( Object3D.prototype ), {
  21196. constructor: Scene,
  21197. copy: function ( source, recursive ) {
  21198. Object3D.prototype.copy.call( this, source, recursive );
  21199. if ( source.background !== null ) this.background = source.background.clone();
  21200. if ( source.fog !== null ) this.fog = source.fog.clone();
  21201. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  21202. this.autoUpdate = source.autoUpdate;
  21203. this.matrixAutoUpdate = source.matrixAutoUpdate;
  21204. return this;
  21205. },
  21206. toJSON: function ( meta ) {
  21207. var data = Object3D.prototype.toJSON.call( this, meta );
  21208. if ( this.background !== null ) data.object.background = this.background.toJSON( meta );
  21209. if ( this.fog !== null ) data.object.fog = this.fog.toJSON();
  21210. return data;
  21211. }
  21212. } );
  21213. /**
  21214. * @author alteredq / http://alteredqualia.com/
  21215. */
  21216. function DataTexture( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  21217. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  21218. this.image = { data: data, width: width, height: height };
  21219. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  21220. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  21221. this.generateMipmaps = false;
  21222. this.flipY = false;
  21223. this.unpackAlignment = 1;
  21224. }
  21225. DataTexture.prototype = Object.create( Texture.prototype );
  21226. DataTexture.prototype.constructor = DataTexture;
  21227. DataTexture.prototype.isDataTexture = true;
  21228. /**
  21229. * @author mrdoob / http://mrdoob.com/
  21230. */
  21231. function CubeTexture( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  21232. images = images !== undefined ? images : [];
  21233. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  21234. Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  21235. this.flipY = false;
  21236. }
  21237. CubeTexture.prototype = Object.create( Texture.prototype );
  21238. CubeTexture.prototype.constructor = CubeTexture;
  21239. CubeTexture.prototype.isCubeTexture = true;
  21240. Object.defineProperty( CubeTexture.prototype, 'images', {
  21241. get: function () {
  21242. return this.image;
  21243. },
  21244. set: function ( value ) {
  21245. this.image = value;
  21246. }
  21247. } );
  21248. /**
  21249. * @author tschw
  21250. *
  21251. * Uniforms of a program.
  21252. * Those form a tree structure with a special top-level container for the root,
  21253. * which you get by calling 'new WebGLUniforms( gl, program, renderer )'.
  21254. *
  21255. *
  21256. * Properties of inner nodes including the top-level container:
  21257. *
  21258. * .seq - array of nested uniforms
  21259. * .map - nested uniforms by name
  21260. *
  21261. *
  21262. * Methods of all nodes except the top-level container:
  21263. *
  21264. * .setValue( gl, value, [renderer] )
  21265. *
  21266. * uploads a uniform value(s)
  21267. * the 'renderer' parameter is needed for sampler uniforms
  21268. *
  21269. *
  21270. * Static methods of the top-level container (renderer factorizations):
  21271. *
  21272. * .upload( gl, seq, values, renderer )
  21273. *
  21274. * sets uniforms in 'seq' to 'values[id].value'
  21275. *
  21276. * .seqWithValue( seq, values ) : filteredSeq
  21277. *
  21278. * filters 'seq' entries with corresponding entry in values
  21279. *
  21280. *
  21281. * Methods of the top-level container (renderer factorizations):
  21282. *
  21283. * .setValue( gl, name, value )
  21284. *
  21285. * sets uniform with name 'name' to 'value'
  21286. *
  21287. * .set( gl, obj, prop )
  21288. *
  21289. * sets uniform from object and property with same name than uniform
  21290. *
  21291. * .setOptional( gl, obj, prop )
  21292. *
  21293. * like .set for an optional property of the object
  21294. *
  21295. */
  21296. var emptyTexture = new Texture();
  21297. var emptyCubeTexture = new CubeTexture();
  21298. // --- Base for inner nodes (including the root) ---
  21299. function UniformContainer() {
  21300. this.seq = [];
  21301. this.map = {};
  21302. }
  21303. // --- Utilities ---
  21304. // Array Caches (provide typed arrays for temporary by size)
  21305. var arrayCacheF32 = [];
  21306. var arrayCacheI32 = [];
  21307. // Float32Array caches used for uploading Matrix uniforms
  21308. var mat4array = new Float32Array( 16 );
  21309. var mat3array = new Float32Array( 9 );
  21310. // Flattening for arrays of vectors and matrices
  21311. function flatten( array, nBlocks, blockSize ) {
  21312. var firstElem = array[ 0 ];
  21313. if ( firstElem <= 0 || firstElem > 0 ) return array;
  21314. // unoptimized: ! isNaN( firstElem )
  21315. // see http://jacksondunstan.com/articles/983
  21316. var n = nBlocks * blockSize,
  21317. r = arrayCacheF32[ n ];
  21318. if ( r === undefined ) {
  21319. r = new Float32Array( n );
  21320. arrayCacheF32[ n ] = r;
  21321. }
  21322. if ( nBlocks !== 0 ) {
  21323. firstElem.toArray( r, 0 );
  21324. for ( var i = 1, offset = 0; i !== nBlocks; ++ i ) {
  21325. offset += blockSize;
  21326. array[ i ].toArray( r, offset );
  21327. }
  21328. }
  21329. return r;
  21330. }
  21331. // Texture unit allocation
  21332. function allocTexUnits( renderer, n ) {
  21333. var r = arrayCacheI32[ n ];
  21334. if ( r === undefined ) {
  21335. r = new Int32Array( n );
  21336. arrayCacheI32[ n ] = r;
  21337. }
  21338. for ( var i = 0; i !== n; ++ i )
  21339. r[ i ] = renderer.allocTextureUnit();
  21340. return r;
  21341. }
  21342. // --- Setters ---
  21343. // Note: Defining these methods externally, because they come in a bunch
  21344. // and this way their names minify.
  21345. // Single scalar
  21346. function setValue1f( gl, v ) {
  21347. gl.uniform1f( this.addr, v );
  21348. }
  21349. function setValue1i( gl, v ) {
  21350. gl.uniform1i( this.addr, v );
  21351. }
  21352. // Single float vector (from flat array or THREE.VectorN)
  21353. function setValue2fv( gl, v ) {
  21354. if ( v.x === undefined ) {
  21355. gl.uniform2fv( this.addr, v );
  21356. } else {
  21357. gl.uniform2f( this.addr, v.x, v.y );
  21358. }
  21359. }
  21360. function setValue3fv( gl, v ) {
  21361. if ( v.x !== undefined ) {
  21362. gl.uniform3f( this.addr, v.x, v.y, v.z );
  21363. } else if ( v.r !== undefined ) {
  21364. gl.uniform3f( this.addr, v.r, v.g, v.b );
  21365. } else {
  21366. gl.uniform3fv( this.addr, v );
  21367. }
  21368. }
  21369. function setValue4fv( gl, v ) {
  21370. if ( v.x === undefined ) {
  21371. gl.uniform4fv( this.addr, v );
  21372. } else {
  21373. gl.uniform4f( this.addr, v.x, v.y, v.z, v.w );
  21374. }
  21375. }
  21376. // Single matrix (from flat array or MatrixN)
  21377. function setValue2fm( gl, v ) {
  21378. gl.uniformMatrix2fv( this.addr, false, v.elements || v );
  21379. }
  21380. function setValue3fm( gl, v ) {
  21381. if ( v.elements === undefined ) {
  21382. gl.uniformMatrix3fv( this.addr, false, v );
  21383. } else {
  21384. mat3array.set( v.elements );
  21385. gl.uniformMatrix3fv( this.addr, false, mat3array );
  21386. }
  21387. }
  21388. function setValue4fm( gl, v ) {
  21389. if ( v.elements === undefined ) {
  21390. gl.uniformMatrix4fv( this.addr, false, v );
  21391. } else {
  21392. mat4array.set( v.elements );
  21393. gl.uniformMatrix4fv( this.addr, false, mat4array );
  21394. }
  21395. }
  21396. // Single texture (2D / Cube)
  21397. function setValueT1( gl, v, renderer ) {
  21398. var unit = renderer.allocTextureUnit();
  21399. gl.uniform1i( this.addr, unit );
  21400. renderer.setTexture2D( v || emptyTexture, unit );
  21401. }
  21402. function setValueT6( gl, v, renderer ) {
  21403. var unit = renderer.allocTextureUnit();
  21404. gl.uniform1i( this.addr, unit );
  21405. renderer.setTextureCube( v || emptyCubeTexture, unit );
  21406. }
  21407. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  21408. function setValue2iv( gl, v ) {
  21409. gl.uniform2iv( this.addr, v );
  21410. }
  21411. function setValue3iv( gl, v ) {
  21412. gl.uniform3iv( this.addr, v );
  21413. }
  21414. function setValue4iv( gl, v ) {
  21415. gl.uniform4iv( this.addr, v );
  21416. }
  21417. // Helper to pick the right setter for the singular case
  21418. function getSingularSetter( type ) {
  21419. switch ( type ) {
  21420. case 0x1406: return setValue1f; // FLOAT
  21421. case 0x8b50: return setValue2fv; // _VEC2
  21422. case 0x8b51: return setValue3fv; // _VEC3
  21423. case 0x8b52: return setValue4fv; // _VEC4
  21424. case 0x8b5a: return setValue2fm; // _MAT2
  21425. case 0x8b5b: return setValue3fm; // _MAT3
  21426. case 0x8b5c: return setValue4fm; // _MAT4
  21427. case 0x8b5e: case 0x8d66: return setValueT1; // SAMPLER_2D, SAMPLER_EXTERNAL_OES
  21428. case 0x8b60: return setValueT6; // SAMPLER_CUBE
  21429. case 0x1404: case 0x8b56: return setValue1i; // INT, BOOL
  21430. case 0x8b53: case 0x8b57: return setValue2iv; // _VEC2
  21431. case 0x8b54: case 0x8b58: return setValue3iv; // _VEC3
  21432. case 0x8b55: case 0x8b59: return setValue4iv; // _VEC4
  21433. }
  21434. }
  21435. // Array of scalars
  21436. function setValue1fv( gl, v ) {
  21437. gl.uniform1fv( this.addr, v );
  21438. }
  21439. function setValue1iv( gl, v ) {
  21440. gl.uniform1iv( this.addr, v );
  21441. }
  21442. // Array of vectors (flat or from THREE classes)
  21443. function setValueV2a( gl, v ) {
  21444. gl.uniform2fv( this.addr, flatten( v, this.size, 2 ) );
  21445. }
  21446. function setValueV3a( gl, v ) {
  21447. gl.uniform3fv( this.addr, flatten( v, this.size, 3 ) );
  21448. }
  21449. function setValueV4a( gl, v ) {
  21450. gl.uniform4fv( this.addr, flatten( v, this.size, 4 ) );
  21451. }
  21452. // Array of matrices (flat or from THREE clases)
  21453. function setValueM2a( gl, v ) {
  21454. gl.uniformMatrix2fv( this.addr, false, flatten( v, this.size, 4 ) );
  21455. }
  21456. function setValueM3a( gl, v ) {
  21457. gl.uniformMatrix3fv( this.addr, false, flatten( v, this.size, 9 ) );
  21458. }
  21459. function setValueM4a( gl, v ) {
  21460. gl.uniformMatrix4fv( this.addr, false, flatten( v, this.size, 16 ) );
  21461. }
  21462. // Array of textures (2D / Cube)
  21463. function setValueT1a( gl, v, renderer ) {
  21464. var n = v.length,
  21465. units = allocTexUnits( renderer, n );
  21466. gl.uniform1iv( this.addr, units );
  21467. for ( var i = 0; i !== n; ++ i ) {
  21468. renderer.setTexture2D( v[ i ] || emptyTexture, units[ i ] );
  21469. }
  21470. }
  21471. function setValueT6a( gl, v, renderer ) {
  21472. var n = v.length,
  21473. units = allocTexUnits( renderer, n );
  21474. gl.uniform1iv( this.addr, units );
  21475. for ( var i = 0; i !== n; ++ i ) {
  21476. renderer.setTextureCube( v[ i ] || emptyCubeTexture, units[ i ] );
  21477. }
  21478. }
  21479. // Helper to pick the right setter for a pure (bottom-level) array
  21480. function getPureArraySetter( type ) {
  21481. switch ( type ) {
  21482. case 0x1406: return setValue1fv; // FLOAT
  21483. case 0x8b50: return setValueV2a; // _VEC2
  21484. case 0x8b51: return setValueV3a; // _VEC3
  21485. case 0x8b52: return setValueV4a; // _VEC4
  21486. case 0x8b5a: return setValueM2a; // _MAT2
  21487. case 0x8b5b: return setValueM3a; // _MAT3
  21488. case 0x8b5c: return setValueM4a; // _MAT4
  21489. case 0x8b5e: return setValueT1a; // SAMPLER_2D
  21490. case 0x8b60: return setValueT6a; // SAMPLER_CUBE
  21491. case 0x1404: case 0x8b56: return setValue1iv; // INT, BOOL
  21492. case 0x8b53: case 0x8b57: return setValue2iv; // _VEC2
  21493. case 0x8b54: case 0x8b58: return setValue3iv; // _VEC3
  21494. case 0x8b55: case 0x8b59: return setValue4iv; // _VEC4
  21495. }
  21496. }
  21497. // --- Uniform Classes ---
  21498. function SingleUniform( id, activeInfo, addr ) {
  21499. this.id = id;
  21500. this.addr = addr;
  21501. this.setValue = getSingularSetter( activeInfo.type );
  21502. // this.path = activeInfo.name; // DEBUG
  21503. }
  21504. function PureArrayUniform( id, activeInfo, addr ) {
  21505. this.id = id;
  21506. this.addr = addr;
  21507. this.size = activeInfo.size;
  21508. this.setValue = getPureArraySetter( activeInfo.type );
  21509. // this.path = activeInfo.name; // DEBUG
  21510. }
  21511. function StructuredUniform( id ) {
  21512. this.id = id;
  21513. UniformContainer.call( this ); // mix-in
  21514. }
  21515. StructuredUniform.prototype.setValue = function ( gl, value ) {
  21516. // Note: Don't need an extra 'renderer' parameter, since samplers
  21517. // are not allowed in structured uniforms.
  21518. var seq = this.seq;
  21519. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  21520. var u = seq[ i ];
  21521. u.setValue( gl, value[ u.id ] );
  21522. }
  21523. };
  21524. // --- Top-level ---
  21525. // Parser - builds up the property tree from the path strings
  21526. var RePathPart = /([\w\d_]+)(\])?(\[|\.)?/g;
  21527. // extracts
  21528. // - the identifier (member name or array index)
  21529. // - followed by an optional right bracket (found when array index)
  21530. // - followed by an optional left bracket or dot (type of subscript)
  21531. //
  21532. // Note: These portions can be read in a non-overlapping fashion and
  21533. // allow straightforward parsing of the hierarchy that WebGL encodes
  21534. // in the uniform names.
  21535. function addUniform( container, uniformObject ) {
  21536. container.seq.push( uniformObject );
  21537. container.map[ uniformObject.id ] = uniformObject;
  21538. }
  21539. function parseUniform( activeInfo, addr, container ) {
  21540. var path = activeInfo.name,
  21541. pathLength = path.length;
  21542. // reset RegExp object, because of the early exit of a previous run
  21543. RePathPart.lastIndex = 0;
  21544. for ( ; ; ) {
  21545. var match = RePathPart.exec( path ),
  21546. matchEnd = RePathPart.lastIndex,
  21547. id = match[ 1 ],
  21548. idIsIndex = match[ 2 ] === ']',
  21549. subscript = match[ 3 ];
  21550. if ( idIsIndex ) id = id | 0; // convert to integer
  21551. if ( subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength ) {
  21552. // bare name or "pure" bottom-level array "[0]" suffix
  21553. addUniform( container, subscript === undefined ?
  21554. new SingleUniform( id, activeInfo, addr ) :
  21555. new PureArrayUniform( id, activeInfo, addr ) );
  21556. break;
  21557. } else {
  21558. // step into inner node / create it in case it doesn't exist
  21559. var map = container.map, next = map[ id ];
  21560. if ( next === undefined ) {
  21561. next = new StructuredUniform( id );
  21562. addUniform( container, next );
  21563. }
  21564. container = next;
  21565. }
  21566. }
  21567. }
  21568. // Root Container
  21569. function WebGLUniforms( gl, program, renderer ) {
  21570. UniformContainer.call( this );
  21571. this.renderer = renderer;
  21572. var n = gl.getProgramParameter( program, gl.ACTIVE_UNIFORMS );
  21573. for ( var i = 0; i < n; ++ i ) {
  21574. var info = gl.getActiveUniform( program, i ),
  21575. path = info.name,
  21576. addr = gl.getUniformLocation( program, path );
  21577. parseUniform( info, addr, this );
  21578. }
  21579. }
  21580. WebGLUniforms.prototype.setValue = function ( gl, name, value ) {
  21581. var u = this.map[ name ];
  21582. if ( u !== undefined ) u.setValue( gl, value, this.renderer );
  21583. };
  21584. WebGLUniforms.prototype.setOptional = function ( gl, object, name ) {
  21585. var v = object[ name ];
  21586. if ( v !== undefined ) this.setValue( gl, name, v );
  21587. };
  21588. // Static interface
  21589. WebGLUniforms.upload = function ( gl, seq, values, renderer ) {
  21590. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  21591. var u = seq[ i ],
  21592. v = values[ u.id ];
  21593. if ( v.needsUpdate !== false ) {
  21594. // note: always updating when .needsUpdate is undefined
  21595. u.setValue( gl, v.value, renderer );
  21596. }
  21597. }
  21598. };
  21599. WebGLUniforms.seqWithValue = function ( seq, values ) {
  21600. var r = [];
  21601. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  21602. var u = seq[ i ];
  21603. if ( u.id in values ) r.push( u );
  21604. }
  21605. return r;
  21606. };
  21607. /**
  21608. * Uniforms library for shared webgl shaders
  21609. */
  21610. var UniformsLib = {
  21611. common: {
  21612. diffuse: { value: new Color( 0xeeeeee ) },
  21613. opacity: { value: 1.0 },
  21614. map: { value: null },
  21615. uvTransform: { value: new Matrix3() },
  21616. alphaMap: { value: null },
  21617. },
  21618. specularmap: {
  21619. specularMap: { value: null },
  21620. },
  21621. envmap: {
  21622. envMap: { value: null },
  21623. flipEnvMap: { value: - 1 },
  21624. reflectivity: { value: 1.0 },
  21625. refractionRatio: { value: 0.98 }
  21626. },
  21627. aomap: {
  21628. aoMap: { value: null },
  21629. aoMapIntensity: { value: 1 }
  21630. },
  21631. lightmap: {
  21632. lightMap: { value: null },
  21633. lightMapIntensity: { value: 1 }
  21634. },
  21635. emissivemap: {
  21636. emissiveMap: { value: null }
  21637. },
  21638. bumpmap: {
  21639. bumpMap: { value: null },
  21640. bumpScale: { value: 1 }
  21641. },
  21642. normalmap: {
  21643. normalMap: { value: null },
  21644. normalScale: { value: new Vector2( 1, 1 ) }
  21645. },
  21646. displacementmap: {
  21647. displacementMap: { value: null },
  21648. displacementScale: { value: 1 },
  21649. displacementBias: { value: 0 }
  21650. },
  21651. roughnessmap: {
  21652. roughnessMap: { value: null }
  21653. },
  21654. metalnessmap: {
  21655. metalnessMap: { value: null }
  21656. },
  21657. gradientmap: {
  21658. gradientMap: { value: null }
  21659. },
  21660. fog: {
  21661. fogDensity: { value: 0.00025 },
  21662. fogNear: { value: 1 },
  21663. fogFar: { value: 2000 },
  21664. fogColor: { value: new Color( 0xffffff ) }
  21665. },
  21666. lights: {
  21667. ambientLightColor: { value: [] },
  21668. directionalLights: { value: [], properties: {
  21669. direction: {},
  21670. color: {},
  21671. shadow: {},
  21672. shadowBias: {},
  21673. shadowRadius: {},
  21674. shadowMapSize: {}
  21675. } },
  21676. directionalShadowMap: { value: [] },
  21677. directionalShadowMatrix: { value: [] },
  21678. spotLights: { value: [], properties: {
  21679. color: {},
  21680. position: {},
  21681. direction: {},
  21682. distance: {},
  21683. coneCos: {},
  21684. penumbraCos: {},
  21685. decay: {},
  21686. shadow: {},
  21687. shadowBias: {},
  21688. shadowRadius: {},
  21689. shadowMapSize: {}
  21690. } },
  21691. spotShadowMap: { value: [] },
  21692. spotShadowMatrix: { value: [] },
  21693. pointLights: { value: [], properties: {
  21694. color: {},
  21695. position: {},
  21696. decay: {},
  21697. distance: {},
  21698. shadow: {},
  21699. shadowBias: {},
  21700. shadowRadius: {},
  21701. shadowMapSize: {},
  21702. shadowCameraNear: {},
  21703. shadowCameraFar: {}
  21704. } },
  21705. pointShadowMap: { value: [] },
  21706. pointShadowMatrix: { value: [] },
  21707. hemisphereLights: { value: [], properties: {
  21708. direction: {},
  21709. skyColor: {},
  21710. groundColor: {}
  21711. } },
  21712. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  21713. rectAreaLights: { value: [], properties: {
  21714. color: {},
  21715. position: {},
  21716. width: {},
  21717. height: {}
  21718. } }
  21719. },
  21720. points: {
  21721. diffuse: { value: new Color( 0xeeeeee ) },
  21722. opacity: { value: 1.0 },
  21723. size: { value: 1.0 },
  21724. scale: { value: 1.0 },
  21725. map: { value: null },
  21726. uvTransform: { value: new Matrix3() }
  21727. }
  21728. };
  21729. var alphamap_fragment = "#ifdef USE_ALPHAMAP\r\n\r\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\r\n\r\n#endif\r\n";
  21730. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\r\n\r\n\tuniform sampler2D alphaMap;\r\n\r\n#endif\r\n";
  21731. var alphatest_fragment = "#ifdef ALPHATEST\r\n\r\n\tif ( diffuseColor.a < ALPHATEST ) discard;\r\n\r\n#endif\r\n";
  21732. 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";
  21733. var aomap_pars_fragment = "#ifdef USE_AOMAP\r\n\r\n\tuniform sampler2D aoMap;\r\n\tuniform float aoMapIntensity;\r\n\r\n#endif";
  21734. var begin_vertex = "\r\nvec3 transformed = vec3( position );\r\n";
  21735. var beginnormal_vertex = "\r\nvec3 objectNormal = vec3( normal );\r\n";
  21736. 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";
  21737. 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";
  21738. 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";
  21739. 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";
  21740. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG )\r\n\tvarying vec3 vViewPosition;\r\n#endif\r\n";
  21741. 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";
  21742. var color_fragment = "#ifdef USE_COLOR\r\n\r\n\tdiffuseColor.rgb *= vColor;\r\n\r\n#endif";
  21743. var color_pars_fragment = "#ifdef USE_COLOR\r\n\r\n\tvarying vec3 vColor;\r\n\r\n#endif\r\n";
  21744. var color_pars_vertex = "#ifdef USE_COLOR\r\n\r\n\tvarying vec3 vColor;\r\n\r\n#endif";
  21745. var color_vertex = "#ifdef USE_COLOR\r\n\r\n\tvColor.xyz = color.xyz;\r\n\r\n#endif";
  21746. 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";
  21747. 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";
  21748. 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";
  21749. 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";
  21750. 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";
  21751. 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";
  21752. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\r\n\r\n\tuniform sampler2D emissiveMap;\r\n\r\n#endif\r\n";
  21753. var encodings_fragment = " gl_FragColor = linearToOutputTexel( gl_FragColor );\r\n";
  21754. 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";
  21755. 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";
  21756. 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";
  21757. 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";
  21758. 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";
  21759. var fog_vertex = "\r\n#ifdef USE_FOG\r\nfogDepth = -mvPosition.z;\r\n#endif";
  21760. var fog_pars_vertex = "#ifdef USE_FOG\r\n\r\n varying float fogDepth;\r\n\r\n#endif\r\n";
  21761. 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";
  21762. 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";
  21763. 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";
  21764. 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";
  21765. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\r\n\r\n\tuniform sampler2D lightMap;\r\n\tuniform float lightMapIntensity;\r\n\r\n#endif";
  21766. 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";
  21767. 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";
  21768. 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";
  21769. 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";
  21770. 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";
  21771. 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";
  21772. 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";
  21773. 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";
  21774. 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";
  21775. 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";
  21776. 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";
  21777. 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";
  21778. var map_pars_fragment = "#ifdef USE_MAP\r\n\r\n\tuniform sampler2D map;\r\n\r\n#endif\r\n";
  21779. 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";
  21780. 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";
  21781. 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";
  21782. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\r\n\r\n\tuniform sampler2D metalnessMap;\r\n\r\n#endif";
  21783. 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";
  21784. 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";
  21785. 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";
  21786. 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";
  21787. 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";
  21788. 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";
  21789. 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";
  21790. var project_vertex = "vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );\r\n\r\ngl_Position = projectionMatrix * mvPosition;\r\n";
  21791. var dithering_fragment = "#if defined( DITHERING )\r\n\r\n gl_FragColor.rgb = dithering( gl_FragColor.rgb );\r\n\r\n#endif\r\n";
  21792. 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";
  21793. 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";
  21794. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\r\n\r\n\tuniform sampler2D roughnessMap;\r\n\r\n#endif";
  21795. 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";
  21796. 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";
  21797. 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";
  21798. 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";
  21799. 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";
  21800. 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";
  21801. 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";
  21802. 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";
  21803. 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";
  21804. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\r\n\r\n\tuniform sampler2D specularMap;\r\n\r\n#endif";
  21805. 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";
  21806. var tonemapping_pars_fragment = "#define saturate(a) clamp( a, 0.0, 1.0 )\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";
  21807. 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";
  21808. 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";
  21809. 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";
  21810. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\r\n\r\n\tvarying vec2 vUv2;\r\n\r\n#endif";
  21811. 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";
  21812. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\r\n\r\n\tvUv2 = uv2;\r\n\r\n#endif";
  21813. 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";
  21814. 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";
  21815. 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";
  21816. 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";
  21817. 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";
  21818. 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";
  21819. 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";
  21820. 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";
  21821. 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";
  21822. 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";
  21823. 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";
  21824. 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";
  21825. 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";
  21826. 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";
  21827. 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";
  21828. 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";
  21829. 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";
  21830. 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";
  21831. 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";
  21832. 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";
  21833. 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";
  21834. 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";
  21835. 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";
  21836. 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";
  21837. 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";
  21838. var ShaderChunk = {
  21839. alphamap_fragment: alphamap_fragment,
  21840. alphamap_pars_fragment: alphamap_pars_fragment,
  21841. alphatest_fragment: alphatest_fragment,
  21842. aomap_fragment: aomap_fragment,
  21843. aomap_pars_fragment: aomap_pars_fragment,
  21844. begin_vertex: begin_vertex,
  21845. beginnormal_vertex: beginnormal_vertex,
  21846. bsdfs: bsdfs,
  21847. bumpmap_pars_fragment: bumpmap_pars_fragment,
  21848. clipping_planes_fragment: clipping_planes_fragment,
  21849. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  21850. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  21851. clipping_planes_vertex: clipping_planes_vertex,
  21852. color_fragment: color_fragment,
  21853. color_pars_fragment: color_pars_fragment,
  21854. color_pars_vertex: color_pars_vertex,
  21855. color_vertex: color_vertex,
  21856. common: common,
  21857. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  21858. defaultnormal_vertex: defaultnormal_vertex,
  21859. displacementmap_pars_vertex: displacementmap_pars_vertex,
  21860. displacementmap_vertex: displacementmap_vertex,
  21861. emissivemap_fragment: emissivemap_fragment,
  21862. emissivemap_pars_fragment: emissivemap_pars_fragment,
  21863. encodings_fragment: encodings_fragment,
  21864. encodings_pars_fragment: encodings_pars_fragment,
  21865. envmap_fragment: envmap_fragment,
  21866. envmap_pars_fragment: envmap_pars_fragment,
  21867. envmap_pars_vertex: envmap_pars_vertex,
  21868. envmap_vertex: envmap_vertex,
  21869. fog_vertex: fog_vertex,
  21870. fog_pars_vertex: fog_pars_vertex,
  21871. fog_fragment: fog_fragment,
  21872. fog_pars_fragment: fog_pars_fragment,
  21873. gradientmap_pars_fragment: gradientmap_pars_fragment,
  21874. lightmap_fragment: lightmap_fragment,
  21875. lightmap_pars_fragment: lightmap_pars_fragment,
  21876. lights_lambert_vertex: lights_lambert_vertex,
  21877. lights_pars: lights_pars,
  21878. lights_phong_fragment: lights_phong_fragment,
  21879. lights_phong_pars_fragment: lights_phong_pars_fragment,
  21880. lights_physical_fragment: lights_physical_fragment,
  21881. lights_physical_pars_fragment: lights_physical_pars_fragment,
  21882. lights_template: lights_template,
  21883. logdepthbuf_fragment: logdepthbuf_fragment,
  21884. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  21885. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  21886. logdepthbuf_vertex: logdepthbuf_vertex,
  21887. map_fragment: map_fragment,
  21888. map_pars_fragment: map_pars_fragment,
  21889. map_particle_fragment: map_particle_fragment,
  21890. map_particle_pars_fragment: map_particle_pars_fragment,
  21891. metalnessmap_fragment: metalnessmap_fragment,
  21892. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  21893. morphnormal_vertex: morphnormal_vertex,
  21894. morphtarget_pars_vertex: morphtarget_pars_vertex,
  21895. morphtarget_vertex: morphtarget_vertex,
  21896. normal_fragment: normal_fragment,
  21897. normalmap_pars_fragment: normalmap_pars_fragment,
  21898. packing: packing,
  21899. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  21900. project_vertex: project_vertex,
  21901. dithering_fragment: dithering_fragment,
  21902. dithering_pars_fragment: dithering_pars_fragment,
  21903. roughnessmap_fragment: roughnessmap_fragment,
  21904. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  21905. shadowmap_pars_fragment: shadowmap_pars_fragment,
  21906. shadowmap_pars_vertex: shadowmap_pars_vertex,
  21907. shadowmap_vertex: shadowmap_vertex,
  21908. shadowmask_pars_fragment: shadowmask_pars_fragment,
  21909. skinbase_vertex: skinbase_vertex,
  21910. skinning_pars_vertex: skinning_pars_vertex,
  21911. skinning_vertex: skinning_vertex,
  21912. skinnormal_vertex: skinnormal_vertex,
  21913. specularmap_fragment: specularmap_fragment,
  21914. specularmap_pars_fragment: specularmap_pars_fragment,
  21915. tonemapping_fragment: tonemapping_fragment,
  21916. tonemapping_pars_fragment: tonemapping_pars_fragment,
  21917. uv_pars_fragment: uv_pars_fragment,
  21918. uv_pars_vertex: uv_pars_vertex,
  21919. uv_vertex: uv_vertex,
  21920. uv2_pars_fragment: uv2_pars_fragment,
  21921. uv2_pars_vertex: uv2_pars_vertex,
  21922. uv2_vertex: uv2_vertex,
  21923. worldpos_vertex: worldpos_vertex,
  21924. cube_frag: cube_frag,
  21925. cube_vert: cube_vert,
  21926. depth_frag: depth_frag,
  21927. depth_vert: depth_vert,
  21928. distanceRGBA_frag: distanceRGBA_frag,
  21929. distanceRGBA_vert: distanceRGBA_vert,
  21930. equirect_frag: equirect_frag,
  21931. equirect_vert: equirect_vert,
  21932. linedashed_frag: linedashed_frag,
  21933. linedashed_vert: linedashed_vert,
  21934. meshbasic_frag: meshbasic_frag,
  21935. meshbasic_vert: meshbasic_vert,
  21936. meshlambert_frag: meshlambert_frag,
  21937. meshlambert_vert: meshlambert_vert,
  21938. meshphong_frag: meshphong_frag,
  21939. meshphong_vert: meshphong_vert,
  21940. meshphysical_frag: meshphysical_frag,
  21941. meshphysical_vert: meshphysical_vert,
  21942. normal_frag: normal_frag,
  21943. normal_vert: normal_vert,
  21944. points_frag: points_frag,
  21945. points_vert: points_vert,
  21946. shadow_frag: shadow_frag,
  21947. shadow_vert: shadow_vert
  21948. };
  21949. /**
  21950. * @author alteredq / http://alteredqualia.com/
  21951. * @author mrdoob / http://mrdoob.com/
  21952. * @author mikael emtinger / http://gomo.se/
  21953. */
  21954. var ShaderLib = {
  21955. basic: {
  21956. uniforms: UniformsUtils.merge( [
  21957. UniformsLib.common,
  21958. UniformsLib.specularmap,
  21959. UniformsLib.envmap,
  21960. UniformsLib.aomap,
  21961. UniformsLib.lightmap,
  21962. UniformsLib.fog
  21963. ] ),
  21964. vertexShader: ShaderChunk.meshbasic_vert,
  21965. fragmentShader: ShaderChunk.meshbasic_frag
  21966. },
  21967. lambert: {
  21968. uniforms: UniformsUtils.merge( [
  21969. UniformsLib.common,
  21970. UniformsLib.specularmap,
  21971. UniformsLib.envmap,
  21972. UniformsLib.aomap,
  21973. UniformsLib.lightmap,
  21974. UniformsLib.emissivemap,
  21975. UniformsLib.fog,
  21976. UniformsLib.lights,
  21977. {
  21978. emissive: { value: new Color( 0x000000 ) }
  21979. }
  21980. ] ),
  21981. vertexShader: ShaderChunk.meshlambert_vert,
  21982. fragmentShader: ShaderChunk.meshlambert_frag
  21983. },
  21984. phong: {
  21985. uniforms: UniformsUtils.merge( [
  21986. UniformsLib.common,
  21987. UniformsLib.specularmap,
  21988. UniformsLib.envmap,
  21989. UniformsLib.aomap,
  21990. UniformsLib.lightmap,
  21991. UniformsLib.emissivemap,
  21992. UniformsLib.bumpmap,
  21993. UniformsLib.normalmap,
  21994. UniformsLib.displacementmap,
  21995. UniformsLib.gradientmap,
  21996. UniformsLib.fog,
  21997. UniformsLib.lights,
  21998. {
  21999. emissive: { value: new Color( 0x000000 ) },
  22000. specular: { value: new Color( 0x111111 ) },
  22001. shininess: { value: 30 }
  22002. }
  22003. ] ),
  22004. vertexShader: ShaderChunk.meshphong_vert,
  22005. fragmentShader: ShaderChunk.meshphong_frag
  22006. },
  22007. standard: {
  22008. uniforms: UniformsUtils.merge( [
  22009. UniformsLib.common,
  22010. UniformsLib.envmap,
  22011. UniformsLib.aomap,
  22012. UniformsLib.lightmap,
  22013. UniformsLib.emissivemap,
  22014. UniformsLib.bumpmap,
  22015. UniformsLib.normalmap,
  22016. UniformsLib.displacementmap,
  22017. UniformsLib.roughnessmap,
  22018. UniformsLib.metalnessmap,
  22019. UniformsLib.fog,
  22020. UniformsLib.lights,
  22021. {
  22022. emissive: { value: new Color( 0x000000 ) },
  22023. roughness: { value: 0.5 },
  22024. metalness: { value: 0.5 },
  22025. envMapIntensity: { value: 1 } // temporary
  22026. }
  22027. ] ),
  22028. vertexShader: ShaderChunk.meshphysical_vert,
  22029. fragmentShader: ShaderChunk.meshphysical_frag
  22030. },
  22031. points: {
  22032. uniforms: UniformsUtils.merge( [
  22033. UniformsLib.points,
  22034. UniformsLib.fog
  22035. ] ),
  22036. vertexShader: ShaderChunk.points_vert,
  22037. fragmentShader: ShaderChunk.points_frag
  22038. },
  22039. dashed: {
  22040. uniforms: UniformsUtils.merge( [
  22041. UniformsLib.common,
  22042. UniformsLib.fog,
  22043. {
  22044. scale: { value: 1 },
  22045. dashSize: { value: 1 },
  22046. totalSize: { value: 2 }
  22047. }
  22048. ] ),
  22049. vertexShader: ShaderChunk.linedashed_vert,
  22050. fragmentShader: ShaderChunk.linedashed_frag
  22051. },
  22052. depth: {
  22053. uniforms: UniformsUtils.merge( [
  22054. UniformsLib.common,
  22055. UniformsLib.displacementmap
  22056. ] ),
  22057. vertexShader: ShaderChunk.depth_vert,
  22058. fragmentShader: ShaderChunk.depth_frag
  22059. },
  22060. normal: {
  22061. uniforms: UniformsUtils.merge( [
  22062. UniformsLib.common,
  22063. UniformsLib.bumpmap,
  22064. UniformsLib.normalmap,
  22065. UniformsLib.displacementmap,
  22066. {
  22067. opacity: { value: 1.0 }
  22068. }
  22069. ] ),
  22070. vertexShader: ShaderChunk.normal_vert,
  22071. fragmentShader: ShaderChunk.normal_frag
  22072. },
  22073. /* -------------------------------------------------------------------------
  22074. // Cube map shader
  22075. ------------------------------------------------------------------------- */
  22076. cube: {
  22077. uniforms: {
  22078. tCube: { value: null },
  22079. tFlip: { value: - 1 },
  22080. opacity: { value: 1.0 }
  22081. },
  22082. vertexShader: ShaderChunk.cube_vert,
  22083. fragmentShader: ShaderChunk.cube_frag
  22084. },
  22085. equirect: {
  22086. uniforms: {
  22087. tEquirect: { value: null },
  22088. },
  22089. vertexShader: ShaderChunk.equirect_vert,
  22090. fragmentShader: ShaderChunk.equirect_frag
  22091. },
  22092. distanceRGBA: {
  22093. uniforms: UniformsUtils.merge( [
  22094. UniformsLib.common,
  22095. UniformsLib.displacementmap,
  22096. {
  22097. referencePosition: { value: new Vector3() },
  22098. nearDistance: { value: 1 },
  22099. farDistance: { value: 1000 }
  22100. }
  22101. ] ),
  22102. vertexShader: ShaderChunk.distanceRGBA_vert,
  22103. fragmentShader: ShaderChunk.distanceRGBA_frag
  22104. },
  22105. shadow: {
  22106. uniforms: UniformsUtils.merge( [
  22107. UniformsLib.lights,
  22108. UniformsLib.fog,
  22109. {
  22110. color: { value: new Color( 0x00000 ) },
  22111. opacity: { value: 1.0 }
  22112. },
  22113. ] ),
  22114. vertexShader: ShaderChunk.shadow_vert,
  22115. fragmentShader: ShaderChunk.shadow_frag
  22116. }
  22117. };
  22118. ShaderLib.physical = {
  22119. uniforms: UniformsUtils.merge( [
  22120. ShaderLib.standard.uniforms,
  22121. {
  22122. clearCoat: { value: 0 },
  22123. clearCoatRoughness: { value: 0 }
  22124. }
  22125. ] ),
  22126. vertexShader: ShaderChunk.meshphysical_vert,
  22127. fragmentShader: ShaderChunk.meshphysical_frag
  22128. };
  22129. /**
  22130. * @author bhouston / http://clara.io
  22131. */
  22132. function Box2( min, max ) {
  22133. this.min = ( min !== undefined ) ? min : new Vector2( + Infinity, + Infinity );
  22134. this.max = ( max !== undefined ) ? max : new Vector2( - Infinity, - Infinity );
  22135. }
  22136. Object.assign( Box2.prototype, {
  22137. set: function ( min, max ) {
  22138. this.min.copy( min );
  22139. this.max.copy( max );
  22140. return this;
  22141. },
  22142. setFromPoints: function ( points ) {
  22143. this.makeEmpty();
  22144. for ( var i = 0, il = points.length; i < il; i ++ ) {
  22145. this.expandByPoint( points[ i ] );
  22146. }
  22147. return this;
  22148. },
  22149. setFromCenterAndSize: function () {
  22150. var v1 = new Vector2();
  22151. return function setFromCenterAndSize( center, size ) {
  22152. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  22153. this.min.copy( center ).sub( halfSize );
  22154. this.max.copy( center ).add( halfSize );
  22155. return this;
  22156. };
  22157. }(),
  22158. clone: function () {
  22159. return new this.constructor().copy( this );
  22160. },
  22161. copy: function ( box ) {
  22162. this.min.copy( box.min );
  22163. this.max.copy( box.max );
  22164. return this;
  22165. },
  22166. makeEmpty: function () {
  22167. this.min.x = this.min.y = + Infinity;
  22168. this.max.x = this.max.y = - Infinity;
  22169. return this;
  22170. },
  22171. isEmpty: function () {
  22172. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  22173. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  22174. },
  22175. getCenter: function ( optionalTarget ) {
  22176. var result = optionalTarget || new Vector2();
  22177. return this.isEmpty() ? result.set( 0, 0 ) : result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  22178. },
  22179. getSize: function ( optionalTarget ) {
  22180. var result = optionalTarget || new Vector2();
  22181. return this.isEmpty() ? result.set( 0, 0 ) : result.subVectors( this.max, this.min );
  22182. },
  22183. expandByPoint: function ( point ) {
  22184. this.min.min( point );
  22185. this.max.max( point );
  22186. return this;
  22187. },
  22188. expandByVector: function ( vector ) {
  22189. this.min.sub( vector );
  22190. this.max.add( vector );
  22191. return this;
  22192. },
  22193. expandByScalar: function ( scalar ) {
  22194. this.min.addScalar( - scalar );
  22195. this.max.addScalar( scalar );
  22196. return this;
  22197. },
  22198. containsPoint: function ( point ) {
  22199. return point.x < this.min.x || point.x > this.max.x ||
  22200. point.y < this.min.y || point.y > this.max.y ? false : true;
  22201. },
  22202. containsBox: function ( box ) {
  22203. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  22204. this.min.y <= box.min.y && box.max.y <= this.max.y;
  22205. },
  22206. getParameter: function ( point, optionalTarget ) {
  22207. // This can potentially have a divide by zero if the box
  22208. // has a size dimension of 0.
  22209. var result = optionalTarget || new Vector2();
  22210. return result.set(
  22211. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  22212. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  22213. );
  22214. },
  22215. intersectsBox: function ( box ) {
  22216. // using 4 splitting planes to rule out intersections
  22217. return box.max.x < this.min.x || box.min.x > this.max.x ||
  22218. box.max.y < this.min.y || box.min.y > this.max.y ? false : true;
  22219. },
  22220. clampPoint: function ( point, optionalTarget ) {
  22221. var result = optionalTarget || new Vector2();
  22222. return result.copy( point ).clamp( this.min, this.max );
  22223. },
  22224. distanceToPoint: function () {
  22225. var v1 = new Vector2();
  22226. return function distanceToPoint( point ) {
  22227. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  22228. return clampedPoint.sub( point ).length();
  22229. };
  22230. }(),
  22231. intersect: function ( box ) {
  22232. this.min.max( box.min );
  22233. this.max.min( box.max );
  22234. return this;
  22235. },
  22236. union: function ( box ) {
  22237. this.min.min( box.min );
  22238. this.max.max( box.max );
  22239. return this;
  22240. },
  22241. translate: function ( offset ) {
  22242. this.min.add( offset );
  22243. this.max.add( offset );
  22244. return this;
  22245. },
  22246. equals: function ( box ) {
  22247. return box.min.equals( this.min ) && box.max.equals( this.max );
  22248. }
  22249. } );
  22250. /**
  22251. * @author mikael emtinger / http://gomo.se/
  22252. * @author alteredq / http://alteredqualia.com/
  22253. */
  22254. function WebGLFlareRenderer( renderer, gl, state, textures, capabilities ) {
  22255. var vertexBuffer, elementBuffer;
  22256. var shader, program, attributes, uniforms;
  22257. var tempTexture, occlusionTexture;
  22258. function init() {
  22259. var vertices = new Float32Array( [
  22260. - 1, - 1, 0, 0,
  22261. 1, - 1, 1, 0,
  22262. 1, 1, 1, 1,
  22263. - 1, 1, 0, 1
  22264. ] );
  22265. var faces = new Uint16Array( [
  22266. 0, 1, 2,
  22267. 0, 2, 3
  22268. ] );
  22269. // buffers
  22270. vertexBuffer = gl.createBuffer();
  22271. elementBuffer = gl.createBuffer();
  22272. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  22273. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  22274. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  22275. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  22276. // textures
  22277. tempTexture = gl.createTexture();
  22278. occlusionTexture = gl.createTexture();
  22279. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  22280. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGB, 16, 16, 0, gl.RGB, gl.UNSIGNED_BYTE, null );
  22281. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  22282. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  22283. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  22284. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  22285. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  22286. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGBA, 16, 16, 0, gl.RGBA, gl.UNSIGNED_BYTE, null );
  22287. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  22288. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  22289. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  22290. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  22291. shader = {
  22292. vertexShader: [
  22293. 'uniform lowp int renderType;',
  22294. 'uniform vec3 screenPosition;',
  22295. 'uniform vec2 scale;',
  22296. 'uniform float rotation;',
  22297. 'uniform sampler2D occlusionMap;',
  22298. 'attribute vec2 position;',
  22299. 'attribute vec2 uv;',
  22300. 'varying vec2 vUV;',
  22301. 'varying float vVisibility;',
  22302. 'void main() {',
  22303. ' vUV = uv;',
  22304. ' vec2 pos = position;',
  22305. ' if ( renderType == 2 ) {',
  22306. ' vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) );',
  22307. ' visibility += texture2D( occlusionMap, vec2( 0.5, 0.1 ) );',
  22308. ' visibility += texture2D( occlusionMap, vec2( 0.9, 0.1 ) );',
  22309. ' visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) );',
  22310. ' visibility += texture2D( occlusionMap, vec2( 0.9, 0.9 ) );',
  22311. ' visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) );',
  22312. ' visibility += texture2D( occlusionMap, vec2( 0.1, 0.9 ) );',
  22313. ' visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) );',
  22314. ' visibility += texture2D( occlusionMap, vec2( 0.5, 0.5 ) );',
  22315. ' vVisibility = visibility.r / 9.0;',
  22316. ' vVisibility *= 1.0 - visibility.g / 9.0;',
  22317. ' vVisibility *= visibility.b / 9.0;',
  22318. ' vVisibility *= 1.0 - visibility.a / 9.0;',
  22319. ' pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;',
  22320. ' pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;',
  22321. ' }',
  22322. ' gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );',
  22323. '}'
  22324. ].join( '\n' ),
  22325. fragmentShader: [
  22326. 'uniform lowp int renderType;',
  22327. 'uniform sampler2D map;',
  22328. 'uniform float opacity;',
  22329. 'uniform vec3 color;',
  22330. 'varying vec2 vUV;',
  22331. 'varying float vVisibility;',
  22332. 'void main() {',
  22333. // pink square
  22334. ' if ( renderType == 0 ) {',
  22335. ' gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );',
  22336. // restore
  22337. ' } else if ( renderType == 1 ) {',
  22338. ' gl_FragColor = texture2D( map, vUV );',
  22339. // flare
  22340. ' } else {',
  22341. ' vec4 texture = texture2D( map, vUV );',
  22342. ' texture.a *= opacity * vVisibility;',
  22343. ' gl_FragColor = texture;',
  22344. ' gl_FragColor.rgb *= color;',
  22345. ' }',
  22346. '}'
  22347. ].join( '\n' )
  22348. };
  22349. program = createProgram( shader );
  22350. attributes = {
  22351. vertex: gl.getAttribLocation( program, 'position' ),
  22352. uv: gl.getAttribLocation( program, 'uv' )
  22353. };
  22354. uniforms = {
  22355. renderType: gl.getUniformLocation( program, 'renderType' ),
  22356. map: gl.getUniformLocation( program, 'map' ),
  22357. occlusionMap: gl.getUniformLocation( program, 'occlusionMap' ),
  22358. opacity: gl.getUniformLocation( program, 'opacity' ),
  22359. color: gl.getUniformLocation( program, 'color' ),
  22360. scale: gl.getUniformLocation( program, 'scale' ),
  22361. rotation: gl.getUniformLocation( program, 'rotation' ),
  22362. screenPosition: gl.getUniformLocation( program, 'screenPosition' )
  22363. };
  22364. }
  22365. /*
  22366. * Render lens flares
  22367. * Method: renders 16x16 0xff00ff-colored points scattered over the light source area,
  22368. * reads these back and calculates occlusion.
  22369. */
  22370. this.render = function ( flares, scene, camera, viewport ) {
  22371. if ( flares.length === 0 ) return;
  22372. var tempPosition = new Vector3();
  22373. var invAspect = viewport.w / viewport.z,
  22374. halfViewportWidth = viewport.z * 0.5,
  22375. halfViewportHeight = viewport.w * 0.5;
  22376. var size = 16 / viewport.w,
  22377. scale = new Vector2( size * invAspect, size );
  22378. var screenPosition = new Vector3( 1, 1, 0 ),
  22379. screenPositionPixels = new Vector2( 1, 1 );
  22380. var validArea = new Box2();
  22381. validArea.min.set( viewport.x, viewport.y );
  22382. validArea.max.set( viewport.x + ( viewport.z - 16 ), viewport.y + ( viewport.w - 16 ) );
  22383. if ( program === undefined ) {
  22384. init();
  22385. }
  22386. state.useProgram( program );
  22387. state.initAttributes();
  22388. state.enableAttribute( attributes.vertex );
  22389. state.enableAttribute( attributes.uv );
  22390. state.disableUnusedAttributes();
  22391. // loop through all lens flares to update their occlusion and positions
  22392. // setup gl and common used attribs/uniforms
  22393. gl.uniform1i( uniforms.occlusionMap, 0 );
  22394. gl.uniform1i( uniforms.map, 1 );
  22395. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  22396. gl.vertexAttribPointer( attributes.vertex, 2, gl.FLOAT, false, 2 * 8, 0 );
  22397. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  22398. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  22399. state.disable( gl.CULL_FACE );
  22400. state.buffers.depth.setMask( false );
  22401. for ( var i = 0, l = flares.length; i < l; i ++ ) {
  22402. size = 16 / viewport.w;
  22403. scale.set( size * invAspect, size );
  22404. // calc object screen position
  22405. var flare = flares[ i ];
  22406. tempPosition.set( flare.matrixWorld.elements[ 12 ], flare.matrixWorld.elements[ 13 ], flare.matrixWorld.elements[ 14 ] );
  22407. tempPosition.applyMatrix4( camera.matrixWorldInverse );
  22408. tempPosition.applyMatrix4( camera.projectionMatrix );
  22409. // setup arrays for gl programs
  22410. screenPosition.copy( tempPosition );
  22411. // horizontal and vertical coordinate of the lower left corner of the pixels to copy
  22412. screenPositionPixels.x = viewport.x + ( screenPosition.x * halfViewportWidth ) + halfViewportWidth - 8;
  22413. screenPositionPixels.y = viewport.y + ( screenPosition.y * halfViewportHeight ) + halfViewportHeight - 8;
  22414. // screen cull
  22415. if ( validArea.containsPoint( screenPositionPixels ) === true ) {
  22416. // save current RGB to temp texture
  22417. state.activeTexture( gl.TEXTURE0 );
  22418. state.bindTexture( gl.TEXTURE_2D, null );
  22419. state.activeTexture( gl.TEXTURE1 );
  22420. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  22421. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGB, screenPositionPixels.x, screenPositionPixels.y, 16, 16, 0 );
  22422. // render pink quad
  22423. gl.uniform1i( uniforms.renderType, 0 );
  22424. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  22425. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  22426. state.disable( gl.BLEND );
  22427. state.enable( gl.DEPTH_TEST );
  22428. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  22429. // copy result to occlusionMap
  22430. state.activeTexture( gl.TEXTURE0 );
  22431. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  22432. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGBA, screenPositionPixels.x, screenPositionPixels.y, 16, 16, 0 );
  22433. // restore graphics
  22434. gl.uniform1i( uniforms.renderType, 1 );
  22435. state.disable( gl.DEPTH_TEST );
  22436. state.activeTexture( gl.TEXTURE1 );
  22437. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  22438. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  22439. // update object positions
  22440. flare.positionScreen.copy( screenPosition );
  22441. if ( flare.customUpdateCallback ) {
  22442. flare.customUpdateCallback( flare );
  22443. } else {
  22444. flare.updateLensFlares();
  22445. }
  22446. // render flares
  22447. gl.uniform1i( uniforms.renderType, 2 );
  22448. state.enable( gl.BLEND );
  22449. for ( var j = 0, jl = flare.lensFlares.length; j < jl; j ++ ) {
  22450. var sprite = flare.lensFlares[ j ];
  22451. if ( sprite.opacity > 0.001 && sprite.scale > 0.001 ) {
  22452. screenPosition.x = sprite.x;
  22453. screenPosition.y = sprite.y;
  22454. screenPosition.z = sprite.z;
  22455. size = sprite.size * sprite.scale / viewport.w;
  22456. scale.x = size * invAspect;
  22457. scale.y = size;
  22458. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  22459. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  22460. gl.uniform1f( uniforms.rotation, sprite.rotation );
  22461. gl.uniform1f( uniforms.opacity, sprite.opacity );
  22462. gl.uniform3f( uniforms.color, sprite.color.r, sprite.color.g, sprite.color.b );
  22463. state.setBlending( sprite.blending, sprite.blendEquation, sprite.blendSrc, sprite.blendDst );
  22464. textures.setTexture2D( sprite.texture, 1 );
  22465. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  22466. }
  22467. }
  22468. }
  22469. }
  22470. // restore gl
  22471. state.enable( gl.CULL_FACE );
  22472. state.enable( gl.DEPTH_TEST );
  22473. state.buffers.depth.setMask( true );
  22474. state.reset();
  22475. };
  22476. function createProgram( shader ) {
  22477. var program = gl.createProgram();
  22478. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  22479. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  22480. var prefix = 'precision ' + capabilities.precision + ' float;\n';
  22481. gl.shaderSource( fragmentShader, prefix + shader.fragmentShader );
  22482. gl.shaderSource( vertexShader, prefix + shader.vertexShader );
  22483. gl.compileShader( fragmentShader );
  22484. gl.compileShader( vertexShader );
  22485. gl.attachShader( program, fragmentShader );
  22486. gl.attachShader( program, vertexShader );
  22487. gl.linkProgram( program );
  22488. return program;
  22489. }
  22490. }
  22491. /**
  22492. * @author mrdoob / http://mrdoob.com/
  22493. */
  22494. function CanvasTexture( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  22495. Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  22496. this.needsUpdate = true;
  22497. }
  22498. CanvasTexture.prototype = Object.create( Texture.prototype );
  22499. CanvasTexture.prototype.constructor = CanvasTexture;
  22500. /**
  22501. * @author mikael emtinger / http://gomo.se/
  22502. * @author alteredq / http://alteredqualia.com/
  22503. */
  22504. function WebGLSpriteRenderer( renderer, gl, state, textures, capabilities ) {
  22505. var vertexBuffer, elementBuffer;
  22506. var program, attributes, uniforms;
  22507. var texture;
  22508. // decompose matrixWorld
  22509. var spritePosition = new Vector3();
  22510. var spriteRotation = new Quaternion();
  22511. var spriteScale = new Vector3();
  22512. function init() {
  22513. var vertices = new Float32Array( [
  22514. - 0.5, - 0.5, 0, 0,
  22515. 0.5, - 0.5, 1, 0,
  22516. 0.5, 0.5, 1, 1,
  22517. - 0.5, 0.5, 0, 1
  22518. ] );
  22519. var faces = new Uint16Array( [
  22520. 0, 1, 2,
  22521. 0, 2, 3
  22522. ] );
  22523. vertexBuffer = gl.createBuffer();
  22524. elementBuffer = gl.createBuffer();
  22525. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  22526. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  22527. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  22528. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  22529. program = createProgram();
  22530. attributes = {
  22531. position: gl.getAttribLocation( program, 'position' ),
  22532. uv: gl.getAttribLocation( program, 'uv' )
  22533. };
  22534. uniforms = {
  22535. uvOffset: gl.getUniformLocation( program, 'uvOffset' ),
  22536. uvScale: gl.getUniformLocation( program, 'uvScale' ),
  22537. rotation: gl.getUniformLocation( program, 'rotation' ),
  22538. scale: gl.getUniformLocation( program, 'scale' ),
  22539. color: gl.getUniformLocation( program, 'color' ),
  22540. map: gl.getUniformLocation( program, 'map' ),
  22541. opacity: gl.getUniformLocation( program, 'opacity' ),
  22542. modelViewMatrix: gl.getUniformLocation( program, 'modelViewMatrix' ),
  22543. projectionMatrix: gl.getUniformLocation( program, 'projectionMatrix' ),
  22544. fogType: gl.getUniformLocation( program, 'fogType' ),
  22545. fogDensity: gl.getUniformLocation( program, 'fogDensity' ),
  22546. fogNear: gl.getUniformLocation( program, 'fogNear' ),
  22547. fogFar: gl.getUniformLocation( program, 'fogFar' ),
  22548. fogColor: gl.getUniformLocation( program, 'fogColor' ),
  22549. fogDepth: gl.getUniformLocation( program, 'fogDepth' ),
  22550. alphaTest: gl.getUniformLocation( program, 'alphaTest' )
  22551. };
  22552. var canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  22553. canvas.width = 8;
  22554. canvas.height = 8;
  22555. var context = canvas.getContext( '2d' );
  22556. context.fillStyle = 'white';
  22557. context.fillRect( 0, 0, 8, 8 );
  22558. texture = new CanvasTexture( canvas );
  22559. }
  22560. this.render = function ( sprites, scene, camera ) {
  22561. if ( sprites.length === 0 ) return;
  22562. // setup gl
  22563. if ( program === undefined ) {
  22564. init();
  22565. }
  22566. state.useProgram( program );
  22567. state.initAttributes();
  22568. state.enableAttribute( attributes.position );
  22569. state.enableAttribute( attributes.uv );
  22570. state.disableUnusedAttributes();
  22571. state.disable( gl.CULL_FACE );
  22572. state.enable( gl.BLEND );
  22573. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  22574. gl.vertexAttribPointer( attributes.position, 2, gl.FLOAT, false, 2 * 8, 0 );
  22575. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  22576. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  22577. gl.uniformMatrix4fv( uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  22578. state.activeTexture( gl.TEXTURE0 );
  22579. gl.uniform1i( uniforms.map, 0 );
  22580. var oldFogType = 0;
  22581. var sceneFogType = 0;
  22582. var fog = scene.fog;
  22583. if ( fog ) {
  22584. gl.uniform3f( uniforms.fogColor, fog.color.r, fog.color.g, fog.color.b );
  22585. if ( fog.isFog ) {
  22586. gl.uniform1f( uniforms.fogNear, fog.near );
  22587. gl.uniform1f( uniforms.fogFar, fog.far );
  22588. gl.uniform1i( uniforms.fogType, 1 );
  22589. oldFogType = 1;
  22590. sceneFogType = 1;
  22591. } else if ( fog.isFogExp2 ) {
  22592. gl.uniform1f( uniforms.fogDensity, fog.density );
  22593. gl.uniform1i( uniforms.fogType, 2 );
  22594. oldFogType = 2;
  22595. sceneFogType = 2;
  22596. }
  22597. } else {
  22598. gl.uniform1i( uniforms.fogType, 0 );
  22599. oldFogType = 0;
  22600. sceneFogType = 0;
  22601. }
  22602. // update positions and sort
  22603. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  22604. var sprite = sprites[ i ];
  22605. sprite.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, sprite.matrixWorld );
  22606. sprite.z = - sprite.modelViewMatrix.elements[ 14 ];
  22607. }
  22608. sprites.sort( painterSortStable );
  22609. // render all sprites
  22610. var scale = [];
  22611. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  22612. var sprite = sprites[ i ];
  22613. var material = sprite.material;
  22614. if ( material.visible === false ) continue;
  22615. sprite.onBeforeRender( renderer, scene, camera, undefined, material, undefined );
  22616. gl.uniform1f( uniforms.alphaTest, material.alphaTest );
  22617. gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, sprite.modelViewMatrix.elements );
  22618. sprite.matrixWorld.decompose( spritePosition, spriteRotation, spriteScale );
  22619. scale[ 0 ] = spriteScale.x;
  22620. scale[ 1 ] = spriteScale.y;
  22621. var fogType = 0;
  22622. if ( scene.fog && material.fog ) {
  22623. fogType = sceneFogType;
  22624. }
  22625. if ( oldFogType !== fogType ) {
  22626. gl.uniform1i( uniforms.fogType, fogType );
  22627. oldFogType = fogType;
  22628. }
  22629. if ( material.map !== null ) {
  22630. gl.uniform2f( uniforms.uvOffset, material.map.offset.x, material.map.offset.y );
  22631. gl.uniform2f( uniforms.uvScale, material.map.repeat.x, material.map.repeat.y );
  22632. } else {
  22633. gl.uniform2f( uniforms.uvOffset, 0, 0 );
  22634. gl.uniform2f( uniforms.uvScale, 1, 1 );
  22635. }
  22636. gl.uniform1f( uniforms.opacity, material.opacity );
  22637. gl.uniform3f( uniforms.color, material.color.r, material.color.g, material.color.b );
  22638. gl.uniform1f( uniforms.rotation, material.rotation );
  22639. gl.uniform2fv( uniforms.scale, scale );
  22640. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha );
  22641. state.buffers.depth.setTest( material.depthTest );
  22642. state.buffers.depth.setMask( material.depthWrite );
  22643. state.buffers.color.setMask( material.colorWrite );
  22644. textures.setTexture2D( material.map || texture, 0 );
  22645. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  22646. sprite.onAfterRender( renderer, scene, camera, undefined, material, undefined );
  22647. }
  22648. // restore gl
  22649. state.enable( gl.CULL_FACE );
  22650. state.reset();
  22651. };
  22652. function createProgram() {
  22653. var program = gl.createProgram();
  22654. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  22655. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  22656. gl.shaderSource( vertexShader, [
  22657. 'precision ' + capabilities.precision + ' float;',
  22658. '#define SHADER_NAME ' + 'SpriteMaterial',
  22659. 'uniform mat4 modelViewMatrix;',
  22660. 'uniform mat4 projectionMatrix;',
  22661. 'uniform float rotation;',
  22662. 'uniform vec2 scale;',
  22663. 'uniform vec2 uvOffset;',
  22664. 'uniform vec2 uvScale;',
  22665. 'attribute vec2 position;',
  22666. 'attribute vec2 uv;',
  22667. 'varying vec2 vUV;',
  22668. 'varying float fogDepth;',
  22669. 'void main() {',
  22670. ' vUV = uvOffset + uv * uvScale;',
  22671. ' vec2 alignedPosition = position * scale;',
  22672. ' vec2 rotatedPosition;',
  22673. ' rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;',
  22674. ' rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;',
  22675. ' vec4 mvPosition;',
  22676. ' mvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );',
  22677. ' mvPosition.xy += rotatedPosition;',
  22678. ' gl_Position = projectionMatrix * mvPosition;',
  22679. ' fogDepth = - mvPosition.z;',
  22680. '}'
  22681. ].join( '\n' ) );
  22682. gl.shaderSource( fragmentShader, [
  22683. 'precision ' + capabilities.precision + ' float;',
  22684. '#define SHADER_NAME ' + 'SpriteMaterial',
  22685. 'uniform vec3 color;',
  22686. 'uniform sampler2D map;',
  22687. 'uniform float opacity;',
  22688. 'uniform int fogType;',
  22689. 'uniform vec3 fogColor;',
  22690. 'uniform float fogDensity;',
  22691. 'uniform float fogNear;',
  22692. 'uniform float fogFar;',
  22693. 'uniform float alphaTest;',
  22694. 'varying vec2 vUV;',
  22695. 'varying float fogDepth;',
  22696. 'void main() {',
  22697. ' vec4 texture = texture2D( map, vUV );',
  22698. ' gl_FragColor = vec4( color * texture.xyz, texture.a * opacity );',
  22699. ' if ( gl_FragColor.a < alphaTest ) discard;',
  22700. ' if ( fogType > 0 ) {',
  22701. ' float fogFactor = 0.0;',
  22702. ' if ( fogType == 1 ) {',
  22703. ' fogFactor = smoothstep( fogNear, fogFar, fogDepth );',
  22704. ' } else {',
  22705. ' const float LOG2 = 1.442695;',
  22706. ' fogFactor = exp2( - fogDensity * fogDensity * fogDepth * fogDepth * LOG2 );',
  22707. ' fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );',
  22708. ' }',
  22709. ' gl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );',
  22710. ' }',
  22711. '}'
  22712. ].join( '\n' ) );
  22713. gl.compileShader( vertexShader );
  22714. gl.compileShader( fragmentShader );
  22715. gl.attachShader( program, vertexShader );
  22716. gl.attachShader( program, fragmentShader );
  22717. gl.linkProgram( program );
  22718. return program;
  22719. }
  22720. function painterSortStable( a, b ) {
  22721. if ( a.renderOrder !== b.renderOrder ) {
  22722. return a.renderOrder - b.renderOrder;
  22723. } else if ( a.z !== b.z ) {
  22724. return b.z - a.z;
  22725. } else {
  22726. return b.id - a.id;
  22727. }
  22728. }
  22729. }
  22730. /**
  22731. * @author mrdoob / http://mrdoob.com/
  22732. * @author alteredq / http://alteredqualia.com/
  22733. * @author bhouston / http://clara.io
  22734. */
  22735. function Frustum( p0, p1, p2, p3, p4, p5 ) {
  22736. this.planes = [
  22737. ( p0 !== undefined ) ? p0 : new Plane(),
  22738. ( p1 !== undefined ) ? p1 : new Plane(),
  22739. ( p2 !== undefined ) ? p2 : new Plane(),
  22740. ( p3 !== undefined ) ? p3 : new Plane(),
  22741. ( p4 !== undefined ) ? p4 : new Plane(),
  22742. ( p5 !== undefined ) ? p5 : new Plane()
  22743. ];
  22744. }
  22745. Object.assign( Frustum.prototype, {
  22746. set: function ( p0, p1, p2, p3, p4, p5 ) {
  22747. var planes = this.planes;
  22748. planes[ 0 ].copy( p0 );
  22749. planes[ 1 ].copy( p1 );
  22750. planes[ 2 ].copy( p2 );
  22751. planes[ 3 ].copy( p3 );
  22752. planes[ 4 ].copy( p4 );
  22753. planes[ 5 ].copy( p5 );
  22754. return this;
  22755. },
  22756. clone: function () {
  22757. return new this.constructor().copy( this );
  22758. },
  22759. copy: function ( frustum ) {
  22760. var planes = this.planes;
  22761. for ( var i = 0; i < 6; i ++ ) {
  22762. planes[ i ].copy( frustum.planes[ i ] );
  22763. }
  22764. return this;
  22765. },
  22766. setFromMatrix: function ( m ) {
  22767. var planes = this.planes;
  22768. var me = m.elements;
  22769. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  22770. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  22771. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  22772. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  22773. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  22774. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  22775. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  22776. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  22777. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  22778. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  22779. return this;
  22780. },
  22781. intersectsObject: function () {
  22782. var sphere = new Sphere();
  22783. return function intersectsObject( object ) {
  22784. var geometry = object.geometry;
  22785. if ( geometry.boundingSphere === null )
  22786. geometry.computeBoundingSphere();
  22787. sphere.copy( geometry.boundingSphere )
  22788. .applyMatrix4( object.matrixWorld );
  22789. return this.intersectsSphere( sphere );
  22790. };
  22791. }(),
  22792. intersectsSprite: function () {
  22793. var sphere = new Sphere();
  22794. return function intersectsSprite( sprite ) {
  22795. sphere.center.set( 0, 0, 0 );
  22796. sphere.radius = 0.7071067811865476;
  22797. sphere.applyMatrix4( sprite.matrixWorld );
  22798. return this.intersectsSphere( sphere );
  22799. };
  22800. }(),
  22801. intersectsSphere: function ( sphere ) {
  22802. var planes = this.planes;
  22803. var center = sphere.center;
  22804. var negRadius = - sphere.radius;
  22805. for ( var i = 0; i < 6; i ++ ) {
  22806. var distance = planes[ i ].distanceToPoint( center );
  22807. if ( distance < negRadius ) {
  22808. return false;
  22809. }
  22810. }
  22811. return true;
  22812. },
  22813. intersectsBox: function () {
  22814. var p1 = new Vector3(),
  22815. p2 = new Vector3();
  22816. return function intersectsBox( box ) {
  22817. var planes = this.planes;
  22818. for ( var i = 0; i < 6; i ++ ) {
  22819. var plane = planes[ i ];
  22820. p1.x = plane.normal.x > 0 ? box.min.x : box.max.x;
  22821. p2.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  22822. p1.y = plane.normal.y > 0 ? box.min.y : box.max.y;
  22823. p2.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  22824. p1.z = plane.normal.z > 0 ? box.min.z : box.max.z;
  22825. p2.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  22826. var d1 = plane.distanceToPoint( p1 );
  22827. var d2 = plane.distanceToPoint( p2 );
  22828. // if both outside plane, no intersection
  22829. if ( d1 < 0 && d2 < 0 ) {
  22830. return false;
  22831. }
  22832. }
  22833. return true;
  22834. };
  22835. }(),
  22836. containsPoint: function ( point ) {
  22837. var planes = this.planes;
  22838. for ( var i = 0; i < 6; i ++ ) {
  22839. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  22840. return false;
  22841. }
  22842. }
  22843. return true;
  22844. }
  22845. } );
  22846. /**
  22847. * @author alteredq / http://alteredqualia.com/
  22848. * @author mrdoob / http://mrdoob.com/
  22849. */
  22850. function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
  22851. var _frustum = new Frustum(),
  22852. _projScreenMatrix = new Matrix4(),
  22853. _shadowMapSize = new Vector2(),
  22854. _maxShadowMapSize = new Vector2( maxTextureSize, maxTextureSize ),
  22855. _lookTarget = new Vector3(),
  22856. _lightPositionWorld = new Vector3(),
  22857. _MorphingFlag = 1,
  22858. _SkinningFlag = 2,
  22859. _NumberOfMaterialVariants = ( _MorphingFlag | _SkinningFlag ) + 1,
  22860. _depthMaterials = new Array( _NumberOfMaterialVariants ),
  22861. _distanceMaterials = new Array( _NumberOfMaterialVariants ),
  22862. _materialCache = {};
  22863. var cubeDirections = [
  22864. new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ),
  22865. new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 )
  22866. ];
  22867. var cubeUps = [
  22868. new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ),
  22869. new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 )
  22870. ];
  22871. var cube2DViewPorts = [
  22872. new Vector4(), new Vector4(), new Vector4(),
  22873. new Vector4(), new Vector4(), new Vector4()
  22874. ];
  22875. // init
  22876. for ( var i = 0; i !== _NumberOfMaterialVariants; ++ i ) {
  22877. var useMorphing = ( i & _MorphingFlag ) !== 0;
  22878. var useSkinning = ( i & _SkinningFlag ) !== 0;
  22879. var depthMaterial = new MeshDepthMaterial( {
  22880. depthPacking: RGBADepthPacking,
  22881. morphTargets: useMorphing,
  22882. skinning: useSkinning
  22883. } );
  22884. _depthMaterials[ i ] = depthMaterial;
  22885. //
  22886. var distanceMaterial = new MeshDistanceMaterial( {
  22887. morphTargets: useMorphing,
  22888. skinning: useSkinning
  22889. } );
  22890. _distanceMaterials[ i ] = distanceMaterial;
  22891. }
  22892. //
  22893. var scope = this;
  22894. this.enabled = false;
  22895. this.autoUpdate = true;
  22896. this.needsUpdate = false;
  22897. this.type = PCFShadowMap;
  22898. this.renderReverseSided = true;
  22899. this.renderSingleSided = true;
  22900. this.render = function ( lights, scene, camera ) {
  22901. if ( scope.enabled === false ) return;
  22902. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  22903. if ( lights.length === 0 ) return;
  22904. // TODO Clean up (needed in case of contextlost)
  22905. var _gl = _renderer.context;
  22906. var _state = _renderer.state;
  22907. // Set GL state for depth map.
  22908. _state.disable( _gl.BLEND );
  22909. _state.buffers.color.setClear( 1, 1, 1, 1 );
  22910. _state.buffers.depth.setTest( true );
  22911. _state.setScissorTest( false );
  22912. // render depth map
  22913. var faceCount;
  22914. for ( var i = 0, il = lights.length; i < il; i ++ ) {
  22915. var light = lights[ i ];
  22916. var shadow = light.shadow;
  22917. var isPointLight = light && light.isPointLight;
  22918. if ( shadow === undefined ) {
  22919. console.warn( 'THREE.WebGLShadowMap:', light, 'has no shadow.' );
  22920. continue;
  22921. }
  22922. var shadowCamera = shadow.camera;
  22923. _shadowMapSize.copy( shadow.mapSize );
  22924. _shadowMapSize.min( _maxShadowMapSize );
  22925. if ( isPointLight ) {
  22926. var vpWidth = _shadowMapSize.x;
  22927. var vpHeight = _shadowMapSize.y;
  22928. // These viewports map a cube-map onto a 2D texture with the
  22929. // following orientation:
  22930. //
  22931. // xzXZ
  22932. // y Y
  22933. //
  22934. // X - Positive x direction
  22935. // x - Negative x direction
  22936. // Y - Positive y direction
  22937. // y - Negative y direction
  22938. // Z - Positive z direction
  22939. // z - Negative z direction
  22940. // positive X
  22941. cube2DViewPorts[ 0 ].set( vpWidth * 2, vpHeight, vpWidth, vpHeight );
  22942. // negative X
  22943. cube2DViewPorts[ 1 ].set( 0, vpHeight, vpWidth, vpHeight );
  22944. // positive Z
  22945. cube2DViewPorts[ 2 ].set( vpWidth * 3, vpHeight, vpWidth, vpHeight );
  22946. // negative Z
  22947. cube2DViewPorts[ 3 ].set( vpWidth, vpHeight, vpWidth, vpHeight );
  22948. // positive Y
  22949. cube2DViewPorts[ 4 ].set( vpWidth * 3, 0, vpWidth, vpHeight );
  22950. // negative Y
  22951. cube2DViewPorts[ 5 ].set( vpWidth, 0, vpWidth, vpHeight );
  22952. _shadowMapSize.x *= 4.0;
  22953. _shadowMapSize.y *= 2.0;
  22954. }
  22955. if ( shadow.map === null ) {
  22956. var pars = { minFilter: NearestFilter, magFilter: NearestFilter, format: RGBAFormat };
  22957. shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  22958. shadow.map.texture.name = light.name + ".shadowMap";
  22959. shadowCamera.updateProjectionMatrix();
  22960. }
  22961. if ( shadow.isSpotLightShadow ) {
  22962. shadow.update( light );
  22963. }
  22964. var shadowMap = shadow.map;
  22965. var shadowMatrix = shadow.matrix;
  22966. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  22967. shadowCamera.position.copy( _lightPositionWorld );
  22968. if ( isPointLight ) {
  22969. faceCount = 6;
  22970. // for point lights we set the shadow matrix to be a translation-only matrix
  22971. // equal to inverse of the light's position
  22972. shadowMatrix.makeTranslation( - _lightPositionWorld.x, - _lightPositionWorld.y, - _lightPositionWorld.z );
  22973. } else {
  22974. faceCount = 1;
  22975. _lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  22976. shadowCamera.lookAt( _lookTarget );
  22977. shadowCamera.updateMatrixWorld();
  22978. // compute shadow matrix
  22979. shadowMatrix.set(
  22980. 0.5, 0.0, 0.0, 0.5,
  22981. 0.0, 0.5, 0.0, 0.5,
  22982. 0.0, 0.0, 0.5, 0.5,
  22983. 0.0, 0.0, 0.0, 1.0
  22984. );
  22985. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  22986. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  22987. }
  22988. _renderer.setRenderTarget( shadowMap );
  22989. _renderer.clear();
  22990. // render shadow map for each cube face (if omni-directional) or
  22991. // run a single pass if not
  22992. for ( var face = 0; face < faceCount; face ++ ) {
  22993. if ( isPointLight ) {
  22994. _lookTarget.copy( shadowCamera.position );
  22995. _lookTarget.add( cubeDirections[ face ] );
  22996. shadowCamera.up.copy( cubeUps[ face ] );
  22997. shadowCamera.lookAt( _lookTarget );
  22998. shadowCamera.updateMatrixWorld();
  22999. var vpDimensions = cube2DViewPorts[ face ];
  23000. _state.viewport( vpDimensions );
  23001. }
  23002. // update camera matrices and frustum
  23003. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  23004. _frustum.setFromMatrix( _projScreenMatrix );
  23005. // set object matrices & frustum culling
  23006. renderObject( scene, camera, shadowCamera, isPointLight );
  23007. }
  23008. }
  23009. scope.needsUpdate = false;
  23010. };
  23011. function getDepthMaterial( object, material, isPointLight, lightPositionWorld, shadowCameraNear, shadowCameraFar ) {
  23012. var geometry = object.geometry;
  23013. var result = null;
  23014. var materialVariants = _depthMaterials;
  23015. var customMaterial = object.customDepthMaterial;
  23016. if ( isPointLight ) {
  23017. materialVariants = _distanceMaterials;
  23018. customMaterial = object.customDistanceMaterial;
  23019. }
  23020. if ( ! customMaterial ) {
  23021. var useMorphing = false;
  23022. if ( material.morphTargets ) {
  23023. if ( geometry && geometry.isBufferGeometry ) {
  23024. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  23025. } else if ( geometry && geometry.isGeometry ) {
  23026. useMorphing = geometry.morphTargets && geometry.morphTargets.length > 0;
  23027. }
  23028. }
  23029. if ( object.isSkinnedMesh && material.skinning === false ) {
  23030. console.warn( 'THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object );
  23031. }
  23032. var useSkinning = object.isSkinnedMesh && material.skinning;
  23033. var variantIndex = 0;
  23034. if ( useMorphing ) variantIndex |= _MorphingFlag;
  23035. if ( useSkinning ) variantIndex |= _SkinningFlag;
  23036. result = materialVariants[ variantIndex ];
  23037. } else {
  23038. result = customMaterial;
  23039. }
  23040. if ( _renderer.localClippingEnabled &&
  23041. material.clipShadows === true &&
  23042. material.clippingPlanes.length !== 0 ) {
  23043. // in this case we need a unique material instance reflecting the
  23044. // appropriate state
  23045. var keyA = result.uuid, keyB = material.uuid;
  23046. var materialsForVariant = _materialCache[ keyA ];
  23047. if ( materialsForVariant === undefined ) {
  23048. materialsForVariant = {};
  23049. _materialCache[ keyA ] = materialsForVariant;
  23050. }
  23051. var cachedMaterial = materialsForVariant[ keyB ];
  23052. if ( cachedMaterial === undefined ) {
  23053. cachedMaterial = result.clone();
  23054. materialsForVariant[ keyB ] = cachedMaterial;
  23055. }
  23056. result = cachedMaterial;
  23057. }
  23058. result.visible = material.visible;
  23059. result.wireframe = material.wireframe;
  23060. var side = material.side;
  23061. if ( scope.renderSingleSided && side == DoubleSide ) {
  23062. side = FrontSide;
  23063. }
  23064. if ( scope.renderReverseSided ) {
  23065. if ( side === FrontSide ) side = BackSide;
  23066. else if ( side === BackSide ) side = FrontSide;
  23067. }
  23068. result.side = side;
  23069. result.clipShadows = material.clipShadows;
  23070. result.clippingPlanes = material.clippingPlanes;
  23071. result.clipIntersection = material.clipIntersection;
  23072. result.wireframeLinewidth = material.wireframeLinewidth;
  23073. result.linewidth = material.linewidth;
  23074. if ( isPointLight && result.isMeshDistanceMaterial ) {
  23075. result.referencePosition.copy( lightPositionWorld );
  23076. result.nearDistance = shadowCameraNear;
  23077. result.farDistance = shadowCameraFar;
  23078. }
  23079. return result;
  23080. }
  23081. function renderObject( object, camera, shadowCamera, isPointLight ) {
  23082. if ( object.visible === false ) return;
  23083. var visible = object.layers.test( camera.layers );
  23084. if ( visible && ( object.isMesh || object.isLine || object.isPoints ) ) {
  23085. if ( object.castShadow && ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) ) {
  23086. object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  23087. var geometry = _objects.update( object );
  23088. var material = object.material;
  23089. if ( Array.isArray( material ) ) {
  23090. var groups = geometry.groups;
  23091. for ( var k = 0, kl = groups.length; k < kl; k ++ ) {
  23092. var group = groups[ k ];
  23093. var groupMaterial = material[ group.materialIndex ];
  23094. if ( groupMaterial && groupMaterial.visible ) {
  23095. var depthMaterial = getDepthMaterial( object, groupMaterial, isPointLight, _lightPositionWorld, shadowCamera.near, shadowCamera.far );
  23096. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group );
  23097. }
  23098. }
  23099. } else if ( material.visible ) {
  23100. var depthMaterial = getDepthMaterial( object, material, isPointLight, _lightPositionWorld, shadowCamera.near, shadowCamera.far );
  23101. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null );
  23102. }
  23103. }
  23104. }
  23105. var children = object.children;
  23106. for ( var i = 0, l = children.length; i < l; i ++ ) {
  23107. renderObject( children[ i ], camera, shadowCamera, isPointLight );
  23108. }
  23109. }
  23110. }
  23111. /**
  23112. * @author mrdoob / http://mrdoob.com/
  23113. */
  23114. function WebGLAttributes( gl ) {
  23115. var buffers = {};
  23116. function createBuffer( attribute, bufferType ) {
  23117. var array = attribute.array;
  23118. var usage = attribute.dynamic ? gl.DYNAMIC_DRAW : gl.STATIC_DRAW;
  23119. var buffer = gl.createBuffer();
  23120. gl.bindBuffer( bufferType, buffer );
  23121. gl.bufferData( bufferType, array, usage );
  23122. attribute.onUploadCallback();
  23123. var type = gl.FLOAT;
  23124. if ( array instanceof Float32Array ) {
  23125. type = gl.FLOAT;
  23126. } else if ( array instanceof Float64Array ) {
  23127. console.warn( 'THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.' );
  23128. } else if ( array instanceof Uint16Array ) {
  23129. type = gl.UNSIGNED_SHORT;
  23130. } else if ( array instanceof Int16Array ) {
  23131. type = gl.SHORT;
  23132. } else if ( array instanceof Uint32Array ) {
  23133. type = gl.UNSIGNED_INT;
  23134. } else if ( array instanceof Int32Array ) {
  23135. type = gl.INT;
  23136. } else if ( array instanceof Int8Array ) {
  23137. type = gl.BYTE;
  23138. } else if ( array instanceof Uint8Array ) {
  23139. type = gl.UNSIGNED_BYTE;
  23140. }
  23141. return {
  23142. buffer: buffer,
  23143. type: type,
  23144. bytesPerElement: array.BYTES_PER_ELEMENT,
  23145. version: attribute.version
  23146. };
  23147. }
  23148. function updateBuffer( buffer, attribute, bufferType ) {
  23149. var array = attribute.array;
  23150. var updateRange = attribute.updateRange;
  23151. gl.bindBuffer( bufferType, buffer );
  23152. if ( attribute.dynamic === false ) {
  23153. gl.bufferData( bufferType, array, gl.STATIC_DRAW );
  23154. } else if ( updateRange.count === - 1 ) {
  23155. // Not using update ranges
  23156. gl.bufferSubData( bufferType, 0, array );
  23157. } else if ( updateRange.count === 0 ) {
  23158. 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.' );
  23159. } else {
  23160. gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
  23161. array.subarray( updateRange.offset, updateRange.offset + updateRange.count ) );
  23162. updateRange.count = - 1; // reset range
  23163. }
  23164. }
  23165. //
  23166. function get( attribute ) {
  23167. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  23168. return buffers[ attribute.uuid ];
  23169. }
  23170. function remove( attribute ) {
  23171. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  23172. var data = buffers[ attribute.uuid ];
  23173. if ( data ) {
  23174. gl.deleteBuffer( data.buffer );
  23175. delete buffers[ attribute.uuid ];
  23176. }
  23177. }
  23178. function update( attribute, bufferType ) {
  23179. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  23180. var data = buffers[ attribute.uuid ];
  23181. if ( data === undefined ) {
  23182. buffers[ attribute.uuid ] = createBuffer( attribute, bufferType );
  23183. } else if ( data.version < attribute.version ) {
  23184. updateBuffer( data.buffer, attribute, bufferType );
  23185. data.version = attribute.version;
  23186. }
  23187. }
  23188. return {
  23189. get: get,
  23190. remove: remove,
  23191. update: update
  23192. };
  23193. }
  23194. /**
  23195. * @author mrdoob / http://mrdoob.com/
  23196. * @author Mugen87 / https://github.com/Mugen87
  23197. */
  23198. // PlaneGeometry
  23199. function PlaneGeometry( width, height, widthSegments, heightSegments ) {
  23200. Geometry.call( this );
  23201. this.type = 'PlaneGeometry';
  23202. this.parameters = {
  23203. width: width,
  23204. height: height,
  23205. widthSegments: widthSegments,
  23206. heightSegments: heightSegments
  23207. };
  23208. this.fromBufferGeometry( new PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  23209. this.mergeVertices();
  23210. }
  23211. PlaneGeometry.prototype = Object.create( Geometry.prototype );
  23212. PlaneGeometry.prototype.constructor = PlaneGeometry;
  23213. // PlaneBufferGeometry
  23214. function PlaneBufferGeometry( width, height, widthSegments, heightSegments ) {
  23215. BufferGeometry.call( this );
  23216. this.type = 'PlaneBufferGeometry';
  23217. this.parameters = {
  23218. width: width,
  23219. height: height,
  23220. widthSegments: widthSegments,
  23221. heightSegments: heightSegments
  23222. };
  23223. width = width || 1;
  23224. height = height || 1;
  23225. var width_half = width / 2;
  23226. var height_half = height / 2;
  23227. var gridX = Math.floor( widthSegments ) || 1;
  23228. var gridY = Math.floor( heightSegments ) || 1;
  23229. var gridX1 = gridX + 1;
  23230. var gridY1 = gridY + 1;
  23231. var segment_width = width / gridX;
  23232. var segment_height = height / gridY;
  23233. var ix, iy;
  23234. // buffers
  23235. var indices = [];
  23236. var vertices = [];
  23237. var normals = [];
  23238. var uvs = [];
  23239. // generate vertices, normals and uvs
  23240. for ( iy = 0; iy < gridY1; iy ++ ) {
  23241. var y = iy * segment_height - height_half;
  23242. for ( ix = 0; ix < gridX1; ix ++ ) {
  23243. var x = ix * segment_width - width_half;
  23244. vertices.push( x, - y, 0 );
  23245. normals.push( 0, 0, 1 );
  23246. uvs.push( ix / gridX );
  23247. uvs.push( 1 - ( iy / gridY ) );
  23248. }
  23249. }
  23250. // indices
  23251. for ( iy = 0; iy < gridY; iy ++ ) {
  23252. for ( ix = 0; ix < gridX; ix ++ ) {
  23253. var a = ix + gridX1 * iy;
  23254. var b = ix + gridX1 * ( iy + 1 );
  23255. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  23256. var d = ( ix + 1 ) + gridX1 * iy;
  23257. // faces
  23258. indices.push( a, b, d );
  23259. indices.push( b, c, d );
  23260. }
  23261. }
  23262. // build geometry
  23263. this.setIndex( indices );
  23264. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  23265. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  23266. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  23267. }
  23268. PlaneBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  23269. PlaneBufferGeometry.prototype.constructor = PlaneBufferGeometry;
  23270. /**
  23271. * @author mrdoob / http://mrdoob.com/
  23272. */
  23273. function WebGLBackground( renderer, state, geometries, premultipliedAlpha ) {
  23274. var clearColor = new Color( 0x000000 );
  23275. var clearAlpha = 0;
  23276. var planeCamera, planeMesh;
  23277. var boxMesh;
  23278. function render( renderList, scene, camera, forceClear ) {
  23279. var background = scene.background;
  23280. if ( background === null ) {
  23281. setClear( clearColor, clearAlpha );
  23282. } else if ( background && background.isColor ) {
  23283. setClear( background, 1 );
  23284. forceClear = true;
  23285. }
  23286. if ( renderer.autoClear || forceClear ) {
  23287. renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil );
  23288. }
  23289. if ( background && background.isCubeTexture ) {
  23290. if ( boxMesh === undefined ) {
  23291. boxMesh = new Mesh(
  23292. new BoxBufferGeometry( 1, 1, 1 ),
  23293. new ShaderMaterial( {
  23294. uniforms: ShaderLib.cube.uniforms,
  23295. vertexShader: ShaderLib.cube.vertexShader,
  23296. fragmentShader: ShaderLib.cube.fragmentShader,
  23297. side: BackSide,
  23298. depthTest: true,
  23299. depthWrite: false,
  23300. fog: false
  23301. } )
  23302. );
  23303. boxMesh.geometry.removeAttribute( 'normal' );
  23304. boxMesh.geometry.removeAttribute( 'uv' );
  23305. boxMesh.onBeforeRender = function ( renderer, scene, camera ) {
  23306. this.matrixWorld.copyPosition( camera.matrixWorld );
  23307. };
  23308. geometries.update( boxMesh.geometry );
  23309. }
  23310. boxMesh.material.uniforms.tCube.value = background;
  23311. renderList.push( boxMesh, boxMesh.geometry, boxMesh.material, 0, null );
  23312. } else if ( background && background.isTexture ) {
  23313. if ( planeCamera === undefined ) {
  23314. planeCamera = new OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
  23315. planeMesh = new Mesh(
  23316. new PlaneBufferGeometry( 2, 2 ),
  23317. new MeshBasicMaterial( { depthTest: false, depthWrite: false, fog: false } )
  23318. );
  23319. geometries.update( planeMesh.geometry );
  23320. }
  23321. planeMesh.material.map = background;
  23322. // TODO Push this to renderList
  23323. renderer.renderBufferDirect( planeCamera, null, planeMesh.geometry, planeMesh.material, planeMesh, null );
  23324. }
  23325. }
  23326. function setClear( color, alpha ) {
  23327. state.buffers.color.setClear( color.r, color.g, color.b, alpha, premultipliedAlpha );
  23328. }
  23329. return {
  23330. getClearColor: function () {
  23331. return clearColor;
  23332. },
  23333. setClearColor: function ( color, alpha ) {
  23334. clearColor.set( color );
  23335. clearAlpha = alpha !== undefined ? alpha : 1;
  23336. setClear( clearColor, clearAlpha );
  23337. },
  23338. getClearAlpha: function () {
  23339. return clearAlpha;
  23340. },
  23341. setClearAlpha: function ( alpha ) {
  23342. clearAlpha = alpha;
  23343. setClear( clearColor, clearAlpha );
  23344. },
  23345. render: render
  23346. };
  23347. }
  23348. /**
  23349. * @author mrdoob / http://mrdoob.com/
  23350. */
  23351. function painterSortStable( a, b ) {
  23352. if ( a.renderOrder !== b.renderOrder ) {
  23353. return a.renderOrder - b.renderOrder;
  23354. } else if ( a.program && b.program && a.program !== b.program ) {
  23355. return a.program.id - b.program.id;
  23356. } else if ( a.material.id !== b.material.id ) {
  23357. return a.material.id - b.material.id;
  23358. } else if ( a.z !== b.z ) {
  23359. return a.z - b.z;
  23360. } else {
  23361. return a.id - b.id;
  23362. }
  23363. }
  23364. function reversePainterSortStable( a, b ) {
  23365. if ( a.renderOrder !== b.renderOrder ) {
  23366. return a.renderOrder - b.renderOrder;
  23367. } if ( a.z !== b.z ) {
  23368. return b.z - a.z;
  23369. } else {
  23370. return a.id - b.id;
  23371. }
  23372. }
  23373. function WebGLRenderList() {
  23374. var renderItems = [];
  23375. var renderItemsIndex = 0;
  23376. var opaque = [];
  23377. var transparent = [];
  23378. function init() {
  23379. renderItemsIndex = 0;
  23380. opaque.length = 0;
  23381. transparent.length = 0;
  23382. }
  23383. function push( object, geometry, material, z, group ) {
  23384. var renderItem = renderItems[ renderItemsIndex ];
  23385. if ( renderItem === undefined ) {
  23386. renderItem = {
  23387. id: object.id,
  23388. object: object,
  23389. geometry: geometry,
  23390. material: material,
  23391. program: material.program,
  23392. renderOrder: object.renderOrder,
  23393. z: z,
  23394. group: group
  23395. };
  23396. renderItems[ renderItemsIndex ] = renderItem;
  23397. } else {
  23398. renderItem.id = object.id;
  23399. renderItem.object = object;
  23400. renderItem.geometry = geometry;
  23401. renderItem.material = material;
  23402. renderItem.program = material.program;
  23403. renderItem.renderOrder = object.renderOrder;
  23404. renderItem.z = z;
  23405. renderItem.group = group;
  23406. }
  23407. ( material.transparent === true ? transparent : opaque ).push( renderItem );
  23408. renderItemsIndex ++;
  23409. }
  23410. function sort() {
  23411. if ( opaque.length > 1 ) opaque.sort( painterSortStable );
  23412. if ( transparent.length > 1 ) transparent.sort( reversePainterSortStable );
  23413. }
  23414. return {
  23415. opaque: opaque,
  23416. transparent: transparent,
  23417. init: init,
  23418. push: push,
  23419. sort: sort
  23420. };
  23421. }
  23422. function WebGLRenderLists() {
  23423. var lists = {};
  23424. function get( scene, camera ) {
  23425. var hash = scene.id + ',' + camera.id;
  23426. var list = lists[ hash ];
  23427. if ( list === undefined ) {
  23428. // console.log( 'THREE.WebGLRenderLists:', hash );
  23429. list = new WebGLRenderList();
  23430. lists[ hash ] = list;
  23431. }
  23432. return list;
  23433. }
  23434. function dispose() {
  23435. lists = {};
  23436. }
  23437. return {
  23438. get: get,
  23439. dispose: dispose
  23440. };
  23441. }
  23442. /**
  23443. * @author mrdoob / http://mrdoob.com/
  23444. */
  23445. function absNumericalSort( a, b ) {
  23446. return Math.abs( b[ 1 ] ) - Math.abs( a[ 1 ] );
  23447. }
  23448. function WebGLMorphtargets( gl ) {
  23449. var influencesList = {};
  23450. var morphInfluences = new Float32Array( 8 );
  23451. function update( object, geometry, material, program ) {
  23452. var objectInfluences = object.morphTargetInfluences;
  23453. var length = objectInfluences.length;
  23454. var influences = influencesList[ geometry.id ];
  23455. if ( influences === undefined ) {
  23456. // initialise list
  23457. influences = [];
  23458. for ( var i = 0; i < length; i ++ ) {
  23459. influences[ i ] = [ i, 0 ];
  23460. }
  23461. influencesList[ geometry.id ] = influences;
  23462. }
  23463. var morphTargets = material.morphTargets && geometry.morphAttributes.position;
  23464. var morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  23465. // Remove current morphAttributes
  23466. for ( var i = 0; i < length; i ++ ) {
  23467. var influence = influences[ i ];
  23468. if ( influence[ 1 ] !== 0 ) {
  23469. if ( morphTargets ) geometry.removeAttribute( 'morphTarget' + i );
  23470. if ( morphNormals ) geometry.removeAttribute( 'morphNormal' + i );
  23471. }
  23472. }
  23473. // Collect influences
  23474. for ( var i = 0; i < length; i ++ ) {
  23475. var influence = influences[ i ];
  23476. influence[ 0 ] = i;
  23477. influence[ 1 ] = objectInfluences[ i ];
  23478. }
  23479. influences.sort( absNumericalSort );
  23480. // Add morphAttributes
  23481. for ( var i = 0; i < 8; i ++ ) {
  23482. var influence = influences[ i ];
  23483. if ( influence ) {
  23484. var index = influence[ 0 ];
  23485. var value = influence[ 1 ];
  23486. if ( value ) {
  23487. if ( morphTargets ) geometry.addAttribute( 'morphTarget' + i, morphTargets[ index ] );
  23488. if ( morphNormals ) geometry.addAttribute( 'morphNormal' + i, morphNormals[ index ] );
  23489. morphInfluences[ i ] = value;
  23490. continue;
  23491. }
  23492. }
  23493. morphInfluences[ i ] = 0;
  23494. }
  23495. program.getUniforms().setValue( gl, 'morphTargetInfluences', morphInfluences );
  23496. }
  23497. return {
  23498. update: update
  23499. };
  23500. }
  23501. /**
  23502. * @author mrdoob / http://mrdoob.com/
  23503. */
  23504. function WebGLIndexedBufferRenderer( gl, extensions, infoRender ) {
  23505. var mode;
  23506. function setMode( value ) {
  23507. mode = value;
  23508. }
  23509. var type, bytesPerElement;
  23510. function setIndex( value ) {
  23511. type = value.type;
  23512. bytesPerElement = value.bytesPerElement;
  23513. }
  23514. function render( start, count ) {
  23515. gl.drawElements( mode, count, type, start * bytesPerElement );
  23516. infoRender.calls ++;
  23517. infoRender.vertices += count;
  23518. if ( mode === gl.TRIANGLES ) infoRender.faces += count / 3;
  23519. else if ( mode === gl.POINTS ) infoRender.points += count;
  23520. }
  23521. function renderInstances( geometry, start, count ) {
  23522. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  23523. if ( extension === null ) {
  23524. console.error( 'THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  23525. return;
  23526. }
  23527. extension.drawElementsInstancedANGLE( mode, count, type, start * bytesPerElement, geometry.maxInstancedCount );
  23528. infoRender.calls ++;
  23529. infoRender.vertices += count * geometry.maxInstancedCount;
  23530. if ( mode === gl.TRIANGLES ) infoRender.faces += geometry.maxInstancedCount * count / 3;
  23531. else if ( mode === gl.POINTS ) infoRender.points += geometry.maxInstancedCount * count;
  23532. }
  23533. //
  23534. this.setMode = setMode;
  23535. this.setIndex = setIndex;
  23536. this.render = render;
  23537. this.renderInstances = renderInstances;
  23538. }
  23539. /**
  23540. * @author mrdoob / http://mrdoob.com/
  23541. */
  23542. function WebGLBufferRenderer( gl, extensions, infoRender ) {
  23543. var mode;
  23544. function setMode( value ) {
  23545. mode = value;
  23546. }
  23547. function render( start, count ) {
  23548. gl.drawArrays( mode, start, count );
  23549. infoRender.calls ++;
  23550. infoRender.vertices += count;
  23551. if ( mode === gl.TRIANGLES ) infoRender.faces += count / 3;
  23552. else if ( mode === gl.POINTS ) infoRender.points += count;
  23553. }
  23554. function renderInstances( geometry, start, count ) {
  23555. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  23556. if ( extension === null ) {
  23557. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  23558. return;
  23559. }
  23560. var position = geometry.attributes.position;
  23561. if ( position.isInterleavedBufferAttribute ) {
  23562. count = position.data.count;
  23563. extension.drawArraysInstancedANGLE( mode, 0, count, geometry.maxInstancedCount );
  23564. } else {
  23565. extension.drawArraysInstancedANGLE( mode, start, count, geometry.maxInstancedCount );
  23566. }
  23567. infoRender.calls ++;
  23568. infoRender.vertices += count * geometry.maxInstancedCount;
  23569. if ( mode === gl.TRIANGLES ) infoRender.faces += geometry.maxInstancedCount * count / 3;
  23570. else if ( mode === gl.POINTS ) infoRender.points += geometry.maxInstancedCount * count;
  23571. }
  23572. //
  23573. this.setMode = setMode;
  23574. this.render = render;
  23575. this.renderInstances = renderInstances;
  23576. }
  23577. /**
  23578. * @author mrdoob / http://mrdoob.com/
  23579. */
  23580. function WebGLGeometries( gl, attributes, infoMemory ) {
  23581. var geometries = {};
  23582. var wireframeAttributes = {};
  23583. function onGeometryDispose( event ) {
  23584. var geometry = event.target;
  23585. var buffergeometry = geometries[ geometry.id ];
  23586. if ( buffergeometry.index !== null ) {
  23587. attributes.remove( buffergeometry.index );
  23588. }
  23589. for ( var name in buffergeometry.attributes ) {
  23590. attributes.remove( buffergeometry.attributes[ name ] );
  23591. }
  23592. geometry.removeEventListener( 'dispose', onGeometryDispose );
  23593. delete geometries[ geometry.id ];
  23594. // TODO Remove duplicate code
  23595. var attribute = wireframeAttributes[ geometry.id ];
  23596. if ( attribute ) {
  23597. attributes.remove( attribute );
  23598. delete wireframeAttributes[ geometry.id ];
  23599. }
  23600. attribute = wireframeAttributes[ buffergeometry.id ];
  23601. if ( attribute ) {
  23602. attributes.remove( attribute );
  23603. delete wireframeAttributes[ buffergeometry.id ];
  23604. }
  23605. //
  23606. infoMemory.geometries --;
  23607. }
  23608. function get( object, geometry ) {
  23609. var buffergeometry = geometries[ geometry.id ];
  23610. if ( buffergeometry ) return buffergeometry;
  23611. geometry.addEventListener( 'dispose', onGeometryDispose );
  23612. if ( geometry.isBufferGeometry ) {
  23613. buffergeometry = geometry;
  23614. } else if ( geometry.isGeometry ) {
  23615. if ( geometry._bufferGeometry === undefined ) {
  23616. geometry._bufferGeometry = new BufferGeometry().setFromObject( object );
  23617. }
  23618. buffergeometry = geometry._bufferGeometry;
  23619. }
  23620. geometries[ geometry.id ] = buffergeometry;
  23621. infoMemory.geometries ++;
  23622. return buffergeometry;
  23623. }
  23624. function update( geometry ) {
  23625. var index = geometry.index;
  23626. var geometryAttributes = geometry.attributes;
  23627. if ( index !== null ) {
  23628. attributes.update( index, gl.ELEMENT_ARRAY_BUFFER );
  23629. }
  23630. for ( var name in geometryAttributes ) {
  23631. attributes.update( geometryAttributes[ name ], gl.ARRAY_BUFFER );
  23632. }
  23633. // morph targets
  23634. var morphAttributes = geometry.morphAttributes;
  23635. for ( var name in morphAttributes ) {
  23636. var array = morphAttributes[ name ];
  23637. for ( var i = 0, l = array.length; i < l; i ++ ) {
  23638. attributes.update( array[ i ], gl.ARRAY_BUFFER );
  23639. }
  23640. }
  23641. }
  23642. function getWireframeAttribute( geometry ) {
  23643. var attribute = wireframeAttributes[ geometry.id ];
  23644. if ( attribute ) return attribute;
  23645. var indices = [];
  23646. var geometryIndex = geometry.index;
  23647. var geometryAttributes = geometry.attributes;
  23648. // console.time( 'wireframe' );
  23649. if ( geometryIndex !== null ) {
  23650. var array = geometryIndex.array;
  23651. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  23652. var a = array[ i + 0 ];
  23653. var b = array[ i + 1 ];
  23654. var c = array[ i + 2 ];
  23655. indices.push( a, b, b, c, c, a );
  23656. }
  23657. } else {
  23658. var array = geometryAttributes.position.array;
  23659. for ( var i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  23660. var a = i + 0;
  23661. var b = i + 1;
  23662. var c = i + 2;
  23663. indices.push( a, b, b, c, c, a );
  23664. }
  23665. }
  23666. // console.timeEnd( 'wireframe' );
  23667. attribute = new ( arrayMax( indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 );
  23668. attributes.update( attribute, gl.ELEMENT_ARRAY_BUFFER );
  23669. wireframeAttributes[ geometry.id ] = attribute;
  23670. return attribute;
  23671. }
  23672. return {
  23673. get: get,
  23674. update: update,
  23675. getWireframeAttribute: getWireframeAttribute
  23676. };
  23677. }
  23678. /**
  23679. * @author mrdoob / http://mrdoob.com/
  23680. */
  23681. function UniformsCache() {
  23682. var lights = {};
  23683. return {
  23684. get: function ( light ) {
  23685. if ( lights[ light.id ] !== undefined ) {
  23686. return lights[ light.id ];
  23687. }
  23688. var uniforms;
  23689. switch ( light.type ) {
  23690. case 'DirectionalLight':
  23691. uniforms = {
  23692. direction: new Vector3(),
  23693. color: new Color(),
  23694. shadow: false,
  23695. shadowBias: 0,
  23696. shadowRadius: 1,
  23697. shadowMapSize: new Vector2()
  23698. };
  23699. break;
  23700. case 'SpotLight':
  23701. uniforms = {
  23702. position: new Vector3(),
  23703. direction: new Vector3(),
  23704. color: new Color(),
  23705. distance: 0,
  23706. coneCos: 0,
  23707. penumbraCos: 0,
  23708. decay: 0,
  23709. shadow: false,
  23710. shadowBias: 0,
  23711. shadowRadius: 1,
  23712. shadowMapSize: new Vector2()
  23713. };
  23714. break;
  23715. case 'PointLight':
  23716. uniforms = {
  23717. position: new Vector3(),
  23718. color: new Color(),
  23719. distance: 0,
  23720. decay: 0,
  23721. shadow: false,
  23722. shadowBias: 0,
  23723. shadowRadius: 1,
  23724. shadowMapSize: new Vector2(),
  23725. shadowCameraNear: 1,
  23726. shadowCameraFar: 1000
  23727. };
  23728. break;
  23729. case 'HemisphereLight':
  23730. uniforms = {
  23731. direction: new Vector3(),
  23732. skyColor: new Color(),
  23733. groundColor: new Color()
  23734. };
  23735. break;
  23736. case 'RectAreaLight':
  23737. uniforms = {
  23738. color: new Color(),
  23739. position: new Vector3(),
  23740. halfWidth: new Vector3(),
  23741. halfHeight: new Vector3()
  23742. // TODO (abelnation): set RectAreaLight shadow uniforms
  23743. };
  23744. break;
  23745. }
  23746. lights[ light.id ] = uniforms;
  23747. return uniforms;
  23748. }
  23749. };
  23750. }
  23751. function WebGLLights() {
  23752. var cache = new UniformsCache();
  23753. var state = {
  23754. hash: '',
  23755. ambient: [ 0, 0, 0 ],
  23756. directional: [],
  23757. directionalShadowMap: [],
  23758. directionalShadowMatrix: [],
  23759. spot: [],
  23760. spotShadowMap: [],
  23761. spotShadowMatrix: [],
  23762. rectArea: [],
  23763. point: [],
  23764. pointShadowMap: [],
  23765. pointShadowMatrix: [],
  23766. hemi: []
  23767. };
  23768. var vector3 = new Vector3();
  23769. var matrix4 = new Matrix4();
  23770. var matrix42 = new Matrix4();
  23771. function setup( lights, shadows, camera ) {
  23772. var r = 0, g = 0, b = 0;
  23773. var directionalLength = 0;
  23774. var pointLength = 0;
  23775. var spotLength = 0;
  23776. var rectAreaLength = 0;
  23777. var hemiLength = 0;
  23778. var viewMatrix = camera.matrixWorldInverse;
  23779. for ( var i = 0, l = lights.length; i < l; i ++ ) {
  23780. var light = lights[ i ];
  23781. var color = light.color;
  23782. var intensity = light.intensity;
  23783. var distance = light.distance;
  23784. var shadowMap = ( light.shadow && light.shadow.map ) ? light.shadow.map.texture : null;
  23785. if ( light.isAmbientLight ) {
  23786. r += color.r * intensity;
  23787. g += color.g * intensity;
  23788. b += color.b * intensity;
  23789. } else if ( light.isDirectionalLight ) {
  23790. var uniforms = cache.get( light );
  23791. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  23792. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  23793. vector3.setFromMatrixPosition( light.target.matrixWorld );
  23794. uniforms.direction.sub( vector3 );
  23795. uniforms.direction.transformDirection( viewMatrix );
  23796. uniforms.shadow = light.castShadow;
  23797. if ( light.castShadow ) {
  23798. var shadow = light.shadow;
  23799. uniforms.shadowBias = shadow.bias;
  23800. uniforms.shadowRadius = shadow.radius;
  23801. uniforms.shadowMapSize = shadow.mapSize;
  23802. }
  23803. state.directionalShadowMap[ directionalLength ] = shadowMap;
  23804. state.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix;
  23805. state.directional[ directionalLength ] = uniforms;
  23806. directionalLength ++;
  23807. } else if ( light.isSpotLight ) {
  23808. var uniforms = cache.get( light );
  23809. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  23810. uniforms.position.applyMatrix4( viewMatrix );
  23811. uniforms.color.copy( color ).multiplyScalar( intensity );
  23812. uniforms.distance = distance;
  23813. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  23814. vector3.setFromMatrixPosition( light.target.matrixWorld );
  23815. uniforms.direction.sub( vector3 );
  23816. uniforms.direction.transformDirection( viewMatrix );
  23817. uniforms.coneCos = Math.cos( light.angle );
  23818. uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) );
  23819. uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
  23820. uniforms.shadow = light.castShadow;
  23821. if ( light.castShadow ) {
  23822. var shadow = light.shadow;
  23823. uniforms.shadowBias = shadow.bias;
  23824. uniforms.shadowRadius = shadow.radius;
  23825. uniforms.shadowMapSize = shadow.mapSize;
  23826. }
  23827. state.spotShadowMap[ spotLength ] = shadowMap;
  23828. state.spotShadowMatrix[ spotLength ] = light.shadow.matrix;
  23829. state.spot[ spotLength ] = uniforms;
  23830. spotLength ++;
  23831. } else if ( light.isRectAreaLight ) {
  23832. var uniforms = cache.get( light );
  23833. // (a) intensity controls irradiance of entire light
  23834. uniforms.color
  23835. .copy( color )
  23836. .multiplyScalar( intensity / ( light.width * light.height ) );
  23837. // (b) intensity controls the radiance per light area
  23838. // uniforms.color.copy( color ).multiplyScalar( intensity );
  23839. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  23840. uniforms.position.applyMatrix4( viewMatrix );
  23841. // extract local rotation of light to derive width/height half vectors
  23842. matrix42.identity();
  23843. matrix4.copy( light.matrixWorld );
  23844. matrix4.premultiply( viewMatrix );
  23845. matrix42.extractRotation( matrix4 );
  23846. uniforms.halfWidth.set( light.width * 0.5, 0.0, 0.0 );
  23847. uniforms.halfHeight.set( 0.0, light.height * 0.5, 0.0 );
  23848. uniforms.halfWidth.applyMatrix4( matrix42 );
  23849. uniforms.halfHeight.applyMatrix4( matrix42 );
  23850. // TODO (abelnation): RectAreaLight distance?
  23851. // uniforms.distance = distance;
  23852. state.rectArea[ rectAreaLength ] = uniforms;
  23853. rectAreaLength ++;
  23854. } else if ( light.isPointLight ) {
  23855. var uniforms = cache.get( light );
  23856. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  23857. uniforms.position.applyMatrix4( viewMatrix );
  23858. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  23859. uniforms.distance = light.distance;
  23860. uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
  23861. uniforms.shadow = light.castShadow;
  23862. if ( light.castShadow ) {
  23863. var shadow = light.shadow;
  23864. uniforms.shadowBias = shadow.bias;
  23865. uniforms.shadowRadius = shadow.radius;
  23866. uniforms.shadowMapSize = shadow.mapSize;
  23867. uniforms.shadowCameraNear = shadow.camera.near;
  23868. uniforms.shadowCameraFar = shadow.camera.far;
  23869. }
  23870. state.pointShadowMap[ pointLength ] = shadowMap;
  23871. state.pointShadowMatrix[ pointLength ] = light.shadow.matrix;
  23872. state.point[ pointLength ] = uniforms;
  23873. pointLength ++;
  23874. } else if ( light.isHemisphereLight ) {
  23875. var uniforms = cache.get( light );
  23876. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  23877. uniforms.direction.transformDirection( viewMatrix );
  23878. uniforms.direction.normalize();
  23879. uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
  23880. uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
  23881. state.hemi[ hemiLength ] = uniforms;
  23882. hemiLength ++;
  23883. }
  23884. }
  23885. state.ambient[ 0 ] = r;
  23886. state.ambient[ 1 ] = g;
  23887. state.ambient[ 2 ] = b;
  23888. state.directional.length = directionalLength;
  23889. state.spot.length = spotLength;
  23890. state.rectArea.length = rectAreaLength;
  23891. state.point.length = pointLength;
  23892. state.hemi.length = hemiLength;
  23893. // TODO (sam-g-steel) why aren't we using join
  23894. state.hash = directionalLength + ',' + pointLength + ',' + spotLength + ',' + rectAreaLength + ',' + hemiLength + ',' + shadows.length;
  23895. }
  23896. return {
  23897. setup: setup,
  23898. state: state
  23899. };
  23900. }
  23901. /**
  23902. * @author mrdoob / http://mrdoob.com/
  23903. */
  23904. function WebGLObjects( geometries, infoRender ) {
  23905. var updateList = {};
  23906. function update( object ) {
  23907. var frame = infoRender.frame;
  23908. var geometry = object.geometry;
  23909. var buffergeometry = geometries.get( object, geometry );
  23910. // Update once per frame
  23911. if ( updateList[ buffergeometry.id ] !== frame ) {
  23912. if ( geometry.isGeometry ) {
  23913. buffergeometry.updateFromObject( object );
  23914. }
  23915. geometries.update( buffergeometry );
  23916. updateList[ buffergeometry.id ] = frame;
  23917. }
  23918. return buffergeometry;
  23919. }
  23920. function clear() {
  23921. updateList = {};
  23922. }
  23923. return {
  23924. update: update,
  23925. clear: clear
  23926. };
  23927. }
  23928. /**
  23929. * @author mrdoob / http://mrdoob.com/
  23930. */
  23931. function addLineNumbers( string ) {
  23932. var lines = string.split( '\n' );
  23933. for ( var i = 0; i < lines.length; i ++ ) {
  23934. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  23935. }
  23936. return lines.join( '\n' );
  23937. }
  23938. function WebGLShader( gl, type, string ) {
  23939. var shader = gl.createShader( type );
  23940. gl.shaderSource( shader, string );
  23941. gl.compileShader( shader );
  23942. if ( gl.getShaderParameter( shader, gl.COMPILE_STATUS ) === false ) {
  23943. console.error( 'THREE.WebGLShader: Shader couldn\'t compile.' );
  23944. }
  23945. if ( gl.getShaderInfoLog( shader ) !== '' ) {
  23946. console.warn( 'THREE.WebGLShader: gl.getShaderInfoLog()', type === gl.VERTEX_SHADER ? 'vertex' : 'fragment', gl.getShaderInfoLog( shader ), addLineNumbers( string ) );
  23947. }
  23948. // --enable-privileged-webgl-extension
  23949. // console.log( type, gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  23950. return shader;
  23951. }
  23952. /**
  23953. * @author mrdoob / http://mrdoob.com/
  23954. */
  23955. var programIdCount = 0;
  23956. function getEncodingComponents( encoding ) {
  23957. switch ( encoding ) {
  23958. case LinearEncoding:
  23959. return [ 'Linear', '( value )' ];
  23960. case sRGBEncoding:
  23961. return [ 'sRGB', '( value )' ];
  23962. case RGBEEncoding:
  23963. return [ 'RGBE', '( value )' ];
  23964. case RGBM7Encoding:
  23965. return [ 'RGBM', '( value, 7.0 )' ];
  23966. case RGBM16Encoding:
  23967. return [ 'RGBM', '( value, 16.0 )' ];
  23968. case RGBDEncoding:
  23969. return [ 'RGBD', '( value, 256.0 )' ];
  23970. case GammaEncoding:
  23971. return [ 'Gamma', '( value, float( GAMMA_FACTOR ) )' ];
  23972. default:
  23973. throw new Error( 'unsupported encoding: ' + encoding );
  23974. }
  23975. }
  23976. function getTexelDecodingFunction( functionName, encoding ) {
  23977. var components = getEncodingComponents( encoding );
  23978. return "vec4 " + functionName + "( vec4 value ) { return " + components[ 0 ] + "ToLinear" + components[ 1 ] + "; }";
  23979. }
  23980. function getTexelEncodingFunction( functionName, encoding ) {
  23981. var components = getEncodingComponents( encoding );
  23982. return "vec4 " + functionName + "( vec4 value ) { return LinearTo" + components[ 0 ] + components[ 1 ] + "; }";
  23983. }
  23984. function getToneMappingFunction( functionName, toneMapping ) {
  23985. var toneMappingName;
  23986. switch ( toneMapping ) {
  23987. case LinearToneMapping:
  23988. toneMappingName = "Linear";
  23989. break;
  23990. case ReinhardToneMapping:
  23991. toneMappingName = "Reinhard";
  23992. break;
  23993. case Uncharted2ToneMapping:
  23994. toneMappingName = "Uncharted2";
  23995. break;
  23996. case CineonToneMapping:
  23997. toneMappingName = "OptimizedCineon";
  23998. break;
  23999. default:
  24000. throw new Error( 'unsupported toneMapping: ' + toneMapping );
  24001. }
  24002. return "vec3 " + functionName + "( vec3 color ) { return " + toneMappingName + "ToneMapping( color ); }";
  24003. }
  24004. function generateExtensions( extensions, parameters, rendererExtensions ) {
  24005. extensions = extensions || {};
  24006. var chunks = [
  24007. ( extensions.derivatives || parameters.envMapCubeUV || parameters.bumpMap || parameters.normalMap || parameters.flatShading ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  24008. ( extensions.fragDepth || parameters.logarithmicDepthBuffer ) && rendererExtensions.get( 'EXT_frag_depth' ) ? '#extension GL_EXT_frag_depth : enable' : '',
  24009. ( extensions.drawBuffers ) && rendererExtensions.get( 'WEBGL_draw_buffers' ) ? '#extension GL_EXT_draw_buffers : require' : '',
  24010. ( extensions.shaderTextureLOD || parameters.envMap ) && rendererExtensions.get( 'EXT_shader_texture_lod' ) ? '#extension GL_EXT_shader_texture_lod : enable' : ''
  24011. ];
  24012. return chunks.filter( filterEmptyLine ).join( '\n' );
  24013. }
  24014. function generateDefines( defines ) {
  24015. var chunks = [];
  24016. for ( var name in defines ) {
  24017. var value = defines[ name ];
  24018. if ( value === false ) continue;
  24019. chunks.push( '#define ' + name + ' ' + value );
  24020. }
  24021. return chunks.join( '\n' );
  24022. }
  24023. function fetchAttributeLocations( gl, program ) {
  24024. var attributes = {};
  24025. var n = gl.getProgramParameter( program, gl.ACTIVE_ATTRIBUTES );
  24026. for ( var i = 0; i < n; i ++ ) {
  24027. var info = gl.getActiveAttrib( program, i );
  24028. var name = info.name;
  24029. // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  24030. attributes[ name ] = gl.getAttribLocation( program, name );
  24031. }
  24032. return attributes;
  24033. }
  24034. function filterEmptyLine( string ) {
  24035. return string !== '';
  24036. }
  24037. function replaceLightNums( string, parameters ) {
  24038. return string
  24039. .replace( /NUM_DIR_LIGHTS/g, parameters.numDirLights )
  24040. .replace( /NUM_SPOT_LIGHTS/g, parameters.numSpotLights )
  24041. .replace( /NUM_RECT_AREA_LIGHTS/g, parameters.numRectAreaLights )
  24042. .replace( /NUM_POINT_LIGHTS/g, parameters.numPointLights )
  24043. .replace( /NUM_HEMI_LIGHTS/g, parameters.numHemiLights );
  24044. }
  24045. function parseIncludes( string ) {
  24046. var pattern = /^[ \t]*#include +<([\w\d.]+)>/gm;
  24047. function replace( match, include ) {
  24048. var replace = ShaderChunk[ include ];
  24049. if ( replace === undefined ) {
  24050. throw new Error( 'Can not resolve #include <' + include + '>' );
  24051. }
  24052. return parseIncludes( replace );
  24053. }
  24054. return string.replace( pattern, replace );
  24055. }
  24056. function unrollLoops( string ) {
  24057. var pattern = /for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  24058. function replace( match, start, end, snippet ) {
  24059. var unroll = '';
  24060. for ( var i = parseInt( start ); i < parseInt( end ); i ++ ) {
  24061. unroll += snippet.replace( /\[ i \]/g, '[ ' + i + ' ]' );
  24062. }
  24063. return unroll;
  24064. }
  24065. return string.replace( pattern, replace );
  24066. }
  24067. function WebGLProgram( renderer, extensions, code, material, shader, parameters ) {
  24068. var gl = renderer.context;
  24069. var defines = material.defines;
  24070. var vertexShader = shader.vertexShader;
  24071. var fragmentShader = shader.fragmentShader;
  24072. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  24073. if ( parameters.shadowMapType === PCFShadowMap ) {
  24074. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  24075. } else if ( parameters.shadowMapType === PCFSoftShadowMap ) {
  24076. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  24077. }
  24078. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  24079. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  24080. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  24081. if ( parameters.envMap ) {
  24082. switch ( material.envMap.mapping ) {
  24083. case CubeReflectionMapping:
  24084. case CubeRefractionMapping:
  24085. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  24086. break;
  24087. case CubeUVReflectionMapping:
  24088. case CubeUVRefractionMapping:
  24089. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  24090. break;
  24091. case EquirectangularReflectionMapping:
  24092. case EquirectangularRefractionMapping:
  24093. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  24094. break;
  24095. case SphericalReflectionMapping:
  24096. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  24097. break;
  24098. }
  24099. switch ( material.envMap.mapping ) {
  24100. case CubeRefractionMapping:
  24101. case EquirectangularRefractionMapping:
  24102. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  24103. break;
  24104. }
  24105. switch ( material.combine ) {
  24106. case MultiplyOperation:
  24107. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  24108. break;
  24109. case MixOperation:
  24110. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  24111. break;
  24112. case AddOperation:
  24113. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  24114. break;
  24115. }
  24116. }
  24117. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  24118. // console.log( 'building new program ' );
  24119. //
  24120. var customExtensions = generateExtensions( material.extensions, parameters, extensions );
  24121. var customDefines = generateDefines( defines );
  24122. //
  24123. var program = gl.createProgram();
  24124. var prefixVertex, prefixFragment;
  24125. if ( material.isRawShaderMaterial ) {
  24126. prefixVertex = [
  24127. customDefines
  24128. ].filter( filterEmptyLine ).join( '\n' );
  24129. if ( prefixVertex.length > 0 ) {
  24130. prefixVertex += '\n';
  24131. }
  24132. prefixFragment = [
  24133. customExtensions,
  24134. customDefines
  24135. ].filter( filterEmptyLine ).join( '\n' );
  24136. if ( prefixFragment.length > 0 ) {
  24137. prefixFragment += '\n';
  24138. }
  24139. } else {
  24140. prefixVertex = [
  24141. 'precision ' + parameters.precision + ' float;',
  24142. 'precision ' + parameters.precision + ' int;',
  24143. '#define SHADER_NAME ' + shader.name,
  24144. customDefines,
  24145. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  24146. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  24147. '#define MAX_BONES ' + parameters.maxBones,
  24148. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  24149. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  24150. parameters.map ? '#define USE_MAP' : '',
  24151. parameters.envMap ? '#define USE_ENVMAP' : '',
  24152. parameters.envMap ? '#define ' + envMapModeDefine : '',
  24153. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  24154. parameters.aoMap ? '#define USE_AOMAP' : '',
  24155. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  24156. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  24157. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  24158. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  24159. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  24160. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  24161. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  24162. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  24163. parameters.vertexColors ? '#define USE_COLOR' : '',
  24164. parameters.flatShading ? '#define FLAT_SHADED' : '',
  24165. parameters.skinning ? '#define USE_SKINNING' : '',
  24166. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  24167. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  24168. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  24169. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  24170. parameters.flipSided ? '#define FLIP_SIDED' : '',
  24171. '#define NUM_CLIPPING_PLANES ' + parameters.numClippingPlanes,
  24172. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  24173. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  24174. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  24175. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  24176. parameters.logarithmicDepthBuffer && extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  24177. 'uniform mat4 modelMatrix;',
  24178. 'uniform mat4 modelViewMatrix;',
  24179. 'uniform mat4 projectionMatrix;',
  24180. 'uniform mat4 viewMatrix;',
  24181. 'uniform mat3 normalMatrix;',
  24182. 'uniform vec3 cameraPosition;',
  24183. 'attribute vec3 position;',
  24184. 'attribute vec3 normal;',
  24185. 'attribute vec2 uv;',
  24186. '#ifdef USE_COLOR',
  24187. ' attribute vec3 color;',
  24188. '#endif',
  24189. '#ifdef USE_MORPHTARGETS',
  24190. ' attribute vec3 morphTarget0;',
  24191. ' attribute vec3 morphTarget1;',
  24192. ' attribute vec3 morphTarget2;',
  24193. ' attribute vec3 morphTarget3;',
  24194. ' #ifdef USE_MORPHNORMALS',
  24195. ' attribute vec3 morphNormal0;',
  24196. ' attribute vec3 morphNormal1;',
  24197. ' attribute vec3 morphNormal2;',
  24198. ' attribute vec3 morphNormal3;',
  24199. ' #else',
  24200. ' attribute vec3 morphTarget4;',
  24201. ' attribute vec3 morphTarget5;',
  24202. ' attribute vec3 morphTarget6;',
  24203. ' attribute vec3 morphTarget7;',
  24204. ' #endif',
  24205. '#endif',
  24206. '#ifdef USE_SKINNING',
  24207. ' attribute vec4 skinIndex;',
  24208. ' attribute vec4 skinWeight;',
  24209. '#endif',
  24210. '\n'
  24211. ].filter( filterEmptyLine ).join( '\n' );
  24212. prefixFragment = [
  24213. customExtensions,
  24214. 'precision ' + parameters.precision + ' float;',
  24215. 'precision ' + parameters.precision + ' int;',
  24216. '#define SHADER_NAME ' + shader.name,
  24217. customDefines,
  24218. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest : '',
  24219. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  24220. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  24221. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  24222. parameters.map ? '#define USE_MAP' : '',
  24223. parameters.envMap ? '#define USE_ENVMAP' : '',
  24224. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  24225. parameters.envMap ? '#define ' + envMapModeDefine : '',
  24226. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  24227. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  24228. parameters.aoMap ? '#define USE_AOMAP' : '',
  24229. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  24230. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  24231. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  24232. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  24233. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  24234. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  24235. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  24236. parameters.vertexColors ? '#define USE_COLOR' : '',
  24237. parameters.gradientMap ? '#define USE_GRADIENTMAP' : '',
  24238. parameters.flatShading ? '#define FLAT_SHADED' : '',
  24239. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  24240. parameters.flipSided ? '#define FLIP_SIDED' : '',
  24241. '#define NUM_CLIPPING_PLANES ' + parameters.numClippingPlanes,
  24242. '#define UNION_CLIPPING_PLANES ' + ( parameters.numClippingPlanes - parameters.numClipIntersection ),
  24243. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  24244. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  24245. parameters.premultipliedAlpha ? "#define PREMULTIPLIED_ALPHA" : '',
  24246. parameters.physicallyCorrectLights ? "#define PHYSICALLY_CORRECT_LIGHTS" : '',
  24247. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  24248. parameters.logarithmicDepthBuffer && extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  24249. parameters.envMap && extensions.get( 'EXT_shader_texture_lod' ) ? '#define TEXTURE_LOD_EXT' : '',
  24250. 'uniform mat4 viewMatrix;',
  24251. 'uniform vec3 cameraPosition;',
  24252. ( parameters.toneMapping !== NoToneMapping ) ? "#define TONE_MAPPING" : '',
  24253. ( parameters.toneMapping !== NoToneMapping ) ? ShaderChunk[ 'tonemapping_pars_fragment' ] : '', // this code is required here because it is used by the toneMapping() function defined below
  24254. ( parameters.toneMapping !== NoToneMapping ) ? getToneMappingFunction( "toneMapping", parameters.toneMapping ) : '',
  24255. parameters.dithering ? '#define DITHERING' : '',
  24256. ( 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
  24257. parameters.mapEncoding ? getTexelDecodingFunction( 'mapTexelToLinear', parameters.mapEncoding ) : '',
  24258. parameters.envMapEncoding ? getTexelDecodingFunction( 'envMapTexelToLinear', parameters.envMapEncoding ) : '',
  24259. parameters.emissiveMapEncoding ? getTexelDecodingFunction( 'emissiveMapTexelToLinear', parameters.emissiveMapEncoding ) : '',
  24260. parameters.outputEncoding ? getTexelEncodingFunction( "linearToOutputTexel", parameters.outputEncoding ) : '',
  24261. parameters.depthPacking ? "#define DEPTH_PACKING " + material.depthPacking : '',
  24262. '\n'
  24263. ].filter( filterEmptyLine ).join( '\n' );
  24264. }
  24265. vertexShader = parseIncludes( vertexShader );
  24266. vertexShader = replaceLightNums( vertexShader, parameters );
  24267. fragmentShader = parseIncludes( fragmentShader );
  24268. fragmentShader = replaceLightNums( fragmentShader, parameters );
  24269. if ( ! material.isShaderMaterial ) {
  24270. vertexShader = unrollLoops( vertexShader );
  24271. fragmentShader = unrollLoops( fragmentShader );
  24272. }
  24273. var vertexGlsl = prefixVertex + vertexShader;
  24274. var fragmentGlsl = prefixFragment + fragmentShader;
  24275. // console.log( '*VERTEX*', vertexGlsl );
  24276. // console.log( '*FRAGMENT*', fragmentGlsl );
  24277. var glVertexShader = WebGLShader( gl, gl.VERTEX_SHADER, vertexGlsl );
  24278. var glFragmentShader = WebGLShader( gl, gl.FRAGMENT_SHADER, fragmentGlsl );
  24279. gl.attachShader( program, glVertexShader );
  24280. gl.attachShader( program, glFragmentShader );
  24281. // Force a particular attribute to index 0.
  24282. if ( material.index0AttributeName !== undefined ) {
  24283. gl.bindAttribLocation( program, 0, material.index0AttributeName );
  24284. } else if ( parameters.morphTargets === true ) {
  24285. // programs with morphTargets displace position out of attribute 0
  24286. gl.bindAttribLocation( program, 0, 'position' );
  24287. }
  24288. gl.linkProgram( program );
  24289. var programLog = gl.getProgramInfoLog( program );
  24290. var vertexLog = gl.getShaderInfoLog( glVertexShader );
  24291. var fragmentLog = gl.getShaderInfoLog( glFragmentShader );
  24292. var runnable = true;
  24293. var haveDiagnostics = true;
  24294. // console.log( '**VERTEX**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glVertexShader ) );
  24295. // console.log( '**FRAGMENT**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glFragmentShader ) );
  24296. if ( gl.getProgramParameter( program, gl.LINK_STATUS ) === false ) {
  24297. runnable = false;
  24298. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), 'gl.VALIDATE_STATUS', gl.getProgramParameter( program, gl.VALIDATE_STATUS ), 'gl.getProgramInfoLog', programLog, vertexLog, fragmentLog );
  24299. } else if ( programLog !== '' ) {
  24300. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  24301. } else if ( vertexLog === '' || fragmentLog === '' ) {
  24302. haveDiagnostics = false;
  24303. }
  24304. if ( haveDiagnostics ) {
  24305. this.diagnostics = {
  24306. runnable: runnable,
  24307. material: material,
  24308. programLog: programLog,
  24309. vertexShader: {
  24310. log: vertexLog,
  24311. prefix: prefixVertex
  24312. },
  24313. fragmentShader: {
  24314. log: fragmentLog,
  24315. prefix: prefixFragment
  24316. }
  24317. };
  24318. }
  24319. // clean up
  24320. gl.deleteShader( glVertexShader );
  24321. gl.deleteShader( glFragmentShader );
  24322. // set up caching for uniform locations
  24323. var cachedUniforms;
  24324. this.getUniforms = function () {
  24325. if ( cachedUniforms === undefined ) {
  24326. cachedUniforms = new WebGLUniforms( gl, program, renderer );
  24327. }
  24328. return cachedUniforms;
  24329. };
  24330. // set up caching for attribute locations
  24331. var cachedAttributes;
  24332. this.getAttributes = function () {
  24333. if ( cachedAttributes === undefined ) {
  24334. cachedAttributes = fetchAttributeLocations( gl, program );
  24335. }
  24336. return cachedAttributes;
  24337. };
  24338. // free resource
  24339. this.destroy = function () {
  24340. gl.deleteProgram( program );
  24341. this.program = undefined;
  24342. };
  24343. // DEPRECATED
  24344. Object.defineProperties( this, {
  24345. uniforms: {
  24346. get: function () {
  24347. console.warn( 'THREE.WebGLProgram: .uniforms is now .getUniforms().' );
  24348. return this.getUniforms();
  24349. }
  24350. },
  24351. attributes: {
  24352. get: function () {
  24353. console.warn( 'THREE.WebGLProgram: .attributes is now .getAttributes().' );
  24354. return this.getAttributes();
  24355. }
  24356. }
  24357. } );
  24358. //
  24359. this.id = programIdCount ++;
  24360. this.code = code;
  24361. this.usedTimes = 1;
  24362. this.program = program;
  24363. this.vertexShader = glVertexShader;
  24364. this.fragmentShader = glFragmentShader;
  24365. return this;
  24366. }
  24367. /**
  24368. * @author mrdoob / http://mrdoob.com/
  24369. */
  24370. function WebGLPrograms( renderer, extensions, capabilities ) {
  24371. var programs = [];
  24372. var shaderIDs = {
  24373. MeshDepthMaterial: 'depth',
  24374. MeshDistanceMaterial: 'distanceRGBA',
  24375. MeshNormalMaterial: 'normal',
  24376. MeshBasicMaterial: 'basic',
  24377. MeshLambertMaterial: 'lambert',
  24378. MeshPhongMaterial: 'phong',
  24379. MeshToonMaterial: 'phong',
  24380. MeshStandardMaterial: 'physical',
  24381. MeshPhysicalMaterial: 'physical',
  24382. LineBasicMaterial: 'basic',
  24383. LineDashedMaterial: 'dashed',
  24384. PointsMaterial: 'points',
  24385. ShadowMaterial: 'shadow'
  24386. };
  24387. var parameterNames = [
  24388. "precision", "supportsVertexTextures", "map", "mapEncoding", "envMap", "envMapMode", "envMapEncoding",
  24389. "lightMap", "aoMap", "emissiveMap", "emissiveMapEncoding", "bumpMap", "normalMap", "displacementMap", "specularMap",
  24390. "roughnessMap", "metalnessMap", "gradientMap",
  24391. "alphaMap", "combine", "vertexColors", "fog", "useFog", "fogExp",
  24392. "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
  24393. "maxBones", "useVertexTexture", "morphTargets", "morphNormals",
  24394. "maxMorphTargets", "maxMorphNormals", "premultipliedAlpha",
  24395. "numDirLights", "numPointLights", "numSpotLights", "numHemiLights", "numRectAreaLights",
  24396. "shadowMapEnabled", "shadowMapType", "toneMapping", 'physicallyCorrectLights',
  24397. "alphaTest", "doubleSided", "flipSided", "numClippingPlanes", "numClipIntersection", "depthPacking", "dithering"
  24398. ];
  24399. function allocateBones( object ) {
  24400. var skeleton = object.skeleton;
  24401. var bones = skeleton.bones;
  24402. if ( capabilities.floatVertexTextures ) {
  24403. return 1024;
  24404. } else {
  24405. // default for when object is not specified
  24406. // ( for example when prebuilding shader to be used with multiple objects )
  24407. //
  24408. // - leave some extra space for other uniforms
  24409. // - limit here is ANGLE's 254 max uniform vectors
  24410. // (up to 54 should be safe)
  24411. var nVertexUniforms = capabilities.maxVertexUniforms;
  24412. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  24413. var maxBones = Math.min( nVertexMatrices, bones.length );
  24414. if ( maxBones < bones.length ) {
  24415. console.warn( 'THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.' );
  24416. return 0;
  24417. }
  24418. return maxBones;
  24419. }
  24420. }
  24421. function getTextureEncodingFromMap( map, gammaOverrideLinear ) {
  24422. var encoding;
  24423. if ( ! map ) {
  24424. encoding = LinearEncoding;
  24425. } else if ( map.isTexture ) {
  24426. encoding = map.encoding;
  24427. } else if ( map.isWebGLRenderTarget ) {
  24428. console.warn( "THREE.WebGLPrograms.getTextureEncodingFromMap: don't use render targets as textures. Use their .texture property instead." );
  24429. encoding = map.texture.encoding;
  24430. }
  24431. // add backwards compatibility for WebGLRenderer.gammaInput/gammaOutput parameter, should probably be removed at some point.
  24432. if ( encoding === LinearEncoding && gammaOverrideLinear ) {
  24433. encoding = GammaEncoding;
  24434. }
  24435. return encoding;
  24436. }
  24437. this.getParameters = function ( material, lights, shadows, fog, nClipPlanes, nClipIntersection, object ) {
  24438. var shaderID = shaderIDs[ material.type ];
  24439. // heuristics to create shader parameters according to lights in the scene
  24440. // (not to blow over maxLights budget)
  24441. var maxBones = object.isSkinnedMesh ? allocateBones( object ) : 0;
  24442. var precision = capabilities.precision;
  24443. if ( material.precision !== null ) {
  24444. precision = capabilities.getMaxPrecision( material.precision );
  24445. if ( precision !== material.precision ) {
  24446. console.warn( 'THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.' );
  24447. }
  24448. }
  24449. var currentRenderTarget = renderer.getRenderTarget();
  24450. var parameters = {
  24451. shaderID: shaderID,
  24452. precision: precision,
  24453. supportsVertexTextures: capabilities.vertexTextures,
  24454. outputEncoding: getTextureEncodingFromMap( ( ! currentRenderTarget ) ? null : currentRenderTarget.texture, renderer.gammaOutput ),
  24455. map: !! material.map,
  24456. mapEncoding: getTextureEncodingFromMap( material.map, renderer.gammaInput ),
  24457. envMap: !! material.envMap,
  24458. envMapMode: material.envMap && material.envMap.mapping,
  24459. envMapEncoding: getTextureEncodingFromMap( material.envMap, renderer.gammaInput ),
  24460. envMapCubeUV: ( !! material.envMap ) && ( ( material.envMap.mapping === CubeUVReflectionMapping ) || ( material.envMap.mapping === CubeUVRefractionMapping ) ),
  24461. lightMap: !! material.lightMap,
  24462. aoMap: !! material.aoMap,
  24463. emissiveMap: !! material.emissiveMap,
  24464. emissiveMapEncoding: getTextureEncodingFromMap( material.emissiveMap, renderer.gammaInput ),
  24465. bumpMap: !! material.bumpMap,
  24466. normalMap: !! material.normalMap,
  24467. displacementMap: !! material.displacementMap,
  24468. roughnessMap: !! material.roughnessMap,
  24469. metalnessMap: !! material.metalnessMap,
  24470. specularMap: !! material.specularMap,
  24471. alphaMap: !! material.alphaMap,
  24472. gradientMap: !! material.gradientMap,
  24473. combine: material.combine,
  24474. vertexColors: material.vertexColors,
  24475. fog: !! fog,
  24476. useFog: material.fog,
  24477. fogExp: ( fog && fog.isFogExp2 ),
  24478. flatShading: material.flatShading,
  24479. sizeAttenuation: material.sizeAttenuation,
  24480. logarithmicDepthBuffer: capabilities.logarithmicDepthBuffer,
  24481. skinning: material.skinning && maxBones > 0,
  24482. maxBones: maxBones,
  24483. useVertexTexture: capabilities.floatVertexTextures,
  24484. morphTargets: material.morphTargets,
  24485. morphNormals: material.morphNormals,
  24486. maxMorphTargets: renderer.maxMorphTargets,
  24487. maxMorphNormals: renderer.maxMorphNormals,
  24488. numDirLights: lights.directional.length,
  24489. numPointLights: lights.point.length,
  24490. numSpotLights: lights.spot.length,
  24491. numRectAreaLights: lights.rectArea.length,
  24492. numHemiLights: lights.hemi.length,
  24493. numClippingPlanes: nClipPlanes,
  24494. numClipIntersection: nClipIntersection,
  24495. dithering: material.dithering,
  24496. shadowMapEnabled: renderer.shadowMap.enabled && object.receiveShadow && shadows.length > 0,
  24497. shadowMapType: renderer.shadowMap.type,
  24498. toneMapping: renderer.toneMapping,
  24499. physicallyCorrectLights: renderer.physicallyCorrectLights,
  24500. premultipliedAlpha: material.premultipliedAlpha,
  24501. alphaTest: material.alphaTest,
  24502. doubleSided: material.side === DoubleSide,
  24503. flipSided: material.side === BackSide,
  24504. depthPacking: ( material.depthPacking !== undefined ) ? material.depthPacking : false
  24505. };
  24506. return parameters;
  24507. };
  24508. this.getProgramCode = function ( material, parameters ) {
  24509. var array = [];
  24510. if ( parameters.shaderID ) {
  24511. array.push( parameters.shaderID );
  24512. } else {
  24513. array.push( material.fragmentShader );
  24514. array.push( material.vertexShader );
  24515. }
  24516. if ( material.defines !== undefined ) {
  24517. for ( var name in material.defines ) {
  24518. array.push( name );
  24519. array.push( material.defines[ name ] );
  24520. }
  24521. }
  24522. for ( var i = 0; i < parameterNames.length; i ++ ) {
  24523. array.push( parameters[ parameterNames[ i ] ] );
  24524. }
  24525. array.push( material.onBeforeCompile.toString() );
  24526. array.push( renderer.gammaOutput );
  24527. return array.join();
  24528. };
  24529. this.acquireProgram = function ( material, shader, parameters, code ) {
  24530. var program;
  24531. // Check if code has been already compiled
  24532. for ( var p = 0, pl = programs.length; p < pl; p ++ ) {
  24533. var programInfo = programs[ p ];
  24534. if ( programInfo.code === code ) {
  24535. program = programInfo;
  24536. ++ program.usedTimes;
  24537. break;
  24538. }
  24539. }
  24540. if ( program === undefined ) {
  24541. program = new WebGLProgram( renderer, extensions, code, material, shader, parameters );
  24542. programs.push( program );
  24543. }
  24544. return program;
  24545. };
  24546. this.releaseProgram = function ( program ) {
  24547. if ( -- program.usedTimes === 0 ) {
  24548. // Remove from unordered set
  24549. var i = programs.indexOf( program );
  24550. programs[ i ] = programs[ programs.length - 1 ];
  24551. programs.pop();
  24552. // Free WebGL resources
  24553. program.destroy();
  24554. }
  24555. };
  24556. // Exposed for resource monitoring & error feedback via renderer.info:
  24557. this.programs = programs;
  24558. }
  24559. /**
  24560. * @author mrdoob / http://mrdoob.com/
  24561. */
  24562. function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, infoMemory ) {
  24563. var _isWebGL2 = ( typeof WebGL2RenderingContext !== 'undefined' && _gl instanceof window.WebGL2RenderingContext );
  24564. //
  24565. function clampToMaxSize( image, maxSize ) {
  24566. if ( image.width > maxSize || image.height > maxSize ) {
  24567. // Warning: Scaling through the canvas will only work with images that use
  24568. // premultiplied alpha.
  24569. var scale = maxSize / Math.max( image.width, image.height );
  24570. var canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  24571. canvas.width = Math.floor( image.width * scale );
  24572. canvas.height = Math.floor( image.height * scale );
  24573. var context = canvas.getContext( '2d' );
  24574. context.drawImage( image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height );
  24575. console.warn( 'THREE.WebGLRenderer: image is too big (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  24576. return canvas;
  24577. }
  24578. return image;
  24579. }
  24580. function isPowerOfTwo( image ) {
  24581. return _Math.isPowerOfTwo( image.width ) && _Math.isPowerOfTwo( image.height );
  24582. }
  24583. function makePowerOfTwo( image ) {
  24584. if ( image instanceof HTMLImageElement || image instanceof HTMLCanvasElement || image instanceof ImageBitmap ) {
  24585. var canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  24586. canvas.width = _Math.floorPowerOfTwo( image.width );
  24587. canvas.height = _Math.floorPowerOfTwo( image.height );
  24588. var context = canvas.getContext( '2d' );
  24589. context.drawImage( image, 0, 0, canvas.width, canvas.height );
  24590. console.warn( 'THREE.WebGLRenderer: image is not power of two (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  24591. return canvas;
  24592. }
  24593. return image;
  24594. }
  24595. function textureNeedsPowerOfTwo( texture ) {
  24596. return ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) ||
  24597. ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter );
  24598. }
  24599. function textureNeedsGenerateMipmaps( texture, isPowerOfTwo ) {
  24600. return texture.generateMipmaps && isPowerOfTwo &&
  24601. texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  24602. }
  24603. // Fallback filters for non-power-of-2 textures
  24604. function filterFallback( f ) {
  24605. if ( f === NearestFilter || f === NearestMipMapNearestFilter || f === NearestMipMapLinearFilter ) {
  24606. return _gl.NEAREST;
  24607. }
  24608. return _gl.LINEAR;
  24609. }
  24610. //
  24611. function onTextureDispose( event ) {
  24612. var texture = event.target;
  24613. texture.removeEventListener( 'dispose', onTextureDispose );
  24614. deallocateTexture( texture );
  24615. infoMemory.textures --;
  24616. }
  24617. function onRenderTargetDispose( event ) {
  24618. var renderTarget = event.target;
  24619. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  24620. deallocateRenderTarget( renderTarget );
  24621. infoMemory.textures --;
  24622. }
  24623. //
  24624. function deallocateTexture( texture ) {
  24625. var textureProperties = properties.get( texture );
  24626. if ( texture.image && textureProperties.__image__webglTextureCube ) {
  24627. // cube texture
  24628. _gl.deleteTexture( textureProperties.__image__webglTextureCube );
  24629. } else {
  24630. // 2D texture
  24631. if ( textureProperties.__webglInit === undefined ) return;
  24632. _gl.deleteTexture( textureProperties.__webglTexture );
  24633. }
  24634. // remove all webgl properties
  24635. properties.remove( texture );
  24636. }
  24637. function deallocateRenderTarget( renderTarget ) {
  24638. var renderTargetProperties = properties.get( renderTarget );
  24639. var textureProperties = properties.get( renderTarget.texture );
  24640. if ( ! renderTarget ) return;
  24641. if ( textureProperties.__webglTexture !== undefined ) {
  24642. _gl.deleteTexture( textureProperties.__webglTexture );
  24643. }
  24644. if ( renderTarget.depthTexture ) {
  24645. renderTarget.depthTexture.dispose();
  24646. }
  24647. if ( renderTarget.isWebGLRenderTargetCube ) {
  24648. for ( var i = 0; i < 6; i ++ ) {
  24649. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  24650. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] );
  24651. }
  24652. } else {
  24653. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  24654. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer );
  24655. }
  24656. properties.remove( renderTarget.texture );
  24657. properties.remove( renderTarget );
  24658. }
  24659. //
  24660. function setTexture2D( texture, slot ) {
  24661. var textureProperties = properties.get( texture );
  24662. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  24663. var image = texture.image;
  24664. if ( image === undefined ) {
  24665. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined', texture );
  24666. } else if ( image.complete === false ) {
  24667. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete', texture );
  24668. } else {
  24669. uploadTexture( textureProperties, texture, slot );
  24670. return;
  24671. }
  24672. }
  24673. state.activeTexture( _gl.TEXTURE0 + slot );
  24674. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  24675. }
  24676. function setTextureCube( texture, slot ) {
  24677. var textureProperties = properties.get( texture );
  24678. if ( texture.image.length === 6 ) {
  24679. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  24680. if ( ! textureProperties.__image__webglTextureCube ) {
  24681. texture.addEventListener( 'dispose', onTextureDispose );
  24682. textureProperties.__image__webglTextureCube = _gl.createTexture();
  24683. infoMemory.textures ++;
  24684. }
  24685. state.activeTexture( _gl.TEXTURE0 + slot );
  24686. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  24687. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  24688. var isCompressed = ( texture && texture.isCompressedTexture );
  24689. var isDataTexture = ( texture.image[ 0 ] && texture.image[ 0 ].isDataTexture );
  24690. var cubeImage = [];
  24691. for ( var i = 0; i < 6; i ++ ) {
  24692. if ( ! isCompressed && ! isDataTexture ) {
  24693. cubeImage[ i ] = clampToMaxSize( texture.image[ i ], capabilities.maxCubemapSize );
  24694. } else {
  24695. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  24696. }
  24697. }
  24698. var image = cubeImage[ 0 ],
  24699. isPowerOfTwoImage = isPowerOfTwo( image ),
  24700. glFormat = utils.convert( texture.format ),
  24701. glType = utils.convert( texture.type );
  24702. setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, isPowerOfTwoImage );
  24703. for ( var i = 0; i < 6; i ++ ) {
  24704. if ( ! isCompressed ) {
  24705. if ( isDataTexture ) {
  24706. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  24707. } else {
  24708. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, glFormat, glType, cubeImage[ i ] );
  24709. }
  24710. } else {
  24711. var mipmap, mipmaps = cubeImage[ i ].mipmaps;
  24712. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  24713. mipmap = mipmaps[ j ];
  24714. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  24715. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  24716. state.compressedTexImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  24717. } else {
  24718. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()' );
  24719. }
  24720. } else {
  24721. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  24722. }
  24723. }
  24724. }
  24725. }
  24726. if ( textureNeedsGenerateMipmaps( texture, isPowerOfTwoImage ) ) {
  24727. _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  24728. }
  24729. textureProperties.__version = texture.version;
  24730. if ( texture.onUpdate ) texture.onUpdate( texture );
  24731. } else {
  24732. state.activeTexture( _gl.TEXTURE0 + slot );
  24733. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  24734. }
  24735. }
  24736. }
  24737. function setTextureCubeDynamic( texture, slot ) {
  24738. state.activeTexture( _gl.TEXTURE0 + slot );
  24739. state.bindTexture( _gl.TEXTURE_CUBE_MAP, properties.get( texture ).__webglTexture );
  24740. }
  24741. function setTextureParameters( textureType, texture, isPowerOfTwoImage ) {
  24742. var extension;
  24743. if ( isPowerOfTwoImage ) {
  24744. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, utils.convert( texture.wrapS ) );
  24745. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, utils.convert( texture.wrapT ) );
  24746. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, utils.convert( texture.magFilter ) );
  24747. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, utils.convert( texture.minFilter ) );
  24748. } else {
  24749. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
  24750. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
  24751. if ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) {
  24752. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.', texture );
  24753. }
  24754. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, filterFallback( texture.magFilter ) );
  24755. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, filterFallback( texture.minFilter ) );
  24756. if ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter ) {
  24757. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.', texture );
  24758. }
  24759. }
  24760. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  24761. if ( extension ) {
  24762. if ( texture.type === FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
  24763. if ( texture.type === HalfFloatType && extensions.get( 'OES_texture_half_float_linear' ) === null ) return;
  24764. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  24765. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, capabilities.getMaxAnisotropy() ) );
  24766. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  24767. }
  24768. }
  24769. }
  24770. function uploadTexture( textureProperties, texture, slot ) {
  24771. if ( textureProperties.__webglInit === undefined ) {
  24772. textureProperties.__webglInit = true;
  24773. texture.addEventListener( 'dispose', onTextureDispose );
  24774. textureProperties.__webglTexture = _gl.createTexture();
  24775. infoMemory.textures ++;
  24776. }
  24777. state.activeTexture( _gl.TEXTURE0 + slot );
  24778. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  24779. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  24780. _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
  24781. _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
  24782. var image = clampToMaxSize( texture.image, capabilities.maxTextureSize );
  24783. if ( textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( image ) === false ) {
  24784. image = makePowerOfTwo( image );
  24785. }
  24786. var isPowerOfTwoImage = isPowerOfTwo( image ),
  24787. glFormat = utils.convert( texture.format ),
  24788. glType = utils.convert( texture.type );
  24789. setTextureParameters( _gl.TEXTURE_2D, texture, isPowerOfTwoImage );
  24790. var mipmap, mipmaps = texture.mipmaps;
  24791. if ( texture.isDepthTexture ) {
  24792. // populate depth texture with dummy data
  24793. var internalFormat = _gl.DEPTH_COMPONENT;
  24794. if ( texture.type === FloatType ) {
  24795. if ( ! _isWebGL2 ) throw new Error( 'Float Depth Texture only supported in WebGL2.0' );
  24796. internalFormat = _gl.DEPTH_COMPONENT32F;
  24797. } else if ( _isWebGL2 ) {
  24798. // WebGL 2.0 requires signed internalformat for glTexImage2D
  24799. internalFormat = _gl.DEPTH_COMPONENT16;
  24800. }
  24801. if ( texture.format === DepthFormat && internalFormat === _gl.DEPTH_COMPONENT ) {
  24802. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  24803. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  24804. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  24805. if ( texture.type !== UnsignedShortType && texture.type !== UnsignedIntType ) {
  24806. console.warn( 'THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.' );
  24807. texture.type = UnsignedShortType;
  24808. glType = utils.convert( texture.type );
  24809. }
  24810. }
  24811. // Depth stencil textures need the DEPTH_STENCIL internal format
  24812. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  24813. if ( texture.format === DepthStencilFormat ) {
  24814. internalFormat = _gl.DEPTH_STENCIL;
  24815. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  24816. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  24817. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  24818. if ( texture.type !== UnsignedInt248Type ) {
  24819. console.warn( 'THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.' );
  24820. texture.type = UnsignedInt248Type;
  24821. glType = utils.convert( texture.type );
  24822. }
  24823. }
  24824. state.texImage2D( _gl.TEXTURE_2D, 0, internalFormat, image.width, image.height, 0, glFormat, glType, null );
  24825. } else if ( texture.isDataTexture ) {
  24826. // use manually created mipmaps if available
  24827. // if there are no manual mipmaps
  24828. // set 0 level mipmap and then use GL to generate other mipmap levels
  24829. if ( mipmaps.length > 0 && isPowerOfTwoImage ) {
  24830. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  24831. mipmap = mipmaps[ i ];
  24832. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  24833. }
  24834. texture.generateMipmaps = false;
  24835. } else {
  24836. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, image.width, image.height, 0, glFormat, glType, image.data );
  24837. }
  24838. } else if ( texture.isCompressedTexture ) {
  24839. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  24840. mipmap = mipmaps[ i ];
  24841. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  24842. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  24843. state.compressedTexImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  24844. } else {
  24845. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()' );
  24846. }
  24847. } else {
  24848. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  24849. }
  24850. }
  24851. } else {
  24852. // regular Texture (image, video, canvas)
  24853. // use manually created mipmaps if available
  24854. // if there are no manual mipmaps
  24855. // set 0 level mipmap and then use GL to generate other mipmap levels
  24856. if ( mipmaps.length > 0 && isPowerOfTwoImage ) {
  24857. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  24858. mipmap = mipmaps[ i ];
  24859. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, glFormat, glType, mipmap );
  24860. }
  24861. texture.generateMipmaps = false;
  24862. } else {
  24863. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, glFormat, glType, image );
  24864. }
  24865. }
  24866. if ( textureNeedsGenerateMipmaps( texture, isPowerOfTwoImage ) ) _gl.generateMipmap( _gl.TEXTURE_2D );
  24867. textureProperties.__version = texture.version;
  24868. if ( texture.onUpdate ) texture.onUpdate( texture );
  24869. }
  24870. // Render targets
  24871. // Setup storage for target texture and bind it to correct framebuffer
  24872. function setupFrameBufferTexture( framebuffer, renderTarget, attachment, textureTarget ) {
  24873. var glFormat = utils.convert( renderTarget.texture.format );
  24874. var glType = utils.convert( renderTarget.texture.type );
  24875. state.texImage2D( textureTarget, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  24876. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  24877. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
  24878. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  24879. }
  24880. // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  24881. function setupRenderBufferStorage( renderbuffer, renderTarget ) {
  24882. _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer );
  24883. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  24884. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_COMPONENT16, renderTarget.width, renderTarget.height );
  24885. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  24886. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  24887. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_STENCIL, renderTarget.width, renderTarget.height );
  24888. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  24889. } else {
  24890. // FIXME: We don't support !depth !stencil
  24891. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.RGBA4, renderTarget.width, renderTarget.height );
  24892. }
  24893. _gl.bindRenderbuffer( _gl.RENDERBUFFER, null );
  24894. }
  24895. // Setup resources for a Depth Texture for a FBO (needs an extension)
  24896. function setupDepthTexture( framebuffer, renderTarget ) {
  24897. var isCube = ( renderTarget && renderTarget.isWebGLRenderTargetCube );
  24898. if ( isCube ) throw new Error( 'Depth Texture with cube render targets is not supported' );
  24899. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  24900. if ( ! ( renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture ) ) {
  24901. throw new Error( 'renderTarget.depthTexture must be an instance of THREE.DepthTexture' );
  24902. }
  24903. // upload an empty depth texture with framebuffer size
  24904. if ( ! properties.get( renderTarget.depthTexture ).__webglTexture ||
  24905. renderTarget.depthTexture.image.width !== renderTarget.width ||
  24906. renderTarget.depthTexture.image.height !== renderTarget.height ) {
  24907. renderTarget.depthTexture.image.width = renderTarget.width;
  24908. renderTarget.depthTexture.image.height = renderTarget.height;
  24909. renderTarget.depthTexture.needsUpdate = true;
  24910. }
  24911. setTexture2D( renderTarget.depthTexture, 0 );
  24912. var webglDepthTexture = properties.get( renderTarget.depthTexture ).__webglTexture;
  24913. if ( renderTarget.depthTexture.format === DepthFormat ) {
  24914. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0 );
  24915. } else if ( renderTarget.depthTexture.format === DepthStencilFormat ) {
  24916. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0 );
  24917. } else {
  24918. throw new Error( 'Unknown depthTexture format' );
  24919. }
  24920. }
  24921. // Setup GL resources for a non-texture depth buffer
  24922. function setupDepthRenderbuffer( renderTarget ) {
  24923. var renderTargetProperties = properties.get( renderTarget );
  24924. var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
  24925. if ( renderTarget.depthTexture ) {
  24926. if ( isCube ) throw new Error( 'target.depthTexture not supported in Cube render targets' );
  24927. setupDepthTexture( renderTargetProperties.__webglFramebuffer, renderTarget );
  24928. } else {
  24929. if ( isCube ) {
  24930. renderTargetProperties.__webglDepthbuffer = [];
  24931. for ( var i = 0; i < 6; i ++ ) {
  24932. _gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer[ i ] );
  24933. renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer();
  24934. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget );
  24935. }
  24936. } else {
  24937. _gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer );
  24938. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  24939. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget );
  24940. }
  24941. }
  24942. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  24943. }
  24944. // Set up GL resources for the render target
  24945. function setupRenderTarget( renderTarget ) {
  24946. var renderTargetProperties = properties.get( renderTarget );
  24947. var textureProperties = properties.get( renderTarget.texture );
  24948. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  24949. textureProperties.__webglTexture = _gl.createTexture();
  24950. infoMemory.textures ++;
  24951. var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
  24952. var isTargetPowerOfTwo = isPowerOfTwo( renderTarget );
  24953. // Setup framebuffer
  24954. if ( isCube ) {
  24955. renderTargetProperties.__webglFramebuffer = [];
  24956. for ( var i = 0; i < 6; i ++ ) {
  24957. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  24958. }
  24959. } else {
  24960. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  24961. }
  24962. // Setup color buffer
  24963. if ( isCube ) {
  24964. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture );
  24965. setTextureParameters( _gl.TEXTURE_CUBE_MAP, renderTarget.texture, isTargetPowerOfTwo );
  24966. for ( var i = 0; i < 6; i ++ ) {
  24967. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i );
  24968. }
  24969. if ( textureNeedsGenerateMipmaps( renderTarget.texture, isTargetPowerOfTwo ) ) _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  24970. state.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  24971. } else {
  24972. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  24973. setTextureParameters( _gl.TEXTURE_2D, renderTarget.texture, isTargetPowerOfTwo );
  24974. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D );
  24975. if ( textureNeedsGenerateMipmaps( renderTarget.texture, isTargetPowerOfTwo ) ) _gl.generateMipmap( _gl.TEXTURE_2D );
  24976. state.bindTexture( _gl.TEXTURE_2D, null );
  24977. }
  24978. // Setup depth and stencil buffers
  24979. if ( renderTarget.depthBuffer ) {
  24980. setupDepthRenderbuffer( renderTarget );
  24981. }
  24982. }
  24983. function updateRenderTargetMipmap( renderTarget ) {
  24984. var texture = renderTarget.texture;
  24985. var isTargetPowerOfTwo = isPowerOfTwo( renderTarget );
  24986. if ( textureNeedsGenerateMipmaps( texture, isTargetPowerOfTwo ) ) {
  24987. var target = renderTarget.isWebGLRenderTargetCube ? _gl.TEXTURE_CUBE_MAP : _gl.TEXTURE_2D;
  24988. var webglTexture = properties.get( texture ).__webglTexture;
  24989. state.bindTexture( target, webglTexture );
  24990. _gl.generateMipmap( target );
  24991. state.bindTexture( target, null );
  24992. }
  24993. }
  24994. this.setTexture2D = setTexture2D;
  24995. this.setTextureCube = setTextureCube;
  24996. this.setTextureCubeDynamic = setTextureCubeDynamic;
  24997. this.setupRenderTarget = setupRenderTarget;
  24998. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  24999. }
  25000. /**
  25001. * @author fordacious / fordacious.github.io
  25002. */
  25003. function WebGLProperties() {
  25004. var properties = {};
  25005. function get( object ) {
  25006. var uuid = object.uuid;
  25007. var map = properties[ uuid ];
  25008. if ( map === undefined ) {
  25009. map = {};
  25010. properties[ uuid ] = map;
  25011. }
  25012. return map;
  25013. }
  25014. function remove( object ) {
  25015. delete properties[ object.uuid ];
  25016. }
  25017. function clear() {
  25018. properties = {};
  25019. }
  25020. return {
  25021. get: get,
  25022. remove: remove,
  25023. clear: clear
  25024. };
  25025. }
  25026. /**
  25027. * @author mrdoob / http://mrdoob.com/
  25028. */
  25029. function WebGLState( gl, extensions, utils ) {
  25030. function ColorBuffer() {
  25031. var locked = false;
  25032. var color = new Vector4();
  25033. var currentColorMask = null;
  25034. var currentColorClear = new Vector4( 0, 0, 0, 0 );
  25035. return {
  25036. setMask: function ( colorMask ) {
  25037. if ( currentColorMask !== colorMask && ! locked ) {
  25038. gl.colorMask( colorMask, colorMask, colorMask, colorMask );
  25039. currentColorMask = colorMask;
  25040. }
  25041. },
  25042. setLocked: function ( lock ) {
  25043. locked = lock;
  25044. },
  25045. setClear: function ( r, g, b, a, premultipliedAlpha ) {
  25046. if ( premultipliedAlpha === true ) {
  25047. r *= a; g *= a; b *= a;
  25048. }
  25049. color.set( r, g, b, a );
  25050. if ( currentColorClear.equals( color ) === false ) {
  25051. gl.clearColor( r, g, b, a );
  25052. currentColorClear.copy( color );
  25053. }
  25054. },
  25055. reset: function () {
  25056. locked = false;
  25057. currentColorMask = null;
  25058. currentColorClear.set( - 1, 0, 0, 0 ); // set to invalid state
  25059. }
  25060. };
  25061. }
  25062. function DepthBuffer() {
  25063. var locked = false;
  25064. var currentDepthMask = null;
  25065. var currentDepthFunc = null;
  25066. var currentDepthClear = null;
  25067. return {
  25068. setTest: function ( depthTest ) {
  25069. if ( depthTest ) {
  25070. enable( gl.DEPTH_TEST );
  25071. } else {
  25072. disable( gl.DEPTH_TEST );
  25073. }
  25074. },
  25075. setMask: function ( depthMask ) {
  25076. if ( currentDepthMask !== depthMask && ! locked ) {
  25077. gl.depthMask( depthMask );
  25078. currentDepthMask = depthMask;
  25079. }
  25080. },
  25081. setFunc: function ( depthFunc ) {
  25082. if ( currentDepthFunc !== depthFunc ) {
  25083. if ( depthFunc ) {
  25084. switch ( depthFunc ) {
  25085. case NeverDepth:
  25086. gl.depthFunc( gl.NEVER );
  25087. break;
  25088. case AlwaysDepth:
  25089. gl.depthFunc( gl.ALWAYS );
  25090. break;
  25091. case LessDepth:
  25092. gl.depthFunc( gl.LESS );
  25093. break;
  25094. case LessEqualDepth:
  25095. gl.depthFunc( gl.LEQUAL );
  25096. break;
  25097. case EqualDepth:
  25098. gl.depthFunc( gl.EQUAL );
  25099. break;
  25100. case GreaterEqualDepth:
  25101. gl.depthFunc( gl.GEQUAL );
  25102. break;
  25103. case GreaterDepth:
  25104. gl.depthFunc( gl.GREATER );
  25105. break;
  25106. case NotEqualDepth:
  25107. gl.depthFunc( gl.NOTEQUAL );
  25108. break;
  25109. default:
  25110. gl.depthFunc( gl.LEQUAL );
  25111. }
  25112. } else {
  25113. gl.depthFunc( gl.LEQUAL );
  25114. }
  25115. currentDepthFunc = depthFunc;
  25116. }
  25117. },
  25118. setLocked: function ( lock ) {
  25119. locked = lock;
  25120. },
  25121. setClear: function ( depth ) {
  25122. if ( currentDepthClear !== depth ) {
  25123. gl.clearDepth( depth );
  25124. currentDepthClear = depth;
  25125. }
  25126. },
  25127. reset: function () {
  25128. locked = false;
  25129. currentDepthMask = null;
  25130. currentDepthFunc = null;
  25131. currentDepthClear = null;
  25132. }
  25133. };
  25134. }
  25135. function StencilBuffer() {
  25136. var locked = false;
  25137. var currentStencilMask = null;
  25138. var currentStencilFunc = null;
  25139. var currentStencilRef = null;
  25140. var currentStencilFuncMask = null;
  25141. var currentStencilFail = null;
  25142. var currentStencilZFail = null;
  25143. var currentStencilZPass = null;
  25144. var currentStencilClear = null;
  25145. return {
  25146. setTest: function ( stencilTest ) {
  25147. if ( stencilTest ) {
  25148. enable( gl.STENCIL_TEST );
  25149. } else {
  25150. disable( gl.STENCIL_TEST );
  25151. }
  25152. },
  25153. setMask: function ( stencilMask ) {
  25154. if ( currentStencilMask !== stencilMask && ! locked ) {
  25155. gl.stencilMask( stencilMask );
  25156. currentStencilMask = stencilMask;
  25157. }
  25158. },
  25159. setFunc: function ( stencilFunc, stencilRef, stencilMask ) {
  25160. if ( currentStencilFunc !== stencilFunc ||
  25161. currentStencilRef !== stencilRef ||
  25162. currentStencilFuncMask !== stencilMask ) {
  25163. gl.stencilFunc( stencilFunc, stencilRef, stencilMask );
  25164. currentStencilFunc = stencilFunc;
  25165. currentStencilRef = stencilRef;
  25166. currentStencilFuncMask = stencilMask;
  25167. }
  25168. },
  25169. setOp: function ( stencilFail, stencilZFail, stencilZPass ) {
  25170. if ( currentStencilFail !== stencilFail ||
  25171. currentStencilZFail !== stencilZFail ||
  25172. currentStencilZPass !== stencilZPass ) {
  25173. gl.stencilOp( stencilFail, stencilZFail, stencilZPass );
  25174. currentStencilFail = stencilFail;
  25175. currentStencilZFail = stencilZFail;
  25176. currentStencilZPass = stencilZPass;
  25177. }
  25178. },
  25179. setLocked: function ( lock ) {
  25180. locked = lock;
  25181. },
  25182. setClear: function ( stencil ) {
  25183. if ( currentStencilClear !== stencil ) {
  25184. gl.clearStencil( stencil );
  25185. currentStencilClear = stencil;
  25186. }
  25187. },
  25188. reset: function () {
  25189. locked = false;
  25190. currentStencilMask = null;
  25191. currentStencilFunc = null;
  25192. currentStencilRef = null;
  25193. currentStencilFuncMask = null;
  25194. currentStencilFail = null;
  25195. currentStencilZFail = null;
  25196. currentStencilZPass = null;
  25197. currentStencilClear = null;
  25198. }
  25199. };
  25200. }
  25201. //
  25202. var colorBuffer = new ColorBuffer();
  25203. var depthBuffer = new DepthBuffer();
  25204. var stencilBuffer = new StencilBuffer();
  25205. var maxVertexAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
  25206. var newAttributes = new Uint8Array( maxVertexAttributes );
  25207. var enabledAttributes = new Uint8Array( maxVertexAttributes );
  25208. var attributeDivisors = new Uint8Array( maxVertexAttributes );
  25209. var capabilities = {};
  25210. var compressedTextureFormats = null;
  25211. var currentProgram = null;
  25212. var currentBlending = null;
  25213. var currentBlendEquation = null;
  25214. var currentBlendSrc = null;
  25215. var currentBlendDst = null;
  25216. var currentBlendEquationAlpha = null;
  25217. var currentBlendSrcAlpha = null;
  25218. var currentBlendDstAlpha = null;
  25219. var currentPremultipledAlpha = false;
  25220. var currentFlipSided = null;
  25221. var currentCullFace = null;
  25222. var currentLineWidth = null;
  25223. var currentPolygonOffsetFactor = null;
  25224. var currentPolygonOffsetUnits = null;
  25225. var maxTextures = gl.getParameter( gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS );
  25226. var version = parseFloat( /^WebGL\ ([0-9])/.exec( gl.getParameter( gl.VERSION ) )[ 1 ] );
  25227. var lineWidthAvailable = parseFloat( version ) >= 1.0;
  25228. var currentTextureSlot = null;
  25229. var currentBoundTextures = {};
  25230. var currentScissor = new Vector4();
  25231. var currentViewport = new Vector4();
  25232. function createTexture( type, target, count ) {
  25233. var data = new Uint8Array( 4 ); // 4 is required to match default unpack alignment of 4.
  25234. var texture = gl.createTexture();
  25235. gl.bindTexture( type, texture );
  25236. gl.texParameteri( type, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  25237. gl.texParameteri( type, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  25238. for ( var i = 0; i < count; i ++ ) {
  25239. gl.texImage2D( target + i, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, data );
  25240. }
  25241. return texture;
  25242. }
  25243. var emptyTextures = {};
  25244. emptyTextures[ gl.TEXTURE_2D ] = createTexture( gl.TEXTURE_2D, gl.TEXTURE_2D, 1 );
  25245. emptyTextures[ gl.TEXTURE_CUBE_MAP ] = createTexture( gl.TEXTURE_CUBE_MAP, gl.TEXTURE_CUBE_MAP_POSITIVE_X, 6 );
  25246. // init
  25247. colorBuffer.setClear( 0, 0, 0, 1 );
  25248. depthBuffer.setClear( 1 );
  25249. stencilBuffer.setClear( 0 );
  25250. enable( gl.DEPTH_TEST );
  25251. depthBuffer.setFunc( LessEqualDepth );
  25252. setFlipSided( false );
  25253. setCullFace( CullFaceBack );
  25254. enable( gl.CULL_FACE );
  25255. enable( gl.BLEND );
  25256. setBlending( NormalBlending );
  25257. //
  25258. function initAttributes() {
  25259. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  25260. newAttributes[ i ] = 0;
  25261. }
  25262. }
  25263. function enableAttribute( attribute ) {
  25264. newAttributes[ attribute ] = 1;
  25265. if ( enabledAttributes[ attribute ] === 0 ) {
  25266. gl.enableVertexAttribArray( attribute );
  25267. enabledAttributes[ attribute ] = 1;
  25268. }
  25269. if ( attributeDivisors[ attribute ] !== 0 ) {
  25270. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  25271. extension.vertexAttribDivisorANGLE( attribute, 0 );
  25272. attributeDivisors[ attribute ] = 0;
  25273. }
  25274. }
  25275. function enableAttributeAndDivisor( attribute, meshPerAttribute ) {
  25276. newAttributes[ attribute ] = 1;
  25277. if ( enabledAttributes[ attribute ] === 0 ) {
  25278. gl.enableVertexAttribArray( attribute );
  25279. enabledAttributes[ attribute ] = 1;
  25280. }
  25281. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  25282. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  25283. extension.vertexAttribDivisorANGLE( attribute, meshPerAttribute );
  25284. attributeDivisors[ attribute ] = meshPerAttribute;
  25285. }
  25286. }
  25287. function disableUnusedAttributes() {
  25288. for ( var i = 0, l = enabledAttributes.length; i !== l; ++ i ) {
  25289. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  25290. gl.disableVertexAttribArray( i );
  25291. enabledAttributes[ i ] = 0;
  25292. }
  25293. }
  25294. }
  25295. function enable( id ) {
  25296. if ( capabilities[ id ] !== true ) {
  25297. gl.enable( id );
  25298. capabilities[ id ] = true;
  25299. }
  25300. }
  25301. function disable( id ) {
  25302. if ( capabilities[ id ] !== false ) {
  25303. gl.disable( id );
  25304. capabilities[ id ] = false;
  25305. }
  25306. }
  25307. function getCompressedTextureFormats() {
  25308. if ( compressedTextureFormats === null ) {
  25309. compressedTextureFormats = [];
  25310. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) ||
  25311. extensions.get( 'WEBGL_compressed_texture_s3tc' ) ||
  25312. extensions.get( 'WEBGL_compressed_texture_etc1' ) ) {
  25313. var formats = gl.getParameter( gl.COMPRESSED_TEXTURE_FORMATS );
  25314. for ( var i = 0; i < formats.length; i ++ ) {
  25315. compressedTextureFormats.push( formats[ i ] );
  25316. }
  25317. }
  25318. }
  25319. return compressedTextureFormats;
  25320. }
  25321. function useProgram( program ) {
  25322. if ( currentProgram !== program ) {
  25323. gl.useProgram( program );
  25324. currentProgram = program;
  25325. return true;
  25326. }
  25327. return false;
  25328. }
  25329. function setBlending( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
  25330. if ( blending !== NoBlending ) {
  25331. enable( gl.BLEND );
  25332. } else {
  25333. disable( gl.BLEND );
  25334. }
  25335. if ( blending !== CustomBlending ) {
  25336. if ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) {
  25337. switch ( blending ) {
  25338. case AdditiveBlending:
  25339. if ( premultipliedAlpha ) {
  25340. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  25341. gl.blendFuncSeparate( gl.ONE, gl.ONE, gl.ONE, gl.ONE );
  25342. } else {
  25343. gl.blendEquation( gl.FUNC_ADD );
  25344. gl.blendFunc( gl.SRC_ALPHA, gl.ONE );
  25345. }
  25346. break;
  25347. case SubtractiveBlending:
  25348. if ( premultipliedAlpha ) {
  25349. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  25350. gl.blendFuncSeparate( gl.ZERO, gl.ZERO, gl.ONE_MINUS_SRC_COLOR, gl.ONE_MINUS_SRC_ALPHA );
  25351. } else {
  25352. gl.blendEquation( gl.FUNC_ADD );
  25353. gl.blendFunc( gl.ZERO, gl.ONE_MINUS_SRC_COLOR );
  25354. }
  25355. break;
  25356. case MultiplyBlending:
  25357. if ( premultipliedAlpha ) {
  25358. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  25359. gl.blendFuncSeparate( gl.ZERO, gl.SRC_COLOR, gl.ZERO, gl.SRC_ALPHA );
  25360. } else {
  25361. gl.blendEquation( gl.FUNC_ADD );
  25362. gl.blendFunc( gl.ZERO, gl.SRC_COLOR );
  25363. }
  25364. break;
  25365. default:
  25366. if ( premultipliedAlpha ) {
  25367. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  25368. gl.blendFuncSeparate( gl.ONE, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  25369. } else {
  25370. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  25371. gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  25372. }
  25373. }
  25374. }
  25375. currentBlendEquation = null;
  25376. currentBlendSrc = null;
  25377. currentBlendDst = null;
  25378. currentBlendEquationAlpha = null;
  25379. currentBlendSrcAlpha = null;
  25380. currentBlendDstAlpha = null;
  25381. } else {
  25382. blendEquationAlpha = blendEquationAlpha || blendEquation;
  25383. blendSrcAlpha = blendSrcAlpha || blendSrc;
  25384. blendDstAlpha = blendDstAlpha || blendDst;
  25385. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  25386. gl.blendEquationSeparate( utils.convert( blendEquation ), utils.convert( blendEquationAlpha ) );
  25387. currentBlendEquation = blendEquation;
  25388. currentBlendEquationAlpha = blendEquationAlpha;
  25389. }
  25390. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  25391. gl.blendFuncSeparate( utils.convert( blendSrc ), utils.convert( blendDst ), utils.convert( blendSrcAlpha ), utils.convert( blendDstAlpha ) );
  25392. currentBlendSrc = blendSrc;
  25393. currentBlendDst = blendDst;
  25394. currentBlendSrcAlpha = blendSrcAlpha;
  25395. currentBlendDstAlpha = blendDstAlpha;
  25396. }
  25397. }
  25398. currentBlending = blending;
  25399. currentPremultipledAlpha = premultipliedAlpha;
  25400. }
  25401. function setMaterial( material ) {
  25402. material.side === DoubleSide
  25403. ? disable( gl.CULL_FACE )
  25404. : enable( gl.CULL_FACE );
  25405. setFlipSided( material.side === BackSide );
  25406. material.transparent === true
  25407. ? setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha )
  25408. : setBlending( NoBlending );
  25409. depthBuffer.setFunc( material.depthFunc );
  25410. depthBuffer.setTest( material.depthTest );
  25411. depthBuffer.setMask( material.depthWrite );
  25412. colorBuffer.setMask( material.colorWrite );
  25413. setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  25414. }
  25415. //
  25416. function setFlipSided( flipSided ) {
  25417. if ( currentFlipSided !== flipSided ) {
  25418. if ( flipSided ) {
  25419. gl.frontFace( gl.CW );
  25420. } else {
  25421. gl.frontFace( gl.CCW );
  25422. }
  25423. currentFlipSided = flipSided;
  25424. }
  25425. }
  25426. function setCullFace( cullFace ) {
  25427. if ( cullFace !== CullFaceNone ) {
  25428. enable( gl.CULL_FACE );
  25429. if ( cullFace !== currentCullFace ) {
  25430. if ( cullFace === CullFaceBack ) {
  25431. gl.cullFace( gl.BACK );
  25432. } else if ( cullFace === CullFaceFront ) {
  25433. gl.cullFace( gl.FRONT );
  25434. } else {
  25435. gl.cullFace( gl.FRONT_AND_BACK );
  25436. }
  25437. }
  25438. } else {
  25439. disable( gl.CULL_FACE );
  25440. }
  25441. currentCullFace = cullFace;
  25442. }
  25443. function setLineWidth( width ) {
  25444. if ( width !== currentLineWidth ) {
  25445. if ( lineWidthAvailable ) gl.lineWidth( width );
  25446. currentLineWidth = width;
  25447. }
  25448. }
  25449. function setPolygonOffset( polygonOffset, factor, units ) {
  25450. if ( polygonOffset ) {
  25451. enable( gl.POLYGON_OFFSET_FILL );
  25452. if ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) {
  25453. gl.polygonOffset( factor, units );
  25454. currentPolygonOffsetFactor = factor;
  25455. currentPolygonOffsetUnits = units;
  25456. }
  25457. } else {
  25458. disable( gl.POLYGON_OFFSET_FILL );
  25459. }
  25460. }
  25461. function setScissorTest( scissorTest ) {
  25462. if ( scissorTest ) {
  25463. enable( gl.SCISSOR_TEST );
  25464. } else {
  25465. disable( gl.SCISSOR_TEST );
  25466. }
  25467. }
  25468. // texture
  25469. function activeTexture( webglSlot ) {
  25470. if ( webglSlot === undefined ) webglSlot = gl.TEXTURE0 + maxTextures - 1;
  25471. if ( currentTextureSlot !== webglSlot ) {
  25472. gl.activeTexture( webglSlot );
  25473. currentTextureSlot = webglSlot;
  25474. }
  25475. }
  25476. function bindTexture( webglType, webglTexture ) {
  25477. if ( currentTextureSlot === null ) {
  25478. activeTexture();
  25479. }
  25480. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  25481. if ( boundTexture === undefined ) {
  25482. boundTexture = { type: undefined, texture: undefined };
  25483. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  25484. }
  25485. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  25486. gl.bindTexture( webglType, webglTexture || emptyTextures[ webglType ] );
  25487. boundTexture.type = webglType;
  25488. boundTexture.texture = webglTexture;
  25489. }
  25490. }
  25491. function compressedTexImage2D() {
  25492. try {
  25493. gl.compressedTexImage2D.apply( gl, arguments );
  25494. } catch ( error ) {
  25495. console.error( 'THREE.WebGLState:', error );
  25496. }
  25497. }
  25498. function texImage2D() {
  25499. try {
  25500. gl.texImage2D.apply( gl, arguments );
  25501. } catch ( error ) {
  25502. console.error( 'THREE.WebGLState:', error );
  25503. }
  25504. }
  25505. //
  25506. function scissor( scissor ) {
  25507. if ( currentScissor.equals( scissor ) === false ) {
  25508. gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );
  25509. currentScissor.copy( scissor );
  25510. }
  25511. }
  25512. function viewport( viewport ) {
  25513. if ( currentViewport.equals( viewport ) === false ) {
  25514. gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );
  25515. currentViewport.copy( viewport );
  25516. }
  25517. }
  25518. //
  25519. function reset() {
  25520. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  25521. if ( enabledAttributes[ i ] === 1 ) {
  25522. gl.disableVertexAttribArray( i );
  25523. enabledAttributes[ i ] = 0;
  25524. }
  25525. }
  25526. capabilities = {};
  25527. compressedTextureFormats = null;
  25528. currentTextureSlot = null;
  25529. currentBoundTextures = {};
  25530. currentProgram = null;
  25531. currentBlending = null;
  25532. currentFlipSided = null;
  25533. currentCullFace = null;
  25534. colorBuffer.reset();
  25535. depthBuffer.reset();
  25536. stencilBuffer.reset();
  25537. }
  25538. return {
  25539. buffers: {
  25540. color: colorBuffer,
  25541. depth: depthBuffer,
  25542. stencil: stencilBuffer
  25543. },
  25544. initAttributes: initAttributes,
  25545. enableAttribute: enableAttribute,
  25546. enableAttributeAndDivisor: enableAttributeAndDivisor,
  25547. disableUnusedAttributes: disableUnusedAttributes,
  25548. enable: enable,
  25549. disable: disable,
  25550. getCompressedTextureFormats: getCompressedTextureFormats,
  25551. useProgram: useProgram,
  25552. setBlending: setBlending,
  25553. setMaterial: setMaterial,
  25554. setFlipSided: setFlipSided,
  25555. setCullFace: setCullFace,
  25556. setLineWidth: setLineWidth,
  25557. setPolygonOffset: setPolygonOffset,
  25558. setScissorTest: setScissorTest,
  25559. activeTexture: activeTexture,
  25560. bindTexture: bindTexture,
  25561. compressedTexImage2D: compressedTexImage2D,
  25562. texImage2D: texImage2D,
  25563. scissor: scissor,
  25564. viewport: viewport,
  25565. reset: reset
  25566. };
  25567. }
  25568. /**
  25569. * @author mrdoob / http://mrdoob.com/
  25570. */
  25571. function WebGLCapabilities( gl, extensions, parameters ) {
  25572. var maxAnisotropy;
  25573. function getMaxAnisotropy() {
  25574. if ( maxAnisotropy !== undefined ) return maxAnisotropy;
  25575. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  25576. if ( extension !== null ) {
  25577. maxAnisotropy = gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  25578. } else {
  25579. maxAnisotropy = 0;
  25580. }
  25581. return maxAnisotropy;
  25582. }
  25583. function getMaxPrecision( precision ) {
  25584. if ( precision === 'highp' ) {
  25585. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.HIGH_FLOAT ).precision > 0 &&
  25586. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.HIGH_FLOAT ).precision > 0 ) {
  25587. return 'highp';
  25588. }
  25589. precision = 'mediump';
  25590. }
  25591. if ( precision === 'mediump' ) {
  25592. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.MEDIUM_FLOAT ).precision > 0 &&
  25593. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT ).precision > 0 ) {
  25594. return 'mediump';
  25595. }
  25596. }
  25597. return 'lowp';
  25598. }
  25599. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  25600. var maxPrecision = getMaxPrecision( precision );
  25601. if ( maxPrecision !== precision ) {
  25602. console.warn( 'THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.' );
  25603. precision = maxPrecision;
  25604. }
  25605. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  25606. var maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  25607. var maxVertexTextures = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );
  25608. var maxTextureSize = gl.getParameter( gl.MAX_TEXTURE_SIZE );
  25609. var maxCubemapSize = gl.getParameter( gl.MAX_CUBE_MAP_TEXTURE_SIZE );
  25610. var maxAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
  25611. var maxVertexUniforms = gl.getParameter( gl.MAX_VERTEX_UNIFORM_VECTORS );
  25612. var maxVaryings = gl.getParameter( gl.MAX_VARYING_VECTORS );
  25613. var maxFragmentUniforms = gl.getParameter( gl.MAX_FRAGMENT_UNIFORM_VECTORS );
  25614. var vertexTextures = maxVertexTextures > 0;
  25615. var floatFragmentTextures = !! extensions.get( 'OES_texture_float' );
  25616. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  25617. return {
  25618. getMaxAnisotropy: getMaxAnisotropy,
  25619. getMaxPrecision: getMaxPrecision,
  25620. precision: precision,
  25621. logarithmicDepthBuffer: logarithmicDepthBuffer,
  25622. maxTextures: maxTextures,
  25623. maxVertexTextures: maxVertexTextures,
  25624. maxTextureSize: maxTextureSize,
  25625. maxCubemapSize: maxCubemapSize,
  25626. maxAttributes: maxAttributes,
  25627. maxVertexUniforms: maxVertexUniforms,
  25628. maxVaryings: maxVaryings,
  25629. maxFragmentUniforms: maxFragmentUniforms,
  25630. vertexTextures: vertexTextures,
  25631. floatFragmentTextures: floatFragmentTextures,
  25632. floatVertexTextures: floatVertexTextures
  25633. };
  25634. }
  25635. /**
  25636. * @author mrdoob / http://mrdoob.com/
  25637. */
  25638. function WebVRManager( renderer ) {
  25639. var scope = this;
  25640. var device = null;
  25641. var frameData = null;
  25642. if ( typeof window !== 'undefined' && 'VRFrameData' in window ) {
  25643. frameData = new window.VRFrameData();
  25644. }
  25645. var matrixWorldInverse = new Matrix4();
  25646. var standingMatrix = new Matrix4();
  25647. var standingMatrixInverse = new Matrix4();
  25648. var cameraL = new PerspectiveCamera();
  25649. cameraL.bounds = new Vector4( 0.0, 0.0, 0.5, 1.0 );
  25650. cameraL.layers.enable( 1 );
  25651. var cameraR = new PerspectiveCamera();
  25652. cameraR.bounds = new Vector4( 0.5, 0.0, 0.5, 1.0 );
  25653. cameraR.layers.enable( 2 );
  25654. var cameraVR = new ArrayCamera( [ cameraL, cameraR ] );
  25655. cameraVR.layers.enable( 1 );
  25656. cameraVR.layers.enable( 2 );
  25657. //
  25658. var currentSize, currentPixelRatio;
  25659. function onVRDisplayPresentChange() {
  25660. if ( device !== null && device.isPresenting ) {
  25661. var eyeParameters = device.getEyeParameters( 'left' );
  25662. var renderWidth = eyeParameters.renderWidth;
  25663. var renderHeight = eyeParameters.renderHeight;
  25664. currentPixelRatio = renderer.getPixelRatio();
  25665. currentSize = renderer.getSize();
  25666. renderer.setDrawingBufferSize( renderWidth * 2, renderHeight, 1 );
  25667. } else if ( scope.enabled ) {
  25668. renderer.setDrawingBufferSize( currentSize.width, currentSize.height, currentPixelRatio );
  25669. }
  25670. }
  25671. if ( typeof window !== 'undefined' ) {
  25672. window.addEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange, false );
  25673. }
  25674. //
  25675. this.enabled = false;
  25676. this.standing = false;
  25677. this.getDevice = function () {
  25678. return device;
  25679. };
  25680. this.setDevice = function ( value ) {
  25681. if ( value !== undefined ) device = value;
  25682. };
  25683. this.getCamera = function ( camera ) {
  25684. if ( device === null ) return camera;
  25685. device.depthNear = camera.near;
  25686. device.depthFar = camera.far;
  25687. device.getFrameData( frameData );
  25688. //
  25689. var pose = frameData.pose;
  25690. if ( pose.position !== null ) {
  25691. camera.position.fromArray( pose.position );
  25692. } else {
  25693. camera.position.set( 0, 0, 0 );
  25694. }
  25695. if ( pose.orientation !== null ) {
  25696. camera.quaternion.fromArray( pose.orientation );
  25697. }
  25698. camera.updateMatrixWorld();
  25699. var stageParameters = device.stageParameters;
  25700. if ( this.standing && stageParameters ) {
  25701. standingMatrix.fromArray( stageParameters.sittingToStandingTransform );
  25702. standingMatrixInverse.getInverse( standingMatrix );
  25703. camera.matrixWorld.multiply( standingMatrix );
  25704. camera.matrixWorldInverse.multiply( standingMatrixInverse );
  25705. }
  25706. if ( device.isPresenting === false ) return camera;
  25707. //
  25708. cameraL.near = camera.near;
  25709. cameraR.near = camera.near;
  25710. cameraL.far = camera.far;
  25711. cameraR.far = camera.far;
  25712. cameraVR.matrixWorld.copy( camera.matrixWorld );
  25713. cameraVR.matrixWorldInverse.copy( camera.matrixWorldInverse );
  25714. cameraL.matrixWorldInverse.fromArray( frameData.leftViewMatrix );
  25715. cameraR.matrixWorldInverse.fromArray( frameData.rightViewMatrix );
  25716. if ( this.standing && stageParameters ) {
  25717. cameraL.matrixWorldInverse.multiply( standingMatrixInverse );
  25718. cameraR.matrixWorldInverse.multiply( standingMatrixInverse );
  25719. }
  25720. var parent = camera.parent;
  25721. if ( parent !== null ) {
  25722. matrixWorldInverse.getInverse( parent.matrixWorld );
  25723. cameraL.matrixWorldInverse.multiply( matrixWorldInverse );
  25724. cameraR.matrixWorldInverse.multiply( matrixWorldInverse );
  25725. }
  25726. // envMap and Mirror needs camera.matrixWorld
  25727. cameraL.matrixWorld.getInverse( cameraL.matrixWorldInverse );
  25728. cameraR.matrixWorld.getInverse( cameraR.matrixWorldInverse );
  25729. cameraL.projectionMatrix.fromArray( frameData.leftProjectionMatrix );
  25730. cameraR.projectionMatrix.fromArray( frameData.rightProjectionMatrix );
  25731. // HACK @mrdoob
  25732. // https://github.com/w3c/webvr/issues/203
  25733. cameraVR.projectionMatrix.copy( cameraL.projectionMatrix );
  25734. //
  25735. var layers = device.getLayers();
  25736. if ( layers.length ) {
  25737. var layer = layers[ 0 ];
  25738. if ( layer.leftBounds !== null && layer.leftBounds.length === 4 ) {
  25739. cameraL.bounds.fromArray( layer.leftBounds );
  25740. }
  25741. if ( layer.rightBounds !== null && layer.rightBounds.length === 4 ) {
  25742. cameraR.bounds.fromArray( layer.rightBounds );
  25743. }
  25744. }
  25745. return cameraVR;
  25746. };
  25747. this.getStandingMatrix = function () {
  25748. return standingMatrix;
  25749. };
  25750. this.submitFrame = function () {
  25751. if ( device && device.isPresenting ) device.submitFrame();
  25752. };
  25753. this.dispose = function () {
  25754. window.removeEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange );
  25755. };
  25756. }
  25757. /**
  25758. * @author mrdoob / http://mrdoob.com/
  25759. */
  25760. function WebGLExtensions( gl ) {
  25761. var extensions = {};
  25762. return {
  25763. get: function ( name ) {
  25764. if ( extensions[ name ] !== undefined ) {
  25765. return extensions[ name ];
  25766. }
  25767. var extension;
  25768. switch ( name ) {
  25769. case 'WEBGL_depth_texture':
  25770. extension = gl.getExtension( 'WEBGL_depth_texture' ) || gl.getExtension( 'MOZ_WEBGL_depth_texture' ) || gl.getExtension( 'WEBKIT_WEBGL_depth_texture' );
  25771. break;
  25772. case 'EXT_texture_filter_anisotropic':
  25773. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  25774. break;
  25775. case 'WEBGL_compressed_texture_s3tc':
  25776. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  25777. break;
  25778. case 'WEBGL_compressed_texture_pvrtc':
  25779. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  25780. break;
  25781. case 'WEBGL_compressed_texture_etc1':
  25782. extension = gl.getExtension( 'WEBGL_compressed_texture_etc1' );
  25783. break;
  25784. default:
  25785. extension = gl.getExtension( name );
  25786. }
  25787. if ( extension === null ) {
  25788. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  25789. }
  25790. extensions[ name ] = extension;
  25791. return extension;
  25792. }
  25793. };
  25794. }
  25795. /**
  25796. * @author tschw
  25797. */
  25798. function WebGLClipping() {
  25799. var scope = this,
  25800. globalState = null,
  25801. numGlobalPlanes = 0,
  25802. localClippingEnabled = false,
  25803. renderingShadows = false,
  25804. plane = new Plane(),
  25805. viewNormalMatrix = new Matrix3(),
  25806. uniform = { value: null, needsUpdate: false };
  25807. this.uniform = uniform;
  25808. this.numPlanes = 0;
  25809. this.numIntersection = 0;
  25810. this.init = function ( planes, enableLocalClipping, camera ) {
  25811. var enabled =
  25812. planes.length !== 0 ||
  25813. enableLocalClipping ||
  25814. // enable state of previous frame - the clipping code has to
  25815. // run another frame in order to reset the state:
  25816. numGlobalPlanes !== 0 ||
  25817. localClippingEnabled;
  25818. localClippingEnabled = enableLocalClipping;
  25819. globalState = projectPlanes( planes, camera, 0 );
  25820. numGlobalPlanes = planes.length;
  25821. return enabled;
  25822. };
  25823. this.beginShadows = function () {
  25824. renderingShadows = true;
  25825. projectPlanes( null );
  25826. };
  25827. this.endShadows = function () {
  25828. renderingShadows = false;
  25829. resetGlobalState();
  25830. };
  25831. this.setState = function ( planes, clipIntersection, clipShadows, camera, cache, fromCache ) {
  25832. if ( ! localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && ! clipShadows ) {
  25833. // there's no local clipping
  25834. if ( renderingShadows ) {
  25835. // there's no global clipping
  25836. projectPlanes( null );
  25837. } else {
  25838. resetGlobalState();
  25839. }
  25840. } else {
  25841. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  25842. lGlobal = nGlobal * 4,
  25843. dstArray = cache.clippingState || null;
  25844. uniform.value = dstArray; // ensure unique state
  25845. dstArray = projectPlanes( planes, camera, lGlobal, fromCache );
  25846. for ( var i = 0; i !== lGlobal; ++ i ) {
  25847. dstArray[ i ] = globalState[ i ];
  25848. }
  25849. cache.clippingState = dstArray;
  25850. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  25851. this.numPlanes += nGlobal;
  25852. }
  25853. };
  25854. function resetGlobalState() {
  25855. if ( uniform.value !== globalState ) {
  25856. uniform.value = globalState;
  25857. uniform.needsUpdate = numGlobalPlanes > 0;
  25858. }
  25859. scope.numPlanes = numGlobalPlanes;
  25860. scope.numIntersection = 0;
  25861. }
  25862. function projectPlanes( planes, camera, dstOffset, skipTransform ) {
  25863. var nPlanes = planes !== null ? planes.length : 0,
  25864. dstArray = null;
  25865. if ( nPlanes !== 0 ) {
  25866. dstArray = uniform.value;
  25867. if ( skipTransform !== true || dstArray === null ) {
  25868. var flatSize = dstOffset + nPlanes * 4,
  25869. viewMatrix = camera.matrixWorldInverse;
  25870. viewNormalMatrix.getNormalMatrix( viewMatrix );
  25871. if ( dstArray === null || dstArray.length < flatSize ) {
  25872. dstArray = new Float32Array( flatSize );
  25873. }
  25874. for ( var i = 0, i4 = dstOffset; i !== nPlanes; ++ i, i4 += 4 ) {
  25875. plane.copy( planes[ i ] ).applyMatrix4( viewMatrix, viewNormalMatrix );
  25876. plane.normal.toArray( dstArray, i4 );
  25877. dstArray[ i4 + 3 ] = plane.constant;
  25878. }
  25879. }
  25880. uniform.value = dstArray;
  25881. uniform.needsUpdate = true;
  25882. }
  25883. scope.numPlanes = nPlanes;
  25884. return dstArray;
  25885. }
  25886. }
  25887. /**
  25888. * @author thespite / http://www.twitter.com/thespite
  25889. */
  25890. function WebGLUtils( gl, extensions ) {
  25891. function convert( p ) {
  25892. var extension;
  25893. if ( p === RepeatWrapping ) return gl.REPEAT;
  25894. if ( p === ClampToEdgeWrapping ) return gl.CLAMP_TO_EDGE;
  25895. if ( p === MirroredRepeatWrapping ) return gl.MIRRORED_REPEAT;
  25896. if ( p === NearestFilter ) return gl.NEAREST;
  25897. if ( p === NearestMipMapNearestFilter ) return gl.NEAREST_MIPMAP_NEAREST;
  25898. if ( p === NearestMipMapLinearFilter ) return gl.NEAREST_MIPMAP_LINEAR;
  25899. if ( p === LinearFilter ) return gl.LINEAR;
  25900. if ( p === LinearMipMapNearestFilter ) return gl.LINEAR_MIPMAP_NEAREST;
  25901. if ( p === LinearMipMapLinearFilter ) return gl.LINEAR_MIPMAP_LINEAR;
  25902. if ( p === UnsignedByteType ) return gl.UNSIGNED_BYTE;
  25903. if ( p === UnsignedShort4444Type ) return gl.UNSIGNED_SHORT_4_4_4_4;
  25904. if ( p === UnsignedShort5551Type ) return gl.UNSIGNED_SHORT_5_5_5_1;
  25905. if ( p === UnsignedShort565Type ) return gl.UNSIGNED_SHORT_5_6_5;
  25906. if ( p === ByteType ) return gl.BYTE;
  25907. if ( p === ShortType ) return gl.SHORT;
  25908. if ( p === UnsignedShortType ) return gl.UNSIGNED_SHORT;
  25909. if ( p === IntType ) return gl.INT;
  25910. if ( p === UnsignedIntType ) return gl.UNSIGNED_INT;
  25911. if ( p === FloatType ) return gl.FLOAT;
  25912. if ( p === HalfFloatType ) {
  25913. extension = extensions.get( 'OES_texture_half_float' );
  25914. if ( extension !== null ) return extension.HALF_FLOAT_OES;
  25915. }
  25916. if ( p === AlphaFormat ) return gl.ALPHA;
  25917. if ( p === RGBFormat ) return gl.RGB;
  25918. if ( p === RGBAFormat ) return gl.RGBA;
  25919. if ( p === LuminanceFormat ) return gl.LUMINANCE;
  25920. if ( p === LuminanceAlphaFormat ) return gl.LUMINANCE_ALPHA;
  25921. if ( p === DepthFormat ) return gl.DEPTH_COMPONENT;
  25922. if ( p === DepthStencilFormat ) return gl.DEPTH_STENCIL;
  25923. if ( p === AddEquation ) return gl.FUNC_ADD;
  25924. if ( p === SubtractEquation ) return gl.FUNC_SUBTRACT;
  25925. if ( p === ReverseSubtractEquation ) return gl.FUNC_REVERSE_SUBTRACT;
  25926. if ( p === ZeroFactor ) return gl.ZERO;
  25927. if ( p === OneFactor ) return gl.ONE;
  25928. if ( p === SrcColorFactor ) return gl.SRC_COLOR;
  25929. if ( p === OneMinusSrcColorFactor ) return gl.ONE_MINUS_SRC_COLOR;
  25930. if ( p === SrcAlphaFactor ) return gl.SRC_ALPHA;
  25931. if ( p === OneMinusSrcAlphaFactor ) return gl.ONE_MINUS_SRC_ALPHA;
  25932. if ( p === DstAlphaFactor ) return gl.DST_ALPHA;
  25933. if ( p === OneMinusDstAlphaFactor ) return gl.ONE_MINUS_DST_ALPHA;
  25934. if ( p === DstColorFactor ) return gl.DST_COLOR;
  25935. if ( p === OneMinusDstColorFactor ) return gl.ONE_MINUS_DST_COLOR;
  25936. if ( p === SrcAlphaSaturateFactor ) return gl.SRC_ALPHA_SATURATE;
  25937. if ( p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format ||
  25938. p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format ) {
  25939. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  25940. if ( extension !== null ) {
  25941. if ( p === RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  25942. if ( p === RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  25943. if ( p === RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  25944. if ( p === RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  25945. }
  25946. }
  25947. if ( p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format ||
  25948. p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format ) {
  25949. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  25950. if ( extension !== null ) {
  25951. if ( p === RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  25952. if ( p === RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  25953. if ( p === RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  25954. if ( p === RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  25955. }
  25956. }
  25957. if ( p === RGB_ETC1_Format ) {
  25958. extension = extensions.get( 'WEBGL_compressed_texture_etc1' );
  25959. if ( extension !== null ) return extension.COMPRESSED_RGB_ETC1_WEBGL;
  25960. }
  25961. if ( p === MinEquation || p === MaxEquation ) {
  25962. extension = extensions.get( 'EXT_blend_minmax' );
  25963. if ( extension !== null ) {
  25964. if ( p === MinEquation ) return extension.MIN_EXT;
  25965. if ( p === MaxEquation ) return extension.MAX_EXT;
  25966. }
  25967. }
  25968. if ( p === UnsignedInt248Type ) {
  25969. extension = extensions.get( 'WEBGL_depth_texture' );
  25970. if ( extension !== null ) return extension.UNSIGNED_INT_24_8_WEBGL;
  25971. }
  25972. return 0;
  25973. }
  25974. return { convert: convert };
  25975. }
  25976. /**
  25977. * @author supereggbert / http://www.paulbrunt.co.uk/
  25978. * @author mrdoob / http://mrdoob.com/
  25979. * @author alteredq / http://alteredqualia.com/
  25980. * @author szimek / https://github.com/szimek/
  25981. * @author tschw
  25982. */
  25983. function WebGLRenderer( parameters ) {
  25984. console.log( 'THREE.WebGLRenderer', REVISION );
  25985. parameters = parameters || {};
  25986. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' ),
  25987. _context = parameters.context !== undefined ? parameters.context : null,
  25988. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  25989. _depth = parameters.depth !== undefined ? parameters.depth : true,
  25990. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  25991. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  25992. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  25993. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false;
  25994. var lightsArray = [];
  25995. var shadowsArray = [];
  25996. var currentRenderList = null;
  25997. var spritesArray = [];
  25998. var flaresArray = [];
  25999. // public properties
  26000. this.domElement = _canvas;
  26001. this.context = null;
  26002. // clearing
  26003. this.autoClear = true;
  26004. this.autoClearColor = true;
  26005. this.autoClearDepth = true;
  26006. this.autoClearStencil = true;
  26007. // scene graph
  26008. this.sortObjects = true;
  26009. // user-defined clipping
  26010. this.clippingPlanes = [];
  26011. this.localClippingEnabled = false;
  26012. // physically based shading
  26013. this.gammaFactor = 2.0; // for backwards compatibility
  26014. this.gammaInput = false;
  26015. this.gammaOutput = false;
  26016. // physical lights
  26017. this.physicallyCorrectLights = false;
  26018. // tone mapping
  26019. this.toneMapping = LinearToneMapping;
  26020. this.toneMappingExposure = 1.0;
  26021. this.toneMappingWhitePoint = 1.0;
  26022. // morphs
  26023. this.maxMorphTargets = 8;
  26024. this.maxMorphNormals = 4;
  26025. // internal properties
  26026. var _this = this,
  26027. _isContextLost = false,
  26028. // internal state cache
  26029. _currentRenderTarget = null,
  26030. _currentFramebuffer = null,
  26031. _currentMaterialId = - 1,
  26032. _currentGeometryProgram = '',
  26033. _currentCamera = null,
  26034. _currentArrayCamera = null,
  26035. _currentViewport = new Vector4(),
  26036. _currentScissor = new Vector4(),
  26037. _currentScissorTest = null,
  26038. //
  26039. _usedTextureUnits = 0,
  26040. //
  26041. _width = _canvas.width,
  26042. _height = _canvas.height,
  26043. _pixelRatio = 1,
  26044. _viewport = new Vector4( 0, 0, _width, _height ),
  26045. _scissor = new Vector4( 0, 0, _width, _height ),
  26046. _scissorTest = false,
  26047. // frustum
  26048. _frustum = new Frustum(),
  26049. // clipping
  26050. _clipping = new WebGLClipping(),
  26051. _clippingEnabled = false,
  26052. _localClippingEnabled = false,
  26053. // camera matrices cache
  26054. _projScreenMatrix = new Matrix4(),
  26055. _vector3 = new Vector3(),
  26056. // info
  26057. _infoMemory = {
  26058. geometries: 0,
  26059. textures: 0
  26060. },
  26061. _infoRender = {
  26062. frame: 0,
  26063. calls: 0,
  26064. vertices: 0,
  26065. faces: 0,
  26066. points: 0
  26067. };
  26068. this.info = {
  26069. render: _infoRender,
  26070. memory: _infoMemory,
  26071. programs: null
  26072. };
  26073. function getTargetPixelRatio() {
  26074. return _currentRenderTarget === null ? _pixelRatio : 1;
  26075. }
  26076. // initialize
  26077. var _gl;
  26078. try {
  26079. var contextAttributes = {
  26080. alpha: _alpha,
  26081. depth: _depth,
  26082. stencil: _stencil,
  26083. antialias: _antialias,
  26084. premultipliedAlpha: _premultipliedAlpha,
  26085. preserveDrawingBuffer: _preserveDrawingBuffer
  26086. };
  26087. _gl = _context || _canvas.getContext( 'webgl', contextAttributes ) || _canvas.getContext( 'experimental-webgl', contextAttributes );
  26088. if ( _gl === null ) {
  26089. if ( _canvas.getContext( 'webgl' ) !== null ) {
  26090. throw 'Error creating WebGL context with your selected attributes.';
  26091. } else {
  26092. throw 'Error creating WebGL context.';
  26093. }
  26094. }
  26095. // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  26096. if ( _gl.getShaderPrecisionFormat === undefined ) {
  26097. _gl.getShaderPrecisionFormat = function () {
  26098. return { 'rangeMin': 1, 'rangeMax': 1, 'precision': 1 };
  26099. };
  26100. }
  26101. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  26102. _canvas.addEventListener( 'webglcontextrestored', onContextRestore, false );
  26103. } catch ( error ) {
  26104. console.error( 'THREE.WebGLRenderer: ' + error );
  26105. }
  26106. var extensions, capabilities, state;
  26107. var properties, textures, attributes, geometries, objects, lights;
  26108. var programCache, renderLists;
  26109. var background, morphtargets, bufferRenderer, indexedBufferRenderer;
  26110. var flareRenderer, spriteRenderer;
  26111. var utils;
  26112. function initGLContext() {
  26113. extensions = new WebGLExtensions( _gl );
  26114. extensions.get( 'WEBGL_depth_texture' );
  26115. extensions.get( 'OES_texture_float' );
  26116. extensions.get( 'OES_texture_float_linear' );
  26117. extensions.get( 'OES_texture_half_float' );
  26118. extensions.get( 'OES_texture_half_float_linear' );
  26119. extensions.get( 'OES_standard_derivatives' );
  26120. extensions.get( 'OES_element_index_uint' );
  26121. extensions.get( 'ANGLE_instanced_arrays' );
  26122. utils = new WebGLUtils( _gl, extensions );
  26123. capabilities = new WebGLCapabilities( _gl, extensions, parameters );
  26124. state = new WebGLState( _gl, extensions, utils );
  26125. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
  26126. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
  26127. properties = new WebGLProperties();
  26128. textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, _infoMemory );
  26129. attributes = new WebGLAttributes( _gl );
  26130. geometries = new WebGLGeometries( _gl, attributes, _infoMemory );
  26131. objects = new WebGLObjects( geometries, _infoRender );
  26132. morphtargets = new WebGLMorphtargets( _gl );
  26133. programCache = new WebGLPrograms( _this, extensions, capabilities );
  26134. lights = new WebGLLights();
  26135. renderLists = new WebGLRenderLists();
  26136. background = new WebGLBackground( _this, state, geometries, _premultipliedAlpha );
  26137. bufferRenderer = new WebGLBufferRenderer( _gl, extensions, _infoRender );
  26138. indexedBufferRenderer = new WebGLIndexedBufferRenderer( _gl, extensions, _infoRender );
  26139. flareRenderer = new WebGLFlareRenderer( _this, _gl, state, textures, capabilities );
  26140. spriteRenderer = new WebGLSpriteRenderer( _this, _gl, state, textures, capabilities );
  26141. _this.info.programs = programCache.programs;
  26142. _this.context = _gl;
  26143. _this.capabilities = capabilities;
  26144. _this.extensions = extensions;
  26145. _this.properties = properties;
  26146. _this.renderLists = renderLists;
  26147. _this.state = state;
  26148. }
  26149. initGLContext();
  26150. // vr
  26151. var vr = new WebVRManager( _this );
  26152. this.vr = vr;
  26153. // shadow map
  26154. var shadowMap = new WebGLShadowMap( _this, objects, capabilities.maxTextureSize );
  26155. this.shadowMap = shadowMap;
  26156. // API
  26157. this.getContext = function () {
  26158. return _gl;
  26159. };
  26160. this.getContextAttributes = function () {
  26161. return _gl.getContextAttributes();
  26162. };
  26163. this.forceContextLoss = function () {
  26164. var extension = extensions.get( 'WEBGL_lose_context' );
  26165. if ( extension ) extension.loseContext();
  26166. };
  26167. this.forceContextRestore = function () {
  26168. var extension = extensions.get( 'WEBGL_lose_context' );
  26169. if ( extension ) extension.restoreContext();
  26170. };
  26171. this.getPixelRatio = function () {
  26172. return _pixelRatio;
  26173. };
  26174. this.setPixelRatio = function ( value ) {
  26175. if ( value === undefined ) return;
  26176. _pixelRatio = value;
  26177. this.setSize( _width, _height, false );
  26178. };
  26179. this.getSize = function () {
  26180. return {
  26181. width: _width,
  26182. height: _height
  26183. };
  26184. };
  26185. this.setSize = function ( width, height, updateStyle ) {
  26186. var device = vr.getDevice();
  26187. if ( device && device.isPresenting ) {
  26188. console.warn( 'THREE.WebGLRenderer: Can\'t change size while VR device is presenting.' );
  26189. return;
  26190. }
  26191. _width = width;
  26192. _height = height;
  26193. _canvas.width = width * _pixelRatio;
  26194. _canvas.height = height * _pixelRatio;
  26195. if ( updateStyle !== false ) {
  26196. _canvas.style.width = width + 'px';
  26197. _canvas.style.height = height + 'px';
  26198. }
  26199. this.setViewport( 0, 0, width, height );
  26200. };
  26201. this.getDrawingBufferSize = function () {
  26202. return {
  26203. width: _width * _pixelRatio,
  26204. height: _height * _pixelRatio
  26205. };
  26206. };
  26207. this.setDrawingBufferSize = function ( width, height, pixelRatio ) {
  26208. _width = width;
  26209. _height = height;
  26210. _pixelRatio = pixelRatio;
  26211. _canvas.width = width * pixelRatio;
  26212. _canvas.height = height * pixelRatio;
  26213. this.setViewport( 0, 0, width, height );
  26214. };
  26215. this.setViewport = function ( x, y, width, height ) {
  26216. _viewport.set( x, _height - y - height, width, height );
  26217. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
  26218. };
  26219. this.setScissor = function ( x, y, width, height ) {
  26220. _scissor.set( x, _height - y - height, width, height );
  26221. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
  26222. };
  26223. this.setScissorTest = function ( boolean ) {
  26224. state.setScissorTest( _scissorTest = boolean );
  26225. };
  26226. // Clearing
  26227. this.getClearColor = function() {
  26228. return background.getClearColor();
  26229. };
  26230. this.setClearColor = function () {
  26231. background.setClearColor.apply( background, arguments );
  26232. };
  26233. this.getClearAlpha = function() {
  26234. return background.getClearAlpha();
  26235. };
  26236. this.setClearAlpha = function() {
  26237. background.setClearAlpha.apply( background, arguments );
  26238. };
  26239. this.clear = function ( color, depth, stencil ) {
  26240. var bits = 0;
  26241. if ( color === undefined || color ) bits |= _gl.COLOR_BUFFER_BIT;
  26242. if ( depth === undefined || depth ) bits |= _gl.DEPTH_BUFFER_BIT;
  26243. if ( stencil === undefined || stencil ) bits |= _gl.STENCIL_BUFFER_BIT;
  26244. _gl.clear( bits );
  26245. };
  26246. this.clearColor = function () {
  26247. this.clear( true, false, false );
  26248. };
  26249. this.clearDepth = function () {
  26250. this.clear( false, true, false );
  26251. };
  26252. this.clearStencil = function () {
  26253. this.clear( false, false, true );
  26254. };
  26255. this.clearTarget = function ( renderTarget, color, depth, stencil ) {
  26256. this.setRenderTarget( renderTarget );
  26257. this.clear( color, depth, stencil );
  26258. };
  26259. //
  26260. this.dispose = function () {
  26261. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  26262. _canvas.removeEventListener( 'webglcontextrestored', onContextRestore, false );
  26263. renderLists.dispose();
  26264. vr.dispose();
  26265. };
  26266. // Events
  26267. function onContextLost( event ) {
  26268. event.preventDefault();
  26269. console.log( 'THREE.WebGLRenderer: Context Lost.' );
  26270. _isContextLost = true;
  26271. }
  26272. function onContextRestore( /* event */ ) {
  26273. console.log( 'THREE.WebGLRenderer: Context Restored.' );
  26274. _isContextLost = false;
  26275. initGLContext();
  26276. }
  26277. function onMaterialDispose( event ) {
  26278. var material = event.target;
  26279. material.removeEventListener( 'dispose', onMaterialDispose );
  26280. deallocateMaterial( material );
  26281. }
  26282. // Buffer deallocation
  26283. function deallocateMaterial( material ) {
  26284. releaseMaterialProgramReference( material );
  26285. properties.remove( material );
  26286. }
  26287. function releaseMaterialProgramReference( material ) {
  26288. var programInfo = properties.get( material ).program;
  26289. material.program = undefined;
  26290. if ( programInfo !== undefined ) {
  26291. programCache.releaseProgram( programInfo );
  26292. }
  26293. }
  26294. // Buffer rendering
  26295. function renderObjectImmediate( object, program, material ) {
  26296. object.render( function ( object ) {
  26297. _this.renderBufferImmediate( object, program, material );
  26298. } );
  26299. }
  26300. this.renderBufferImmediate = function ( object, program, material ) {
  26301. state.initAttributes();
  26302. var buffers = properties.get( object );
  26303. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  26304. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  26305. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  26306. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  26307. var programAttributes = program.getAttributes();
  26308. if ( object.hasPositions ) {
  26309. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.position );
  26310. _gl.bufferData( _gl.ARRAY_BUFFER, object.positionArray, _gl.DYNAMIC_DRAW );
  26311. state.enableAttribute( programAttributes.position );
  26312. _gl.vertexAttribPointer( programAttributes.position, 3, _gl.FLOAT, false, 0, 0 );
  26313. }
  26314. if ( object.hasNormals ) {
  26315. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.normal );
  26316. if ( ! material.isMeshPhongMaterial &&
  26317. ! material.isMeshStandardMaterial &&
  26318. ! material.isMeshNormalMaterial &&
  26319. material.flatShading === true ) {
  26320. for ( var i = 0, l = object.count * 3; i < l; i += 9 ) {
  26321. var array = object.normalArray;
  26322. var nx = ( array[ i + 0 ] + array[ i + 3 ] + array[ i + 6 ] ) / 3;
  26323. var ny = ( array[ i + 1 ] + array[ i + 4 ] + array[ i + 7 ] ) / 3;
  26324. var nz = ( array[ i + 2 ] + array[ i + 5 ] + array[ i + 8 ] ) / 3;
  26325. array[ i + 0 ] = nx;
  26326. array[ i + 1 ] = ny;
  26327. array[ i + 2 ] = nz;
  26328. array[ i + 3 ] = nx;
  26329. array[ i + 4 ] = ny;
  26330. array[ i + 5 ] = nz;
  26331. array[ i + 6 ] = nx;
  26332. array[ i + 7 ] = ny;
  26333. array[ i + 8 ] = nz;
  26334. }
  26335. }
  26336. _gl.bufferData( _gl.ARRAY_BUFFER, object.normalArray, _gl.DYNAMIC_DRAW );
  26337. state.enableAttribute( programAttributes.normal );
  26338. _gl.vertexAttribPointer( programAttributes.normal, 3, _gl.FLOAT, false, 0, 0 );
  26339. }
  26340. if ( object.hasUvs && material.map ) {
  26341. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.uv );
  26342. _gl.bufferData( _gl.ARRAY_BUFFER, object.uvArray, _gl.DYNAMIC_DRAW );
  26343. state.enableAttribute( programAttributes.uv );
  26344. _gl.vertexAttribPointer( programAttributes.uv, 2, _gl.FLOAT, false, 0, 0 );
  26345. }
  26346. if ( object.hasColors && material.vertexColors !== NoColors ) {
  26347. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.color );
  26348. _gl.bufferData( _gl.ARRAY_BUFFER, object.colorArray, _gl.DYNAMIC_DRAW );
  26349. state.enableAttribute( programAttributes.color );
  26350. _gl.vertexAttribPointer( programAttributes.color, 3, _gl.FLOAT, false, 0, 0 );
  26351. }
  26352. state.disableUnusedAttributes();
  26353. _gl.drawArrays( _gl.TRIANGLES, 0, object.count );
  26354. object.count = 0;
  26355. };
  26356. this.renderBufferDirect = function ( camera, fog, geometry, material, object, group ) {
  26357. state.setMaterial( material );
  26358. var program = setProgram( camera, fog, material, object );
  26359. var geometryProgram = geometry.id + '_' + program.id + '_' + ( material.wireframe === true );
  26360. var updateBuffers = false;
  26361. if ( geometryProgram !== _currentGeometryProgram ) {
  26362. _currentGeometryProgram = geometryProgram;
  26363. updateBuffers = true;
  26364. }
  26365. if ( object.morphTargetInfluences ) {
  26366. morphtargets.update( object, geometry, material, program );
  26367. updateBuffers = true;
  26368. }
  26369. //
  26370. var index = geometry.index;
  26371. var position = geometry.attributes.position;
  26372. var rangeFactor = 1;
  26373. if ( material.wireframe === true ) {
  26374. index = geometries.getWireframeAttribute( geometry );
  26375. rangeFactor = 2;
  26376. }
  26377. var attribute;
  26378. var renderer = bufferRenderer;
  26379. if ( index !== null ) {
  26380. attribute = attributes.get( index );
  26381. renderer = indexedBufferRenderer;
  26382. renderer.setIndex( attribute );
  26383. }
  26384. if ( updateBuffers ) {
  26385. setupVertexAttributes( material, program, geometry );
  26386. if ( index !== null ) {
  26387. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, attribute.buffer );
  26388. }
  26389. }
  26390. //
  26391. var dataCount = 0;
  26392. if ( index !== null ) {
  26393. dataCount = index.count;
  26394. } else if ( position !== undefined ) {
  26395. dataCount = position.count;
  26396. }
  26397. var rangeStart = geometry.drawRange.start * rangeFactor;
  26398. var rangeCount = geometry.drawRange.count * rangeFactor;
  26399. var groupStart = group !== null ? group.start * rangeFactor : 0;
  26400. var groupCount = group !== null ? group.count * rangeFactor : Infinity;
  26401. var drawStart = Math.max( rangeStart, groupStart );
  26402. var drawEnd = Math.min( dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
  26403. var drawCount = Math.max( 0, drawEnd - drawStart + 1 );
  26404. if ( drawCount === 0 ) return;
  26405. //
  26406. if ( object.isMesh ) {
  26407. if ( material.wireframe === true ) {
  26408. state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() );
  26409. renderer.setMode( _gl.LINES );
  26410. } else {
  26411. switch ( object.drawMode ) {
  26412. case TrianglesDrawMode:
  26413. renderer.setMode( _gl.TRIANGLES );
  26414. break;
  26415. case TriangleStripDrawMode:
  26416. renderer.setMode( _gl.TRIANGLE_STRIP );
  26417. break;
  26418. case TriangleFanDrawMode:
  26419. renderer.setMode( _gl.TRIANGLE_FAN );
  26420. break;
  26421. }
  26422. }
  26423. } else if ( object.isLine ) {
  26424. var lineWidth = material.linewidth;
  26425. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  26426. state.setLineWidth( lineWidth * getTargetPixelRatio() );
  26427. if ( object.isLineSegments ) {
  26428. renderer.setMode( _gl.LINES );
  26429. } else if ( object.isLineLoop ) {
  26430. renderer.setMode( _gl.LINE_LOOP );
  26431. } else {
  26432. renderer.setMode( _gl.LINE_STRIP );
  26433. }
  26434. } else if ( object.isPoints ) {
  26435. renderer.setMode( _gl.POINTS );
  26436. }
  26437. if ( geometry && geometry.isInstancedBufferGeometry ) {
  26438. if ( geometry.maxInstancedCount > 0 ) {
  26439. renderer.renderInstances( geometry, drawStart, drawCount );
  26440. }
  26441. } else {
  26442. renderer.render( drawStart, drawCount );
  26443. }
  26444. };
  26445. function setupVertexAttributes( material, program, geometry, startIndex ) {
  26446. if ( geometry && geometry.isInstancedBufferGeometry ) {
  26447. if ( extensions.get( 'ANGLE_instanced_arrays' ) === null ) {
  26448. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  26449. return;
  26450. }
  26451. }
  26452. if ( startIndex === undefined ) startIndex = 0;
  26453. state.initAttributes();
  26454. var geometryAttributes = geometry.attributes;
  26455. var programAttributes = program.getAttributes();
  26456. var materialDefaultAttributeValues = material.defaultAttributeValues;
  26457. for ( var name in programAttributes ) {
  26458. var programAttribute = programAttributes[ name ];
  26459. if ( programAttribute >= 0 ) {
  26460. var geometryAttribute = geometryAttributes[ name ];
  26461. if ( geometryAttribute !== undefined ) {
  26462. var normalized = geometryAttribute.normalized;
  26463. var size = geometryAttribute.itemSize;
  26464. var attribute = attributes.get( geometryAttribute );
  26465. // TODO Attribute may not be available on context restore
  26466. if ( attribute === undefined ) continue;
  26467. var buffer = attribute.buffer;
  26468. var type = attribute.type;
  26469. var bytesPerElement = attribute.bytesPerElement;
  26470. if ( geometryAttribute.isInterleavedBufferAttribute ) {
  26471. var data = geometryAttribute.data;
  26472. var stride = data.stride;
  26473. var offset = geometryAttribute.offset;
  26474. if ( data && data.isInstancedInterleavedBuffer ) {
  26475. state.enableAttributeAndDivisor( programAttribute, data.meshPerAttribute );
  26476. if ( geometry.maxInstancedCount === undefined ) {
  26477. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  26478. }
  26479. } else {
  26480. state.enableAttribute( programAttribute );
  26481. }
  26482. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  26483. _gl.vertexAttribPointer( programAttribute, size, type, normalized, stride * bytesPerElement, ( startIndex * stride + offset ) * bytesPerElement );
  26484. } else {
  26485. if ( geometryAttribute.isInstancedBufferAttribute ) {
  26486. state.enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute );
  26487. if ( geometry.maxInstancedCount === undefined ) {
  26488. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  26489. }
  26490. } else {
  26491. state.enableAttribute( programAttribute );
  26492. }
  26493. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  26494. _gl.vertexAttribPointer( programAttribute, size, type, normalized, 0, startIndex * size * bytesPerElement );
  26495. }
  26496. } else if ( materialDefaultAttributeValues !== undefined ) {
  26497. var value = materialDefaultAttributeValues[ name ];
  26498. if ( value !== undefined ) {
  26499. switch ( value.length ) {
  26500. case 2:
  26501. _gl.vertexAttrib2fv( programAttribute, value );
  26502. break;
  26503. case 3:
  26504. _gl.vertexAttrib3fv( programAttribute, value );
  26505. break;
  26506. case 4:
  26507. _gl.vertexAttrib4fv( programAttribute, value );
  26508. break;
  26509. default:
  26510. _gl.vertexAttrib1fv( programAttribute, value );
  26511. }
  26512. }
  26513. }
  26514. }
  26515. }
  26516. state.disableUnusedAttributes();
  26517. }
  26518. // Compile
  26519. this.compile = function ( scene, camera ) {
  26520. lightsArray.length = 0;
  26521. shadowsArray.length = 0;
  26522. scene.traverse( function ( object ) {
  26523. if ( object.isLight ) {
  26524. lightsArray.push( object );
  26525. if ( object.castShadow ) {
  26526. shadowsArray.push( object );
  26527. }
  26528. }
  26529. } );
  26530. lights.setup( lightsArray, shadowsArray, camera );
  26531. scene.traverse( function ( object ) {
  26532. if ( object.material ) {
  26533. if ( Array.isArray( object.material ) ) {
  26534. for ( var i = 0; i < object.material.length; i ++ ) {
  26535. initMaterial( object.material[ i ], scene.fog, object );
  26536. }
  26537. } else {
  26538. initMaterial( object.material, scene.fog, object );
  26539. }
  26540. }
  26541. } );
  26542. };
  26543. // Animation Loop
  26544. var isAnimating = false;
  26545. var onAnimationFrame = null;
  26546. function start() {
  26547. if ( isAnimating ) return;
  26548. ( vr.getDevice() || window ).requestAnimationFrame( loop );
  26549. isAnimating = true;
  26550. }
  26551. function loop( time ) {
  26552. if ( onAnimationFrame !== null ) onAnimationFrame( time );
  26553. ( vr.getDevice() || window ).requestAnimationFrame( loop );
  26554. }
  26555. this.animate = function ( callback ) {
  26556. onAnimationFrame = callback;
  26557. start();
  26558. };
  26559. // Rendering
  26560. this.render = function ( scene, camera, renderTarget, forceClear ) {
  26561. if ( ! ( camera && camera.isCamera ) ) {
  26562. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  26563. return;
  26564. }
  26565. if ( _isContextLost ) return;
  26566. // reset caching for this frame
  26567. _currentGeometryProgram = '';
  26568. _currentMaterialId = - 1;
  26569. _currentCamera = null;
  26570. // update scene graph
  26571. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  26572. // update camera matrices and frustum
  26573. if ( camera.parent === null ) camera.updateMatrixWorld();
  26574. if ( vr.enabled ) {
  26575. camera = vr.getCamera( camera );
  26576. }
  26577. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  26578. _frustum.setFromMatrix( _projScreenMatrix );
  26579. lightsArray.length = 0;
  26580. shadowsArray.length = 0;
  26581. spritesArray.length = 0;
  26582. flaresArray.length = 0;
  26583. _localClippingEnabled = this.localClippingEnabled;
  26584. _clippingEnabled = _clipping.init( this.clippingPlanes, _localClippingEnabled, camera );
  26585. currentRenderList = renderLists.get( scene, camera );
  26586. currentRenderList.init();
  26587. projectObject( scene, camera, _this.sortObjects );
  26588. if ( _this.sortObjects === true ) {
  26589. currentRenderList.sort();
  26590. }
  26591. //
  26592. if ( _clippingEnabled ) _clipping.beginShadows();
  26593. shadowMap.render( shadowsArray, scene, camera );
  26594. lights.setup( lightsArray, shadowsArray, camera );
  26595. if ( _clippingEnabled ) _clipping.endShadows();
  26596. //
  26597. _infoRender.frame ++;
  26598. _infoRender.calls = 0;
  26599. _infoRender.vertices = 0;
  26600. _infoRender.faces = 0;
  26601. _infoRender.points = 0;
  26602. if ( renderTarget === undefined ) {
  26603. renderTarget = null;
  26604. }
  26605. this.setRenderTarget( renderTarget );
  26606. //
  26607. background.render( currentRenderList, scene, camera, forceClear );
  26608. // render scene
  26609. var opaqueObjects = currentRenderList.opaque;
  26610. var transparentObjects = currentRenderList.transparent;
  26611. if ( scene.overrideMaterial ) {
  26612. var overrideMaterial = scene.overrideMaterial;
  26613. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera, overrideMaterial );
  26614. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera, overrideMaterial );
  26615. } else {
  26616. // opaque pass (front-to-back order)
  26617. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera );
  26618. // transparent pass (back-to-front order)
  26619. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera );
  26620. }
  26621. // custom renderers
  26622. spriteRenderer.render( spritesArray, scene, camera );
  26623. flareRenderer.render( flaresArray, scene, camera, _currentViewport );
  26624. // Generate mipmap if we're using any kind of mipmap filtering
  26625. if ( renderTarget ) {
  26626. textures.updateRenderTargetMipmap( renderTarget );
  26627. }
  26628. // Ensure depth buffer writing is enabled so it can be cleared on next render
  26629. state.buffers.depth.setTest( true );
  26630. state.buffers.depth.setMask( true );
  26631. state.buffers.color.setMask( true );
  26632. state.setPolygonOffset( false );
  26633. if ( vr.enabled ) {
  26634. vr.submitFrame();
  26635. }
  26636. // _gl.finish();
  26637. };
  26638. /*
  26639. // TODO Duplicated code (Frustum)
  26640. var _sphere = new Sphere();
  26641. function isObjectViewable( object ) {
  26642. var geometry = object.geometry;
  26643. if ( geometry.boundingSphere === null )
  26644. geometry.computeBoundingSphere();
  26645. _sphere.copy( geometry.boundingSphere ).
  26646. applyMatrix4( object.matrixWorld );
  26647. return isSphereViewable( _sphere );
  26648. }
  26649. function isSpriteViewable( sprite ) {
  26650. _sphere.center.set( 0, 0, 0 );
  26651. _sphere.radius = 0.7071067811865476;
  26652. _sphere.applyMatrix4( sprite.matrixWorld );
  26653. return isSphereViewable( _sphere );
  26654. }
  26655. function isSphereViewable( sphere ) {
  26656. if ( ! _frustum.intersectsSphere( sphere ) ) return false;
  26657. var numPlanes = _clipping.numPlanes;
  26658. if ( numPlanes === 0 ) return true;
  26659. var planes = _this.clippingPlanes,
  26660. center = sphere.center,
  26661. negRad = - sphere.radius,
  26662. i = 0;
  26663. do {
  26664. // out when deeper than radius in the negative halfspace
  26665. if ( planes[ i ].distanceToPoint( center ) < negRad ) return false;
  26666. } while ( ++ i !== numPlanes );
  26667. return true;
  26668. }
  26669. */
  26670. function projectObject( object, camera, sortObjects ) {
  26671. if ( object.visible === false ) return;
  26672. var visible = object.layers.test( camera.layers );
  26673. if ( visible ) {
  26674. if ( object.isLight ) {
  26675. lightsArray.push( object );
  26676. if ( object.castShadow ) {
  26677. shadowsArray.push( object );
  26678. }
  26679. } else if ( object.isSprite ) {
  26680. if ( ! object.frustumCulled || _frustum.intersectsSprite( object ) ) {
  26681. spritesArray.push( object );
  26682. }
  26683. } else if ( object.isLensFlare ) {
  26684. flaresArray.push( object );
  26685. } else if ( object.isImmediateRenderObject ) {
  26686. if ( sortObjects ) {
  26687. _vector3.setFromMatrixPosition( object.matrixWorld )
  26688. .applyMatrix4( _projScreenMatrix );
  26689. }
  26690. currentRenderList.push( object, null, object.material, _vector3.z, null );
  26691. } else if ( object.isMesh || object.isLine || object.isPoints ) {
  26692. if ( object.isSkinnedMesh ) {
  26693. object.skeleton.update();
  26694. }
  26695. if ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) {
  26696. if ( sortObjects ) {
  26697. _vector3.setFromMatrixPosition( object.matrixWorld )
  26698. .applyMatrix4( _projScreenMatrix );
  26699. }
  26700. var geometry = objects.update( object );
  26701. var material = object.material;
  26702. if ( Array.isArray( material ) ) {
  26703. var groups = geometry.groups;
  26704. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  26705. var group = groups[ i ];
  26706. var groupMaterial = material[ group.materialIndex ];
  26707. if ( groupMaterial && groupMaterial.visible ) {
  26708. currentRenderList.push( object, geometry, groupMaterial, _vector3.z, group );
  26709. }
  26710. }
  26711. } else if ( material.visible ) {
  26712. currentRenderList.push( object, geometry, material, _vector3.z, null );
  26713. }
  26714. }
  26715. }
  26716. }
  26717. var children = object.children;
  26718. for ( var i = 0, l = children.length; i < l; i ++ ) {
  26719. projectObject( children[ i ], camera, sortObjects );
  26720. }
  26721. }
  26722. function renderObjects( renderList, scene, camera, overrideMaterial ) {
  26723. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  26724. var renderItem = renderList[ i ];
  26725. var object = renderItem.object;
  26726. var geometry = renderItem.geometry;
  26727. var material = overrideMaterial === undefined ? renderItem.material : overrideMaterial;
  26728. var group = renderItem.group;
  26729. if ( camera.isArrayCamera ) {
  26730. _currentArrayCamera = camera;
  26731. var cameras = camera.cameras;
  26732. for ( var j = 0, jl = cameras.length; j < jl; j ++ ) {
  26733. var camera2 = cameras[ j ];
  26734. if ( object.layers.test( camera2.layers ) ) {
  26735. var bounds = camera2.bounds;
  26736. var x = bounds.x * _width;
  26737. var y = bounds.y * _height;
  26738. var width = bounds.z * _width;
  26739. var height = bounds.w * _height;
  26740. state.viewport( _currentViewport.set( x, y, width, height ).multiplyScalar( _pixelRatio ) );
  26741. renderObject( object, scene, camera2, geometry, material, group );
  26742. }
  26743. }
  26744. } else {
  26745. _currentArrayCamera = null;
  26746. renderObject( object, scene, camera, geometry, material, group );
  26747. }
  26748. }
  26749. }
  26750. function renderObject( object, scene, camera, geometry, material, group ) {
  26751. object.onBeforeRender( _this, scene, camera, geometry, material, group );
  26752. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  26753. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  26754. if ( object.isImmediateRenderObject ) {
  26755. state.setMaterial( material );
  26756. var program = setProgram( camera, scene.fog, material, object );
  26757. _currentGeometryProgram = '';
  26758. renderObjectImmediate( object, program, material );
  26759. } else {
  26760. _this.renderBufferDirect( camera, scene.fog, geometry, material, object, group );
  26761. }
  26762. object.onAfterRender( _this, scene, camera, geometry, material, group );
  26763. }
  26764. function initMaterial( material, fog, object ) {
  26765. var materialProperties = properties.get( material );
  26766. var parameters = programCache.getParameters(
  26767. material, lights.state, shadowsArray, fog, _clipping.numPlanes, _clipping.numIntersection, object );
  26768. var code = programCache.getProgramCode( material, parameters );
  26769. var program = materialProperties.program;
  26770. var programChange = true;
  26771. if ( program === undefined ) {
  26772. // new material
  26773. material.addEventListener( 'dispose', onMaterialDispose );
  26774. } else if ( program.code !== code ) {
  26775. // changed glsl or parameters
  26776. releaseMaterialProgramReference( material );
  26777. } else if ( parameters.shaderID !== undefined ) {
  26778. // same glsl and uniform list
  26779. return;
  26780. } else {
  26781. // only rebuild uniform list
  26782. programChange = false;
  26783. }
  26784. if ( programChange ) {
  26785. if ( parameters.shaderID ) {
  26786. var shader = ShaderLib[ parameters.shaderID ];
  26787. materialProperties.shader = {
  26788. name: material.type,
  26789. uniforms: UniformsUtils.clone( shader.uniforms ),
  26790. vertexShader: shader.vertexShader,
  26791. fragmentShader: shader.fragmentShader
  26792. };
  26793. } else {
  26794. materialProperties.shader = {
  26795. name: material.type,
  26796. uniforms: material.uniforms,
  26797. vertexShader: material.vertexShader,
  26798. fragmentShader: material.fragmentShader
  26799. };
  26800. }
  26801. material.onBeforeCompile( materialProperties.shader );
  26802. program = programCache.acquireProgram( material, materialProperties.shader, parameters, code );
  26803. materialProperties.program = program;
  26804. material.program = program;
  26805. }
  26806. var programAttributes = program.getAttributes();
  26807. if ( material.morphTargets ) {
  26808. material.numSupportedMorphTargets = 0;
  26809. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  26810. if ( programAttributes[ 'morphTarget' + i ] >= 0 ) {
  26811. material.numSupportedMorphTargets ++;
  26812. }
  26813. }
  26814. }
  26815. if ( material.morphNormals ) {
  26816. material.numSupportedMorphNormals = 0;
  26817. for ( var i = 0; i < _this.maxMorphNormals; i ++ ) {
  26818. if ( programAttributes[ 'morphNormal' + i ] >= 0 ) {
  26819. material.numSupportedMorphNormals ++;
  26820. }
  26821. }
  26822. }
  26823. var uniforms = materialProperties.shader.uniforms;
  26824. if ( ! material.isShaderMaterial &&
  26825. ! material.isRawShaderMaterial ||
  26826. material.clipping === true ) {
  26827. materialProperties.numClippingPlanes = _clipping.numPlanes;
  26828. materialProperties.numIntersection = _clipping.numIntersection;
  26829. uniforms.clippingPlanes = _clipping.uniform;
  26830. }
  26831. materialProperties.fog = fog;
  26832. // store the light setup it was created for
  26833. materialProperties.lightsHash = lights.state.hash;
  26834. if ( material.lights ) {
  26835. // wire up the material to this renderer's lighting state
  26836. uniforms.ambientLightColor.value = lights.state.ambient;
  26837. uniforms.directionalLights.value = lights.state.directional;
  26838. uniforms.spotLights.value = lights.state.spot;
  26839. uniforms.rectAreaLights.value = lights.state.rectArea;
  26840. uniforms.pointLights.value = lights.state.point;
  26841. uniforms.hemisphereLights.value = lights.state.hemi;
  26842. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  26843. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  26844. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  26845. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  26846. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  26847. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix;
  26848. // TODO (abelnation): add area lights shadow info to uniforms
  26849. }
  26850. var progUniforms = materialProperties.program.getUniforms(),
  26851. uniformsList =
  26852. WebGLUniforms.seqWithValue( progUniforms.seq, uniforms );
  26853. materialProperties.uniformsList = uniformsList;
  26854. }
  26855. function setProgram( camera, fog, material, object ) {
  26856. _usedTextureUnits = 0;
  26857. var materialProperties = properties.get( material );
  26858. if ( _clippingEnabled ) {
  26859. if ( _localClippingEnabled || camera !== _currentCamera ) {
  26860. var useCache =
  26861. camera === _currentCamera &&
  26862. material.id === _currentMaterialId;
  26863. // we might want to call this function with some ClippingGroup
  26864. // object instead of the material, once it becomes feasible
  26865. // (#8465, #8379)
  26866. _clipping.setState(
  26867. material.clippingPlanes, material.clipIntersection, material.clipShadows,
  26868. camera, materialProperties, useCache );
  26869. }
  26870. }
  26871. if ( material.needsUpdate === false ) {
  26872. if ( materialProperties.program === undefined ) {
  26873. material.needsUpdate = true;
  26874. } else if ( material.fog && materialProperties.fog !== fog ) {
  26875. material.needsUpdate = true;
  26876. } else if ( material.lights && materialProperties.lightsHash !== lights.state.hash ) {
  26877. material.needsUpdate = true;
  26878. } else if ( materialProperties.numClippingPlanes !== undefined &&
  26879. ( materialProperties.numClippingPlanes !== _clipping.numPlanes ||
  26880. materialProperties.numIntersection !== _clipping.numIntersection ) ) {
  26881. material.needsUpdate = true;
  26882. }
  26883. }
  26884. if ( material.needsUpdate ) {
  26885. initMaterial( material, fog, object );
  26886. material.needsUpdate = false;
  26887. }
  26888. var refreshProgram = false;
  26889. var refreshMaterial = false;
  26890. var refreshLights = false;
  26891. var program = materialProperties.program,
  26892. p_uniforms = program.getUniforms(),
  26893. m_uniforms = materialProperties.shader.uniforms;
  26894. if ( state.useProgram( program.program ) ) {
  26895. refreshProgram = true;
  26896. refreshMaterial = true;
  26897. refreshLights = true;
  26898. }
  26899. if ( material.id !== _currentMaterialId ) {
  26900. _currentMaterialId = material.id;
  26901. refreshMaterial = true;
  26902. }
  26903. if ( refreshProgram || camera !== _currentCamera ) {
  26904. p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
  26905. if ( capabilities.logarithmicDepthBuffer ) {
  26906. p_uniforms.setValue( _gl, 'logDepthBufFC',
  26907. 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  26908. }
  26909. // Avoid unneeded uniform updates per ArrayCamera's sub-camera
  26910. if ( _currentCamera !== ( _currentArrayCamera || camera ) ) {
  26911. _currentCamera = ( _currentArrayCamera || camera );
  26912. // lighting uniforms depend on the camera so enforce an update
  26913. // now, in case this material supports lights - or later, when
  26914. // the next material that does gets activated:
  26915. refreshMaterial = true; // set to true on material change
  26916. refreshLights = true; // remains set until update done
  26917. }
  26918. // load material specific uniforms
  26919. // (shader material also gets them for the sake of genericity)
  26920. if ( material.isShaderMaterial ||
  26921. material.isMeshPhongMaterial ||
  26922. material.isMeshStandardMaterial ||
  26923. material.envMap ) {
  26924. var uCamPos = p_uniforms.map.cameraPosition;
  26925. if ( uCamPos !== undefined ) {
  26926. uCamPos.setValue( _gl,
  26927. _vector3.setFromMatrixPosition( camera.matrixWorld ) );
  26928. }
  26929. }
  26930. if ( material.isMeshPhongMaterial ||
  26931. material.isMeshLambertMaterial ||
  26932. material.isMeshBasicMaterial ||
  26933. material.isMeshStandardMaterial ||
  26934. material.isShaderMaterial ||
  26935. material.skinning ) {
  26936. p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
  26937. }
  26938. }
  26939. // skinning uniforms must be set even if material didn't change
  26940. // auto-setting of texture unit for bone texture must go before other textures
  26941. // not sure why, but otherwise weird things happen
  26942. if ( material.skinning ) {
  26943. p_uniforms.setOptional( _gl, object, 'bindMatrix' );
  26944. p_uniforms.setOptional( _gl, object, 'bindMatrixInverse' );
  26945. var skeleton = object.skeleton;
  26946. if ( skeleton ) {
  26947. var bones = skeleton.bones;
  26948. if ( capabilities.floatVertexTextures ) {
  26949. if ( skeleton.boneTexture === undefined ) {
  26950. // layout (1 matrix = 4 pixels)
  26951. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  26952. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  26953. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  26954. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  26955. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  26956. var size = Math.sqrt( bones.length * 4 ); // 4 pixels needed for 1 matrix
  26957. size = _Math.ceilPowerOfTwo( size );
  26958. size = Math.max( size, 4 );
  26959. var boneMatrices = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel
  26960. boneMatrices.set( skeleton.boneMatrices ); // copy current values
  26961. var boneTexture = new DataTexture( boneMatrices, size, size, RGBAFormat, FloatType );
  26962. skeleton.boneMatrices = boneMatrices;
  26963. skeleton.boneTexture = boneTexture;
  26964. skeleton.boneTextureSize = size;
  26965. }
  26966. p_uniforms.setValue( _gl, 'boneTexture', skeleton.boneTexture );
  26967. p_uniforms.setValue( _gl, 'boneTextureSize', skeleton.boneTextureSize );
  26968. } else {
  26969. p_uniforms.setOptional( _gl, skeleton, 'boneMatrices' );
  26970. }
  26971. }
  26972. }
  26973. if ( refreshMaterial ) {
  26974. p_uniforms.setValue( _gl, 'toneMappingExposure', _this.toneMappingExposure );
  26975. p_uniforms.setValue( _gl, 'toneMappingWhitePoint', _this.toneMappingWhitePoint );
  26976. if ( material.lights ) {
  26977. // the current material requires lighting info
  26978. // note: all lighting uniforms are always set correctly
  26979. // they simply reference the renderer's state for their
  26980. // values
  26981. //
  26982. // use the current material's .needsUpdate flags to set
  26983. // the GL state when required
  26984. markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
  26985. }
  26986. // refresh uniforms common to several materials
  26987. if ( fog && material.fog ) {
  26988. refreshUniformsFog( m_uniforms, fog );
  26989. }
  26990. if ( material.isMeshBasicMaterial ) {
  26991. refreshUniformsCommon( m_uniforms, material );
  26992. } else if ( material.isMeshLambertMaterial ) {
  26993. refreshUniformsCommon( m_uniforms, material );
  26994. refreshUniformsLambert( m_uniforms, material );
  26995. } else if ( material.isMeshPhongMaterial ) {
  26996. refreshUniformsCommon( m_uniforms, material );
  26997. if ( material.isMeshToonMaterial ) {
  26998. refreshUniformsToon( m_uniforms, material );
  26999. } else {
  27000. refreshUniformsPhong( m_uniforms, material );
  27001. }
  27002. } else if ( material.isMeshStandardMaterial ) {
  27003. refreshUniformsCommon( m_uniforms, material );
  27004. if ( material.isMeshPhysicalMaterial ) {
  27005. refreshUniformsPhysical( m_uniforms, material );
  27006. } else {
  27007. refreshUniformsStandard( m_uniforms, material );
  27008. }
  27009. } else if ( material.isMeshDepthMaterial ) {
  27010. refreshUniformsCommon( m_uniforms, material );
  27011. refreshUniformsDepth( m_uniforms, material );
  27012. } else if ( material.isMeshDistanceMaterial ) {
  27013. refreshUniformsCommon( m_uniforms, material );
  27014. refreshUniformsDistance( m_uniforms, material );
  27015. } else if ( material.isMeshNormalMaterial ) {
  27016. refreshUniformsCommon( m_uniforms, material );
  27017. refreshUniformsNormal( m_uniforms, material );
  27018. } else if ( material.isLineBasicMaterial ) {
  27019. refreshUniformsLine( m_uniforms, material );
  27020. if ( material.isLineDashedMaterial ) {
  27021. refreshUniformsDash( m_uniforms, material );
  27022. }
  27023. } else if ( material.isPointsMaterial ) {
  27024. refreshUniformsPoints( m_uniforms, material );
  27025. } else if ( material.isShadowMaterial ) {
  27026. m_uniforms.color.value = material.color;
  27027. m_uniforms.opacity.value = material.opacity;
  27028. }
  27029. // RectAreaLight Texture
  27030. // TODO (mrdoob): Find a nicer implementation
  27031. if ( m_uniforms.ltcMat !== undefined ) m_uniforms.ltcMat.value = UniformsLib.LTC_MAT_TEXTURE;
  27032. if ( m_uniforms.ltcMag !== undefined ) m_uniforms.ltcMag.value = UniformsLib.LTC_MAG_TEXTURE;
  27033. WebGLUniforms.upload(
  27034. _gl, materialProperties.uniformsList, m_uniforms, _this );
  27035. }
  27036. // common matrices
  27037. p_uniforms.setValue( _gl, 'modelViewMatrix', object.modelViewMatrix );
  27038. p_uniforms.setValue( _gl, 'normalMatrix', object.normalMatrix );
  27039. p_uniforms.setValue( _gl, 'modelMatrix', object.matrixWorld );
  27040. return program;
  27041. }
  27042. // Uniforms (refresh uniforms objects)
  27043. function refreshUniformsCommon( uniforms, material ) {
  27044. uniforms.opacity.value = material.opacity;
  27045. if ( material.color ) {
  27046. uniforms.diffuse.value = material.color;
  27047. }
  27048. if ( material.emissive ) {
  27049. uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity );
  27050. }
  27051. if ( material.map ) {
  27052. uniforms.map.value = material.map;
  27053. }
  27054. if ( material.alphaMap ) {
  27055. uniforms.alphaMap.value = material.alphaMap;
  27056. }
  27057. if ( material.specularMap ) {
  27058. uniforms.specularMap.value = material.specularMap;
  27059. }
  27060. if ( material.envMap ) {
  27061. uniforms.envMap.value = material.envMap;
  27062. // don't flip CubeTexture envMaps, flip everything else:
  27063. // WebGLRenderTargetCube will be flipped for backwards compatibility
  27064. // WebGLRenderTargetCube.texture will be flipped because it's a Texture and NOT a CubeTexture
  27065. // this check must be handled differently, or removed entirely, if WebGLRenderTargetCube uses a CubeTexture in the future
  27066. uniforms.flipEnvMap.value = ( ! ( material.envMap && material.envMap.isCubeTexture ) ) ? 1 : - 1;
  27067. uniforms.reflectivity.value = material.reflectivity;
  27068. uniforms.refractionRatio.value = material.refractionRatio;
  27069. }
  27070. if ( material.lightMap ) {
  27071. uniforms.lightMap.value = material.lightMap;
  27072. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  27073. }
  27074. if ( material.aoMap ) {
  27075. uniforms.aoMap.value = material.aoMap;
  27076. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  27077. }
  27078. // uv repeat and offset setting priorities
  27079. // 1. color map
  27080. // 2. specular map
  27081. // 3. normal map
  27082. // 4. bump map
  27083. // 5. alpha map
  27084. // 6. emissive map
  27085. var uvScaleMap;
  27086. if ( material.map ) {
  27087. uvScaleMap = material.map;
  27088. } else if ( material.specularMap ) {
  27089. uvScaleMap = material.specularMap;
  27090. } else if ( material.displacementMap ) {
  27091. uvScaleMap = material.displacementMap;
  27092. } else if ( material.normalMap ) {
  27093. uvScaleMap = material.normalMap;
  27094. } else if ( material.bumpMap ) {
  27095. uvScaleMap = material.bumpMap;
  27096. } else if ( material.roughnessMap ) {
  27097. uvScaleMap = material.roughnessMap;
  27098. } else if ( material.metalnessMap ) {
  27099. uvScaleMap = material.metalnessMap;
  27100. } else if ( material.alphaMap ) {
  27101. uvScaleMap = material.alphaMap;
  27102. } else if ( material.emissiveMap ) {
  27103. uvScaleMap = material.emissiveMap;
  27104. }
  27105. if ( uvScaleMap !== undefined ) {
  27106. // backwards compatibility
  27107. if ( uvScaleMap.isWebGLRenderTarget ) {
  27108. uvScaleMap = uvScaleMap.texture;
  27109. }
  27110. if ( uvScaleMap.matrixAutoUpdate === true ) {
  27111. var offset = uvScaleMap.offset;
  27112. var repeat = uvScaleMap.repeat;
  27113. var rotation = uvScaleMap.rotation;
  27114. var center = uvScaleMap.center;
  27115. uvScaleMap.matrix.setUvTransform( offset.x, offset.y, repeat.x, repeat.y, rotation, center.x, center.y );
  27116. }
  27117. uniforms.uvTransform.value.copy( uvScaleMap.matrix );
  27118. }
  27119. }
  27120. function refreshUniformsLine( uniforms, material ) {
  27121. uniforms.diffuse.value = material.color;
  27122. uniforms.opacity.value = material.opacity;
  27123. }
  27124. function refreshUniformsDash( uniforms, material ) {
  27125. uniforms.dashSize.value = material.dashSize;
  27126. uniforms.totalSize.value = material.dashSize + material.gapSize;
  27127. uniforms.scale.value = material.scale;
  27128. }
  27129. function refreshUniformsPoints( uniforms, material ) {
  27130. uniforms.diffuse.value = material.color;
  27131. uniforms.opacity.value = material.opacity;
  27132. uniforms.size.value = material.size * _pixelRatio;
  27133. uniforms.scale.value = _height * 0.5;
  27134. uniforms.map.value = material.map;
  27135. if ( material.map !== null ) {
  27136. if ( material.map.matrixAutoUpdate === true ) {
  27137. var offset = material.map.offset;
  27138. var repeat = material.map.repeat;
  27139. var rotation = material.map.rotation;
  27140. var center = material.map.center;
  27141. material.map.matrix.setUvTransform( offset.x, offset.y, repeat.x, repeat.y, rotation, center.x, center.y );
  27142. }
  27143. uniforms.uvTransform.value.copy( material.map.matrix );
  27144. }
  27145. }
  27146. function refreshUniformsFog( uniforms, fog ) {
  27147. uniforms.fogColor.value = fog.color;
  27148. if ( fog.isFog ) {
  27149. uniforms.fogNear.value = fog.near;
  27150. uniforms.fogFar.value = fog.far;
  27151. } else if ( fog.isFogExp2 ) {
  27152. uniforms.fogDensity.value = fog.density;
  27153. }
  27154. }
  27155. function refreshUniformsLambert( uniforms, material ) {
  27156. if ( material.emissiveMap ) {
  27157. uniforms.emissiveMap.value = material.emissiveMap;
  27158. }
  27159. }
  27160. function refreshUniformsPhong( uniforms, material ) {
  27161. uniforms.specular.value = material.specular;
  27162. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  27163. if ( material.emissiveMap ) {
  27164. uniforms.emissiveMap.value = material.emissiveMap;
  27165. }
  27166. if ( material.bumpMap ) {
  27167. uniforms.bumpMap.value = material.bumpMap;
  27168. uniforms.bumpScale.value = material.bumpScale;
  27169. }
  27170. if ( material.normalMap ) {
  27171. uniforms.normalMap.value = material.normalMap;
  27172. uniforms.normalScale.value.copy( material.normalScale );
  27173. }
  27174. if ( material.displacementMap ) {
  27175. uniforms.displacementMap.value = material.displacementMap;
  27176. uniforms.displacementScale.value = material.displacementScale;
  27177. uniforms.displacementBias.value = material.displacementBias;
  27178. }
  27179. }
  27180. function refreshUniformsToon( uniforms, material ) {
  27181. refreshUniformsPhong( uniforms, material );
  27182. if ( material.gradientMap ) {
  27183. uniforms.gradientMap.value = material.gradientMap;
  27184. }
  27185. }
  27186. function refreshUniformsStandard( uniforms, material ) {
  27187. uniforms.roughness.value = material.roughness;
  27188. uniforms.metalness.value = material.metalness;
  27189. if ( material.roughnessMap ) {
  27190. uniforms.roughnessMap.value = material.roughnessMap;
  27191. }
  27192. if ( material.metalnessMap ) {
  27193. uniforms.metalnessMap.value = material.metalnessMap;
  27194. }
  27195. if ( material.emissiveMap ) {
  27196. uniforms.emissiveMap.value = material.emissiveMap;
  27197. }
  27198. if ( material.bumpMap ) {
  27199. uniforms.bumpMap.value = material.bumpMap;
  27200. uniforms.bumpScale.value = material.bumpScale;
  27201. }
  27202. if ( material.normalMap ) {
  27203. uniforms.normalMap.value = material.normalMap;
  27204. uniforms.normalScale.value.copy( material.normalScale );
  27205. }
  27206. if ( material.displacementMap ) {
  27207. uniforms.displacementMap.value = material.displacementMap;
  27208. uniforms.displacementScale.value = material.displacementScale;
  27209. uniforms.displacementBias.value = material.displacementBias;
  27210. }
  27211. if ( material.envMap ) {
  27212. //uniforms.envMap.value = material.envMap; // part of uniforms common
  27213. uniforms.envMapIntensity.value = material.envMapIntensity;
  27214. }
  27215. }
  27216. function refreshUniformsPhysical( uniforms, material ) {
  27217. uniforms.clearCoat.value = material.clearCoat;
  27218. uniforms.clearCoatRoughness.value = material.clearCoatRoughness;
  27219. refreshUniformsStandard( uniforms, material );
  27220. }
  27221. function refreshUniformsDepth( uniforms, material ) {
  27222. if ( material.displacementMap ) {
  27223. uniforms.displacementMap.value = material.displacementMap;
  27224. uniforms.displacementScale.value = material.displacementScale;
  27225. uniforms.displacementBias.value = material.displacementBias;
  27226. }
  27227. }
  27228. function refreshUniformsDistance( uniforms, material ) {
  27229. if ( material.displacementMap ) {
  27230. uniforms.displacementMap.value = material.displacementMap;
  27231. uniforms.displacementScale.value = material.displacementScale;
  27232. uniforms.displacementBias.value = material.displacementBias;
  27233. }
  27234. uniforms.referencePosition.value.copy( material.referencePosition );
  27235. uniforms.nearDistance.value = material.nearDistance;
  27236. uniforms.farDistance.value = material.farDistance;
  27237. }
  27238. function refreshUniformsNormal( uniforms, material ) {
  27239. if ( material.bumpMap ) {
  27240. uniforms.bumpMap.value = material.bumpMap;
  27241. uniforms.bumpScale.value = material.bumpScale;
  27242. }
  27243. if ( material.normalMap ) {
  27244. uniforms.normalMap.value = material.normalMap;
  27245. uniforms.normalScale.value.copy( material.normalScale );
  27246. }
  27247. if ( material.displacementMap ) {
  27248. uniforms.displacementMap.value = material.displacementMap;
  27249. uniforms.displacementScale.value = material.displacementScale;
  27250. uniforms.displacementBias.value = material.displacementBias;
  27251. }
  27252. }
  27253. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  27254. function markUniformsLightsNeedsUpdate( uniforms, value ) {
  27255. uniforms.ambientLightColor.needsUpdate = value;
  27256. uniforms.directionalLights.needsUpdate = value;
  27257. uniforms.pointLights.needsUpdate = value;
  27258. uniforms.spotLights.needsUpdate = value;
  27259. uniforms.rectAreaLights.needsUpdate = value;
  27260. uniforms.hemisphereLights.needsUpdate = value;
  27261. }
  27262. // GL state setting
  27263. this.setFaceCulling = function ( cullFace, frontFaceDirection ) {
  27264. state.setCullFace( cullFace );
  27265. state.setFlipSided( frontFaceDirection === FrontFaceDirectionCW );
  27266. };
  27267. // Textures
  27268. function allocTextureUnit() {
  27269. var textureUnit = _usedTextureUnits;
  27270. if ( textureUnit >= capabilities.maxTextures ) {
  27271. console.warn( 'THREE.WebGLRenderer: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + capabilities.maxTextures );
  27272. }
  27273. _usedTextureUnits += 1;
  27274. return textureUnit;
  27275. }
  27276. this.allocTextureUnit = allocTextureUnit;
  27277. // this.setTexture2D = setTexture2D;
  27278. this.setTexture2D = ( function () {
  27279. var warned = false;
  27280. // backwards compatibility: peel texture.texture
  27281. return function setTexture2D( texture, slot ) {
  27282. if ( texture && texture.isWebGLRenderTarget ) {
  27283. if ( ! warned ) {
  27284. console.warn( "THREE.WebGLRenderer.setTexture2D: don't use render targets as textures. Use their .texture property instead." );
  27285. warned = true;
  27286. }
  27287. texture = texture.texture;
  27288. }
  27289. textures.setTexture2D( texture, slot );
  27290. };
  27291. }() );
  27292. this.setTexture = ( function () {
  27293. var warned = false;
  27294. return function setTexture( texture, slot ) {
  27295. if ( ! warned ) {
  27296. console.warn( "THREE.WebGLRenderer: .setTexture is deprecated, use setTexture2D instead." );
  27297. warned = true;
  27298. }
  27299. textures.setTexture2D( texture, slot );
  27300. };
  27301. }() );
  27302. this.setTextureCube = ( function () {
  27303. var warned = false;
  27304. return function setTextureCube( texture, slot ) {
  27305. // backwards compatibility: peel texture.texture
  27306. if ( texture && texture.isWebGLRenderTargetCube ) {
  27307. if ( ! warned ) {
  27308. console.warn( "THREE.WebGLRenderer.setTextureCube: don't use cube render targets as textures. Use their .texture property instead." );
  27309. warned = true;
  27310. }
  27311. texture = texture.texture;
  27312. }
  27313. // currently relying on the fact that WebGLRenderTargetCube.texture is a Texture and NOT a CubeTexture
  27314. // TODO: unify these code paths
  27315. if ( ( texture && texture.isCubeTexture ) ||
  27316. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  27317. // CompressedTexture can have Array in image :/
  27318. // this function alone should take care of cube textures
  27319. textures.setTextureCube( texture, slot );
  27320. } else {
  27321. // assumed: texture property of THREE.WebGLRenderTargetCube
  27322. textures.setTextureCubeDynamic( texture, slot );
  27323. }
  27324. };
  27325. }() );
  27326. this.getRenderTarget = function () {
  27327. return _currentRenderTarget;
  27328. };
  27329. this.setRenderTarget = function ( renderTarget ) {
  27330. _currentRenderTarget = renderTarget;
  27331. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  27332. textures.setupRenderTarget( renderTarget );
  27333. }
  27334. var framebuffer = null;
  27335. var isCube = false;
  27336. if ( renderTarget ) {
  27337. var __webglFramebuffer = properties.get( renderTarget ).__webglFramebuffer;
  27338. if ( renderTarget.isWebGLRenderTargetCube ) {
  27339. framebuffer = __webglFramebuffer[ renderTarget.activeCubeFace ];
  27340. isCube = true;
  27341. } else {
  27342. framebuffer = __webglFramebuffer;
  27343. }
  27344. _currentViewport.copy( renderTarget.viewport );
  27345. _currentScissor.copy( renderTarget.scissor );
  27346. _currentScissorTest = renderTarget.scissorTest;
  27347. } else {
  27348. _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio );
  27349. _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio );
  27350. _currentScissorTest = _scissorTest;
  27351. }
  27352. if ( _currentFramebuffer !== framebuffer ) {
  27353. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  27354. _currentFramebuffer = framebuffer;
  27355. }
  27356. state.viewport( _currentViewport );
  27357. state.scissor( _currentScissor );
  27358. state.setScissorTest( _currentScissorTest );
  27359. if ( isCube ) {
  27360. var textureProperties = properties.get( renderTarget.texture );
  27361. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + renderTarget.activeCubeFace, textureProperties.__webglTexture, renderTarget.activeMipMapLevel );
  27362. }
  27363. };
  27364. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer ) {
  27365. if ( ! ( renderTarget && renderTarget.isWebGLRenderTarget ) ) {
  27366. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  27367. return;
  27368. }
  27369. var framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  27370. if ( framebuffer ) {
  27371. var restore = false;
  27372. if ( framebuffer !== _currentFramebuffer ) {
  27373. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  27374. restore = true;
  27375. }
  27376. try {
  27377. var texture = renderTarget.texture;
  27378. var textureFormat = texture.format;
  27379. var textureType = texture.type;
  27380. if ( textureFormat !== RGBAFormat && utils.convert( textureFormat ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) {
  27381. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  27382. return;
  27383. }
  27384. if ( textureType !== UnsignedByteType && utils.convert( textureType ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_TYPE ) && // IE11, Edge and Chrome Mac < 52 (#9513)
  27385. ! ( textureType === FloatType && ( extensions.get( 'OES_texture_float' ) || extensions.get( 'WEBGL_color_buffer_float' ) ) ) && // Chrome Mac >= 52 and Firefox
  27386. ! ( textureType === HalfFloatType && extensions.get( 'EXT_color_buffer_half_float' ) ) ) {
  27387. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  27388. return;
  27389. }
  27390. if ( _gl.checkFramebufferStatus( _gl.FRAMEBUFFER ) === _gl.FRAMEBUFFER_COMPLETE ) {
  27391. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  27392. if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
  27393. _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), buffer );
  27394. }
  27395. } else {
  27396. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  27397. }
  27398. } finally {
  27399. if ( restore ) {
  27400. _gl.bindFramebuffer( _gl.FRAMEBUFFER, _currentFramebuffer );
  27401. }
  27402. }
  27403. }
  27404. };
  27405. }
  27406. /**
  27407. * @author TristanVALCKE / https://github.com/Itee
  27408. * @author Anonymous
  27409. */
  27410. /* global QUnit */
  27411. // DEBUGGING
  27412. //
  27413. // HELPERS
  27414. //
  27415. function testEdges( vertList, idxList, numAfter, assert ) {
  27416. var geoms = createGeometries( vertList, idxList );
  27417. for ( var i = 0; i < geoms.length; i ++ ) {
  27418. var geom = geoms[ i ];
  27419. var numBefore = idxList.length;
  27420. assert.equal( countEdges( geom ), numBefore, "Edges before!" );
  27421. var egeom = new EdgesGeometry( geom );
  27422. assert.equal( countEdges( egeom ), numAfter, "Edges after!" );
  27423. output( geom, egeom );
  27424. }
  27425. }
  27426. function createGeometries( vertList, idxList ) {
  27427. var geomIB = createIndexedBufferGeometry( vertList, idxList );
  27428. var geom = new Geometry().fromBufferGeometry( geomIB );
  27429. var geomB = new BufferGeometry().fromGeometry( geom );
  27430. var geomDC = addDrawCalls( geomIB.clone() );
  27431. return [ geom, geomB, geomIB, geomDC ];
  27432. }
  27433. function createIndexedBufferGeometry( vertList, idxList ) {
  27434. var geom = new BufferGeometry();
  27435. var indexTable = [];
  27436. var numTris = idxList.length / 3;
  27437. var numVerts = 0;
  27438. var indices = new Uint32Array( numTris * 3 );
  27439. var vertices = new Float32Array( vertList.length * 3 );
  27440. for ( var i = 0; i < numTris; i ++ ) {
  27441. for ( var j = 0; j < 3; j ++ ) {
  27442. var idx = idxList[ 3 * i + j ];
  27443. if ( indexTable[ idx ] === undefined ) {
  27444. var v = vertList[ idx ];
  27445. vertices[ 3 * numVerts ] = v.x;
  27446. vertices[ 3 * numVerts + 1 ] = v.y;
  27447. vertices[ 3 * numVerts + 2 ] = v.z;
  27448. indexTable[ idx ] = numVerts;
  27449. numVerts ++;
  27450. }
  27451. indices[ 3 * i + j ] = indexTable[ idx ];
  27452. }
  27453. }
  27454. vertices = vertices.subarray( 0, 3 * numVerts );
  27455. geom.setIndex( new BufferAttribute( indices, 1 ) );
  27456. geom.addAttribute( 'position', new BufferAttribute( vertices, 3 ) );
  27457. geom.computeFaceNormals();
  27458. return geom;
  27459. }
  27460. function addDrawCalls( geometry ) {
  27461. var numTris = geometry.index.count / 3;
  27462. for ( var i = 0; i < numTris; i ++ ) {
  27463. var start = i * 3;
  27464. var count = 3;
  27465. geometry.addGroup( start, count );
  27466. }
  27467. return geometry;
  27468. }
  27469. function countEdges( geom ) {
  27470. if ( geom instanceof EdgesGeometry ) {
  27471. return geom.getAttribute( 'position' ).count / 2;
  27472. }
  27473. if ( geom.faces !== undefined ) {
  27474. return geom.faces.length * 3;
  27475. }
  27476. var indices = geom.index;
  27477. if ( indices ) {
  27478. return indices.count;
  27479. }
  27480. return geom.getAttribute( 'position' ).count;
  27481. }
  27482. //
  27483. // DEBUGGING
  27484. //
  27485. var DEBUG = false;
  27486. var renderer;
  27487. var camera;
  27488. var scene = new Scene();
  27489. var xoffset = 0;
  27490. function output( geom, egeom ) {
  27491. if ( DEBUG !== true ) return;
  27492. if ( ! renderer ) initDebug();
  27493. var mesh = new Mesh( geom, undefined );
  27494. var edges = new LineSegments( egeom, new LineBasicMaterial( { color: 'black' } ) );
  27495. mesh.position.setX( xoffset );
  27496. edges.position.setX( xoffset ++ );
  27497. scene.add( mesh );
  27498. scene.add( edges );
  27499. if ( scene.children.length % 8 === 0 ) {
  27500. xoffset += 2;
  27501. }
  27502. }
  27503. function initDebug() {
  27504. renderer = new WebGLRenderer( {
  27505. antialias: true
  27506. } );
  27507. var width = 600;
  27508. var height = 480;
  27509. renderer.setSize( width, height );
  27510. renderer.setClearColor( 0xCCCCCC );
  27511. camera = new PerspectiveCamera( 45, width / height, 1, 100 );
  27512. camera.position.x = 30;
  27513. camera.position.z = 40;
  27514. camera.lookAt( new Vector3( 30, 0, 0 ) );
  27515. document.body.appendChild( renderer.domElement );
  27516. var controls = new THREE.OrbitControls( camera, renderer.domElement ); // TODO: please do somethings for that -_-'
  27517. controls.target = new Vector3( 30, 0, 0 );
  27518. animate();
  27519. function animate() {
  27520. requestAnimationFrame( animate );
  27521. controls.update();
  27522. renderer.render( scene, camera );
  27523. }
  27524. }
  27525. QUnit.module( 'Geometries', () => {
  27526. QUnit.module.todo( 'EdgesGeometry', () => {
  27527. var vertList = [
  27528. new Vector3( 0, 0, 0 ),
  27529. new Vector3( 1, 0, 0 ),
  27530. new Vector3( 1, 1, 0 ),
  27531. new Vector3( 0, 1, 0 ),
  27532. new Vector3( 1, 1, 1 ),
  27533. ];
  27534. // INHERITANCE
  27535. QUnit.test( "Extending", ( assert ) => {
  27536. assert.ok( false, "everything's gonna be alright" );
  27537. } );
  27538. // INSTANCING
  27539. QUnit.test( "Instancing", ( assert ) => {
  27540. assert.ok( false, "everything's gonna be alright" );
  27541. } );
  27542. // OTHERS
  27543. QUnit.test( "singularity", ( assert ) => {
  27544. testEdges( vertList, [ 1, 1, 1 ], 0, assert );
  27545. } );
  27546. QUnit.test( "needle", ( assert ) => {
  27547. testEdges( vertList, [ 0, 0, 1 ], 0, assert );
  27548. } );
  27549. QUnit.test( "single triangle", ( assert ) => {
  27550. testEdges( vertList, [ 0, 1, 2 ], 3, assert );
  27551. } );
  27552. QUnit.test( "two isolated triangles", ( assert ) => {
  27553. var vertList = [
  27554. new Vector3( 0, 0, 0 ),
  27555. new Vector3( 1, 0, 0 ),
  27556. new Vector3( 1, 1, 0 ),
  27557. new Vector3( 0, 0, 1 ),
  27558. new Vector3( 1, 0, 1 ),
  27559. new Vector3( 1, 1, 1 ),
  27560. ];
  27561. testEdges( vertList, [ 0, 1, 2, 3, 4, 5 ], 6, assert );
  27562. } );
  27563. QUnit.test( "two flat triangles", ( assert ) => {
  27564. testEdges( vertList, [ 0, 1, 2, 0, 2, 3 ], 4, assert );
  27565. } );
  27566. QUnit.test( "two flat triangles, inverted", ( assert ) => {
  27567. testEdges( vertList, [ 0, 1, 2, 0, 3, 2 ], 5, assert );
  27568. } );
  27569. QUnit.test( "two non-coplanar triangles", ( assert ) => {
  27570. testEdges( vertList, [ 0, 1, 2, 0, 4, 2 ], 5, assert );
  27571. } );
  27572. QUnit.test( "three triangles, coplanar first", ( assert ) => {
  27573. testEdges( vertList, [ 0, 1, 2, 0, 2, 3, 0, 4, 2 ], 7, assert );
  27574. } );
  27575. QUnit.test( "three triangles, coplanar last", ( assert ) => {
  27576. testEdges( vertList, [ 0, 1, 2, 0, 4, 2, 0, 2, 3 ], 6, assert ); // Should be 7
  27577. } );
  27578. QUnit.test( "tetrahedron", ( assert ) => {
  27579. testEdges( vertList, [ 0, 1, 2, 0, 1, 4, 0, 4, 2, 1, 2, 4 ], 6, assert );
  27580. } );
  27581. } );
  27582. } );
  27583. /**
  27584. * @author zz85 / http://www.lab4games.net/zz85/blog
  27585. *
  27586. * Creates extruded geometry from a path shape.
  27587. *
  27588. * parameters = {
  27589. *
  27590. * curveSegments: <int>, // number of points on the curves
  27591. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  27592. * amount: <int>, // Depth to extrude the shape
  27593. *
  27594. * bevelEnabled: <bool>, // turn on bevel
  27595. * bevelThickness: <float>, // how deep into the original shape bevel goes
  27596. * bevelSize: <float>, // how far from shape outline is bevel
  27597. * bevelSegments: <int>, // number of bevel layers
  27598. *
  27599. * extrudePath: <THREE.Curve> // curve to extrude shape along
  27600. * frames: <Object> // containing arrays of tangents, normals, binormals
  27601. *
  27602. * UVGenerator: <Object> // object that provides UV generator functions
  27603. *
  27604. * }
  27605. */
  27606. // ExtrudeGeometry
  27607. function ExtrudeGeometry( shapes, options ) {
  27608. Geometry.call( this );
  27609. this.type = 'ExtrudeGeometry';
  27610. this.parameters = {
  27611. shapes: shapes,
  27612. options: options
  27613. };
  27614. this.fromBufferGeometry( new ExtrudeBufferGeometry( shapes, options ) );
  27615. this.mergeVertices();
  27616. }
  27617. ExtrudeGeometry.prototype = Object.create( Geometry.prototype );
  27618. ExtrudeGeometry.prototype.constructor = ExtrudeGeometry;
  27619. // ExtrudeBufferGeometry
  27620. function ExtrudeBufferGeometry( shapes, options ) {
  27621. if ( typeof ( shapes ) === "undefined" ) {
  27622. return;
  27623. }
  27624. BufferGeometry.call( this );
  27625. this.type = 'ExtrudeBufferGeometry';
  27626. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  27627. this.addShapeList( shapes, options );
  27628. this.computeVertexNormals();
  27629. // can't really use automatic vertex normals
  27630. // as then front and back sides get smoothed too
  27631. // should do separate smoothing just for sides
  27632. //this.computeVertexNormals();
  27633. //console.log( "took", ( Date.now() - startTime ) );
  27634. }
  27635. ExtrudeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  27636. ExtrudeBufferGeometry.prototype.constructor = ExtrudeBufferGeometry;
  27637. ExtrudeBufferGeometry.prototype.getArrays = function () {
  27638. var positionAttribute = this.getAttribute( "position" );
  27639. var verticesArray = positionAttribute ? Array.prototype.slice.call( positionAttribute.array ) : [];
  27640. var uvAttribute = this.getAttribute( "uv" );
  27641. var uvArray = uvAttribute ? Array.prototype.slice.call( uvAttribute.array ) : [];
  27642. var IndexAttribute = this.index;
  27643. var indicesArray = IndexAttribute ? Array.prototype.slice.call( IndexAttribute.array ) : [];
  27644. return {
  27645. position: verticesArray,
  27646. uv: uvArray,
  27647. index: indicesArray
  27648. };
  27649. };
  27650. ExtrudeBufferGeometry.prototype.addShapeList = function ( shapes, options ) {
  27651. var sl = shapes.length;
  27652. options.arrays = this.getArrays();
  27653. for ( var s = 0; s < sl; s ++ ) {
  27654. var shape = shapes[ s ];
  27655. this.addShape( shape, options );
  27656. }
  27657. this.setIndex( options.arrays.index );
  27658. this.addAttribute( 'position', new Float32BufferAttribute( options.arrays.position, 3 ) );
  27659. this.addAttribute( 'uv', new Float32BufferAttribute( options.arrays.uv, 2 ) );
  27660. };
  27661. ExtrudeBufferGeometry.prototype.addShape = function ( shape, options ) {
  27662. var arrays = options.arrays ? options.arrays : this.getArrays();
  27663. var verticesArray = arrays.position;
  27664. var indicesArray = arrays.index;
  27665. var uvArray = arrays.uv;
  27666. var placeholder = [];
  27667. var amount = options.amount !== undefined ? options.amount : 100;
  27668. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6; // 10
  27669. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2; // 8
  27670. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  27671. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true; // false
  27672. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  27673. var steps = options.steps !== undefined ? options.steps : 1;
  27674. var extrudePath = options.extrudePath;
  27675. var extrudePts, extrudeByPath = false;
  27676. // Use default WorldUVGenerator if no UV generators are specified.
  27677. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : ExtrudeGeometry.WorldUVGenerator;
  27678. var splineTube, binormal, normal, position2;
  27679. if ( extrudePath ) {
  27680. extrudePts = extrudePath.getSpacedPoints( steps );
  27681. extrudeByPath = true;
  27682. bevelEnabled = false; // bevels not supported for path extrusion
  27683. // SETUP TNB variables
  27684. // TODO1 - have a .isClosed in spline?
  27685. splineTube = options.frames !== undefined ? options.frames : extrudePath.computeFrenetFrames( steps, false );
  27686. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  27687. binormal = new Vector3();
  27688. normal = new Vector3();
  27689. position2 = new Vector3();
  27690. }
  27691. // Safeguards if bevels are not enabled
  27692. if ( ! bevelEnabled ) {
  27693. bevelSegments = 0;
  27694. bevelThickness = 0;
  27695. bevelSize = 0;
  27696. }
  27697. // Variables initialization
  27698. var ahole, h, hl; // looping of holes
  27699. var scope = this;
  27700. var shapePoints = shape.extractPoints( curveSegments );
  27701. var vertices = shapePoints.shape;
  27702. var holes = shapePoints.holes;
  27703. var reverse = ! ShapeUtils.isClockWise( vertices );
  27704. if ( reverse ) {
  27705. vertices = vertices.reverse();
  27706. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  27707. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  27708. ahole = holes[ h ];
  27709. if ( ShapeUtils.isClockWise( ahole ) ) {
  27710. holes[ h ] = ahole.reverse();
  27711. }
  27712. }
  27713. }
  27714. var faces = ShapeUtils.triangulateShape( vertices, holes );
  27715. /* Vertices */
  27716. var contour = vertices; // vertices has all points but contour has only points of circumference
  27717. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  27718. ahole = holes[ h ];
  27719. vertices = vertices.concat( ahole );
  27720. }
  27721. function scalePt2( pt, vec, size ) {
  27722. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  27723. return vec.clone().multiplyScalar( size ).add( pt );
  27724. }
  27725. var b, bs, t, z,
  27726. vert, vlen = vertices.length,
  27727. face, flen = faces.length;
  27728. // Find directions for point movement
  27729. function getBevelVec( inPt, inPrev, inNext ) {
  27730. // computes for inPt the corresponding point inPt' on a new contour
  27731. // shifted by 1 unit (length of normalized vector) to the left
  27732. // if we walk along contour clockwise, this new contour is outside the old one
  27733. //
  27734. // inPt' is the intersection of the two lines parallel to the two
  27735. // adjacent edges of inPt at a distance of 1 unit on the left side.
  27736. var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  27737. // good reading for geometry algorithms (here: line-line intersection)
  27738. // http://geomalgorithms.com/a05-_intersect-1.html
  27739. var v_prev_x = inPt.x - inPrev.x,
  27740. v_prev_y = inPt.y - inPrev.y;
  27741. var v_next_x = inNext.x - inPt.x,
  27742. v_next_y = inNext.y - inPt.y;
  27743. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  27744. // check for collinear edges
  27745. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  27746. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  27747. // not collinear
  27748. // length of vectors for normalizing
  27749. var v_prev_len = Math.sqrt( v_prev_lensq );
  27750. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  27751. // shift adjacent points by unit vectors to the left
  27752. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  27753. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  27754. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  27755. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  27756. // scaling factor for v_prev to intersection point
  27757. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  27758. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  27759. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  27760. // vector from inPt to intersection point
  27761. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  27762. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  27763. // Don't normalize!, otherwise sharp corners become ugly
  27764. // but prevent crazy spikes
  27765. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  27766. if ( v_trans_lensq <= 2 ) {
  27767. return new Vector2( v_trans_x, v_trans_y );
  27768. } else {
  27769. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  27770. }
  27771. } else {
  27772. // handle special case of collinear edges
  27773. var direction_eq = false; // assumes: opposite
  27774. if ( v_prev_x > Number.EPSILON ) {
  27775. if ( v_next_x > Number.EPSILON ) {
  27776. direction_eq = true;
  27777. }
  27778. } else {
  27779. if ( v_prev_x < - Number.EPSILON ) {
  27780. if ( v_next_x < - Number.EPSILON ) {
  27781. direction_eq = true;
  27782. }
  27783. } else {
  27784. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  27785. direction_eq = true;
  27786. }
  27787. }
  27788. }
  27789. if ( direction_eq ) {
  27790. // console.log("Warning: lines are a straight sequence");
  27791. v_trans_x = - v_prev_y;
  27792. v_trans_y = v_prev_x;
  27793. shrink_by = Math.sqrt( v_prev_lensq );
  27794. } else {
  27795. // console.log("Warning: lines are a straight spike");
  27796. v_trans_x = v_prev_x;
  27797. v_trans_y = v_prev_y;
  27798. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  27799. }
  27800. }
  27801. return new Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  27802. }
  27803. var contourMovements = [];
  27804. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  27805. if ( j === il ) j = 0;
  27806. if ( k === il ) k = 0;
  27807. // (j)---(i)---(k)
  27808. // console.log('i,j,k', i, j , k)
  27809. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  27810. }
  27811. var holesMovements = [],
  27812. oneHoleMovements, verticesMovements = contourMovements.concat();
  27813. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  27814. ahole = holes[ h ];
  27815. oneHoleMovements = [];
  27816. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  27817. if ( j === il ) j = 0;
  27818. if ( k === il ) k = 0;
  27819. // (j)---(i)---(k)
  27820. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  27821. }
  27822. holesMovements.push( oneHoleMovements );
  27823. verticesMovements = verticesMovements.concat( oneHoleMovements );
  27824. }
  27825. // Loop bevelSegments, 1 for the front, 1 for the back
  27826. for ( b = 0; b < bevelSegments; b ++ ) {
  27827. //for ( b = bevelSegments; b > 0; b -- ) {
  27828. t = b / bevelSegments;
  27829. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  27830. bs = bevelSize * Math.sin( t * Math.PI / 2 );
  27831. // contract shape
  27832. for ( i = 0, il = contour.length; i < il; i ++ ) {
  27833. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  27834. v( vert.x, vert.y, - z );
  27835. }
  27836. // expand holes
  27837. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  27838. ahole = holes[ h ];
  27839. oneHoleMovements = holesMovements[ h ];
  27840. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  27841. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  27842. v( vert.x, vert.y, - z );
  27843. }
  27844. }
  27845. }
  27846. bs = bevelSize;
  27847. // Back facing vertices
  27848. for ( i = 0; i < vlen; i ++ ) {
  27849. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  27850. if ( ! extrudeByPath ) {
  27851. v( vert.x, vert.y, 0 );
  27852. } else {
  27853. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  27854. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  27855. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  27856. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  27857. v( position2.x, position2.y, position2.z );
  27858. }
  27859. }
  27860. // Add stepped vertices...
  27861. // Including front facing vertices
  27862. var s;
  27863. for ( s = 1; s <= steps; s ++ ) {
  27864. for ( i = 0; i < vlen; i ++ ) {
  27865. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  27866. if ( ! extrudeByPath ) {
  27867. v( vert.x, vert.y, amount / steps * s );
  27868. } else {
  27869. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  27870. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  27871. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  27872. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  27873. v( position2.x, position2.y, position2.z );
  27874. }
  27875. }
  27876. }
  27877. // Add bevel segments planes
  27878. //for ( b = 1; b <= bevelSegments; b ++ ) {
  27879. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  27880. t = b / bevelSegments;
  27881. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  27882. bs = bevelSize * Math.sin( t * Math.PI / 2 );
  27883. // contract shape
  27884. for ( i = 0, il = contour.length; i < il; i ++ ) {
  27885. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  27886. v( vert.x, vert.y, amount + z );
  27887. }
  27888. // expand holes
  27889. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  27890. ahole = holes[ h ];
  27891. oneHoleMovements = holesMovements[ h ];
  27892. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  27893. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  27894. if ( ! extrudeByPath ) {
  27895. v( vert.x, vert.y, amount + z );
  27896. } else {
  27897. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  27898. }
  27899. }
  27900. }
  27901. }
  27902. /* Faces */
  27903. // Top and bottom faces
  27904. buildLidFaces();
  27905. // Sides faces
  27906. buildSideFaces();
  27907. ///// Internal functions
  27908. function buildLidFaces() {
  27909. var start = verticesArray.length / 3;
  27910. if ( bevelEnabled ) {
  27911. var layer = 0; // steps + 1
  27912. var offset = vlen * layer;
  27913. // Bottom faces
  27914. for ( i = 0; i < flen; i ++ ) {
  27915. face = faces[ i ];
  27916. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  27917. }
  27918. layer = steps + bevelSegments * 2;
  27919. offset = vlen * layer;
  27920. // Top faces
  27921. for ( i = 0; i < flen; i ++ ) {
  27922. face = faces[ i ];
  27923. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  27924. }
  27925. } else {
  27926. // Bottom faces
  27927. for ( i = 0; i < flen; i ++ ) {
  27928. face = faces[ i ];
  27929. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  27930. }
  27931. // Top faces
  27932. for ( i = 0; i < flen; i ++ ) {
  27933. face = faces[ i ];
  27934. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  27935. }
  27936. }
  27937. scope.addGroup( start, verticesArray.length / 3 - start, options.material !== undefined ? options.material : 0 );
  27938. }
  27939. // Create faces for the z-sides of the shape
  27940. function buildSideFaces() {
  27941. var start = verticesArray.length / 3;
  27942. var layeroffset = 0;
  27943. sidewalls( contour, layeroffset );
  27944. layeroffset += contour.length;
  27945. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  27946. ahole = holes[ h ];
  27947. sidewalls( ahole, layeroffset );
  27948. //, true
  27949. layeroffset += ahole.length;
  27950. }
  27951. scope.addGroup( start, verticesArray.length / 3 - start, options.extrudeMaterial !== undefined ? options.extrudeMaterial : 1 );
  27952. }
  27953. function sidewalls( contour, layeroffset ) {
  27954. var j, k;
  27955. i = contour.length;
  27956. while ( -- i >= 0 ) {
  27957. j = i;
  27958. k = i - 1;
  27959. if ( k < 0 ) k = contour.length - 1;
  27960. //console.log('b', i,j, i-1, k,vertices.length);
  27961. var s = 0,
  27962. sl = steps + bevelSegments * 2;
  27963. for ( s = 0; s < sl; s ++ ) {
  27964. var slen1 = vlen * s;
  27965. var slen2 = vlen * ( s + 1 );
  27966. var a = layeroffset + j + slen1,
  27967. b = layeroffset + k + slen1,
  27968. c = layeroffset + k + slen2,
  27969. d = layeroffset + j + slen2;
  27970. f4( a, b, c, d );
  27971. }
  27972. }
  27973. }
  27974. function v( x, y, z ) {
  27975. placeholder.push( x );
  27976. placeholder.push( y );
  27977. placeholder.push( z );
  27978. }
  27979. function f3( a, b, c ) {
  27980. addVertex( a );
  27981. addVertex( b );
  27982. addVertex( c );
  27983. var nextIndex = verticesArray.length / 3;
  27984. var uvs = uvgen.generateTopUV( scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  27985. addUV( uvs[ 0 ] );
  27986. addUV( uvs[ 1 ] );
  27987. addUV( uvs[ 2 ] );
  27988. }
  27989. function f4( a, b, c, d ) {
  27990. addVertex( a );
  27991. addVertex( b );
  27992. addVertex( d );
  27993. addVertex( b );
  27994. addVertex( c );
  27995. addVertex( d );
  27996. var nextIndex = verticesArray.length / 3;
  27997. var uvs = uvgen.generateSideWallUV( scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  27998. addUV( uvs[ 0 ] );
  27999. addUV( uvs[ 1 ] );
  28000. addUV( uvs[ 3 ] );
  28001. addUV( uvs[ 1 ] );
  28002. addUV( uvs[ 2 ] );
  28003. addUV( uvs[ 3 ] );
  28004. }
  28005. function addVertex( index ) {
  28006. indicesArray.push( verticesArray.length / 3 );
  28007. verticesArray.push( placeholder[ index * 3 + 0 ] );
  28008. verticesArray.push( placeholder[ index * 3 + 1 ] );
  28009. verticesArray.push( placeholder[ index * 3 + 2 ] );
  28010. }
  28011. function addUV( vector2 ) {
  28012. uvArray.push( vector2.x );
  28013. uvArray.push( vector2.y );
  28014. }
  28015. if ( ! options.arrays ) {
  28016. this.setIndex( indicesArray );
  28017. this.addAttribute( 'position', new Float32BufferAttribute( verticesArray, 3 ) );
  28018. this.addAttribute( 'uv', new Float32BufferAttribute( options.arrays.uv, 2 ) );
  28019. }
  28020. };
  28021. ExtrudeGeometry.WorldUVGenerator = {
  28022. generateTopUV: function ( geometry, vertices, indexA, indexB, indexC ) {
  28023. var a_x = vertices[ indexA * 3 ];
  28024. var a_y = vertices[ indexA * 3 + 1 ];
  28025. var b_x = vertices[ indexB * 3 ];
  28026. var b_y = vertices[ indexB * 3 + 1 ];
  28027. var c_x = vertices[ indexC * 3 ];
  28028. var c_y = vertices[ indexC * 3 + 1 ];
  28029. return [
  28030. new Vector2( a_x, a_y ),
  28031. new Vector2( b_x, b_y ),
  28032. new Vector2( c_x, c_y )
  28033. ];
  28034. },
  28035. generateSideWallUV: function ( geometry, vertices, indexA, indexB, indexC, indexD ) {
  28036. var a_x = vertices[ indexA * 3 ];
  28037. var a_y = vertices[ indexA * 3 + 1 ];
  28038. var a_z = vertices[ indexA * 3 + 2 ];
  28039. var b_x = vertices[ indexB * 3 ];
  28040. var b_y = vertices[ indexB * 3 + 1 ];
  28041. var b_z = vertices[ indexB * 3 + 2 ];
  28042. var c_x = vertices[ indexC * 3 ];
  28043. var c_y = vertices[ indexC * 3 + 1 ];
  28044. var c_z = vertices[ indexC * 3 + 2 ];
  28045. var d_x = vertices[ indexD * 3 ];
  28046. var d_y = vertices[ indexD * 3 + 1 ];
  28047. var d_z = vertices[ indexD * 3 + 2 ];
  28048. if ( Math.abs( a_y - b_y ) < 0.01 ) {
  28049. return [
  28050. new Vector2( a_x, 1 - a_z ),
  28051. new Vector2( b_x, 1 - b_z ),
  28052. new Vector2( c_x, 1 - c_z ),
  28053. new Vector2( d_x, 1 - d_z )
  28054. ];
  28055. } else {
  28056. return [
  28057. new Vector2( a_y, 1 - a_z ),
  28058. new Vector2( b_y, 1 - b_z ),
  28059. new Vector2( c_y, 1 - c_z ),
  28060. new Vector2( d_y, 1 - d_z )
  28061. ];
  28062. }
  28063. }
  28064. };
  28065. /**
  28066. * @author TristanVALCKE / https://github.com/Itee
  28067. */
  28068. /* global QUnit */
  28069. QUnit.module( 'Geometries', () => {
  28070. QUnit.module.todo( 'ExtrudeGeometry', () => {
  28071. // INHERITANCE
  28072. QUnit.test( "Extending", ( assert ) => {
  28073. assert.ok( false, "everything's gonna be alright" );
  28074. } );
  28075. // INSTANCING
  28076. QUnit.test( "Instancing", ( assert ) => {
  28077. assert.ok( false, "everything's gonna be alright" );
  28078. } );
  28079. } );
  28080. QUnit.module.todo( 'ExtrudeBufferGeometry', () => {
  28081. // INHERITANCE
  28082. QUnit.test( "Extending", ( assert ) => {
  28083. assert.ok( false, "everything's gonna be alright" );
  28084. } );
  28085. // INSTANCING
  28086. QUnit.test( "Instancing", ( assert ) => {
  28087. assert.ok( false, "everything's gonna be alright" );
  28088. } );
  28089. // STATIC STUFF
  28090. QUnit.test( "WorldUVGenerator.generateTopUV", ( assert ) => {
  28091. assert.ok( false, "everything's gonna be alright" );
  28092. } );
  28093. QUnit.test( "WorldUVGenerator.generateSideWallUV", ( assert ) => {
  28094. assert.ok( false, "everything's gonna be alright" );
  28095. } );
  28096. // OTHERS
  28097. QUnit.test( "getArrays", ( assert ) => {
  28098. assert.ok( false, "everything's gonna be alright" );
  28099. } );
  28100. QUnit.test( "addShapeList", ( assert ) => {
  28101. assert.ok( false, "everything's gonna be alright" );
  28102. } );
  28103. QUnit.test( "addShape", ( assert ) => {
  28104. assert.ok( false, "everything's gonna be alright" );
  28105. } );
  28106. } );
  28107. } );
  28108. /**
  28109. * @author timothypratley / https://github.com/timothypratley
  28110. * @author Mugen87 / https://github.com/Mugen87
  28111. */
  28112. // IcosahedronGeometry
  28113. function IcosahedronGeometry( radius, detail ) {
  28114. Geometry.call( this );
  28115. this.type = 'IcosahedronGeometry';
  28116. this.parameters = {
  28117. radius: radius,
  28118. detail: detail
  28119. };
  28120. this.fromBufferGeometry( new IcosahedronBufferGeometry( radius, detail ) );
  28121. this.mergeVertices();
  28122. }
  28123. IcosahedronGeometry.prototype = Object.create( Geometry.prototype );
  28124. IcosahedronGeometry.prototype.constructor = IcosahedronGeometry;
  28125. // IcosahedronBufferGeometry
  28126. function IcosahedronBufferGeometry( radius, detail ) {
  28127. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  28128. var vertices = [
  28129. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  28130. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  28131. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  28132. ];
  28133. var indices = [
  28134. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  28135. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  28136. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  28137. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  28138. ];
  28139. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  28140. this.type = 'IcosahedronBufferGeometry';
  28141. this.parameters = {
  28142. radius: radius,
  28143. detail: detail
  28144. };
  28145. }
  28146. IcosahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  28147. IcosahedronBufferGeometry.prototype.constructor = IcosahedronBufferGeometry;
  28148. /**
  28149. * @author TristanVALCKE / https://github.com/Itee
  28150. * @author Anonymous
  28151. */
  28152. /* global QUnit */
  28153. QUnit.module( 'Geometries', () => {
  28154. QUnit.module.todo( 'IcosahedronGeometry', ( hooks ) => {
  28155. var geometries = undefined;
  28156. hooks.beforeEach( function () {
  28157. const parameters = {
  28158. radius: 10,
  28159. detail: undefined
  28160. };
  28161. geometries = [
  28162. new IcosahedronGeometry(),
  28163. new IcosahedronGeometry( parameters.radius ),
  28164. new IcosahedronGeometry( parameters.radius, parameters.detail ),
  28165. ];
  28166. } );
  28167. // INHERITANCE
  28168. QUnit.test( "Extending", ( assert ) => {
  28169. assert.ok( false, "everything's gonna be alright" );
  28170. } );
  28171. // INSTANCING
  28172. QUnit.test( "Instancing", ( assert ) => {
  28173. assert.ok( false, "everything's gonna be alright" );
  28174. } );
  28175. // OTHERS
  28176. QUnit.test( 'Standard geometry tests', ( assert ) => {
  28177. runStdGeometryTests( assert, geometries );
  28178. } );
  28179. } );
  28180. QUnit.module.todo( 'IcosahedronBufferGeometry', ( hooks ) => {
  28181. var geometries = undefined;
  28182. hooks.beforeEach( function () {
  28183. const parameters = {
  28184. radius: 10,
  28185. detail: undefined
  28186. };
  28187. geometries = [
  28188. new IcosahedronBufferGeometry(),
  28189. new IcosahedronBufferGeometry( parameters.radius ),
  28190. new IcosahedronBufferGeometry( parameters.radius, parameters.detail ),
  28191. ];
  28192. } );
  28193. // INHERITANCE
  28194. QUnit.test( "Extending", ( assert ) => {
  28195. assert.ok( false, "everything's gonna be alright" );
  28196. } );
  28197. // INSTANCING
  28198. QUnit.test( "Instancing", ( assert ) => {
  28199. assert.ok( false, "everything's gonna be alright" );
  28200. } );
  28201. // OTHERS
  28202. QUnit.test( 'Standard geometry tests', ( assert ) => {
  28203. runStdGeometryTests( assert, geometries );
  28204. } );
  28205. } );
  28206. } );
  28207. /**
  28208. * @author astrodud / http://astrodud.isgreat.org/
  28209. * @author zz85 / https://github.com/zz85
  28210. * @author bhouston / http://clara.io
  28211. * @author Mugen87 / https://github.com/Mugen87
  28212. */
  28213. // LatheGeometry
  28214. function LatheGeometry( points, segments, phiStart, phiLength ) {
  28215. Geometry.call( this );
  28216. this.type = 'LatheGeometry';
  28217. this.parameters = {
  28218. points: points,
  28219. segments: segments,
  28220. phiStart: phiStart,
  28221. phiLength: phiLength
  28222. };
  28223. this.fromBufferGeometry( new LatheBufferGeometry( points, segments, phiStart, phiLength ) );
  28224. this.mergeVertices();
  28225. }
  28226. LatheGeometry.prototype = Object.create( Geometry.prototype );
  28227. LatheGeometry.prototype.constructor = LatheGeometry;
  28228. // LatheBufferGeometry
  28229. function LatheBufferGeometry( points, segments, phiStart, phiLength ) {
  28230. BufferGeometry.call( this );
  28231. this.type = 'LatheBufferGeometry';
  28232. this.parameters = {
  28233. points: points,
  28234. segments: segments,
  28235. phiStart: phiStart,
  28236. phiLength: phiLength
  28237. };
  28238. segments = Math.floor( segments ) || 12;
  28239. phiStart = phiStart || 0;
  28240. phiLength = phiLength || Math.PI * 2;
  28241. // clamp phiLength so it's in range of [ 0, 2PI ]
  28242. phiLength = _Math.clamp( phiLength, 0, Math.PI * 2 );
  28243. // buffers
  28244. var indices = [];
  28245. var vertices = [];
  28246. var uvs = [];
  28247. // helper variables
  28248. var base;
  28249. var inverseSegments = 1.0 / segments;
  28250. var vertex = new Vector3();
  28251. var uv = new Vector2();
  28252. var i, j;
  28253. // generate vertices and uvs
  28254. for ( i = 0; i <= segments; i ++ ) {
  28255. var phi = phiStart + i * inverseSegments * phiLength;
  28256. var sin = Math.sin( phi );
  28257. var cos = Math.cos( phi );
  28258. for ( j = 0; j <= ( points.length - 1 ); j ++ ) {
  28259. // vertex
  28260. vertex.x = points[ j ].x * sin;
  28261. vertex.y = points[ j ].y;
  28262. vertex.z = points[ j ].x * cos;
  28263. vertices.push( vertex.x, vertex.y, vertex.z );
  28264. // uv
  28265. uv.x = i / segments;
  28266. uv.y = j / ( points.length - 1 );
  28267. uvs.push( uv.x, uv.y );
  28268. }
  28269. }
  28270. // indices
  28271. for ( i = 0; i < segments; i ++ ) {
  28272. for ( j = 0; j < ( points.length - 1 ); j ++ ) {
  28273. base = j + i * points.length;
  28274. var a = base;
  28275. var b = base + points.length;
  28276. var c = base + points.length + 1;
  28277. var d = base + 1;
  28278. // faces
  28279. indices.push( a, b, d );
  28280. indices.push( b, c, d );
  28281. }
  28282. }
  28283. // build geometry
  28284. this.setIndex( indices );
  28285. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28286. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  28287. // generate normals
  28288. this.computeVertexNormals();
  28289. // if the geometry is closed, we need to average the normals along the seam.
  28290. // because the corresponding vertices are identical (but still have different UVs).
  28291. if ( phiLength === Math.PI * 2 ) {
  28292. var normals = this.attributes.normal.array;
  28293. var n1 = new Vector3();
  28294. var n2 = new Vector3();
  28295. var n = new Vector3();
  28296. // this is the buffer offset for the last line of vertices
  28297. base = segments * points.length * 3;
  28298. for ( i = 0, j = 0; i < points.length; i ++, j += 3 ) {
  28299. // select the normal of the vertex in the first line
  28300. n1.x = normals[ j + 0 ];
  28301. n1.y = normals[ j + 1 ];
  28302. n1.z = normals[ j + 2 ];
  28303. // select the normal of the vertex in the last line
  28304. n2.x = normals[ base + j + 0 ];
  28305. n2.y = normals[ base + j + 1 ];
  28306. n2.z = normals[ base + j + 2 ];
  28307. // average normals
  28308. n.addVectors( n1, n2 ).normalize();
  28309. // assign the new values to both normals
  28310. normals[ j + 0 ] = normals[ base + j + 0 ] = n.x;
  28311. normals[ j + 1 ] = normals[ base + j + 1 ] = n.y;
  28312. normals[ j + 2 ] = normals[ base + j + 2 ] = n.z;
  28313. }
  28314. }
  28315. }
  28316. LatheBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  28317. LatheBufferGeometry.prototype.constructor = LatheBufferGeometry;
  28318. /**
  28319. * @author TristanVALCKE / https://github.com/Itee
  28320. */
  28321. /* global QUnit */
  28322. QUnit.module( 'Geometries', () => {
  28323. QUnit.module.todo( 'LatheGeometry', ( hooks ) => {
  28324. var geometries = undefined;
  28325. hooks.beforeEach( function () {
  28326. const parameters = {
  28327. points: [],
  28328. segments: 0,
  28329. phiStart: 0,
  28330. phiLength: 0
  28331. };
  28332. geometries = [
  28333. // new LatheGeometry(), // Todo: error for undefined point
  28334. new LatheGeometry( parameters.points )
  28335. ];
  28336. } );
  28337. // INHERITANCE
  28338. QUnit.test( "Extending", ( assert ) => {
  28339. assert.ok( false, "everything's gonna be alright" );
  28340. } );
  28341. // INSTANCING
  28342. QUnit.test( "Instancing", ( assert ) => {
  28343. assert.ok( false, "everything's gonna be alright" );
  28344. } );
  28345. // OTHERS
  28346. QUnit.test( 'Standard geometry tests', ( assert ) => {
  28347. runStdGeometryTests( assert, geometries );
  28348. } );
  28349. } );
  28350. QUnit.module.todo( 'LatheBufferGeometry', ( hooks ) => {
  28351. var geometries = undefined;
  28352. hooks.beforeEach( function () {
  28353. const parameters = {
  28354. points: [],
  28355. segments: 0,
  28356. phiStart: 0,
  28357. phiLength: 0
  28358. };
  28359. geometries = [
  28360. // new LatheBufferGeometry(), // Todo: error for undefined point
  28361. new LatheBufferGeometry( parameters.points )
  28362. ];
  28363. } );
  28364. // INHERITANCE
  28365. QUnit.test( "Extending", ( assert ) => {
  28366. assert.ok( false, "everything's gonna be alright" );
  28367. } );
  28368. // INSTANCING
  28369. QUnit.test( "Instancing", ( assert ) => {
  28370. assert.ok( false, "everything's gonna be alright" );
  28371. } );
  28372. // OTHERS
  28373. QUnit.test( 'Standard geometry tests', ( assert ) => {
  28374. runStdGeometryTests( assert, geometries );
  28375. } );
  28376. } );
  28377. } );
  28378. /**
  28379. * @author timothypratley / https://github.com/timothypratley
  28380. * @author Mugen87 / https://github.com/Mugen87
  28381. */
  28382. // OctahedronGeometry
  28383. function OctahedronGeometry( radius, detail ) {
  28384. Geometry.call( this );
  28385. this.type = 'OctahedronGeometry';
  28386. this.parameters = {
  28387. radius: radius,
  28388. detail: detail
  28389. };
  28390. this.fromBufferGeometry( new OctahedronBufferGeometry( radius, detail ) );
  28391. this.mergeVertices();
  28392. }
  28393. OctahedronGeometry.prototype = Object.create( Geometry.prototype );
  28394. OctahedronGeometry.prototype.constructor = OctahedronGeometry;
  28395. // OctahedronBufferGeometry
  28396. function OctahedronBufferGeometry( radius, detail ) {
  28397. var vertices = [
  28398. 1, 0, 0, - 1, 0, 0, 0, 1, 0,
  28399. 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  28400. ];
  28401. var indices = [
  28402. 0, 2, 4, 0, 4, 3, 0, 3, 5,
  28403. 0, 5, 2, 1, 2, 5, 1, 5, 3,
  28404. 1, 3, 4, 1, 4, 2
  28405. ];
  28406. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  28407. this.type = 'OctahedronBufferGeometry';
  28408. this.parameters = {
  28409. radius: radius,
  28410. detail: detail
  28411. };
  28412. }
  28413. OctahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  28414. OctahedronBufferGeometry.prototype.constructor = OctahedronBufferGeometry;
  28415. /**
  28416. * @author TristanVALCKE / https://github.com/Itee
  28417. * @author Anonymous
  28418. */
  28419. /* global QUnit */
  28420. QUnit.module( 'Geometries', () => {
  28421. QUnit.module.todo( 'OctahedronGeometry', ( hooks ) => {
  28422. var geometries = undefined;
  28423. hooks.beforeEach( function () {
  28424. const parameters = {
  28425. radius: 10,
  28426. detail: undefined
  28427. };
  28428. geometries = [
  28429. new OctahedronGeometry(),
  28430. new OctahedronGeometry( parameters.radius ),
  28431. new OctahedronGeometry( parameters.radius, parameters.detail ),
  28432. ];
  28433. } );
  28434. // INHERITANCE
  28435. QUnit.test( "Extending", ( assert ) => {
  28436. assert.ok( false, "everything's gonna be alright" );
  28437. } );
  28438. // INSTANCING
  28439. QUnit.test( "Instancing", ( assert ) => {
  28440. assert.ok( false, "everything's gonna be alright" );
  28441. } );
  28442. // OTHERS
  28443. QUnit.test( 'Standard geometry tests', ( assert ) => {
  28444. runStdGeometryTests( assert, geometries );
  28445. } );
  28446. } );
  28447. QUnit.module.todo( 'OctahedronBufferGeometry', ( hooks ) => {
  28448. var geometries = undefined;
  28449. hooks.beforeEach( function () {
  28450. const parameters = {
  28451. radius: 10,
  28452. detail: undefined
  28453. };
  28454. geometries = [
  28455. new OctahedronBufferGeometry(),
  28456. new OctahedronBufferGeometry( parameters.radius ),
  28457. new OctahedronBufferGeometry( parameters.radius, parameters.detail ),
  28458. ];
  28459. } );
  28460. // INHERITANCE
  28461. QUnit.test( "Extending", ( assert ) => {
  28462. assert.ok( false, "everything's gonna be alright" );
  28463. } );
  28464. // INSTANCING
  28465. QUnit.test( "Instancing", ( assert ) => {
  28466. assert.ok( false, "everything's gonna be alright" );
  28467. } );
  28468. // OTHERS
  28469. QUnit.test( 'Standard geometry tests', ( assert ) => {
  28470. runStdGeometryTests( assert, geometries );
  28471. } );
  28472. } );
  28473. } );
  28474. /**
  28475. * @author zz85 / https://github.com/zz85
  28476. * @author Mugen87 / https://github.com/Mugen87
  28477. *
  28478. * Parametric Surfaces Geometry
  28479. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  28480. */
  28481. // ParametricGeometry
  28482. function ParametricGeometry( func, slices, stacks ) {
  28483. Geometry.call( this );
  28484. this.type = 'ParametricGeometry';
  28485. this.parameters = {
  28486. func: func,
  28487. slices: slices,
  28488. stacks: stacks
  28489. };
  28490. this.fromBufferGeometry( new ParametricBufferGeometry( func, slices, stacks ) );
  28491. this.mergeVertices();
  28492. }
  28493. ParametricGeometry.prototype = Object.create( Geometry.prototype );
  28494. ParametricGeometry.prototype.constructor = ParametricGeometry;
  28495. // ParametricBufferGeometry
  28496. function ParametricBufferGeometry( func, slices, stacks ) {
  28497. BufferGeometry.call( this );
  28498. this.type = 'ParametricBufferGeometry';
  28499. this.parameters = {
  28500. func: func,
  28501. slices: slices,
  28502. stacks: stacks
  28503. };
  28504. // buffers
  28505. var indices = [];
  28506. var vertices = [];
  28507. var normals = [];
  28508. var uvs = [];
  28509. var EPS = 0.00001;
  28510. var normal = new Vector3();
  28511. var p0 = new Vector3(), p1 = new Vector3();
  28512. var pu = new Vector3(), pv = new Vector3();
  28513. var i, j;
  28514. // generate vertices, normals and uvs
  28515. var sliceCount = slices + 1;
  28516. for ( i = 0; i <= stacks; i ++ ) {
  28517. var v = i / stacks;
  28518. for ( j = 0; j <= slices; j ++ ) {
  28519. var u = j / slices;
  28520. // vertex
  28521. p0 = func( u, v, p0 );
  28522. vertices.push( p0.x, p0.y, p0.z );
  28523. // normal
  28524. // approximate tangent vectors via finite differences
  28525. if ( u - EPS >= 0 ) {
  28526. p1 = func( u - EPS, v, p1 );
  28527. pu.subVectors( p0, p1 );
  28528. } else {
  28529. p1 = func( u + EPS, v, p1 );
  28530. pu.subVectors( p1, p0 );
  28531. }
  28532. if ( v - EPS >= 0 ) {
  28533. p1 = func( u, v - EPS, p1 );
  28534. pv.subVectors( p0, p1 );
  28535. } else {
  28536. p1 = func( u, v + EPS, p1 );
  28537. pv.subVectors( p1, p0 );
  28538. }
  28539. // cross product of tangent vectors returns surface normal
  28540. normal.crossVectors( pu, pv ).normalize();
  28541. normals.push( normal.x, normal.y, normal.z );
  28542. // uv
  28543. uvs.push( u, v );
  28544. }
  28545. }
  28546. // generate indices
  28547. for ( i = 0; i < stacks; i ++ ) {
  28548. for ( j = 0; j < slices; j ++ ) {
  28549. var a = i * sliceCount + j;
  28550. var b = i * sliceCount + j + 1;
  28551. var c = ( i + 1 ) * sliceCount + j + 1;
  28552. var d = ( i + 1 ) * sliceCount + j;
  28553. // faces one and two
  28554. indices.push( a, b, d );
  28555. indices.push( b, c, d );
  28556. }
  28557. }
  28558. // build geometry
  28559. this.setIndex( indices );
  28560. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28561. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  28562. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  28563. }
  28564. ParametricBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  28565. ParametricBufferGeometry.prototype.constructor = ParametricBufferGeometry;
  28566. /**
  28567. * @author TristanVALCKE / https://github.com/Itee
  28568. */
  28569. /* global QUnit */
  28570. QUnit.module( 'Geometries', () => {
  28571. QUnit.module.todo( 'ParametricGeometry', ( hooks ) => {
  28572. var geometries = undefined;
  28573. hooks.beforeEach( function () {
  28574. const parameters = {};
  28575. geometries = [
  28576. new ParametricGeometry()
  28577. ];
  28578. } );
  28579. // INHERITANCE
  28580. QUnit.test( "Extending", ( assert ) => {
  28581. assert.ok( false, "everything's gonna be alright" );
  28582. } );
  28583. // INSTANCING
  28584. QUnit.test( "Instancing", ( assert ) => {
  28585. assert.ok( false, "everything's gonna be alright" );
  28586. } );
  28587. // OTHERS
  28588. QUnit.test( 'Standard geometry tests', ( assert ) => {
  28589. runStdGeometryTests( assert, geometries );
  28590. } );
  28591. } );
  28592. QUnit.module.todo( 'ParametricBufferGeometry', ( hooks ) => {
  28593. var geometries = undefined;
  28594. hooks.beforeEach( function () {
  28595. const parameters = {};
  28596. geometries = [
  28597. new ParametricBufferGeometry()
  28598. ];
  28599. } );
  28600. // INHERITANCE
  28601. QUnit.test( "Extending", ( assert ) => {
  28602. assert.ok( false, "everything's gonna be alright" );
  28603. } );
  28604. // INSTANCING
  28605. QUnit.test( "Instancing", ( assert ) => {
  28606. assert.ok( false, "everything's gonna be alright" );
  28607. } );
  28608. // OTHERS
  28609. QUnit.test( 'Standard geometry tests', ( assert ) => {
  28610. runStdGeometryTests( assert, geometries );
  28611. } );
  28612. } );
  28613. } );
  28614. /**
  28615. * @author TristanVALCKE / https://github.com/Itee
  28616. * @author Anonymous
  28617. */
  28618. /* global QUnit */
  28619. QUnit.module( 'Geometries', () => {
  28620. QUnit.module.todo( 'PlaneGeometry', ( hooks ) => {
  28621. var geometries = undefined;
  28622. hooks.beforeEach( function () {
  28623. const parameters = {
  28624. width: 10,
  28625. height: 30,
  28626. widthSegments: 3,
  28627. heightSegments: 5
  28628. };
  28629. geometries = [
  28630. new PlaneGeometry(),
  28631. new PlaneGeometry( parameters.width ),
  28632. new PlaneGeometry( parameters.width, parameters.height ),
  28633. new PlaneGeometry( parameters.width, parameters.height, parameters.widthSegments ),
  28634. new PlaneGeometry( parameters.width, parameters.height, parameters.widthSegments, parameters.heightSegments ),
  28635. ];
  28636. } );
  28637. // INHERITANCE
  28638. QUnit.test( "Extending", ( assert ) => {
  28639. assert.ok( false, "everything's gonna be alright" );
  28640. } );
  28641. // INSTANCING
  28642. QUnit.test( "Instancing", ( assert ) => {
  28643. assert.ok( false, "everything's gonna be alright" );
  28644. } );
  28645. // OTHERS
  28646. QUnit.test( 'Standard geometry tests', ( assert ) => {
  28647. runStdGeometryTests( assert, geometries );
  28648. } );
  28649. } );
  28650. QUnit.module.todo( 'PlaneBufferGeometry', ( hooks ) => {
  28651. var geometries = undefined;
  28652. hooks.beforeEach( function () {
  28653. const parameters = {
  28654. width: 10,
  28655. height: 30,
  28656. widthSegments: 3,
  28657. heightSegments: 5
  28658. };
  28659. geometries = [
  28660. new PlaneBufferGeometry(),
  28661. new PlaneBufferGeometry( parameters.width ),
  28662. new PlaneBufferGeometry( parameters.width, parameters.height ),
  28663. new PlaneBufferGeometry( parameters.width, parameters.height, parameters.widthSegments ),
  28664. new PlaneBufferGeometry( parameters.width, parameters.height, parameters.widthSegments, parameters.heightSegments ),
  28665. ];
  28666. } );
  28667. // INHERITANCE
  28668. QUnit.test( "Extending", ( assert ) => {
  28669. assert.ok( false, "everything's gonna be alright" );
  28670. } );
  28671. // INSTANCING
  28672. QUnit.test( "Instancing", ( assert ) => {
  28673. assert.ok( false, "everything's gonna be alright" );
  28674. } );
  28675. // OTHERS
  28676. QUnit.test( 'Standard geometry tests', ( assert ) => {
  28677. runStdGeometryTests( assert, geometries );
  28678. } );
  28679. } );
  28680. } );
  28681. /**
  28682. * @author TristanVALCKE / https://github.com/Itee
  28683. */
  28684. /* global QUnit */
  28685. QUnit.module( 'Geometries', () => {
  28686. QUnit.module.todo( 'PolyhedronGeometry', ( hooks ) => {
  28687. var geometries = undefined;
  28688. hooks.beforeEach( function () {
  28689. const parameters = {};
  28690. geometries = [
  28691. new PolyhedronGeometry()
  28692. ];
  28693. } );
  28694. // INHERITANCE
  28695. QUnit.test( "Extending", ( assert ) => {
  28696. assert.ok( false, "everything's gonna be alright" );
  28697. } );
  28698. // INSTANCING
  28699. QUnit.test( "Instancing", ( assert ) => {
  28700. assert.ok( false, "everything's gonna be alright" );
  28701. } );
  28702. // OTHERS
  28703. QUnit.test( 'Standard geometry tests', ( assert ) => {
  28704. runStdGeometryTests( assert, geometries );
  28705. } );
  28706. } );
  28707. QUnit.module.todo( 'PolyhedronBufferGeometry', ( hooks ) => {
  28708. var geometries = undefined;
  28709. hooks.beforeEach( function () {
  28710. const parameters = {};
  28711. geometries = [
  28712. new PolyhedronBufferGeometry()
  28713. ];
  28714. } );
  28715. // INHERITANCE
  28716. QUnit.test( "Extending", ( assert ) => {
  28717. assert.ok( false, "everything's gonna be alright" );
  28718. } );
  28719. // INSTANCING
  28720. QUnit.test( "Instancing", ( assert ) => {
  28721. assert.ok( false, "everything's gonna be alright" );
  28722. } );
  28723. // OTHERS
  28724. QUnit.test( 'Standard geometry tests', ( assert ) => {
  28725. runStdGeometryTests( assert, geometries );
  28726. } );
  28727. } );
  28728. } );
  28729. /**
  28730. * @author Kaleb Murphy
  28731. * @author Mugen87 / https://github.com/Mugen87
  28732. */
  28733. // RingGeometry
  28734. function RingGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  28735. Geometry.call( this );
  28736. this.type = 'RingGeometry';
  28737. this.parameters = {
  28738. innerRadius: innerRadius,
  28739. outerRadius: outerRadius,
  28740. thetaSegments: thetaSegments,
  28741. phiSegments: phiSegments,
  28742. thetaStart: thetaStart,
  28743. thetaLength: thetaLength
  28744. };
  28745. this.fromBufferGeometry( new RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) );
  28746. this.mergeVertices();
  28747. }
  28748. RingGeometry.prototype = Object.create( Geometry.prototype );
  28749. RingGeometry.prototype.constructor = RingGeometry;
  28750. // RingBufferGeometry
  28751. function RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  28752. BufferGeometry.call( this );
  28753. this.type = 'RingBufferGeometry';
  28754. this.parameters = {
  28755. innerRadius: innerRadius,
  28756. outerRadius: outerRadius,
  28757. thetaSegments: thetaSegments,
  28758. phiSegments: phiSegments,
  28759. thetaStart: thetaStart,
  28760. thetaLength: thetaLength
  28761. };
  28762. innerRadius = innerRadius || 20;
  28763. outerRadius = outerRadius || 50;
  28764. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  28765. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  28766. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  28767. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 1;
  28768. // buffers
  28769. var indices = [];
  28770. var vertices = [];
  28771. var normals = [];
  28772. var uvs = [];
  28773. // some helper variables
  28774. var segment;
  28775. var radius = innerRadius;
  28776. var radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  28777. var vertex = new Vector3();
  28778. var uv = new Vector2();
  28779. var j, i;
  28780. // generate vertices, normals and uvs
  28781. for ( j = 0; j <= phiSegments; j ++ ) {
  28782. for ( i = 0; i <= thetaSegments; i ++ ) {
  28783. // values are generate from the inside of the ring to the outside
  28784. segment = thetaStart + i / thetaSegments * thetaLength;
  28785. // vertex
  28786. vertex.x = radius * Math.cos( segment );
  28787. vertex.y = radius * Math.sin( segment );
  28788. vertices.push( vertex.x, vertex.y, vertex.z );
  28789. // normal
  28790. normals.push( 0, 0, 1 );
  28791. // uv
  28792. uv.x = ( vertex.x / outerRadius + 1 ) / 2;
  28793. uv.y = ( vertex.y / outerRadius + 1 ) / 2;
  28794. uvs.push( uv.x, uv.y );
  28795. }
  28796. // increase the radius for next row of vertices
  28797. radius += radiusStep;
  28798. }
  28799. // indices
  28800. for ( j = 0; j < phiSegments; j ++ ) {
  28801. var thetaSegmentLevel = j * ( thetaSegments + 1 );
  28802. for ( i = 0; i < thetaSegments; i ++ ) {
  28803. segment = i + thetaSegmentLevel;
  28804. var a = segment;
  28805. var b = segment + thetaSegments + 1;
  28806. var c = segment + thetaSegments + 2;
  28807. var d = segment + 1;
  28808. // faces
  28809. indices.push( a, b, d );
  28810. indices.push( b, c, d );
  28811. }
  28812. }
  28813. // build geometry
  28814. this.setIndex( indices );
  28815. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28816. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  28817. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  28818. }
  28819. RingBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  28820. RingBufferGeometry.prototype.constructor = RingBufferGeometry;
  28821. /**
  28822. * @author TristanVALCKE / https://github.com/Itee
  28823. * @author Anonymous
  28824. */
  28825. /* global QUnit */
  28826. QUnit.module( 'Geometries', () => {
  28827. QUnit.module.todo( 'RingGeometry', ( hooks ) => {
  28828. var geometries = undefined;
  28829. hooks.beforeEach( function () {
  28830. const parameters = {
  28831. innerRadius: 10,
  28832. outerRadius: 60,
  28833. thetaSegments: 12,
  28834. phiSegments: 14,
  28835. thetaStart: 0.1,
  28836. thetaLength: 2.0
  28837. };
  28838. geometries = [
  28839. new RingGeometry(),
  28840. new RingGeometry( parameters.innerRadius ),
  28841. new RingGeometry( parameters.innerRadius, parameters.outerRadius ),
  28842. new RingGeometry( parameters.innerRadius, parameters.outerRadius, parameters.thetaSegments ),
  28843. new RingGeometry( parameters.innerRadius, parameters.outerRadius, parameters.thetaSegments, parameters.phiSegments ),
  28844. new RingGeometry( parameters.innerRadius, parameters.outerRadius, parameters.thetaSegments, parameters.phiSegments, parameters.thetaStart ),
  28845. new RingGeometry( parameters.innerRadius, parameters.outerRadius, parameters.thetaSegments, parameters.phiSegments, parameters.thetaStart, parameters.thetaLength ),
  28846. ];
  28847. } );
  28848. // INHERITANCE
  28849. QUnit.test( "Extending", ( assert ) => {
  28850. assert.ok( false, "everything's gonna be alright" );
  28851. } );
  28852. // INSTANCING
  28853. QUnit.test( "Instancing", ( assert ) => {
  28854. assert.ok( false, "everything's gonna be alright" );
  28855. } );
  28856. // OTHERS
  28857. QUnit.test( 'Standard geometry tests', ( assert ) => {
  28858. runStdGeometryTests( assert, geometries );
  28859. } );
  28860. } );
  28861. QUnit.module.todo( 'RingBufferGeometry', ( hooks ) => {
  28862. var geometries = undefined;
  28863. hooks.beforeEach( function () {
  28864. const parameters = {
  28865. innerRadius: 10,
  28866. outerRadius: 60,
  28867. thetaSegments: 12,
  28868. phiSegments: 14,
  28869. thetaStart: 0.1,
  28870. thetaLength: 2.0
  28871. };
  28872. geometries = [
  28873. new RingBufferGeometry(),
  28874. new RingBufferGeometry( parameters.innerRadius ),
  28875. new RingBufferGeometry( parameters.innerRadius, parameters.outerRadius ),
  28876. new RingBufferGeometry( parameters.innerRadius, parameters.outerRadius, parameters.thetaSegments ),
  28877. new RingBufferGeometry( parameters.innerRadius, parameters.outerRadius, parameters.thetaSegments, parameters.phiSegments ),
  28878. new RingBufferGeometry( parameters.innerRadius, parameters.outerRadius, parameters.thetaSegments, parameters.phiSegments, parameters.thetaStart ),
  28879. new RingBufferGeometry( parameters.innerRadius, parameters.outerRadius, parameters.thetaSegments, parameters.phiSegments, parameters.thetaStart, parameters.thetaLength ),
  28880. ];
  28881. } );
  28882. // INHERITANCE
  28883. QUnit.test( "Extending", ( assert ) => {
  28884. assert.ok( false, "everything's gonna be alright" );
  28885. } );
  28886. // INSTANCING
  28887. QUnit.test( "Instancing", ( assert ) => {
  28888. assert.ok( false, "everything's gonna be alright" );
  28889. } );
  28890. // OTHERS
  28891. QUnit.test( 'Standard geometry tests', ( assert ) => {
  28892. runStdGeometryTests( assert, geometries );
  28893. } );
  28894. } );
  28895. } );
  28896. /**
  28897. * @author jonobr1 / http://jonobr1.com
  28898. * @author Mugen87 / https://github.com/Mugen87
  28899. */
  28900. // ShapeGeometry
  28901. function ShapeGeometry( shapes, curveSegments ) {
  28902. Geometry.call( this );
  28903. this.type = 'ShapeGeometry';
  28904. if ( typeof curveSegments === 'object' ) {
  28905. console.warn( 'THREE.ShapeGeometry: Options parameter has been removed.' );
  28906. curveSegments = curveSegments.curveSegments;
  28907. }
  28908. this.parameters = {
  28909. shapes: shapes,
  28910. curveSegments: curveSegments
  28911. };
  28912. this.fromBufferGeometry( new ShapeBufferGeometry( shapes, curveSegments ) );
  28913. this.mergeVertices();
  28914. }
  28915. ShapeGeometry.prototype = Object.create( Geometry.prototype );
  28916. ShapeGeometry.prototype.constructor = ShapeGeometry;
  28917. // ShapeBufferGeometry
  28918. function ShapeBufferGeometry( shapes, curveSegments ) {
  28919. BufferGeometry.call( this );
  28920. this.type = 'ShapeBufferGeometry';
  28921. this.parameters = {
  28922. shapes: shapes,
  28923. curveSegments: curveSegments
  28924. };
  28925. curveSegments = curveSegments || 12;
  28926. // buffers
  28927. var indices = [];
  28928. var vertices = [];
  28929. var normals = [];
  28930. var uvs = [];
  28931. // helper variables
  28932. var groupStart = 0;
  28933. var groupCount = 0;
  28934. // allow single and array values for "shapes" parameter
  28935. if ( Array.isArray( shapes ) === false ) {
  28936. addShape( shapes );
  28937. } else {
  28938. for ( var i = 0; i < shapes.length; i ++ ) {
  28939. addShape( shapes[ i ] );
  28940. this.addGroup( groupStart, groupCount, i ); // enables MultiMaterial support
  28941. groupStart += groupCount;
  28942. groupCount = 0;
  28943. }
  28944. }
  28945. // build geometry
  28946. this.setIndex( indices );
  28947. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28948. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  28949. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  28950. // helper functions
  28951. function addShape( shape ) {
  28952. var i, l, shapeHole;
  28953. var indexOffset = vertices.length / 3;
  28954. var points = shape.extractPoints( curveSegments );
  28955. var shapeVertices = points.shape;
  28956. var shapeHoles = points.holes;
  28957. // check direction of vertices
  28958. if ( ShapeUtils.isClockWise( shapeVertices ) === false ) {
  28959. shapeVertices = shapeVertices.reverse();
  28960. // also check if holes are in the opposite direction
  28961. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  28962. shapeHole = shapeHoles[ i ];
  28963. if ( ShapeUtils.isClockWise( shapeHole ) === true ) {
  28964. shapeHoles[ i ] = shapeHole.reverse();
  28965. }
  28966. }
  28967. }
  28968. var faces = ShapeUtils.triangulateShape( shapeVertices, shapeHoles );
  28969. // join vertices of inner and outer paths to a single array
  28970. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  28971. shapeHole = shapeHoles[ i ];
  28972. shapeVertices = shapeVertices.concat( shapeHole );
  28973. }
  28974. // vertices, normals, uvs
  28975. for ( i = 0, l = shapeVertices.length; i < l; i ++ ) {
  28976. var vertex = shapeVertices[ i ];
  28977. vertices.push( vertex.x, vertex.y, 0 );
  28978. normals.push( 0, 0, 1 );
  28979. uvs.push( vertex.x, vertex.y ); // world uvs
  28980. }
  28981. // incides
  28982. for ( i = 0, l = faces.length; i < l; i ++ ) {
  28983. var face = faces[ i ];
  28984. var a = face[ 0 ] + indexOffset;
  28985. var b = face[ 1 ] + indexOffset;
  28986. var c = face[ 2 ] + indexOffset;
  28987. indices.push( a, b, c );
  28988. groupCount += 3;
  28989. }
  28990. }
  28991. }
  28992. ShapeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  28993. ShapeBufferGeometry.prototype.constructor = ShapeBufferGeometry;
  28994. /**
  28995. * @author TristanVALCKE / https://github.com/Itee
  28996. */
  28997. /* global QUnit */
  28998. QUnit.module( 'Geometries', () => {
  28999. QUnit.module.todo( 'ShapeGeometry', ( hooks ) => {
  29000. var geometries = undefined;
  29001. hooks.beforeEach( function () {
  29002. const parameters = {};
  29003. geometries = [
  29004. new ShapeGeometry()
  29005. ];
  29006. } );
  29007. // INHERITANCE
  29008. QUnit.test( "Extending", ( assert ) => {
  29009. assert.ok( false, "everything's gonna be alright" );
  29010. } );
  29011. // INSTANCING
  29012. QUnit.test( "Instancing", ( assert ) => {
  29013. assert.ok( false, "everything's gonna be alright" );
  29014. } );
  29015. // OTHERS
  29016. QUnit.test( 'Standard geometry tests', ( assert ) => {
  29017. runStdGeometryTests( assert, geometries );
  29018. } );
  29019. } );
  29020. QUnit.module.todo( 'ShapeBufferGeometry', ( hooks ) => {
  29021. var geometries = undefined;
  29022. hooks.beforeEach( function () {
  29023. const parameters = {};
  29024. geometries = [
  29025. new ShapeBufferGeometry()
  29026. ];
  29027. } );
  29028. // INHERITANCE
  29029. QUnit.test( "Extending", ( assert ) => {
  29030. assert.ok( false, "everything's gonna be alright" );
  29031. } );
  29032. // INSTANCING
  29033. QUnit.test( "Instancing", ( assert ) => {
  29034. assert.ok( false, "everything's gonna be alright" );
  29035. } );
  29036. // OTHERS
  29037. QUnit.test( 'Standard geometry tests', ( assert ) => {
  29038. runStdGeometryTests( assert, geometries );
  29039. } );
  29040. } );
  29041. } );
  29042. /**
  29043. * @author TristanVALCKE / https://github.com/Itee
  29044. * @author Anonymous
  29045. */
  29046. /* global QUnit */
  29047. QUnit.module( 'Geometries', () => {
  29048. QUnit.module.todo( 'SphereGeometry', ( hooks ) => {
  29049. var geometries = undefined;
  29050. hooks.beforeEach( function () {
  29051. const parameters = {
  29052. radius: 10,
  29053. widthSegments: 20,
  29054. heightSegments: 30,
  29055. phiStart: 0.5,
  29056. phiLength: 1.0,
  29057. thetaStart: 0.4,
  29058. thetaLength: 2.0,
  29059. };
  29060. geometries = [
  29061. new SphereGeometry(),
  29062. new SphereGeometry( parameters.radius ),
  29063. new SphereGeometry( parameters.radius, parameters.widthSegments ),
  29064. new SphereGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments ),
  29065. new SphereGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart ),
  29066. new SphereGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart, parameters.phiLength ),
  29067. new SphereGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart, parameters.phiLength, parameters.thetaStart ),
  29068. new SphereGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart, parameters.phiLength, parameters.thetaStart, parameters.thetaLength ),
  29069. ];
  29070. } );
  29071. // INHERITANCE
  29072. QUnit.test( "Extending", ( assert ) => {
  29073. assert.ok( false, "everything's gonna be alright" );
  29074. } );
  29075. // INSTANCING
  29076. QUnit.test( "Instancing", ( assert ) => {
  29077. assert.ok( false, "everything's gonna be alright" );
  29078. } );
  29079. // OTHERS
  29080. QUnit.test( 'Standard geometry tests', ( assert ) => {
  29081. runStdGeometryTests( assert, geometries );
  29082. } );
  29083. } );
  29084. QUnit.module.todo( 'SphereBufferGeometry', ( hooks ) => {
  29085. var geometries = undefined;
  29086. hooks.beforeEach( function () {
  29087. const parameters = {
  29088. radius: 10,
  29089. widthSegments: 20,
  29090. heightSegments: 30,
  29091. phiStart: 0.5,
  29092. phiLength: 1.0,
  29093. thetaStart: 0.4,
  29094. thetaLength: 2.0,
  29095. };
  29096. geometries = [
  29097. new SphereBufferGeometry(),
  29098. new SphereBufferGeometry( parameters.radius ),
  29099. new SphereBufferGeometry( parameters.radius, parameters.widthSegments ),
  29100. new SphereBufferGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments ),
  29101. new SphereBufferGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart ),
  29102. new SphereBufferGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart, parameters.phiLength ),
  29103. new SphereBufferGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart, parameters.phiLength, parameters.thetaStart ),
  29104. new SphereBufferGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart, parameters.phiLength, parameters.thetaStart, parameters.thetaLength ),
  29105. ];
  29106. } );
  29107. // INHERITANCE
  29108. QUnit.test( "Extending", ( assert ) => {
  29109. assert.ok( false, "everything's gonna be alright" );
  29110. } );
  29111. // INSTANCING
  29112. QUnit.test( "Instancing", ( assert ) => {
  29113. assert.ok( false, "everything's gonna be alright" );
  29114. } );
  29115. // OTHERS
  29116. QUnit.test( 'Standard geometry tests', ( assert ) => {
  29117. runStdGeometryTests( assert, geometries );
  29118. } );
  29119. } );
  29120. } );
  29121. /**
  29122. * @author timothypratley / https://github.com/timothypratley
  29123. * @author Mugen87 / https://github.com/Mugen87
  29124. */
  29125. // TetrahedronGeometry
  29126. function TetrahedronGeometry( radius, detail ) {
  29127. Geometry.call( this );
  29128. this.type = 'TetrahedronGeometry';
  29129. this.parameters = {
  29130. radius: radius,
  29131. detail: detail
  29132. };
  29133. this.fromBufferGeometry( new TetrahedronBufferGeometry( radius, detail ) );
  29134. this.mergeVertices();
  29135. }
  29136. TetrahedronGeometry.prototype = Object.create( Geometry.prototype );
  29137. TetrahedronGeometry.prototype.constructor = TetrahedronGeometry;
  29138. // TetrahedronBufferGeometry
  29139. function TetrahedronBufferGeometry( radius, detail ) {
  29140. var vertices = [
  29141. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  29142. ];
  29143. var indices = [
  29144. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  29145. ];
  29146. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  29147. this.type = 'TetrahedronBufferGeometry';
  29148. this.parameters = {
  29149. radius: radius,
  29150. detail: detail
  29151. };
  29152. }
  29153. TetrahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  29154. TetrahedronBufferGeometry.prototype.constructor = TetrahedronBufferGeometry;
  29155. /**
  29156. * @author TristanVALCKE / https://github.com/Itee
  29157. * @author Anonymous
  29158. */
  29159. /* global QUnit */
  29160. QUnit.module( 'Geometries', () => {
  29161. QUnit.module.todo( 'TetrahedronGeometry', ( hooks ) => {
  29162. var geometries = undefined;
  29163. hooks.beforeEach( function () {
  29164. const parameters = {
  29165. radius: 10,
  29166. detail: undefined
  29167. };
  29168. geometries = [
  29169. new TetrahedronGeometry(),
  29170. new TetrahedronGeometry( parameters.radius ),
  29171. new TetrahedronGeometry( parameters.radius, parameters.widthSegments ),
  29172. new TetrahedronGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments ),
  29173. new TetrahedronGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart ),
  29174. new TetrahedronGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart, parameters.phiLength ),
  29175. new TetrahedronGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart, parameters.phiLength, parameters.thetaStart ),
  29176. new TetrahedronGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart, parameters.phiLength, parameters.thetaStart, parameters.thetaLength ),
  29177. ];
  29178. } );
  29179. // INHERITANCE
  29180. QUnit.test( "Extending", ( assert ) => {
  29181. assert.ok( false, "everything's gonna be alright" );
  29182. } );
  29183. // INSTANCING
  29184. QUnit.test( "Instancing", ( assert ) => {
  29185. assert.ok( false, "everything's gonna be alright" );
  29186. } );
  29187. // OTHERS
  29188. QUnit.test( 'Standard geometry tests', ( assert ) => {
  29189. runStdGeometryTests( assert, geometries );
  29190. } );
  29191. } );
  29192. QUnit.module.todo( 'SphereBufferGeometry', ( hooks ) => {
  29193. var geometries = undefined;
  29194. hooks.beforeEach( function () {
  29195. const parameters = {
  29196. radius: 10,
  29197. detail: undefined
  29198. };
  29199. geometries = [
  29200. new TetrahedronBufferGeometry(),
  29201. new TetrahedronBufferGeometry( parameters.radius ),
  29202. new TetrahedronBufferGeometry( parameters.radius, parameters.widthSegments ),
  29203. new TetrahedronBufferGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments ),
  29204. new TetrahedronBufferGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart ),
  29205. new TetrahedronBufferGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart, parameters.phiLength ),
  29206. new TetrahedronBufferGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart, parameters.phiLength, parameters.thetaStart ),
  29207. new TetrahedronBufferGeometry( parameters.radius, parameters.widthSegments, parameters.heightSegments, parameters.phiStart, parameters.phiLength, parameters.thetaStart, parameters.thetaLength ),
  29208. ];
  29209. } );
  29210. // INHERITANCE
  29211. QUnit.test( "Extending", ( assert ) => {
  29212. assert.ok( false, "everything's gonna be alright" );
  29213. } );
  29214. // INSTANCING
  29215. QUnit.test( "Instancing", ( assert ) => {
  29216. assert.ok( false, "everything's gonna be alright" );
  29217. } );
  29218. // OTHERS
  29219. QUnit.test( 'Standard geometry tests', ( assert ) => {
  29220. runStdGeometryTests( assert, geometries );
  29221. } );
  29222. } );
  29223. } );
  29224. /**
  29225. * @author zz85 / http://www.lab4games.net/zz85/blog
  29226. * @author alteredq / http://alteredqualia.com/
  29227. *
  29228. * Text = 3D Text
  29229. *
  29230. * parameters = {
  29231. * font: <THREE.Font>, // font
  29232. *
  29233. * size: <float>, // size of the text
  29234. * height: <float>, // thickness to extrude text
  29235. * curveSegments: <int>, // number of points on the curves
  29236. *
  29237. * bevelEnabled: <bool>, // turn on bevel
  29238. * bevelThickness: <float>, // how deep into text bevel goes
  29239. * bevelSize: <float> // how far from text outline is bevel
  29240. * }
  29241. */
  29242. // TextGeometry
  29243. function TextGeometry( text, parameters ) {
  29244. Geometry.call( this );
  29245. this.type = 'TextGeometry';
  29246. this.parameters = {
  29247. text: text,
  29248. parameters: parameters
  29249. };
  29250. this.fromBufferGeometry( new TextBufferGeometry( text, parameters ) );
  29251. this.mergeVertices();
  29252. }
  29253. TextGeometry.prototype = Object.create( Geometry.prototype );
  29254. TextGeometry.prototype.constructor = TextGeometry;
  29255. // TextBufferGeometry
  29256. function TextBufferGeometry( text, parameters ) {
  29257. parameters = parameters || {};
  29258. var font = parameters.font;
  29259. if ( ! ( font && font.isFont ) ) {
  29260. console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
  29261. return new Geometry();
  29262. }
  29263. var shapes = font.generateShapes( text, parameters.size, parameters.curveSegments );
  29264. // translate parameters to ExtrudeGeometry API
  29265. parameters.amount = parameters.height !== undefined ? parameters.height : 50;
  29266. // defaults
  29267. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  29268. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  29269. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  29270. ExtrudeBufferGeometry.call( this, shapes, parameters );
  29271. this.type = 'TextBufferGeometry';
  29272. }
  29273. TextBufferGeometry.prototype = Object.create( ExtrudeBufferGeometry.prototype );
  29274. TextBufferGeometry.prototype.constructor = TextBufferGeometry;
  29275. /**
  29276. * @author TristanVALCKE / https://github.com/Itee
  29277. */
  29278. /* global QUnit */
  29279. QUnit.module( 'Geometries', () => {
  29280. QUnit.module.todo( 'TextGeometry', ( hooks ) => {
  29281. var geometries = undefined;
  29282. hooks.beforeEach( function () {
  29283. // TODO: we cannot load any font from Threejs package :S
  29284. const parameters = {
  29285. font: undefined
  29286. };
  29287. geometries = [
  29288. new TextGeometry()
  29289. ];
  29290. } );
  29291. // INHERITANCE
  29292. QUnit.test( "Extending", ( assert ) => {
  29293. assert.ok( false, "everything's gonna be alright" );
  29294. } );
  29295. // INSTANCING
  29296. QUnit.test( "Instancing", ( assert ) => {
  29297. assert.ok( false, "everything's gonna be alright" );
  29298. } );
  29299. // OTHERS
  29300. QUnit.test( 'Standard geometry tests', ( assert ) => {
  29301. runStdGeometryTests( assert, geometries );
  29302. } );
  29303. } );
  29304. QUnit.module.todo( 'TextBufferGeometry', ( hooks ) => {
  29305. var geometries = undefined;
  29306. hooks.beforeEach( function () {
  29307. const parameters = {};
  29308. geometries = [
  29309. new TextBufferGeometry()
  29310. ];
  29311. } );
  29312. // INHERITANCE
  29313. QUnit.test( "Extending", ( assert ) => {
  29314. assert.ok( false, "everything's gonna be alright" );
  29315. } );
  29316. // INSTANCING
  29317. QUnit.test( "Instancing", ( assert ) => {
  29318. assert.ok( false, "everything's gonna be alright" );
  29319. } );
  29320. // OTHERS
  29321. QUnit.test( 'Standard geometry tests', ( assert ) => {
  29322. runStdGeometryTests( assert, geometries );
  29323. } );
  29324. } );
  29325. } );
  29326. /**
  29327. * @author oosmoxiecode
  29328. * @author mrdoob / http://mrdoob.com/
  29329. * @author Mugen87 / https://github.com/Mugen87
  29330. */
  29331. // TorusGeometry
  29332. function TorusGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  29333. Geometry.call( this );
  29334. this.type = 'TorusGeometry';
  29335. this.parameters = {
  29336. radius: radius,
  29337. tube: tube,
  29338. radialSegments: radialSegments,
  29339. tubularSegments: tubularSegments,
  29340. arc: arc
  29341. };
  29342. this.fromBufferGeometry( new TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) );
  29343. this.mergeVertices();
  29344. }
  29345. TorusGeometry.prototype = Object.create( Geometry.prototype );
  29346. TorusGeometry.prototype.constructor = TorusGeometry;
  29347. // TorusBufferGeometry
  29348. function TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  29349. BufferGeometry.call( this );
  29350. this.type = 'TorusBufferGeometry';
  29351. this.parameters = {
  29352. radius: radius,
  29353. tube: tube,
  29354. radialSegments: radialSegments,
  29355. tubularSegments: tubularSegments,
  29356. arc: arc
  29357. };
  29358. radius = radius || 100;
  29359. tube = tube || 40;
  29360. radialSegments = Math.floor( radialSegments ) || 8;
  29361. tubularSegments = Math.floor( tubularSegments ) || 6;
  29362. arc = arc || Math.PI * 2;
  29363. // buffers
  29364. var indices = [];
  29365. var vertices = [];
  29366. var normals = [];
  29367. var uvs = [];
  29368. // helper variables
  29369. var center = new Vector3();
  29370. var vertex = new Vector3();
  29371. var normal = new Vector3();
  29372. var j, i;
  29373. // generate vertices, normals and uvs
  29374. for ( j = 0; j <= radialSegments; j ++ ) {
  29375. for ( i = 0; i <= tubularSegments; i ++ ) {
  29376. var u = i / tubularSegments * arc;
  29377. var v = j / radialSegments * Math.PI * 2;
  29378. // vertex
  29379. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  29380. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  29381. vertex.z = tube * Math.sin( v );
  29382. vertices.push( vertex.x, vertex.y, vertex.z );
  29383. // normal
  29384. center.x = radius * Math.cos( u );
  29385. center.y = radius * Math.sin( u );
  29386. normal.subVectors( vertex, center ).normalize();
  29387. normals.push( normal.x, normal.y, normal.z );
  29388. // uv
  29389. uvs.push( i / tubularSegments );
  29390. uvs.push( j / radialSegments );
  29391. }
  29392. }
  29393. // generate indices
  29394. for ( j = 1; j <= radialSegments; j ++ ) {
  29395. for ( i = 1; i <= tubularSegments; i ++ ) {
  29396. // indices
  29397. var a = ( tubularSegments + 1 ) * j + i - 1;
  29398. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  29399. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  29400. var d = ( tubularSegments + 1 ) * j + i;
  29401. // faces
  29402. indices.push( a, b, d );
  29403. indices.push( b, c, d );
  29404. }
  29405. }
  29406. // build geometry
  29407. this.setIndex( indices );
  29408. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  29409. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  29410. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  29411. }
  29412. TorusBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  29413. TorusBufferGeometry.prototype.constructor = TorusBufferGeometry;
  29414. /**
  29415. * @author TristanVALCKE / https://github.com/Itee
  29416. * @author Anonymous
  29417. */
  29418. /* global QUnit */
  29419. QUnit.module( 'Geometries', () => {
  29420. QUnit.module.todo( 'TorusGeometry', ( hooks ) => {
  29421. var geometries = undefined;
  29422. hooks.beforeEach( function () {
  29423. const parameters = {
  29424. radius: 10,
  29425. tube: 20,
  29426. radialSegments: 30,
  29427. tubularSegments: 10,
  29428. arc: 2.0,
  29429. };
  29430. geometries = [
  29431. new TorusGeometry(),
  29432. new TorusGeometry( parameters.radius ),
  29433. new TorusGeometry( parameters.radius, parameters.tube ),
  29434. new TorusGeometry( parameters.radius, parameters.tube, parameters.radialSegments ),
  29435. new TorusGeometry( parameters.radius, parameters.tube, parameters.radialSegments, parameters.tubularSegments ),
  29436. new TorusGeometry( parameters.radius, parameters.tube, parameters.radialSegments, parameters.tubularSegments, parameters.arc ),
  29437. ];
  29438. } );
  29439. // INHERITANCE
  29440. QUnit.test( "Extending", ( assert ) => {
  29441. assert.ok( false, "everything's gonna be alright" );
  29442. } );
  29443. // INSTANCING
  29444. QUnit.test( "Instancing", ( assert ) => {
  29445. assert.ok( false, "everything's gonna be alright" );
  29446. } );
  29447. // OTHERS
  29448. QUnit.test( 'Standard geometry tests', ( assert ) => {
  29449. runStdGeometryTests( assert, geometries );
  29450. } );
  29451. } );
  29452. QUnit.module.todo( 'TorusBufferGeometry', ( hooks ) => {
  29453. var geometries = undefined;
  29454. hooks.beforeEach( function () {
  29455. const parameters = {
  29456. radius: 10,
  29457. tube: 20,
  29458. radialSegments: 30,
  29459. tubularSegments: 10,
  29460. arc: 2.0,
  29461. };
  29462. geometries = [
  29463. new TorusBufferGeometry(),
  29464. new TorusBufferGeometry( parameters.radius ),
  29465. new TorusBufferGeometry( parameters.radius, parameters.tube ),
  29466. new TorusBufferGeometry( parameters.radius, parameters.tube, parameters.radialSegments ),
  29467. new TorusBufferGeometry( parameters.radius, parameters.tube, parameters.radialSegments, parameters.tubularSegments ),
  29468. new TorusBufferGeometry( parameters.radius, parameters.tube, parameters.radialSegments, parameters.tubularSegments, parameters.arc ),
  29469. ];
  29470. } );
  29471. // INHERITANCE
  29472. QUnit.test( "Extending", ( assert ) => {
  29473. assert.ok( false, "everything's gonna be alright" );
  29474. } );
  29475. // INSTANCING
  29476. QUnit.test( "Instancing", ( assert ) => {
  29477. assert.ok( false, "everything's gonna be alright" );
  29478. } );
  29479. // OTHERS
  29480. QUnit.test( 'Standard geometry tests', ( assert ) => {
  29481. runStdGeometryTests( assert, geometries );
  29482. } );
  29483. } );
  29484. } );
  29485. /**
  29486. * @author oosmoxiecode
  29487. * @author Mugen87 / https://github.com/Mugen87
  29488. *
  29489. * based on http://www.blackpawn.com/texts/pqtorus/
  29490. */
  29491. // TorusKnotGeometry
  29492. function TorusKnotGeometry( radius, tube, tubularSegments, radialSegments, p, q, heightScale ) {
  29493. Geometry.call( this );
  29494. this.type = 'TorusKnotGeometry';
  29495. this.parameters = {
  29496. radius: radius,
  29497. tube: tube,
  29498. tubularSegments: tubularSegments,
  29499. radialSegments: radialSegments,
  29500. p: p,
  29501. q: q
  29502. };
  29503. if ( heightScale !== undefined ) console.warn( 'THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.' );
  29504. this.fromBufferGeometry( new TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) );
  29505. this.mergeVertices();
  29506. }
  29507. TorusKnotGeometry.prototype = Object.create( Geometry.prototype );
  29508. TorusKnotGeometry.prototype.constructor = TorusKnotGeometry;
  29509. // TorusKnotBufferGeometry
  29510. function TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) {
  29511. BufferGeometry.call( this );
  29512. this.type = 'TorusKnotBufferGeometry';
  29513. this.parameters = {
  29514. radius: radius,
  29515. tube: tube,
  29516. tubularSegments: tubularSegments,
  29517. radialSegments: radialSegments,
  29518. p: p,
  29519. q: q
  29520. };
  29521. radius = radius || 100;
  29522. tube = tube || 40;
  29523. tubularSegments = Math.floor( tubularSegments ) || 64;
  29524. radialSegments = Math.floor( radialSegments ) || 8;
  29525. p = p || 2;
  29526. q = q || 3;
  29527. // buffers
  29528. var indices = [];
  29529. var vertices = [];
  29530. var normals = [];
  29531. var uvs = [];
  29532. // helper variables
  29533. var i, j;
  29534. var vertex = new Vector3();
  29535. var normal = new Vector3();
  29536. var P1 = new Vector3();
  29537. var P2 = new Vector3();
  29538. var B = new Vector3();
  29539. var T = new Vector3();
  29540. var N = new Vector3();
  29541. // generate vertices, normals and uvs
  29542. for ( i = 0; i <= tubularSegments; ++ i ) {
  29543. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  29544. var u = i / tubularSegments * p * Math.PI * 2;
  29545. // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
  29546. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  29547. calculatePositionOnCurve( u, p, q, radius, P1 );
  29548. calculatePositionOnCurve( u + 0.01, p, q, radius, P2 );
  29549. // calculate orthonormal basis
  29550. T.subVectors( P2, P1 );
  29551. N.addVectors( P2, P1 );
  29552. B.crossVectors( T, N );
  29553. N.crossVectors( B, T );
  29554. // normalize B, N. T can be ignored, we don't use it
  29555. B.normalize();
  29556. N.normalize();
  29557. for ( j = 0; j <= radialSegments; ++ j ) {
  29558. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  29559. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  29560. var v = j / radialSegments * Math.PI * 2;
  29561. var cx = - tube * Math.cos( v );
  29562. var cy = tube * Math.sin( v );
  29563. // now calculate the final vertex position.
  29564. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  29565. vertex.x = P1.x + ( cx * N.x + cy * B.x );
  29566. vertex.y = P1.y + ( cx * N.y + cy * B.y );
  29567. vertex.z = P1.z + ( cx * N.z + cy * B.z );
  29568. vertices.push( vertex.x, vertex.y, vertex.z );
  29569. // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
  29570. normal.subVectors( vertex, P1 ).normalize();
  29571. normals.push( normal.x, normal.y, normal.z );
  29572. // uv
  29573. uvs.push( i / tubularSegments );
  29574. uvs.push( j / radialSegments );
  29575. }
  29576. }
  29577. // generate indices
  29578. for ( j = 1; j <= tubularSegments; j ++ ) {
  29579. for ( i = 1; i <= radialSegments; i ++ ) {
  29580. // indices
  29581. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  29582. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  29583. var c = ( radialSegments + 1 ) * j + i;
  29584. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  29585. // faces
  29586. indices.push( a, b, d );
  29587. indices.push( b, c, d );
  29588. }
  29589. }
  29590. // build geometry
  29591. this.setIndex( indices );
  29592. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  29593. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  29594. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  29595. // this function calculates the current position on the torus curve
  29596. function calculatePositionOnCurve( u, p, q, radius, position ) {
  29597. var cu = Math.cos( u );
  29598. var su = Math.sin( u );
  29599. var quOverP = q / p * u;
  29600. var cs = Math.cos( quOverP );
  29601. position.x = radius * ( 2 + cs ) * 0.5 * cu;
  29602. position.y = radius * ( 2 + cs ) * su * 0.5;
  29603. position.z = radius * Math.sin( quOverP ) * 0.5;
  29604. }
  29605. }
  29606. TorusKnotBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  29607. TorusKnotBufferGeometry.prototype.constructor = TorusKnotBufferGeometry;
  29608. /**
  29609. * @author TristanVALCKE / https://github.com/Itee
  29610. * @author Anonymous
  29611. */
  29612. /* global QUnit */
  29613. QUnit.module( 'Geometries', () => {
  29614. QUnit.module.todo( 'SphereGeometry', ( hooks ) => {
  29615. var geometries = undefined;
  29616. hooks.beforeEach( function () {
  29617. const parameters = {
  29618. radius: 10,
  29619. tube: 20,
  29620. tubularSegments: 30,
  29621. radialSegments: 10,
  29622. p: 3,
  29623. q: 2
  29624. };
  29625. geometries = [
  29626. new TorusKnotGeometry(),
  29627. new TorusKnotGeometry( parameters.radius ),
  29628. new TorusKnotGeometry( parameters.radius, parameters.tube ),
  29629. new TorusKnotGeometry( parameters.radius, parameters.tube, parameters.tubularSegments ),
  29630. new TorusKnotGeometry( parameters.radius, parameters.tube, parameters.tubularSegments, parameters.radialSegments ),
  29631. new TorusKnotGeometry( parameters.radius, parameters.tube, parameters.tubularSegments, parameters.radialSegments, parameters.p, parameters.q ),
  29632. ];
  29633. } );
  29634. // INHERITANCE
  29635. QUnit.test( "Extending", ( assert ) => {
  29636. assert.ok( false, "everything's gonna be alright" );
  29637. } );
  29638. // INSTANCING
  29639. QUnit.test( "Instancing", ( assert ) => {
  29640. assert.ok( false, "everything's gonna be alright" );
  29641. } );
  29642. // OTHERS
  29643. QUnit.test( 'Standard geometry tests', ( assert ) => {
  29644. runStdGeometryTests( assert, geometries );
  29645. } );
  29646. } );
  29647. QUnit.module.todo( 'TorusKnotBufferGeometry', ( hooks ) => {
  29648. var geometries = undefined;
  29649. hooks.beforeEach( function () {
  29650. const parameters = {
  29651. radius: 10,
  29652. tube: 20,
  29653. tubularSegments: 30,
  29654. radialSegments: 10,
  29655. p: 3,
  29656. q: 2
  29657. };
  29658. geometries = [
  29659. new TorusKnotBufferGeometry(),
  29660. new TorusKnotBufferGeometry( parameters.radius ),
  29661. new TorusKnotBufferGeometry( parameters.radius, parameters.tube ),
  29662. new TorusKnotBufferGeometry( parameters.radius, parameters.tube, parameters.tubularSegments ),
  29663. new TorusKnotBufferGeometry( parameters.radius, parameters.tube, parameters.tubularSegments, parameters.radialSegments ),
  29664. new TorusKnotBufferGeometry( parameters.radius, parameters.tube, parameters.tubularSegments, parameters.radialSegments, parameters.p, parameters.q ),
  29665. ];
  29666. } );
  29667. // INHERITANCE
  29668. QUnit.test( "Extending", ( assert ) => {
  29669. assert.ok( false, "everything's gonna be alright" );
  29670. } );
  29671. // INSTANCING
  29672. QUnit.test( "Instancing", ( assert ) => {
  29673. assert.ok( false, "everything's gonna be alright" );
  29674. } );
  29675. // OTHERS
  29676. QUnit.test( 'Standard geometry tests', ( assert ) => {
  29677. runStdGeometryTests( assert, geometries );
  29678. } );
  29679. } );
  29680. } );
  29681. /**
  29682. * @author oosmoxiecode / https://github.com/oosmoxiecode
  29683. * @author WestLangley / https://github.com/WestLangley
  29684. * @author zz85 / https://github.com/zz85
  29685. * @author miningold / https://github.com/miningold
  29686. * @author jonobr1 / https://github.com/jonobr1
  29687. * @author Mugen87 / https://github.com/Mugen87
  29688. *
  29689. */
  29690. // TubeGeometry
  29691. function TubeGeometry( path, tubularSegments, radius, radialSegments, closed, taper ) {
  29692. Geometry.call( this );
  29693. this.type = 'TubeGeometry';
  29694. this.parameters = {
  29695. path: path,
  29696. tubularSegments: tubularSegments,
  29697. radius: radius,
  29698. radialSegments: radialSegments,
  29699. closed: closed
  29700. };
  29701. if ( taper !== undefined ) console.warn( 'THREE.TubeGeometry: taper has been removed.' );
  29702. var bufferGeometry = new TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed );
  29703. // expose internals
  29704. this.tangents = bufferGeometry.tangents;
  29705. this.normals = bufferGeometry.normals;
  29706. this.binormals = bufferGeometry.binormals;
  29707. // create geometry
  29708. this.fromBufferGeometry( bufferGeometry );
  29709. this.mergeVertices();
  29710. }
  29711. TubeGeometry.prototype = Object.create( Geometry.prototype );
  29712. TubeGeometry.prototype.constructor = TubeGeometry;
  29713. // TubeBufferGeometry
  29714. function TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed ) {
  29715. BufferGeometry.call( this );
  29716. this.type = 'TubeBufferGeometry';
  29717. this.parameters = {
  29718. path: path,
  29719. tubularSegments: tubularSegments,
  29720. radius: radius,
  29721. radialSegments: radialSegments,
  29722. closed: closed
  29723. };
  29724. tubularSegments = tubularSegments || 64;
  29725. radius = radius || 1;
  29726. radialSegments = radialSegments || 8;
  29727. closed = closed || false;
  29728. var frames = path.computeFrenetFrames( tubularSegments, closed );
  29729. // expose internals
  29730. this.tangents = frames.tangents;
  29731. this.normals = frames.normals;
  29732. this.binormals = frames.binormals;
  29733. // helper variables
  29734. var vertex = new Vector3();
  29735. var normal = new Vector3();
  29736. var uv = new Vector2();
  29737. var P = new Vector3();
  29738. var i, j;
  29739. // buffer
  29740. var vertices = [];
  29741. var normals = [];
  29742. var uvs = [];
  29743. var indices = [];
  29744. // create buffer data
  29745. generateBufferData();
  29746. // build geometry
  29747. this.setIndex( indices );
  29748. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  29749. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  29750. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  29751. // functions
  29752. function generateBufferData() {
  29753. for ( i = 0; i < tubularSegments; i ++ ) {
  29754. generateSegment( i );
  29755. }
  29756. // if the geometry is not closed, generate the last row of vertices and normals
  29757. // at the regular position on the given path
  29758. //
  29759. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  29760. generateSegment( ( closed === false ) ? tubularSegments : 0 );
  29761. // uvs are generated in a separate function.
  29762. // this makes it easy compute correct values for closed geometries
  29763. generateUVs();
  29764. // finally create faces
  29765. generateIndices();
  29766. }
  29767. function generateSegment( i ) {
  29768. // we use getPointAt to sample evenly distributed points from the given path
  29769. P = path.getPointAt( i / tubularSegments, P );
  29770. // retrieve corresponding normal and binormal
  29771. var N = frames.normals[ i ];
  29772. var B = frames.binormals[ i ];
  29773. // generate normals and vertices for the current segment
  29774. for ( j = 0; j <= radialSegments; j ++ ) {
  29775. var v = j / radialSegments * Math.PI * 2;
  29776. var sin = Math.sin( v );
  29777. var cos = - Math.cos( v );
  29778. // normal
  29779. normal.x = ( cos * N.x + sin * B.x );
  29780. normal.y = ( cos * N.y + sin * B.y );
  29781. normal.z = ( cos * N.z + sin * B.z );
  29782. normal.normalize();
  29783. normals.push( normal.x, normal.y, normal.z );
  29784. // vertex
  29785. vertex.x = P.x + radius * normal.x;
  29786. vertex.y = P.y + radius * normal.y;
  29787. vertex.z = P.z + radius * normal.z;
  29788. vertices.push( vertex.x, vertex.y, vertex.z );
  29789. }
  29790. }
  29791. function generateIndices() {
  29792. for ( j = 1; j <= tubularSegments; j ++ ) {
  29793. for ( i = 1; i <= radialSegments; i ++ ) {
  29794. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  29795. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  29796. var c = ( radialSegments + 1 ) * j + i;
  29797. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  29798. // faces
  29799. indices.push( a, b, d );
  29800. indices.push( b, c, d );
  29801. }
  29802. }
  29803. }
  29804. function generateUVs() {
  29805. for ( i = 0; i <= tubularSegments; i ++ ) {
  29806. for ( j = 0; j <= radialSegments; j ++ ) {
  29807. uv.x = i / tubularSegments;
  29808. uv.y = j / radialSegments;
  29809. uvs.push( uv.x, uv.y );
  29810. }
  29811. }
  29812. }
  29813. }
  29814. TubeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  29815. TubeBufferGeometry.prototype.constructor = TubeBufferGeometry;
  29816. /**
  29817. * @author TristanVALCKE / https://github.com/Itee
  29818. */
  29819. /* global QUnit */
  29820. QUnit.module( 'Geometries', () => {
  29821. QUnit.module.todo( 'TubeGeometry', ( hooks ) => {
  29822. var geometries = undefined;
  29823. hooks.beforeEach( function () {
  29824. const parameters = {};
  29825. geometries = [
  29826. new TubeGeometry()
  29827. ];
  29828. } );
  29829. // INHERITANCE
  29830. QUnit.test( "Extending", ( assert ) => {
  29831. assert.ok( false, "everything's gonna be alright" );
  29832. } );
  29833. // INSTANCING
  29834. QUnit.test( "Instancing", ( assert ) => {
  29835. assert.ok( false, "everything's gonna be alright" );
  29836. } );
  29837. // OTHERS
  29838. QUnit.test( 'Standard geometry tests', ( assert ) => {
  29839. runStdGeometryTests( assert, geometries );
  29840. } );
  29841. } );
  29842. QUnit.module.todo( 'TubeBufferGeometry', ( hooks ) => {
  29843. var geometries = undefined;
  29844. hooks.beforeEach( function () {
  29845. const parameters = {};
  29846. geometries = [
  29847. new TubeBufferGeometry()
  29848. ];
  29849. } );
  29850. // INHERITANCE
  29851. QUnit.test( "Extending", ( assert ) => {
  29852. assert.ok( false, "everything's gonna be alright" );
  29853. } );
  29854. // INSTANCING
  29855. QUnit.test( "Instancing", ( assert ) => {
  29856. assert.ok( false, "everything's gonna be alright" );
  29857. } );
  29858. // OTHERS
  29859. QUnit.test( 'Standard geometry tests', ( assert ) => {
  29860. runStdGeometryTests( assert, geometries );
  29861. } );
  29862. } );
  29863. } );
  29864. /**
  29865. * @author mrdoob / http://mrdoob.com/
  29866. * @author Mugen87 / https://github.com/Mugen87
  29867. */
  29868. function WireframeGeometry( geometry ) {
  29869. BufferGeometry.call( this );
  29870. this.type = 'WireframeGeometry';
  29871. // buffer
  29872. var vertices = [];
  29873. // helper variables
  29874. var i, j, l, o, ol;
  29875. var edge = [ 0, 0 ], edges = {}, e, edge1, edge2;
  29876. var key, keys = [ 'a', 'b', 'c' ];
  29877. var vertex;
  29878. // different logic for Geometry and BufferGeometry
  29879. if ( geometry && geometry.isGeometry ) {
  29880. // create a data structure that contains all edges without duplicates
  29881. var faces = geometry.faces;
  29882. for ( i = 0, l = faces.length; i < l; i ++ ) {
  29883. var face = faces[ i ];
  29884. for ( j = 0; j < 3; j ++ ) {
  29885. edge1 = face[ keys[ j ] ];
  29886. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  29887. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  29888. edge[ 1 ] = Math.max( edge1, edge2 );
  29889. key = edge[ 0 ] + ',' + edge[ 1 ];
  29890. if ( edges[ key ] === undefined ) {
  29891. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  29892. }
  29893. }
  29894. }
  29895. // generate vertices
  29896. for ( key in edges ) {
  29897. e = edges[ key ];
  29898. vertex = geometry.vertices[ e.index1 ];
  29899. vertices.push( vertex.x, vertex.y, vertex.z );
  29900. vertex = geometry.vertices[ e.index2 ];
  29901. vertices.push( vertex.x, vertex.y, vertex.z );
  29902. }
  29903. } else if ( geometry && geometry.isBufferGeometry ) {
  29904. var position, indices, groups;
  29905. var group, start, count;
  29906. var index1, index2;
  29907. vertex = new Vector3();
  29908. if ( geometry.index !== null ) {
  29909. // indexed BufferGeometry
  29910. position = geometry.attributes.position;
  29911. indices = geometry.index;
  29912. groups = geometry.groups;
  29913. if ( groups.length === 0 ) {
  29914. groups = [ { start: 0, count: indices.count, materialIndex: 0 } ];
  29915. }
  29916. // create a data structure that contains all eges without duplicates
  29917. for ( o = 0, ol = groups.length; o < ol; ++ o ) {
  29918. group = groups[ o ];
  29919. start = group.start;
  29920. count = group.count;
  29921. for ( i = start, l = ( start + count ); i < l; i += 3 ) {
  29922. for ( j = 0; j < 3; j ++ ) {
  29923. edge1 = indices.getX( i + j );
  29924. edge2 = indices.getX( i + ( j + 1 ) % 3 );
  29925. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  29926. edge[ 1 ] = Math.max( edge1, edge2 );
  29927. key = edge[ 0 ] + ',' + edge[ 1 ];
  29928. if ( edges[ key ] === undefined ) {
  29929. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  29930. }
  29931. }
  29932. }
  29933. }
  29934. // generate vertices
  29935. for ( key in edges ) {
  29936. e = edges[ key ];
  29937. vertex.fromBufferAttribute( position, e.index1 );
  29938. vertices.push( vertex.x, vertex.y, vertex.z );
  29939. vertex.fromBufferAttribute( position, e.index2 );
  29940. vertices.push( vertex.x, vertex.y, vertex.z );
  29941. }
  29942. } else {
  29943. // non-indexed BufferGeometry
  29944. position = geometry.attributes.position;
  29945. for ( i = 0, l = ( position.count / 3 ); i < l; i ++ ) {
  29946. for ( j = 0; j < 3; j ++ ) {
  29947. // three edges per triangle, an edge is represented as (index1, index2)
  29948. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  29949. index1 = 3 * i + j;
  29950. vertex.fromBufferAttribute( position, index1 );
  29951. vertices.push( vertex.x, vertex.y, vertex.z );
  29952. index2 = 3 * i + ( ( j + 1 ) % 3 );
  29953. vertex.fromBufferAttribute( position, index2 );
  29954. vertices.push( vertex.x, vertex.y, vertex.z );
  29955. }
  29956. }
  29957. }
  29958. }
  29959. // build geometry
  29960. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  29961. }
  29962. WireframeGeometry.prototype = Object.create( BufferGeometry.prototype );
  29963. WireframeGeometry.prototype.constructor = WireframeGeometry;
  29964. /**
  29965. * @author TristanVALCKE / https://github.com/Itee
  29966. */
  29967. /* global QUnit */
  29968. QUnit.module( 'Geometries', () => {
  29969. QUnit.module.todo( 'WireframeGeometry', ( hooks ) => {
  29970. var geometries = undefined;
  29971. hooks.beforeEach( function () {
  29972. const parameters = {};
  29973. geometries = [
  29974. new WireframeGeometry()
  29975. ];
  29976. } );
  29977. // INHERITANCE
  29978. QUnit.test( "Extending", ( assert ) => {
  29979. assert.ok( false, "everything's gonna be alright" );
  29980. } );
  29981. // INSTANCING
  29982. QUnit.test( "Instancing", ( assert ) => {
  29983. assert.ok( false, "everything's gonna be alright" );
  29984. } );
  29985. // OTHERS
  29986. QUnit.test( 'Standard geometry tests', ( assert ) => {
  29987. runStdGeometryTests( assert, geometries );
  29988. } );
  29989. } );
  29990. } );
  29991. /**
  29992. * @author WestLangley / http://github.com/WestLangley
  29993. * @author zz85 / http://github.com/zz85
  29994. * @author bhouston / http://clara.io
  29995. *
  29996. * Creates an arrow for visualizing directions
  29997. *
  29998. * Parameters:
  29999. * dir - Vector3
  30000. * origin - Vector3
  30001. * length - Number
  30002. * color - color in hex value
  30003. * headLength - Number
  30004. * headWidth - Number
  30005. */
  30006. /**
  30007. * @author TristanVALCKE / https://github.com/Itee
  30008. */
  30009. /* global QUnit */
  30010. QUnit.module( 'Helpers', () => {
  30011. QUnit.module.todo( 'ArrowHelper', () => {
  30012. // INHERITANCE
  30013. QUnit.test( "Extending", ( assert ) => {
  30014. assert.ok( false, "everything's gonna be alright" );
  30015. } );
  30016. // INSTANCING
  30017. QUnit.test( "Instancing", ( assert ) => {
  30018. assert.ok( false, "everything's gonna be alright" );
  30019. } );
  30020. // PUBLIC STUFF
  30021. QUnit.test( "setDirection", ( assert ) => {
  30022. assert.ok( false, "everything's gonna be alright" );
  30023. } );
  30024. QUnit.test( "setLength", ( assert ) => {
  30025. assert.ok( false, "everything's gonna be alright" );
  30026. } );
  30027. QUnit.test( "setColor", ( assert ) => {
  30028. assert.ok( false, "everything's gonna be alright" );
  30029. } );
  30030. } );
  30031. } );
  30032. /**
  30033. * @author sroucheray / http://sroucheray.org/
  30034. * @author mrdoob / http://mrdoob.com/
  30035. */
  30036. /**
  30037. * @author TristanVALCKE / https://github.com/Itee
  30038. */
  30039. /* global QUnit */
  30040. QUnit.module( 'Helpers', () => {
  30041. QUnit.module.todo( 'AxesHelper', () => {
  30042. // INHERITANCE
  30043. QUnit.test( "Extending", ( assert ) => {
  30044. assert.ok( false, "everything's gonna be alright" );
  30045. } );
  30046. // INSTANCING
  30047. QUnit.test( "Instancing", ( assert ) => {
  30048. assert.ok( false, "everything's gonna be alright" );
  30049. } );
  30050. } );
  30051. } );
  30052. /**
  30053. * @author WestLangley / http://github.com/WestLangley
  30054. */
  30055. /**
  30056. * @author TristanVALCKE / https://github.com/Itee
  30057. */
  30058. /* global QUnit */
  30059. QUnit.module( 'Helpers', () => {
  30060. QUnit.module.todo( 'Box3Helper', () => {
  30061. // INHERITANCE
  30062. QUnit.test( "Extending", ( assert ) => {
  30063. assert.ok( false, "everything's gonna be alright" );
  30064. } );
  30065. // INSTANCING
  30066. QUnit.test( "Instancing", ( assert ) => {
  30067. assert.ok( false, "everything's gonna be alright" );
  30068. } );
  30069. // PUBLIC STUFF
  30070. QUnit.test( "updateMatrixWorld", ( assert ) => {
  30071. assert.ok( false, "everything's gonna be alright" );
  30072. } );
  30073. } );
  30074. } );
  30075. /**
  30076. * @author mrdoob / http://mrdoob.com/
  30077. * @author Mugen87 / http://github.com/Mugen87
  30078. */
  30079. function BoxHelper( object, color ) {
  30080. this.object = object;
  30081. if ( color === undefined ) color = 0xffff00;
  30082. 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 ] );
  30083. var positions = new Float32Array( 8 * 3 );
  30084. var geometry = new BufferGeometry();
  30085. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  30086. geometry.addAttribute( 'position', new BufferAttribute( positions, 3 ) );
  30087. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  30088. this.matrixAutoUpdate = false;
  30089. this.update();
  30090. }
  30091. BoxHelper.prototype = Object.create( LineSegments.prototype );
  30092. BoxHelper.prototype.constructor = BoxHelper;
  30093. BoxHelper.prototype.update = ( function () {
  30094. var box = new Box3();
  30095. return function update( object ) {
  30096. if ( object !== undefined ) {
  30097. console.warn( 'THREE.BoxHelper: .update() has no longer arguments.' );
  30098. }
  30099. if ( this.object !== undefined ) {
  30100. box.setFromObject( this.object );
  30101. }
  30102. if ( box.isEmpty() ) return;
  30103. var min = box.min;
  30104. var max = box.max;
  30105. /*
  30106. 5____4
  30107. 1/___0/|
  30108. | 6__|_7
  30109. 2/___3/
  30110. 0: max.x, max.y, max.z
  30111. 1: min.x, max.y, max.z
  30112. 2: min.x, min.y, max.z
  30113. 3: max.x, min.y, max.z
  30114. 4: max.x, max.y, min.z
  30115. 5: min.x, max.y, min.z
  30116. 6: min.x, min.y, min.z
  30117. 7: max.x, min.y, min.z
  30118. */
  30119. var position = this.geometry.attributes.position;
  30120. var array = position.array;
  30121. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  30122. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  30123. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  30124. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  30125. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  30126. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  30127. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  30128. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  30129. position.needsUpdate = true;
  30130. this.geometry.computeBoundingSphere();
  30131. };
  30132. } )();
  30133. BoxHelper.prototype.setFromObject = function ( object ) {
  30134. this.object = object;
  30135. this.update();
  30136. return this;
  30137. };
  30138. /**
  30139. * @author TristanVALCKE / https://github.com/Itee
  30140. * @author Anonymous
  30141. */
  30142. /* global QUnit */
  30143. QUnit.module( 'Helpers', () => {
  30144. QUnit.module.todo( 'BoxHelper', ( hooks ) => {
  30145. var geometries = undefined;
  30146. hooks.beforeEach( function () {
  30147. const parameters = {
  30148. radius: 10,
  30149. widthSegments: 20,
  30150. heightSegments: 30,
  30151. phiStart: 0.5,
  30152. phiLength: 1.0,
  30153. thetaStart: 0.4,
  30154. thetaLength: 2.0,
  30155. };
  30156. // Test with a normal cube and a box helper
  30157. var boxGeometry = new BoxGeometry( parameters.diameter );
  30158. var box = new Mesh( boxGeometry );
  30159. var boxHelper = new BoxHelper( box );
  30160. // The same should happen with a comparable sphere
  30161. var sphereGeometry = new SphereGeometry( parameters.diameter / 2 );
  30162. var sphere = new Mesh( sphereGeometry );
  30163. var sphereBoxHelper = new BoxHelper( sphere );
  30164. // Note that unlike what I'd like to, these doesn't check the equivalency of the two generated geometries
  30165. geometries = [ boxHelper.geometry, sphereBoxHelper.geometry ];
  30166. } );
  30167. // INHERITANCE
  30168. QUnit.test( "Extending", ( assert ) => {
  30169. assert.ok( false, "everything's gonna be alright" );
  30170. } );
  30171. // INSTANCING
  30172. QUnit.test( "Instancing", ( assert ) => {
  30173. assert.ok( false, "everything's gonna be alright" );
  30174. } );
  30175. // PUBLIC STUFF
  30176. QUnit.test( "update", ( assert ) => {
  30177. assert.ok( false, "everything's gonna be alright" );
  30178. } );
  30179. QUnit.test( "setFromObject", ( assert ) => {
  30180. assert.ok( false, "everything's gonna be alright" );
  30181. } );
  30182. // OTHERS
  30183. QUnit.test( 'Standard geometry tests', ( assert ) => {
  30184. runStdGeometryTests( assert, geometries );
  30185. } );
  30186. } );
  30187. } );
  30188. /**
  30189. * @author alteredq / http://alteredqualia.com/
  30190. * @author Mugen87 / https://github.com/Mugen87
  30191. *
  30192. * - shows frustum, line of sight and up of the camera
  30193. * - suitable for fast updates
  30194. * - based on frustum visualization in lightgl.js shadowmap example
  30195. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  30196. */
  30197. function CameraHelper( camera ) {
  30198. var geometry = new BufferGeometry();
  30199. var material = new LineBasicMaterial( { color: 0xffffff, vertexColors: FaceColors } );
  30200. var vertices = [];
  30201. var colors = [];
  30202. var pointMap = {};
  30203. // colors
  30204. var colorFrustum = new Color( 0xffaa00 );
  30205. var colorCone = new Color( 0xff0000 );
  30206. var colorUp = new Color( 0x00aaff );
  30207. var colorTarget = new Color( 0xffffff );
  30208. var colorCross = new Color( 0x333333 );
  30209. // near
  30210. addLine( 'n1', 'n2', colorFrustum );
  30211. addLine( 'n2', 'n4', colorFrustum );
  30212. addLine( 'n4', 'n3', colorFrustum );
  30213. addLine( 'n3', 'n1', colorFrustum );
  30214. // far
  30215. addLine( 'f1', 'f2', colorFrustum );
  30216. addLine( 'f2', 'f4', colorFrustum );
  30217. addLine( 'f4', 'f3', colorFrustum );
  30218. addLine( 'f3', 'f1', colorFrustum );
  30219. // sides
  30220. addLine( 'n1', 'f1', colorFrustum );
  30221. addLine( 'n2', 'f2', colorFrustum );
  30222. addLine( 'n3', 'f3', colorFrustum );
  30223. addLine( 'n4', 'f4', colorFrustum );
  30224. // cone
  30225. addLine( 'p', 'n1', colorCone );
  30226. addLine( 'p', 'n2', colorCone );
  30227. addLine( 'p', 'n3', colorCone );
  30228. addLine( 'p', 'n4', colorCone );
  30229. // up
  30230. addLine( 'u1', 'u2', colorUp );
  30231. addLine( 'u2', 'u3', colorUp );
  30232. addLine( 'u3', 'u1', colorUp );
  30233. // target
  30234. addLine( 'c', 't', colorTarget );
  30235. addLine( 'p', 'c', colorCross );
  30236. // cross
  30237. addLine( 'cn1', 'cn2', colorCross );
  30238. addLine( 'cn3', 'cn4', colorCross );
  30239. addLine( 'cf1', 'cf2', colorCross );
  30240. addLine( 'cf3', 'cf4', colorCross );
  30241. function addLine( a, b, color ) {
  30242. addPoint( a, color );
  30243. addPoint( b, color );
  30244. }
  30245. function addPoint( id, color ) {
  30246. vertices.push( 0, 0, 0 );
  30247. colors.push( color.r, color.g, color.b );
  30248. if ( pointMap[ id ] === undefined ) {
  30249. pointMap[ id ] = [];
  30250. }
  30251. pointMap[ id ].push( ( vertices.length / 3 ) - 1 );
  30252. }
  30253. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  30254. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  30255. LineSegments.call( this, geometry, material );
  30256. this.camera = camera;
  30257. if ( this.camera.updateProjectionMatrix ) this.camera.updateProjectionMatrix();
  30258. this.matrix = camera.matrixWorld;
  30259. this.matrixAutoUpdate = false;
  30260. this.pointMap = pointMap;
  30261. this.update();
  30262. }
  30263. CameraHelper.prototype = Object.create( LineSegments.prototype );
  30264. CameraHelper.prototype.constructor = CameraHelper;
  30265. CameraHelper.prototype.update = function () {
  30266. var geometry, pointMap;
  30267. var vector = new Vector3();
  30268. var camera = new Camera();
  30269. function setPoint( point, x, y, z ) {
  30270. vector.set( x, y, z ).unproject( camera );
  30271. var points = pointMap[ point ];
  30272. if ( points !== undefined ) {
  30273. var position = geometry.getAttribute( 'position' );
  30274. for ( var i = 0, l = points.length; i < l; i ++ ) {
  30275. position.setXYZ( points[ i ], vector.x, vector.y, vector.z );
  30276. }
  30277. }
  30278. }
  30279. return function update() {
  30280. geometry = this.geometry;
  30281. pointMap = this.pointMap;
  30282. var w = 1, h = 1;
  30283. // we need just camera projection matrix
  30284. // world matrix must be identity
  30285. camera.projectionMatrix.copy( this.camera.projectionMatrix );
  30286. // center / target
  30287. setPoint( 'c', 0, 0, - 1 );
  30288. setPoint( 't', 0, 0, 1 );
  30289. // near
  30290. setPoint( 'n1', - w, - h, - 1 );
  30291. setPoint( 'n2', w, - h, - 1 );
  30292. setPoint( 'n3', - w, h, - 1 );
  30293. setPoint( 'n4', w, h, - 1 );
  30294. // far
  30295. setPoint( 'f1', - w, - h, 1 );
  30296. setPoint( 'f2', w, - h, 1 );
  30297. setPoint( 'f3', - w, h, 1 );
  30298. setPoint( 'f4', w, h, 1 );
  30299. // up
  30300. setPoint( 'u1', w * 0.7, h * 1.1, - 1 );
  30301. setPoint( 'u2', - w * 0.7, h * 1.1, - 1 );
  30302. setPoint( 'u3', 0, h * 2, - 1 );
  30303. // cross
  30304. setPoint( 'cf1', - w, 0, 1 );
  30305. setPoint( 'cf2', w, 0, 1 );
  30306. setPoint( 'cf3', 0, - h, 1 );
  30307. setPoint( 'cf4', 0, h, 1 );
  30308. setPoint( 'cn1', - w, 0, - 1 );
  30309. setPoint( 'cn2', w, 0, - 1 );
  30310. setPoint( 'cn3', 0, - h, - 1 );
  30311. setPoint( 'cn4', 0, h, - 1 );
  30312. geometry.getAttribute( 'position' ).needsUpdate = true;
  30313. };
  30314. }();
  30315. /**
  30316. * @author TristanVALCKE / https://github.com/Itee
  30317. */
  30318. /* global QUnit */
  30319. QUnit.module( 'Helpers', () => {
  30320. QUnit.module.todo( 'CameraHelper', () => {
  30321. // INHERITANCE
  30322. QUnit.test( "Extending", ( assert ) => {
  30323. assert.ok( false, "everything's gonna be alright" );
  30324. } );
  30325. // INSTANCING
  30326. QUnit.test( "Instancing", ( assert ) => {
  30327. assert.ok( false, "everything's gonna be alright" );
  30328. } );
  30329. // PUBLIC STUFF
  30330. QUnit.test( "update", ( assert ) => {
  30331. assert.ok( false, "everything's gonna be alright" );
  30332. } );
  30333. } );
  30334. } );
  30335. /**
  30336. * @author alteredq / http://alteredqualia.com/
  30337. * @author mrdoob / http://mrdoob.com/
  30338. * @author WestLangley / http://github.com/WestLangley
  30339. */
  30340. /**
  30341. * @author TristanVALCKE / https://github.com/Itee
  30342. */
  30343. /* global QUnit */
  30344. QUnit.module( 'Helpers', () => {
  30345. QUnit.module.todo( 'DirectionalLightHelper', () => {
  30346. // INHERITANCE
  30347. QUnit.test( "Extending", ( assert ) => {
  30348. assert.ok( false, "everything's gonna be alright" );
  30349. } );
  30350. // INSTANCING
  30351. QUnit.test( "Instancing", ( assert ) => {
  30352. assert.ok( false, "everything's gonna be alright" );
  30353. } );
  30354. // PUBLIC STUFF
  30355. QUnit.test( "dispose", ( assert ) => {
  30356. assert.ok( false, "everything's gonna be alright" );
  30357. } );
  30358. QUnit.test( "update", ( assert ) => {
  30359. assert.ok( false, "everything's gonna be alright" );
  30360. } );
  30361. } );
  30362. } );
  30363. /**
  30364. * @author mrdoob / http://mrdoob.com/
  30365. * @author WestLangley / http://github.com/WestLangley
  30366. */
  30367. function FaceNormalsHelper( object, size, hex, linewidth ) {
  30368. // FaceNormalsHelper only supports THREE.Geometry
  30369. this.object = object;
  30370. this.size = ( size !== undefined ) ? size : 1;
  30371. var color = ( hex !== undefined ) ? hex : 0xffff00;
  30372. var width = ( linewidth !== undefined ) ? linewidth : 1;
  30373. //
  30374. var nNormals = 0;
  30375. var objGeometry = this.object.geometry;
  30376. if ( objGeometry && objGeometry.isGeometry ) {
  30377. nNormals = objGeometry.faces.length;
  30378. } else {
  30379. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  30380. }
  30381. //
  30382. var geometry = new BufferGeometry();
  30383. var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
  30384. geometry.addAttribute( 'position', positions );
  30385. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
  30386. //
  30387. this.matrixAutoUpdate = false;
  30388. this.update();
  30389. }
  30390. FaceNormalsHelper.prototype = Object.create( LineSegments.prototype );
  30391. FaceNormalsHelper.prototype.constructor = FaceNormalsHelper;
  30392. FaceNormalsHelper.prototype.update = ( function () {
  30393. var v1 = new Vector3();
  30394. var v2 = new Vector3();
  30395. var normalMatrix = new Matrix3();
  30396. return function update() {
  30397. this.object.updateMatrixWorld( true );
  30398. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  30399. var matrixWorld = this.object.matrixWorld;
  30400. var position = this.geometry.attributes.position;
  30401. //
  30402. var objGeometry = this.object.geometry;
  30403. var vertices = objGeometry.vertices;
  30404. var faces = objGeometry.faces;
  30405. var idx = 0;
  30406. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  30407. var face = faces[ i ];
  30408. var normal = face.normal;
  30409. v1.copy( vertices[ face.a ] )
  30410. .add( vertices[ face.b ] )
  30411. .add( vertices[ face.c ] )
  30412. .divideScalar( 3 )
  30413. .applyMatrix4( matrixWorld );
  30414. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  30415. position.setXYZ( idx, v1.x, v1.y, v1.z );
  30416. idx = idx + 1;
  30417. position.setXYZ( idx, v2.x, v2.y, v2.z );
  30418. idx = idx + 1;
  30419. }
  30420. position.needsUpdate = true;
  30421. };
  30422. }() );
  30423. /**
  30424. * @author TristanVALCKE / https://github.com/Itee
  30425. */
  30426. /* global QUnit */
  30427. QUnit.module( 'Helpers', () => {
  30428. QUnit.module.todo( 'FaceNormalsHelper', () => {
  30429. // INHERITANCE
  30430. QUnit.test( "Extending", ( assert ) => {
  30431. assert.ok( false, "everything's gonna be alright" );
  30432. } );
  30433. // INSTANCING
  30434. QUnit.test( "Instancing", ( assert ) => {
  30435. assert.ok( false, "everything's gonna be alright" );
  30436. } );
  30437. // PUBLIC STUFF
  30438. QUnit.test( "update", ( assert ) => {
  30439. assert.ok( false, "everything's gonna be alright" );
  30440. } );
  30441. } );
  30442. } );
  30443. /**
  30444. * @author mrdoob / http://mrdoob.com/
  30445. */
  30446. /**
  30447. * @author TristanVALCKE / https://github.com/Itee
  30448. */
  30449. /* global QUnit */
  30450. QUnit.module( 'Helpers', () => {
  30451. QUnit.module.todo( 'GridHelper', () => {
  30452. // INHERITANCE
  30453. QUnit.test( "Extending", ( assert ) => {
  30454. assert.ok( false, "everything's gonna be alright" );
  30455. } );
  30456. // INSTANCING
  30457. QUnit.test( "Instancing", ( assert ) => {
  30458. assert.ok( false, "everything's gonna be alright" );
  30459. } );
  30460. } );
  30461. } );
  30462. /**
  30463. * @author alteredq / http://alteredqualia.com/
  30464. * @author mrdoob / http://mrdoob.com/
  30465. * @author Mugen87 / https://github.com/Mugen87
  30466. */
  30467. function HemisphereLightHelper( light, size, color ) {
  30468. Object3D.call( this );
  30469. this.light = light;
  30470. this.light.updateMatrixWorld();
  30471. this.matrix = light.matrixWorld;
  30472. this.matrixAutoUpdate = false;
  30473. this.color = color;
  30474. var geometry = new OctahedronBufferGeometry( size );
  30475. geometry.rotateY( Math.PI * 0.5 );
  30476. this.material = new MeshBasicMaterial( { wireframe: true, fog: false } );
  30477. if ( this.color === undefined ) this.material.vertexColors = VertexColors;
  30478. var position = geometry.getAttribute( 'position' );
  30479. var colors = new Float32Array( position.count * 3 );
  30480. geometry.addAttribute( 'color', new BufferAttribute( colors, 3 ) );
  30481. this.add( new Mesh( geometry, this.material ) );
  30482. this.update();
  30483. }
  30484. HemisphereLightHelper.prototype = Object.create( Object3D.prototype );
  30485. HemisphereLightHelper.prototype.constructor = HemisphereLightHelper;
  30486. HemisphereLightHelper.prototype.dispose = function () {
  30487. this.children[ 0 ].geometry.dispose();
  30488. this.children[ 0 ].material.dispose();
  30489. };
  30490. HemisphereLightHelper.prototype.update = function () {
  30491. var vector = new Vector3();
  30492. var color1 = new Color();
  30493. var color2 = new Color();
  30494. return function update() {
  30495. var mesh = this.children[ 0 ];
  30496. if ( this.color !== undefined ) {
  30497. this.material.color.set( this.color );
  30498. } else {
  30499. var colors = mesh.geometry.getAttribute( 'color' );
  30500. color1.copy( this.light.color );
  30501. color2.copy( this.light.groundColor );
  30502. for ( var i = 0, l = colors.count; i < l; i ++ ) {
  30503. var color = ( i < ( l / 2 ) ) ? color1 : color2;
  30504. colors.setXYZ( i, color.r, color.g, color.b );
  30505. }
  30506. colors.needsUpdate = true;
  30507. }
  30508. mesh.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  30509. };
  30510. }();
  30511. /**
  30512. * @author TristanVALCKE / https://github.com/Itee
  30513. */
  30514. /* global QUnit */
  30515. QUnit.module( 'Helpers', () => {
  30516. QUnit.module.todo( 'HemisphereLightHelper', () => {
  30517. // INHERITANCE
  30518. QUnit.test( "Extending", ( assert ) => {
  30519. assert.ok( false, "everything's gonna be alright" );
  30520. } );
  30521. // INSTANCING
  30522. QUnit.test( "Instancing", ( assert ) => {
  30523. assert.ok( false, "everything's gonna be alright" );
  30524. } );
  30525. // PUBLIC STUFF
  30526. QUnit.test( "dispose", ( assert ) => {
  30527. assert.ok( false, "everything's gonna be alright" );
  30528. } );
  30529. QUnit.test( "update", ( assert ) => {
  30530. assert.ok( false, "everything's gonna be alright" );
  30531. } );
  30532. } );
  30533. } );
  30534. /**
  30535. * @author WestLangley / http://github.com/WestLangley
  30536. */
  30537. /**
  30538. * @author TristanVALCKE / https://github.com/Itee
  30539. */
  30540. /* global QUnit */
  30541. QUnit.module( 'Helpers', () => {
  30542. QUnit.module.todo( 'PlaneHelper', () => {
  30543. // INHERITANCE
  30544. QUnit.test( "Extending", ( assert ) => {
  30545. assert.ok( false, "everything's gonna be alright" );
  30546. } );
  30547. // INSTANCING
  30548. QUnit.test( "Instancing", ( assert ) => {
  30549. assert.ok( false, "everything's gonna be alright" );
  30550. } );
  30551. // PUBLIC STUFF
  30552. QUnit.test( "updateMatrixWorld", ( assert ) => {
  30553. assert.ok( false, "everything's gonna be alright" );
  30554. } );
  30555. } );
  30556. } );
  30557. /**
  30558. * @author alteredq / http://alteredqualia.com/
  30559. * @author mrdoob / http://mrdoob.com/
  30560. */
  30561. /**
  30562. * @author TristanVALCKE / https://github.com/Itee
  30563. */
  30564. /* global QUnit */
  30565. QUnit.module( 'Helpers', () => {
  30566. QUnit.module.todo( 'PointLightHelper', () => {
  30567. // INHERITANCE
  30568. QUnit.test( "Extending", ( assert ) => {
  30569. assert.ok( false, "everything's gonna be alright" );
  30570. } );
  30571. // INSTANCING
  30572. QUnit.test( "Instancing", ( assert ) => {
  30573. assert.ok( false, "everything's gonna be alright" );
  30574. } );
  30575. // PUBLIC STUFF
  30576. QUnit.test( "dispose", ( assert ) => {
  30577. assert.ok( false, "everything's gonna be alright" );
  30578. } );
  30579. QUnit.test( "update", ( assert ) => {
  30580. assert.ok( false, "everything's gonna be alright" );
  30581. } );
  30582. } );
  30583. } );
  30584. /**
  30585. * @author mrdoob / http://mrdoob.com/
  30586. * @author Mugen87 / http://github.com/Mugen87
  30587. * @author Hectate / http://www.github.com/Hectate
  30588. */
  30589. /**
  30590. * @author TristanVALCKE / https://github.com/Itee
  30591. */
  30592. /* global QUnit */
  30593. QUnit.module( 'Helpers', () => {
  30594. QUnit.module.todo( 'PolarGridHelper', () => {
  30595. // INHERITANCE
  30596. QUnit.test( "Extending", ( assert ) => {
  30597. assert.ok( false, "everything's gonna be alright" );
  30598. } );
  30599. // INSTANCING
  30600. QUnit.test( "Instancing", ( assert ) => {
  30601. assert.ok( false, "everything's gonna be alright" );
  30602. } );
  30603. } );
  30604. } );
  30605. /**
  30606. * @author abelnation / http://github.com/abelnation
  30607. * @author Mugen87 / http://github.com/Mugen87
  30608. * @author WestLangley / http://github.com/WestLangley
  30609. */
  30610. /**
  30611. * @author TristanVALCKE / https://github.com/Itee
  30612. */
  30613. /* global QUnit */
  30614. QUnit.module( 'Helpers', () => {
  30615. QUnit.module.todo( 'RectAreaLightHelper', () => {
  30616. // INHERITANCE
  30617. QUnit.test( "Extending", ( assert ) => {
  30618. assert.ok( false, "everything's gonna be alright" );
  30619. } );
  30620. // INSTANCING
  30621. QUnit.test( "Instancing", ( assert ) => {
  30622. assert.ok( false, "everything's gonna be alright" );
  30623. } );
  30624. // PUBLIC STUFF
  30625. QUnit.test( "dispose", ( assert ) => {
  30626. assert.ok( false, "everything's gonna be alright" );
  30627. } );
  30628. QUnit.test( "update", ( assert ) => {
  30629. assert.ok( false, "everything's gonna be alright" );
  30630. } );
  30631. } );
  30632. } );
  30633. /**
  30634. * @author Sean Griffin / http://twitter.com/sgrif
  30635. * @author Michael Guerrero / http://realitymeltdown.com
  30636. * @author mrdoob / http://mrdoob.com/
  30637. * @author ikerr / http://verold.com
  30638. * @author Mugen87 / https://github.com/Mugen87
  30639. */
  30640. function getBoneList( object ) {
  30641. var boneList = [];
  30642. if ( object && object.isBone ) {
  30643. boneList.push( object );
  30644. }
  30645. for ( var i = 0; i < object.children.length; i ++ ) {
  30646. boneList.push.apply( boneList, getBoneList( object.children[ i ] ) );
  30647. }
  30648. return boneList;
  30649. }
  30650. function SkeletonHelper( object ) {
  30651. var bones = getBoneList( object );
  30652. var geometry = new BufferGeometry();
  30653. var vertices = [];
  30654. var colors = [];
  30655. var color1 = new Color( 0, 0, 1 );
  30656. var color2 = new Color( 0, 1, 0 );
  30657. for ( var i = 0; i < bones.length; i ++ ) {
  30658. var bone = bones[ i ];
  30659. if ( bone.parent && bone.parent.isBone ) {
  30660. vertices.push( 0, 0, 0 );
  30661. vertices.push( 0, 0, 0 );
  30662. colors.push( color1.r, color1.g, color1.b );
  30663. colors.push( color2.r, color2.g, color2.b );
  30664. }
  30665. }
  30666. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  30667. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  30668. var material = new LineBasicMaterial( { vertexColors: VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  30669. LineSegments.call( this, geometry, material );
  30670. this.root = object;
  30671. this.bones = bones;
  30672. this.matrix = object.matrixWorld;
  30673. this.matrixAutoUpdate = false;
  30674. }
  30675. SkeletonHelper.prototype = Object.create( LineSegments.prototype );
  30676. SkeletonHelper.prototype.constructor = SkeletonHelper;
  30677. SkeletonHelper.prototype.updateMatrixWorld = function () {
  30678. var vector = new Vector3();
  30679. var boneMatrix = new Matrix4();
  30680. var matrixWorldInv = new Matrix4();
  30681. return function updateMatrixWorld( force ) {
  30682. var bones = this.bones;
  30683. var geometry = this.geometry;
  30684. var position = geometry.getAttribute( 'position' );
  30685. matrixWorldInv.getInverse( this.root.matrixWorld );
  30686. for ( var i = 0, j = 0; i < bones.length; i ++ ) {
  30687. var bone = bones[ i ];
  30688. if ( bone.parent && bone.parent.isBone ) {
  30689. boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
  30690. vector.setFromMatrixPosition( boneMatrix );
  30691. position.setXYZ( j, vector.x, vector.y, vector.z );
  30692. boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
  30693. vector.setFromMatrixPosition( boneMatrix );
  30694. position.setXYZ( j + 1, vector.x, vector.y, vector.z );
  30695. j += 2;
  30696. }
  30697. }
  30698. geometry.getAttribute( 'position' ).needsUpdate = true;
  30699. Object3D.prototype.updateMatrixWorld.call( this, force );
  30700. };
  30701. }();
  30702. /**
  30703. * @author TristanVALCKE / https://github.com/Itee
  30704. */
  30705. /* global QUnit */
  30706. QUnit.module( 'Helpers', () => {
  30707. QUnit.module.todo( 'SkeletonHelper', () => {
  30708. // INHERITANCE
  30709. QUnit.test( "Extending", ( assert ) => {
  30710. assert.ok( false, "everything's gonna be alright" );
  30711. } );
  30712. // INSTANCING
  30713. QUnit.test( "Instancing", ( assert ) => {
  30714. assert.ok( false, "everything's gonna be alright" );
  30715. } );
  30716. // PUBLIC STUFF
  30717. QUnit.test( "updateMatrixWorld", ( assert ) => {
  30718. assert.ok( false, "everything's gonna be alright" );
  30719. } );
  30720. } );
  30721. } );
  30722. /**
  30723. * @author alteredq / http://alteredqualia.com/
  30724. * @author mrdoob / http://mrdoob.com/
  30725. * @author WestLangley / http://github.com/WestLangley
  30726. */
  30727. /**
  30728. * @author TristanVALCKE / https://github.com/Itee
  30729. */
  30730. /* global QUnit */
  30731. QUnit.module( 'Helpers', () => {
  30732. QUnit.module.todo( 'SpotLightHelper', () => {
  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( "dispose", ( assert ) => {
  30743. assert.ok( false, "everything's gonna be alright" );
  30744. } );
  30745. QUnit.test( "update", ( assert ) => {
  30746. assert.ok( false, "everything's gonna be alright" );
  30747. } );
  30748. } );
  30749. } );
  30750. /**
  30751. * @author mrdoob / http://mrdoob.com/
  30752. * @author WestLangley / http://github.com/WestLangley
  30753. */
  30754. function VertexNormalsHelper( object, size, hex, linewidth ) {
  30755. this.object = object;
  30756. this.size = ( size !== undefined ) ? size : 1;
  30757. var color = ( hex !== undefined ) ? hex : 0xff0000;
  30758. var width = ( linewidth !== undefined ) ? linewidth : 1;
  30759. //
  30760. var nNormals = 0;
  30761. var objGeometry = this.object.geometry;
  30762. if ( objGeometry && objGeometry.isGeometry ) {
  30763. nNormals = objGeometry.faces.length * 3;
  30764. } else if ( objGeometry && objGeometry.isBufferGeometry ) {
  30765. nNormals = objGeometry.attributes.normal.count;
  30766. }
  30767. //
  30768. var geometry = new BufferGeometry();
  30769. var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
  30770. geometry.addAttribute( 'position', positions );
  30771. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
  30772. //
  30773. this.matrixAutoUpdate = false;
  30774. this.update();
  30775. }
  30776. VertexNormalsHelper.prototype = Object.create( LineSegments.prototype );
  30777. VertexNormalsHelper.prototype.constructor = VertexNormalsHelper;
  30778. VertexNormalsHelper.prototype.update = ( function () {
  30779. var v1 = new Vector3();
  30780. var v2 = new Vector3();
  30781. var normalMatrix = new Matrix3();
  30782. return function update() {
  30783. var keys = [ 'a', 'b', 'c' ];
  30784. this.object.updateMatrixWorld( true );
  30785. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  30786. var matrixWorld = this.object.matrixWorld;
  30787. var position = this.geometry.attributes.position;
  30788. //
  30789. var objGeometry = this.object.geometry;
  30790. if ( objGeometry && objGeometry.isGeometry ) {
  30791. var vertices = objGeometry.vertices;
  30792. var faces = objGeometry.faces;
  30793. var idx = 0;
  30794. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  30795. var face = faces[ i ];
  30796. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  30797. var vertex = vertices[ face[ keys[ j ] ] ];
  30798. var normal = face.vertexNormals[ j ];
  30799. v1.copy( vertex ).applyMatrix4( matrixWorld );
  30800. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  30801. position.setXYZ( idx, v1.x, v1.y, v1.z );
  30802. idx = idx + 1;
  30803. position.setXYZ( idx, v2.x, v2.y, v2.z );
  30804. idx = idx + 1;
  30805. }
  30806. }
  30807. } else if ( objGeometry && objGeometry.isBufferGeometry ) {
  30808. var objPos = objGeometry.attributes.position;
  30809. var objNorm = objGeometry.attributes.normal;
  30810. var idx = 0;
  30811. // for simplicity, ignore index and drawcalls, and render every normal
  30812. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  30813. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  30814. v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  30815. v2.applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  30816. position.setXYZ( idx, v1.x, v1.y, v1.z );
  30817. idx = idx + 1;
  30818. position.setXYZ( idx, v2.x, v2.y, v2.z );
  30819. idx = idx + 1;
  30820. }
  30821. }
  30822. position.needsUpdate = true;
  30823. };
  30824. }() );
  30825. /**
  30826. * @author TristanVALCKE / https://github.com/Itee
  30827. */
  30828. /* global QUnit */
  30829. QUnit.module( 'Helpers', () => {
  30830. QUnit.module.todo( 'VertexNormalsHelper', () => {
  30831. // INHERITANCE
  30832. QUnit.test( "Extending", ( assert ) => {
  30833. assert.ok( false, "everything's gonna be alright" );
  30834. } );
  30835. // INSTANCING
  30836. QUnit.test( "Instancing", ( assert ) => {
  30837. assert.ok( false, "everything's gonna be alright" );
  30838. } );
  30839. // PUBLIC STUFF
  30840. QUnit.test( "update", ( assert ) => {
  30841. assert.ok( false, "everything's gonna be alright" );
  30842. } );
  30843. } );
  30844. } );
  30845. /**
  30846. * @author mrdoob / http://mrdoob.com/
  30847. * @author alteredq / http://alteredqualia.com/
  30848. */
  30849. function Light( color, intensity ) {
  30850. Object3D.call( this );
  30851. this.type = 'Light';
  30852. this.color = new Color( color );
  30853. this.intensity = intensity !== undefined ? intensity : 1;
  30854. this.receiveShadow = undefined;
  30855. }
  30856. Light.prototype = Object.assign( Object.create( Object3D.prototype ), {
  30857. constructor: Light,
  30858. isLight: true,
  30859. copy: function ( source ) {
  30860. Object3D.prototype.copy.call( this, source );
  30861. this.color.copy( source.color );
  30862. this.intensity = source.intensity;
  30863. return this;
  30864. },
  30865. toJSON: function ( meta ) {
  30866. var data = Object3D.prototype.toJSON.call( this, meta );
  30867. data.object.color = this.color.getHex();
  30868. data.object.intensity = this.intensity;
  30869. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  30870. if ( this.distance !== undefined ) data.object.distance = this.distance;
  30871. if ( this.angle !== undefined ) data.object.angle = this.angle;
  30872. if ( this.decay !== undefined ) data.object.decay = this.decay;
  30873. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  30874. if ( this.shadow !== undefined ) data.object.shadow = this.shadow.toJSON();
  30875. return data;
  30876. }
  30877. } );
  30878. /**
  30879. * @author mrdoob / http://mrdoob.com/
  30880. */
  30881. function AmbientLight( color, intensity ) {
  30882. Light.call( this, color, intensity );
  30883. this.type = 'AmbientLight';
  30884. this.castShadow = undefined;
  30885. }
  30886. AmbientLight.prototype = Object.assign( Object.create( Light.prototype ), {
  30887. constructor: AmbientLight,
  30888. isAmbientLight: true
  30889. } );
  30890. /**
  30891. * @author TristanVALCKE / https://github.com/Itee
  30892. * @author moraxy / https://github.com/moraxy
  30893. */
  30894. /* global QUnit */
  30895. QUnit.module( 'Lights', () => {
  30896. QUnit.module.todo( 'ArrowHelper', ( hooks ) => {
  30897. var lights = undefined;
  30898. hooks.beforeEach( function () {
  30899. const parameters = {
  30900. color: 0xaaaaaa,
  30901. intensity: 0.5
  30902. };
  30903. lights = [
  30904. new AmbientLight(),
  30905. new AmbientLight( parameters.color ),
  30906. new AmbientLight( parameters.color, parameters.intensity )
  30907. ];
  30908. } );
  30909. // INHERITANCE
  30910. QUnit.test( "Extending", ( assert ) => {
  30911. assert.ok( false, "everything's gonna be alright" );
  30912. } );
  30913. // INSTANCING
  30914. QUnit.test( "Instancing", ( assert ) => {
  30915. assert.ok( false, "everything's gonna be alright" );
  30916. } );
  30917. // PUBLIC STUFF
  30918. QUnit.test( "isAmbiantLight", ( assert ) => {
  30919. assert.ok( false, "everything's gonna be alright" );
  30920. } );
  30921. // OTHERS
  30922. QUnit.test( 'Standard light tests', ( assert ) => {
  30923. runStdLightTests( assert, lights );
  30924. } );
  30925. } );
  30926. } );
  30927. /**
  30928. * @author mrdoob / http://mrdoob.com/
  30929. */
  30930. function LightShadow( camera ) {
  30931. this.camera = camera;
  30932. this.bias = 0;
  30933. this.radius = 1;
  30934. this.mapSize = new Vector2( 512, 512 );
  30935. this.map = null;
  30936. this.matrix = new Matrix4();
  30937. }
  30938. Object.assign( LightShadow.prototype, {
  30939. copy: function ( source ) {
  30940. this.camera = source.camera.clone();
  30941. this.bias = source.bias;
  30942. this.radius = source.radius;
  30943. this.mapSize.copy( source.mapSize );
  30944. return this;
  30945. },
  30946. clone: function () {
  30947. return new this.constructor().copy( this );
  30948. },
  30949. toJSON: function () {
  30950. var object = {};
  30951. if ( this.bias !== 0 ) object.bias = this.bias;
  30952. if ( this.radius !== 1 ) object.radius = this.radius;
  30953. if ( this.mapSize.x !== 512 || this.mapSize.y !== 512 ) object.mapSize = this.mapSize.toArray();
  30954. object.camera = this.camera.toJSON( false ).object;
  30955. delete object.camera.matrix;
  30956. return object;
  30957. }
  30958. } );
  30959. /**
  30960. * @author mrdoob / http://mrdoob.com/
  30961. */
  30962. function DirectionalLightShadow( ) {
  30963. LightShadow.call( this, new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  30964. }
  30965. DirectionalLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  30966. constructor: DirectionalLightShadow
  30967. } );
  30968. /**
  30969. * @author mrdoob / http://mrdoob.com/
  30970. * @author alteredq / http://alteredqualia.com/
  30971. */
  30972. function DirectionalLight$1( color, intensity ) {
  30973. Light.call( this, color, intensity );
  30974. this.type = 'DirectionalLight';
  30975. this.position.copy( Object3D.DefaultUp );
  30976. this.updateMatrix();
  30977. this.target = new Object3D();
  30978. this.shadow = new DirectionalLightShadow();
  30979. }
  30980. DirectionalLight$1.prototype = Object.assign( Object.create( Light.prototype ), {
  30981. constructor: DirectionalLight$1,
  30982. isDirectionalLight: true,
  30983. copy: function ( source ) {
  30984. Light.prototype.copy.call( this, source );
  30985. this.target = source.target.clone();
  30986. this.shadow = source.shadow.clone();
  30987. return this;
  30988. }
  30989. } );
  30990. /**
  30991. * @author TristanVALCKE / https://github.com/Itee
  30992. * @author moraxy / https://github.com/moraxy
  30993. */
  30994. /* global QUnit */
  30995. QUnit.module( 'Lights', () => {
  30996. QUnit.module.todo( 'DirectionalLight', ( hooks ) => {
  30997. var lights = undefined;
  30998. hooks.beforeEach( function () {
  30999. const parameters = {
  31000. color: 0xaaaaaa,
  31001. intensity: 0.8
  31002. };
  31003. lights = [
  31004. new DirectionalLight$1(),
  31005. new DirectionalLight$1( parameters.color ),
  31006. new DirectionalLight$1( parameters.color, parameters.intensity )
  31007. ];
  31008. } );
  31009. // INHERITANCE
  31010. QUnit.test( "Extending", ( assert ) => {
  31011. assert.ok( false, "everything's gonna be alright" );
  31012. } );
  31013. // INSTANCING
  31014. QUnit.test( "Instancing", ( assert ) => {
  31015. assert.ok( false, "everything's gonna be alright" );
  31016. } );
  31017. // PUBLIC STUFF
  31018. QUnit.test( "isDirectionalLight", ( assert ) => {
  31019. assert.ok( false, "everything's gonna be alright" );
  31020. } );
  31021. QUnit.test( "copy", ( assert ) => {
  31022. assert.ok( false, "everything's gonna be alright" );
  31023. } );
  31024. // OTHERS
  31025. QUnit.test( 'Standard light tests', ( assert ) => {
  31026. runStdLightTests( assert, lights );
  31027. } );
  31028. } );
  31029. } );
  31030. /**
  31031. * @author TristanVALCKE / https://github.com/Itee
  31032. * @author moraxy / https://github.com/moraxy
  31033. */
  31034. /* global QUnit */
  31035. QUnit.module( 'Lights', () => {
  31036. QUnit.module.todo( 'DirectionalLightShadow', () => {
  31037. // INHERITANCE
  31038. QUnit.test( "Extending", ( assert ) => {
  31039. assert.ok( false, "everything's gonna be alright" );
  31040. } );
  31041. // INSTANCING
  31042. QUnit.test( "Instancing", ( assert ) => {
  31043. assert.ok( false, "everything's gonna be alright" );
  31044. } );
  31045. // OTHERS
  31046. QUnit.test( "clone/copy", ( assert ) => {
  31047. var a = new DirectionalLightShadow();
  31048. var b = new DirectionalLightShadow();
  31049. var c;
  31050. assert.notDeepEqual( a, b, "Newly instanced shadows are not equal" );
  31051. c = a.clone();
  31052. assert.smartEqual( a, c, "Shadows are identical after clone()" );
  31053. c.mapSize.set( 1024, 1024 );
  31054. assert.notDeepEqual( a, c, "Shadows are different again after change" );
  31055. b.copy( a );
  31056. assert.smartEqual( a, b, "Shadows are identical after copy()" );
  31057. b.mapSize.set( 512, 512 );
  31058. assert.notDeepEqual( a, b, "Shadows are different again after change" );
  31059. } );
  31060. QUnit.test( "toJSON", ( assert ) => {
  31061. var light = new DirectionalLight();
  31062. var shadow = new DirectionalLightShadow();
  31063. shadow.bias = 10;
  31064. shadow.radius = 5;
  31065. shadow.mapSize.set( 1024, 1024 );
  31066. light.shadow = shadow;
  31067. var json = light.toJSON();
  31068. var newLight = new ObjectLoader().parse( json );
  31069. assert.smartEqual( newLight.shadow, light.shadow, "Reloaded shadow is identical to the original one" );
  31070. } );
  31071. } );
  31072. } );
  31073. /**
  31074. * @author alteredq / http://alteredqualia.com/
  31075. */
  31076. function HemisphereLight( skyColor, groundColor, intensity ) {
  31077. Light.call( this, skyColor, intensity );
  31078. this.type = 'HemisphereLight';
  31079. this.castShadow = undefined;
  31080. this.position.copy( Object3D.DefaultUp );
  31081. this.updateMatrix();
  31082. this.groundColor = new Color( groundColor );
  31083. }
  31084. HemisphereLight.prototype = Object.assign( Object.create( Light.prototype ), {
  31085. constructor: HemisphereLight,
  31086. isHemisphereLight: true,
  31087. copy: function ( source ) {
  31088. Light.prototype.copy.call( this, source );
  31089. this.groundColor.copy( source.groundColor );
  31090. return this;
  31091. }
  31092. } );
  31093. /**
  31094. * @author TristanVALCKE / https://github.com/Itee
  31095. * @author moraxy / https://github.com/moraxy
  31096. */
  31097. /* global QUnit */
  31098. QUnit.module( 'Lights', () => {
  31099. QUnit.module.todo( 'HemisphereLight', ( hooks ) => {
  31100. var lights = undefined;
  31101. hooks.beforeEach( function () {
  31102. const parameters = {
  31103. skyColor: 0x123456,
  31104. groundColor: 0xabc012,
  31105. intensity: 0.6
  31106. };
  31107. lights = [
  31108. new HemisphereLight(),
  31109. new HemisphereLight( parameters.skyColor ),
  31110. new HemisphereLight( parameters.skyColor, parameters.groundColor ),
  31111. new HemisphereLight( parameters.skyColor, parameters.groundColor, parameters.intensity ),
  31112. ];
  31113. } );
  31114. // INHERITANCE
  31115. QUnit.test( "Extending", ( assert ) => {
  31116. assert.ok( false, "everything's gonna be alright" );
  31117. } );
  31118. // INSTANCING
  31119. QUnit.test( "Instancing", ( assert ) => {
  31120. assert.ok( false, "everything's gonna be alright" );
  31121. } );
  31122. // PUBLIC STUFF
  31123. QUnit.test( "isHemisphereLight", ( assert ) => {
  31124. assert.ok( false, "everything's gonna be alright" );
  31125. } );
  31126. QUnit.test( "copy", ( assert ) => {
  31127. assert.ok( false, "everything's gonna be alright" );
  31128. } );
  31129. // OTHERS
  31130. QUnit.test( 'Standard light tests', ( assert ) => {
  31131. runStdLightTests( assert, lights );
  31132. } );
  31133. } );
  31134. } );
  31135. /**
  31136. * @author TristanVALCKE / https://github.com/Itee
  31137. */
  31138. /* global QUnit */
  31139. QUnit.module( 'Lights', () => {
  31140. QUnit.module.todo( 'Light', ( hooks ) => {
  31141. var lights = undefined;
  31142. hooks.beforeEach( function () {
  31143. const parameters = {
  31144. color: 0xaaaaaa,
  31145. intensity: 0.5
  31146. };
  31147. lights = [
  31148. new Light(),
  31149. new Light( parameters.color ),
  31150. new Light( parameters.color, parameters.intensity )
  31151. ];
  31152. } );
  31153. // INHERITANCE
  31154. QUnit.test( "Extending", ( assert ) => {
  31155. assert.ok( false, "everything's gonna be alright" );
  31156. } );
  31157. // INSTANCING
  31158. QUnit.test( "Instancing", ( assert ) => {
  31159. assert.ok( false, "everything's gonna be alright" );
  31160. } );
  31161. // PUBLIC STUFF
  31162. QUnit.test( "isLight", ( assert ) => {
  31163. assert.ok( false, "everything's gonna be alright" );
  31164. } );
  31165. QUnit.test( "copy", ( assert ) => {
  31166. assert.ok( false, "everything's gonna be alright" );
  31167. } );
  31168. QUnit.test( "toJSON", ( assert ) => {
  31169. assert.ok( false, "everything's gonna be alright" );
  31170. } );
  31171. // OTHERS
  31172. QUnit.test( 'Standard light tests', ( assert ) => {
  31173. runStdLightTests( assert, lights );
  31174. } );
  31175. } );
  31176. } );
  31177. /**
  31178. * @author TristanVALCKE / https://github.com/Itee
  31179. * @author moraxy / https://github.com/moraxy
  31180. */
  31181. /* global QUnit */
  31182. QUnit.module( 'Lights', () => {
  31183. QUnit.module.todo( 'LightShadow', () => {
  31184. // INSTANCING
  31185. QUnit.test( "Instancing", ( assert ) => {
  31186. assert.ok( false, "everything's gonna be alright" );
  31187. } );
  31188. // PUBLIC STUFF
  31189. QUnit.test( "clone/copy", ( assert ) => {
  31190. var a = new LightShadow( new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  31191. var b = new LightShadow( new OrthographicCamera( - 3, 3, 3, - 3, 0.3, 300 ) );
  31192. var c;
  31193. assert.notDeepEqual( a, b, "Newly instanced shadows are not equal" );
  31194. c = a.clone();
  31195. assert.smartEqual( a, c, "Shadows are identical after clone()" );
  31196. c.mapSize.set( 256, 256 );
  31197. assert.notDeepEqual( a, c, "Shadows are different again after change" );
  31198. b.copy( a );
  31199. assert.smartEqual( a, b, "Shadows are identical after copy()" );
  31200. b.mapSize.set( 512, 512 );
  31201. assert.notDeepEqual( a, b, "Shadows are different again after change" );
  31202. } );
  31203. QUnit.test( "toJSON", ( assert ) => {
  31204. assert.ok( false, "everything's gonna be alright" );
  31205. } );
  31206. } );
  31207. } );
  31208. /**
  31209. * @author mrdoob / http://mrdoob.com/
  31210. */
  31211. function PointLight( color, intensity, distance, decay ) {
  31212. Light.call( this, color, intensity );
  31213. this.type = 'PointLight';
  31214. Object.defineProperty( this, 'power', {
  31215. get: function () {
  31216. // intensity = power per solid angle.
  31217. // ref: equation (15) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  31218. return this.intensity * 4 * Math.PI;
  31219. },
  31220. set: function ( power ) {
  31221. // intensity = power per solid angle.
  31222. // ref: equation (15) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  31223. this.intensity = power / ( 4 * Math.PI );
  31224. }
  31225. } );
  31226. this.distance = ( distance !== undefined ) ? distance : 0;
  31227. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  31228. this.shadow = new LightShadow( new PerspectiveCamera( 90, 1, 0.5, 500 ) );
  31229. }
  31230. PointLight.prototype = Object.assign( Object.create( Light.prototype ), {
  31231. constructor: PointLight,
  31232. isPointLight: true,
  31233. copy: function ( source ) {
  31234. Light.prototype.copy.call( this, source );
  31235. this.distance = source.distance;
  31236. this.decay = source.decay;
  31237. this.shadow = source.shadow.clone();
  31238. return this;
  31239. }
  31240. } );
  31241. /**
  31242. * @author TristanVALCKE / https://github.com/Itee
  31243. * @author moraxy / https://github.com/moraxy
  31244. */
  31245. /* global QUnit */
  31246. QUnit.module( 'Lights', () => {
  31247. QUnit.module.todo( 'PointLight', ( hooks ) => {
  31248. var lights = undefined;
  31249. hooks.beforeEach( function () {
  31250. const parameters = {
  31251. color: 0xaaaaaa,
  31252. intensity: 0.5,
  31253. distance: 100,
  31254. decay: 2
  31255. };
  31256. lights = [
  31257. new PointLight(),
  31258. new PointLight( parameters.color ),
  31259. new PointLight( parameters.color, parameters.intensity ),
  31260. new PointLight( parameters.color, parameters.intensity, parameters.distance ),
  31261. new PointLight( parameters.color, parameters.intensity, parameters.distance, parameters.decay )
  31262. ];
  31263. } );
  31264. // INHERITANCE
  31265. QUnit.test( "Extending", ( assert ) => {
  31266. assert.ok( false, "everything's gonna be alright" );
  31267. } );
  31268. // INSTANCING
  31269. QUnit.test( "Instancing", ( assert ) => {
  31270. assert.ok( false, "everything's gonna be alright" );
  31271. } );
  31272. // PROPERTIES
  31273. QUnit.test( "power", ( assert ) => {
  31274. var a = new PointLight( 0xaaaaaa );
  31275. a.intensity = 100;
  31276. assert.numEqual( a.power, 100 * Math.PI * 4, "Correct power for an intensity of 100" );
  31277. a.intensity = 40;
  31278. assert.numEqual( a.power, 40 * Math.PI * 4, "Correct power for an intensity of 40" );
  31279. a.power = 100;
  31280. assert.numEqual( a.intensity, 100 / ( 4 * Math.PI ), "Correct intensity for a power of 100" );
  31281. } );
  31282. // PUBLIC STUFF
  31283. QUnit.test( "isPointLight", ( assert ) => {
  31284. assert.ok( false, "everything's gonna be alright" );
  31285. } );
  31286. QUnit.test( "copy", ( assert ) => {
  31287. assert.ok( false, "everything's gonna be alright" );
  31288. } );
  31289. // OTHERS
  31290. QUnit.test( 'Standard light tests', ( assert ) => {
  31291. runStdLightTests( assert, lights );
  31292. } );
  31293. } );
  31294. } );
  31295. /**
  31296. * @author abelnation / http://github.com/abelnation
  31297. */
  31298. function RectAreaLight( color, intensity, width, height ) {
  31299. Light.call( this, color, intensity );
  31300. this.type = 'RectAreaLight';
  31301. this.position.set( 0, 1, 0 );
  31302. this.updateMatrix();
  31303. this.width = ( width !== undefined ) ? width : 10;
  31304. this.height = ( height !== undefined ) ? height : 10;
  31305. // TODO (abelnation): distance/decay
  31306. // TODO (abelnation): update method for RectAreaLight to update transform to lookat target
  31307. // TODO (abelnation): shadows
  31308. }
  31309. // TODO (abelnation): RectAreaLight update when light shape is changed
  31310. RectAreaLight.prototype = Object.assign( Object.create( Light.prototype ), {
  31311. constructor: RectAreaLight,
  31312. isRectAreaLight: true,
  31313. copy: function ( source ) {
  31314. Light.prototype.copy.call( this, source );
  31315. this.width = source.width;
  31316. this.height = source.height;
  31317. return this;
  31318. },
  31319. toJSON: function ( meta ) {
  31320. var data = Light.prototype.toJSON.call( this, meta );
  31321. data.object.width = this.width;
  31322. data.object.height = this.height;
  31323. return data;
  31324. }
  31325. } );
  31326. /**
  31327. * @author TristanVALCKE / https://github.com/Itee
  31328. * @author moraxy / https://github.com/moraxy
  31329. */
  31330. /* global QUnit */
  31331. QUnit.module( 'Lights', () => {
  31332. QUnit.module.todo( 'RectAreaLight', ( hooks ) => {
  31333. var lights = undefined;
  31334. hooks.beforeEach( function () {
  31335. const parameters = {
  31336. color: 0xaaaaaa,
  31337. intensity: 0.5,
  31338. width: 100,
  31339. height: 50
  31340. };
  31341. lights = [
  31342. new RectAreaLight( parameters.color ),
  31343. new RectAreaLight( parameters.color, parameters.intensity ),
  31344. new RectAreaLight( parameters.color, parameters.intensity, parameters.width ),
  31345. new RectAreaLight( parameters.color, parameters.intensity, parameters.width, parameters.height )
  31346. ];
  31347. } );
  31348. // INHERITANCE
  31349. QUnit.test( "Extending", ( assert ) => {
  31350. assert.ok( false, "everything's gonna be alright" );
  31351. } );
  31352. // INSTANCING
  31353. QUnit.test( "Instancing", ( assert ) => {
  31354. assert.ok( false, "everything's gonna be alright" );
  31355. } );
  31356. // PUBLIC STUFF
  31357. QUnit.test( "isRectAreaLight", ( assert ) => {
  31358. assert.ok( false, "everything's gonna be alright" );
  31359. } );
  31360. QUnit.test( "copy", ( assert ) => {
  31361. assert.ok( false, "everything's gonna be alright" );
  31362. } );
  31363. QUnit.test( "toJSON", ( assert ) => {
  31364. assert.ok( false, "everything's gonna be alright" );
  31365. } );
  31366. // OTHERS
  31367. QUnit.test( 'Standard light tests', ( assert ) => {
  31368. runStdLightTests( assert, lights );
  31369. } );
  31370. } );
  31371. } );
  31372. /**
  31373. * @author mrdoob / http://mrdoob.com/
  31374. */
  31375. function SpotLightShadow() {
  31376. LightShadow.call( this, new PerspectiveCamera( 50, 1, 0.5, 500 ) );
  31377. }
  31378. SpotLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  31379. constructor: SpotLightShadow,
  31380. isSpotLightShadow: true,
  31381. update: function ( light ) {
  31382. var camera = this.camera;
  31383. var fov = _Math.RAD2DEG * 2 * light.angle;
  31384. var aspect = this.mapSize.width / this.mapSize.height;
  31385. var far = light.distance || camera.far;
  31386. if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) {
  31387. camera.fov = fov;
  31388. camera.aspect = aspect;
  31389. camera.far = far;
  31390. camera.updateProjectionMatrix();
  31391. }
  31392. }
  31393. } );
  31394. /**
  31395. * @author alteredq / http://alteredqualia.com/
  31396. */
  31397. function SpotLight( color, intensity, distance, angle, penumbra, decay ) {
  31398. Light.call( this, color, intensity );
  31399. this.type = 'SpotLight';
  31400. this.position.copy( Object3D.DefaultUp );
  31401. this.updateMatrix();
  31402. this.target = new Object3D();
  31403. Object.defineProperty( this, 'power', {
  31404. get: function () {
  31405. // intensity = power per solid angle.
  31406. // ref: equation (17) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  31407. return this.intensity * Math.PI;
  31408. },
  31409. set: function ( power ) {
  31410. // intensity = power per solid angle.
  31411. // ref: equation (17) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  31412. this.intensity = power / Math.PI;
  31413. }
  31414. } );
  31415. this.distance = ( distance !== undefined ) ? distance : 0;
  31416. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  31417. this.penumbra = ( penumbra !== undefined ) ? penumbra : 0;
  31418. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  31419. this.shadow = new SpotLightShadow();
  31420. }
  31421. SpotLight.prototype = Object.assign( Object.create( Light.prototype ), {
  31422. constructor: SpotLight,
  31423. isSpotLight: true,
  31424. copy: function ( source ) {
  31425. Light.prototype.copy.call( this, source );
  31426. this.distance = source.distance;
  31427. this.angle = source.angle;
  31428. this.penumbra = source.penumbra;
  31429. this.decay = source.decay;
  31430. this.target = source.target.clone();
  31431. this.shadow = source.shadow.clone();
  31432. return this;
  31433. }
  31434. } );
  31435. /**
  31436. * @author TristanVALCKE / https://github.com/Itee
  31437. * @author moraxy / https://github.com/moraxy
  31438. */
  31439. /* global QUnit */
  31440. QUnit.module( 'Lights', () => {
  31441. QUnit.module.todo( 'SpotLight', ( hooks ) => {
  31442. var lights = undefined;
  31443. hooks.beforeEach( function () {
  31444. const parameters = {
  31445. color: 0xaaaaaa,
  31446. intensity: 0.5,
  31447. distance: 100,
  31448. angle: 0.8,
  31449. penumbra: 8,
  31450. decay: 2
  31451. };
  31452. lights = [
  31453. new SpotLight( parameters.color ),
  31454. new SpotLight( parameters.color, parameters.intensity ),
  31455. new SpotLight( parameters.color, parameters.intensity, parameters.distance ),
  31456. new SpotLight( parameters.color, parameters.intensity, parameters.distance, parameters.angle ),
  31457. new SpotLight( parameters.color, parameters.intensity, parameters.distance, parameters.angle, parameters.penumbra ),
  31458. new SpotLight( parameters.color, parameters.intensity, parameters.distance, parameters.angle, parameters.penumbra, parameters.decay ),
  31459. ];
  31460. } );
  31461. // INHERITANCE
  31462. QUnit.test( "Extending", ( assert ) => {
  31463. assert.ok( false, "everything's gonna be alright" );
  31464. } );
  31465. // INSTANCING
  31466. QUnit.test( "Instancing", ( assert ) => {
  31467. assert.ok( false, "everything's gonna be alright" );
  31468. } );
  31469. // PROPERTIES
  31470. QUnit.test( "power", ( assert ) => {
  31471. var a = new SpotLight( 0xaaaaaa );
  31472. a.intensity = 100;
  31473. assert.numEqual( a.power, 100 * Math.PI, "Correct power for an intensity of 100" );
  31474. a.intensity = 40;
  31475. assert.numEqual( a.power, 40 * Math.PI, "Correct power for an intensity of 40" );
  31476. a.power = 100;
  31477. assert.numEqual( a.intensity, 100 / Math.PI, "Correct intensity for a power of 100" );
  31478. } );
  31479. // PUBLIC STUFF
  31480. QUnit.test( "isSpotLight", ( assert ) => {
  31481. assert.ok( false, "everything's gonna be alright" );
  31482. } );
  31483. QUnit.test( "copy", ( assert ) => {
  31484. assert.ok( false, "everything's gonna be alright" );
  31485. } );
  31486. // OTHERS
  31487. QUnit.test( 'Standard light tests', ( assert ) => {
  31488. runStdLightTests( assert, lights );
  31489. } );
  31490. } );
  31491. } );
  31492. /**
  31493. * @author mikael emtinger / http://gomo.se/
  31494. * @author alteredq / http://alteredqualia.com/
  31495. */
  31496. function Sprite( material ) {
  31497. Object3D.call( this );
  31498. this.type = 'Sprite';
  31499. this.material = ( material !== undefined ) ? material : new SpriteMaterial();
  31500. }
  31501. Sprite.prototype = Object.assign( Object.create( Object3D.prototype ), {
  31502. constructor: Sprite,
  31503. isSprite: true,
  31504. raycast: ( function () {
  31505. var intersectPoint = new Vector3();
  31506. var worldPosition = new Vector3();
  31507. var worldScale = new Vector3();
  31508. return function raycast( raycaster, intersects ) {
  31509. worldPosition.setFromMatrixPosition( this.matrixWorld );
  31510. raycaster.ray.closestPointToPoint( worldPosition, intersectPoint );
  31511. worldScale.setFromMatrixScale( this.matrixWorld );
  31512. var guessSizeSq = worldScale.x * worldScale.y / 4;
  31513. if ( worldPosition.distanceToSquared( intersectPoint ) > guessSizeSq ) return;
  31514. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  31515. if ( distance < raycaster.near || distance > raycaster.far ) return;
  31516. intersects.push( {
  31517. distance: distance,
  31518. point: intersectPoint.clone(),
  31519. face: null,
  31520. object: this
  31521. } );
  31522. };
  31523. }() ),
  31524. clone: function () {
  31525. return new this.constructor( this.material ).copy( this );
  31526. }
  31527. } );
  31528. /**
  31529. * @author alteredq / http://alteredqualia.com/
  31530. */
  31531. function Points( geometry, material ) {
  31532. Object3D.call( this );
  31533. this.type = 'Points';
  31534. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  31535. this.material = material !== undefined ? material : new PointsMaterial( { color: Math.random() * 0xffffff } );
  31536. }
  31537. Points.prototype = Object.assign( Object.create( Object3D.prototype ), {
  31538. constructor: Points,
  31539. isPoints: true,
  31540. raycast: ( function () {
  31541. var inverseMatrix = new Matrix4();
  31542. var ray = new Ray();
  31543. var sphere = new Sphere();
  31544. return function raycast( raycaster, intersects ) {
  31545. var object = this;
  31546. var geometry = this.geometry;
  31547. var matrixWorld = this.matrixWorld;
  31548. var threshold = raycaster.params.Points.threshold;
  31549. // Checking boundingSphere distance to ray
  31550. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  31551. sphere.copy( geometry.boundingSphere );
  31552. sphere.applyMatrix4( matrixWorld );
  31553. sphere.radius += threshold;
  31554. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  31555. //
  31556. inverseMatrix.getInverse( matrixWorld );
  31557. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  31558. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  31559. var localThresholdSq = localThreshold * localThreshold;
  31560. var position = new Vector3();
  31561. function testPoint( point, index ) {
  31562. var rayPointDistanceSq = ray.distanceSqToPoint( point );
  31563. if ( rayPointDistanceSq < localThresholdSq ) {
  31564. var intersectPoint = ray.closestPointToPoint( point );
  31565. intersectPoint.applyMatrix4( matrixWorld );
  31566. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  31567. if ( distance < raycaster.near || distance > raycaster.far ) return;
  31568. intersects.push( {
  31569. distance: distance,
  31570. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  31571. point: intersectPoint.clone(),
  31572. index: index,
  31573. face: null,
  31574. object: object
  31575. } );
  31576. }
  31577. }
  31578. if ( geometry.isBufferGeometry ) {
  31579. var index = geometry.index;
  31580. var attributes = geometry.attributes;
  31581. var positions = attributes.position.array;
  31582. if ( index !== null ) {
  31583. var indices = index.array;
  31584. for ( var i = 0, il = indices.length; i < il; i ++ ) {
  31585. var a = indices[ i ];
  31586. position.fromArray( positions, a * 3 );
  31587. testPoint( position, a );
  31588. }
  31589. } else {
  31590. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  31591. position.fromArray( positions, i * 3 );
  31592. testPoint( position, i );
  31593. }
  31594. }
  31595. } else {
  31596. var vertices = geometry.vertices;
  31597. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  31598. testPoint( vertices[ i ], i );
  31599. }
  31600. }
  31601. };
  31602. }() ),
  31603. clone: function () {
  31604. return new this.constructor( this.geometry, this.material ).copy( this );
  31605. }
  31606. } );
  31607. /**
  31608. * @author mgreter / http://github.com/mgreter
  31609. */
  31610. function LineLoop( geometry, material ) {
  31611. Line.call( this, geometry, material );
  31612. this.type = 'LineLoop';
  31613. }
  31614. LineLoop.prototype = Object.assign( Object.create( Line.prototype ), {
  31615. constructor: LineLoop,
  31616. isLineLoop: true,
  31617. } );
  31618. /**
  31619. * @author mikael emtinger / http://gomo.se/
  31620. * @author alteredq / http://alteredqualia.com/
  31621. * @author mrdoob / http://mrdoob.com/
  31622. */
  31623. function LOD() {
  31624. Object3D.call( this );
  31625. this.type = 'LOD';
  31626. Object.defineProperties( this, {
  31627. levels: {
  31628. enumerable: true,
  31629. value: []
  31630. }
  31631. } );
  31632. }
  31633. LOD.prototype = Object.assign( Object.create( Object3D.prototype ), {
  31634. constructor: LOD,
  31635. copy: function ( source ) {
  31636. Object3D.prototype.copy.call( this, source, false );
  31637. var levels = source.levels;
  31638. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  31639. var level = levels[ i ];
  31640. this.addLevel( level.object.clone(), level.distance );
  31641. }
  31642. return this;
  31643. },
  31644. addLevel: function ( object, distance ) {
  31645. if ( distance === undefined ) distance = 0;
  31646. distance = Math.abs( distance );
  31647. var levels = this.levels;
  31648. for ( var l = 0; l < levels.length; l ++ ) {
  31649. if ( distance < levels[ l ].distance ) {
  31650. break;
  31651. }
  31652. }
  31653. levels.splice( l, 0, { distance: distance, object: object } );
  31654. this.add( object );
  31655. },
  31656. getObjectForDistance: function ( distance ) {
  31657. var levels = this.levels;
  31658. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  31659. if ( distance < levels[ i ].distance ) {
  31660. break;
  31661. }
  31662. }
  31663. return levels[ i - 1 ].object;
  31664. },
  31665. raycast: ( function () {
  31666. var matrixPosition = new Vector3();
  31667. return function raycast( raycaster, intersects ) {
  31668. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  31669. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  31670. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  31671. };
  31672. }() ),
  31673. update: function () {
  31674. var v1 = new Vector3();
  31675. var v2 = new Vector3();
  31676. return function update( camera ) {
  31677. var levels = this.levels;
  31678. if ( levels.length > 1 ) {
  31679. v1.setFromMatrixPosition( camera.matrixWorld );
  31680. v2.setFromMatrixPosition( this.matrixWorld );
  31681. var distance = v1.distanceTo( v2 );
  31682. levels[ 0 ].object.visible = true;
  31683. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  31684. if ( distance >= levels[ i ].distance ) {
  31685. levels[ i - 1 ].object.visible = false;
  31686. levels[ i ].object.visible = true;
  31687. } else {
  31688. break;
  31689. }
  31690. }
  31691. for ( ; i < l; i ++ ) {
  31692. levels[ i ].object.visible = false;
  31693. }
  31694. }
  31695. };
  31696. }(),
  31697. toJSON: function ( meta ) {
  31698. var data = Object3D.prototype.toJSON.call( this, meta );
  31699. data.object.levels = [];
  31700. var levels = this.levels;
  31701. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  31702. var level = levels[ i ];
  31703. data.object.levels.push( {
  31704. object: level.object.uuid,
  31705. distance: level.distance
  31706. } );
  31707. }
  31708. return data;
  31709. }
  31710. } );
  31711. /**
  31712. * @author mikael emtinger / http://gomo.se/
  31713. * @author alteredq / http://alteredqualia.com/
  31714. * @author michael guerrero / http://realitymeltdown.com
  31715. * @author ikerr / http://verold.com
  31716. */
  31717. function Skeleton( bones, boneInverses ) {
  31718. // copy the bone array
  31719. bones = bones || [];
  31720. this.bones = bones.slice( 0 );
  31721. this.boneMatrices = new Float32Array( this.bones.length * 16 );
  31722. // use the supplied bone inverses or calculate the inverses
  31723. if ( boneInverses === undefined ) {
  31724. this.calculateInverses();
  31725. } else {
  31726. if ( this.bones.length === boneInverses.length ) {
  31727. this.boneInverses = boneInverses.slice( 0 );
  31728. } else {
  31729. console.warn( 'THREE.Skeleton boneInverses is the wrong length.' );
  31730. this.boneInverses = [];
  31731. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  31732. this.boneInverses.push( new Matrix4() );
  31733. }
  31734. }
  31735. }
  31736. }
  31737. Object.assign( Skeleton.prototype, {
  31738. calculateInverses: function () {
  31739. this.boneInverses = [];
  31740. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  31741. var inverse = new Matrix4();
  31742. if ( this.bones[ i ] ) {
  31743. inverse.getInverse( this.bones[ i ].matrixWorld );
  31744. }
  31745. this.boneInverses.push( inverse );
  31746. }
  31747. },
  31748. pose: function () {
  31749. var bone, i, il;
  31750. // recover the bind-time world matrices
  31751. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  31752. bone = this.bones[ i ];
  31753. if ( bone ) {
  31754. bone.matrixWorld.getInverse( this.boneInverses[ i ] );
  31755. }
  31756. }
  31757. // compute the local matrices, positions, rotations and scales
  31758. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  31759. bone = this.bones[ i ];
  31760. if ( bone ) {
  31761. if ( bone.parent && bone.parent.isBone ) {
  31762. bone.matrix.getInverse( bone.parent.matrixWorld );
  31763. bone.matrix.multiply( bone.matrixWorld );
  31764. } else {
  31765. bone.matrix.copy( bone.matrixWorld );
  31766. }
  31767. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  31768. }
  31769. }
  31770. },
  31771. update: ( function () {
  31772. var offsetMatrix = new Matrix4();
  31773. var identityMatrix = new Matrix4();
  31774. return function update() {
  31775. var bones = this.bones;
  31776. var boneInverses = this.boneInverses;
  31777. var boneMatrices = this.boneMatrices;
  31778. var boneTexture = this.boneTexture;
  31779. // flatten bone matrices to array
  31780. for ( var i = 0, il = bones.length; i < il; i ++ ) {
  31781. // compute the offset between the current and the original transform
  31782. var matrix = bones[ i ] ? bones[ i ].matrixWorld : identityMatrix;
  31783. offsetMatrix.multiplyMatrices( matrix, boneInverses[ i ] );
  31784. offsetMatrix.toArray( boneMatrices, i * 16 );
  31785. }
  31786. if ( boneTexture !== undefined ) {
  31787. boneTexture.needsUpdate = true;
  31788. }
  31789. };
  31790. } )(),
  31791. clone: function () {
  31792. return new Skeleton( this.bones, this.boneInverses );
  31793. }
  31794. } );
  31795. /**
  31796. * @author mikael emtinger / http://gomo.se/
  31797. * @author alteredq / http://alteredqualia.com/
  31798. * @author ikerr / http://verold.com
  31799. */
  31800. function Bone() {
  31801. Object3D.call( this );
  31802. this.type = 'Bone';
  31803. }
  31804. Bone.prototype = Object.assign( Object.create( Object3D.prototype ), {
  31805. constructor: Bone,
  31806. isBone: true
  31807. } );
  31808. /**
  31809. * @author mikael emtinger / http://gomo.se/
  31810. * @author alteredq / http://alteredqualia.com/
  31811. * @author ikerr / http://verold.com
  31812. */
  31813. function SkinnedMesh( geometry, material ) {
  31814. Mesh.call( this, geometry, material );
  31815. this.type = 'SkinnedMesh';
  31816. this.bindMode = 'attached';
  31817. this.bindMatrix = new Matrix4();
  31818. this.bindMatrixInverse = new Matrix4();
  31819. var bones = this.initBones();
  31820. var skeleton = new Skeleton( bones );
  31821. this.bind( skeleton, this.matrixWorld );
  31822. this.normalizeSkinWeights();
  31823. }
  31824. SkinnedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
  31825. constructor: SkinnedMesh,
  31826. isSkinnedMesh: true,
  31827. initBones: function () {
  31828. var bones = [], bone, gbone;
  31829. var i, il;
  31830. if ( this.geometry && this.geometry.bones !== undefined ) {
  31831. // first, create array of 'Bone' objects from geometry data
  31832. for ( i = 0, il = this.geometry.bones.length; i < il; i ++ ) {
  31833. gbone = this.geometry.bones[ i ];
  31834. // create new 'Bone' object
  31835. bone = new Bone();
  31836. bones.push( bone );
  31837. // apply values
  31838. bone.name = gbone.name;
  31839. bone.position.fromArray( gbone.pos );
  31840. bone.quaternion.fromArray( gbone.rotq );
  31841. if ( gbone.scl !== undefined ) bone.scale.fromArray( gbone.scl );
  31842. }
  31843. // second, create bone hierarchy
  31844. for ( i = 0, il = this.geometry.bones.length; i < il; i ++ ) {
  31845. gbone = this.geometry.bones[ i ];
  31846. if ( ( gbone.parent !== - 1 ) && ( gbone.parent !== null ) && ( bones[ gbone.parent ] !== undefined ) ) {
  31847. // subsequent bones in the hierarchy
  31848. bones[ gbone.parent ].add( bones[ i ] );
  31849. } else {
  31850. // topmost bone, immediate child of the skinned mesh
  31851. this.add( bones[ i ] );
  31852. }
  31853. }
  31854. }
  31855. // now the bones are part of the scene graph and children of the skinned mesh.
  31856. // let's update the corresponding matrices
  31857. this.updateMatrixWorld( true );
  31858. return bones;
  31859. },
  31860. bind: function ( skeleton, bindMatrix ) {
  31861. this.skeleton = skeleton;
  31862. if ( bindMatrix === undefined ) {
  31863. this.updateMatrixWorld( true );
  31864. this.skeleton.calculateInverses();
  31865. bindMatrix = this.matrixWorld;
  31866. }
  31867. this.bindMatrix.copy( bindMatrix );
  31868. this.bindMatrixInverse.getInverse( bindMatrix );
  31869. },
  31870. pose: function () {
  31871. this.skeleton.pose();
  31872. },
  31873. normalizeSkinWeights: function () {
  31874. var scale, i;
  31875. if ( this.geometry && this.geometry.isGeometry ) {
  31876. for ( i = 0; i < this.geometry.skinWeights.length; i ++ ) {
  31877. var sw = this.geometry.skinWeights[ i ];
  31878. scale = 1.0 / sw.manhattanLength();
  31879. if ( scale !== Infinity ) {
  31880. sw.multiplyScalar( scale );
  31881. } else {
  31882. sw.set( 1, 0, 0, 0 ); // do something reasonable
  31883. }
  31884. }
  31885. } else if ( this.geometry && this.geometry.isBufferGeometry ) {
  31886. var vec = new Vector4();
  31887. var skinWeight = this.geometry.attributes.skinWeight;
  31888. for ( i = 0; i < skinWeight.count; i ++ ) {
  31889. vec.x = skinWeight.getX( i );
  31890. vec.y = skinWeight.getY( i );
  31891. vec.z = skinWeight.getZ( i );
  31892. vec.w = skinWeight.getW( i );
  31893. scale = 1.0 / vec.manhattanLength();
  31894. if ( scale !== Infinity ) {
  31895. vec.multiplyScalar( scale );
  31896. } else {
  31897. vec.set( 1, 0, 0, 0 ); // do something reasonable
  31898. }
  31899. skinWeight.setXYZW( i, vec.x, vec.y, vec.z, vec.w );
  31900. }
  31901. }
  31902. },
  31903. updateMatrixWorld: function ( force ) {
  31904. Mesh.prototype.updateMatrixWorld.call( this, force );
  31905. if ( this.bindMode === 'attached' ) {
  31906. this.bindMatrixInverse.getInverse( this.matrixWorld );
  31907. } else if ( this.bindMode === 'detached' ) {
  31908. this.bindMatrixInverse.getInverse( this.bindMatrix );
  31909. } else {
  31910. console.warn( 'THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode );
  31911. }
  31912. },
  31913. clone: function () {
  31914. return new this.constructor( this.geometry, this.material ).copy( this );
  31915. }
  31916. } );
  31917. /**
  31918. * @author mrdoob / http://mrdoob.com/
  31919. * @author alteredq / http://alteredqualia.com/
  31920. */
  31921. function Fog( color, near, far ) {
  31922. this.name = '';
  31923. this.color = new Color( color );
  31924. this.near = ( near !== undefined ) ? near : 1;
  31925. this.far = ( far !== undefined ) ? far : 1000;
  31926. }
  31927. Fog.prototype.isFog = true;
  31928. Fog.prototype.clone = function () {
  31929. return new Fog( this.color.getHex(), this.near, this.far );
  31930. };
  31931. Fog.prototype.toJSON = function ( /* meta */ ) {
  31932. return {
  31933. type: 'Fog',
  31934. color: this.color.getHex(),
  31935. near: this.near,
  31936. far: this.far
  31937. };
  31938. };
  31939. /**
  31940. * @author mrdoob / http://mrdoob.com/
  31941. * @author alteredq / http://alteredqualia.com/
  31942. */
  31943. function FogExp2( color, density ) {
  31944. this.name = '';
  31945. this.color = new Color( color );
  31946. this.density = ( density !== undefined ) ? density : 0.00025;
  31947. }
  31948. FogExp2.prototype.isFogExp2 = true;
  31949. FogExp2.prototype.clone = function () {
  31950. return new FogExp2( this.color.getHex(), this.density );
  31951. };
  31952. FogExp2.prototype.toJSON = function ( /* meta */ ) {
  31953. return {
  31954. type: 'FogExp2',
  31955. color: this.color.getHex(),
  31956. density: this.density
  31957. };
  31958. };
  31959. /**
  31960. * @author mrdoob / http://mrdoob.com/
  31961. */
  31962. function BufferGeometryLoader( manager ) {
  31963. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  31964. }
  31965. Object.assign( BufferGeometryLoader.prototype, {
  31966. load: function ( url, onLoad, onProgress, onError ) {
  31967. var scope = this;
  31968. var loader = new FileLoader( scope.manager );
  31969. loader.load( url, function ( text ) {
  31970. onLoad( scope.parse( JSON.parse( text ) ) );
  31971. }, onProgress, onError );
  31972. },
  31973. parse: function ( json ) {
  31974. var geometry = new BufferGeometry();
  31975. var index = json.data.index;
  31976. if ( index !== undefined ) {
  31977. var typedArray = new TYPED_ARRAYS[ index.type ]( index.array );
  31978. geometry.setIndex( new BufferAttribute( typedArray, 1 ) );
  31979. }
  31980. var attributes = json.data.attributes;
  31981. for ( var key in attributes ) {
  31982. var attribute = attributes[ key ];
  31983. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  31984. geometry.addAttribute( key, new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized ) );
  31985. }
  31986. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  31987. if ( groups !== undefined ) {
  31988. for ( var i = 0, n = groups.length; i !== n; ++ i ) {
  31989. var group = groups[ i ];
  31990. geometry.addGroup( group.start, group.count, group.materialIndex );
  31991. }
  31992. }
  31993. var boundingSphere = json.data.boundingSphere;
  31994. if ( boundingSphere !== undefined ) {
  31995. var center = new Vector3();
  31996. if ( boundingSphere.center !== undefined ) {
  31997. center.fromArray( boundingSphere.center );
  31998. }
  31999. geometry.boundingSphere = new Sphere( center, boundingSphere.radius );
  32000. }
  32001. return geometry;
  32002. }
  32003. } );
  32004. var TYPED_ARRAYS = {
  32005. Int8Array: Int8Array,
  32006. Uint8Array: Uint8Array,
  32007. // Workaround for IE11 pre KB2929437. See #11440
  32008. Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
  32009. Int16Array: Int16Array,
  32010. Uint16Array: Uint16Array,
  32011. Int32Array: Int32Array,
  32012. Uint32Array: Uint32Array,
  32013. Float32Array: Float32Array,
  32014. Float64Array: Float64Array
  32015. };
  32016. var Geometries = Object.freeze({
  32017. WireframeGeometry: WireframeGeometry,
  32018. ParametricGeometry: ParametricGeometry,
  32019. ParametricBufferGeometry: ParametricBufferGeometry,
  32020. TetrahedronGeometry: TetrahedronGeometry,
  32021. TetrahedronBufferGeometry: TetrahedronBufferGeometry,
  32022. OctahedronGeometry: OctahedronGeometry,
  32023. OctahedronBufferGeometry: OctahedronBufferGeometry,
  32024. IcosahedronGeometry: IcosahedronGeometry,
  32025. IcosahedronBufferGeometry: IcosahedronBufferGeometry,
  32026. DodecahedronGeometry: DodecahedronGeometry,
  32027. DodecahedronBufferGeometry: DodecahedronBufferGeometry,
  32028. PolyhedronGeometry: PolyhedronGeometry,
  32029. PolyhedronBufferGeometry: PolyhedronBufferGeometry,
  32030. TubeGeometry: TubeGeometry,
  32031. TubeBufferGeometry: TubeBufferGeometry,
  32032. TorusKnotGeometry: TorusKnotGeometry,
  32033. TorusKnotBufferGeometry: TorusKnotBufferGeometry,
  32034. TorusGeometry: TorusGeometry,
  32035. TorusBufferGeometry: TorusBufferGeometry,
  32036. TextGeometry: TextGeometry,
  32037. TextBufferGeometry: TextBufferGeometry,
  32038. SphereGeometry: SphereGeometry,
  32039. SphereBufferGeometry: SphereBufferGeometry,
  32040. RingGeometry: RingGeometry,
  32041. RingBufferGeometry: RingBufferGeometry,
  32042. PlaneGeometry: PlaneGeometry,
  32043. PlaneBufferGeometry: PlaneBufferGeometry,
  32044. LatheGeometry: LatheGeometry,
  32045. LatheBufferGeometry: LatheBufferGeometry,
  32046. ShapeGeometry: ShapeGeometry,
  32047. ShapeBufferGeometry: ShapeBufferGeometry,
  32048. ExtrudeGeometry: ExtrudeGeometry,
  32049. ExtrudeBufferGeometry: ExtrudeBufferGeometry,
  32050. EdgesGeometry: EdgesGeometry,
  32051. ConeGeometry: ConeGeometry,
  32052. ConeBufferGeometry: ConeBufferGeometry,
  32053. CylinderGeometry: CylinderGeometry,
  32054. CylinderBufferGeometry: CylinderBufferGeometry,
  32055. CircleGeometry: CircleGeometry,
  32056. CircleBufferGeometry: CircleBufferGeometry,
  32057. BoxGeometry: BoxGeometry,
  32058. BoxBufferGeometry: BoxBufferGeometry
  32059. });
  32060. /**
  32061. * @author mrdoob / http://mrdoob.com/
  32062. */
  32063. function ObjectLoader$1( manager ) {
  32064. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  32065. this.texturePath = '';
  32066. }
  32067. Object.assign( ObjectLoader$1.prototype, {
  32068. load: function ( url, onLoad, onProgress, onError ) {
  32069. if ( this.texturePath === '' ) {
  32070. this.texturePath = url.substring( 0, url.lastIndexOf( '/' ) + 1 );
  32071. }
  32072. var scope = this;
  32073. var loader = new FileLoader( scope.manager );
  32074. loader.load( url, function ( text ) {
  32075. var json = null;
  32076. try {
  32077. json = JSON.parse( text );
  32078. } catch ( error ) {
  32079. if ( onError !== undefined ) onError( error );
  32080. console.error( 'THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message );
  32081. return;
  32082. }
  32083. var metadata = json.metadata;
  32084. if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) {
  32085. console.error( 'THREE.ObjectLoader: Can\'t load ' + url + '. Use THREE.JSONLoader instead.' );
  32086. return;
  32087. }
  32088. scope.parse( json, onLoad );
  32089. }, onProgress, onError );
  32090. },
  32091. setTexturePath: function ( value ) {
  32092. this.texturePath = value;
  32093. },
  32094. setCrossOrigin: function ( value ) {
  32095. this.crossOrigin = value;
  32096. },
  32097. parse: function ( json, onLoad ) {
  32098. var geometries = this.parseGeometries( json.geometries );
  32099. var images = this.parseImages( json.images, function () {
  32100. if ( onLoad !== undefined ) onLoad( object );
  32101. } );
  32102. var textures = this.parseTextures( json.textures, images );
  32103. var materials = this.parseMaterials( json.materials, textures );
  32104. var object = this.parseObject( json.object, geometries, materials );
  32105. if ( json.animations ) {
  32106. object.animations = this.parseAnimations( json.animations );
  32107. }
  32108. if ( json.images === undefined || json.images.length === 0 ) {
  32109. if ( onLoad !== undefined ) onLoad( object );
  32110. }
  32111. return object;
  32112. },
  32113. parseGeometries: function ( json ) {
  32114. var geometries = {};
  32115. if ( json !== undefined ) {
  32116. var geometryLoader = new JSONLoader();
  32117. var bufferGeometryLoader = new BufferGeometryLoader();
  32118. for ( var i = 0, l = json.length; i < l; i ++ ) {
  32119. var geometry;
  32120. var data = json[ i ];
  32121. switch ( data.type ) {
  32122. case 'PlaneGeometry':
  32123. case 'PlaneBufferGeometry':
  32124. geometry = new Geometries[ data.type ](
  32125. data.width,
  32126. data.height,
  32127. data.widthSegments,
  32128. data.heightSegments
  32129. );
  32130. break;
  32131. case 'BoxGeometry':
  32132. case 'BoxBufferGeometry':
  32133. case 'CubeGeometry': // backwards compatible
  32134. geometry = new Geometries[ data.type ](
  32135. data.width,
  32136. data.height,
  32137. data.depth,
  32138. data.widthSegments,
  32139. data.heightSegments,
  32140. data.depthSegments
  32141. );
  32142. break;
  32143. case 'CircleGeometry':
  32144. case 'CircleBufferGeometry':
  32145. geometry = new Geometries[ data.type ](
  32146. data.radius,
  32147. data.segments,
  32148. data.thetaStart,
  32149. data.thetaLength
  32150. );
  32151. break;
  32152. case 'CylinderGeometry':
  32153. case 'CylinderBufferGeometry':
  32154. geometry = new Geometries[ data.type ](
  32155. data.radiusTop,
  32156. data.radiusBottom,
  32157. data.height,
  32158. data.radialSegments,
  32159. data.heightSegments,
  32160. data.openEnded,
  32161. data.thetaStart,
  32162. data.thetaLength
  32163. );
  32164. break;
  32165. case 'ConeGeometry':
  32166. case 'ConeBufferGeometry':
  32167. geometry = new Geometries[ data.type ](
  32168. data.radius,
  32169. data.height,
  32170. data.radialSegments,
  32171. data.heightSegments,
  32172. data.openEnded,
  32173. data.thetaStart,
  32174. data.thetaLength
  32175. );
  32176. break;
  32177. case 'SphereGeometry':
  32178. case 'SphereBufferGeometry':
  32179. geometry = new Geometries[ data.type ](
  32180. data.radius,
  32181. data.widthSegments,
  32182. data.heightSegments,
  32183. data.phiStart,
  32184. data.phiLength,
  32185. data.thetaStart,
  32186. data.thetaLength
  32187. );
  32188. break;
  32189. case 'DodecahedronGeometry':
  32190. case 'DodecahedronBufferGeometry':
  32191. case 'IcosahedronGeometry':
  32192. case 'IcosahedronBufferGeometry':
  32193. case 'OctahedronGeometry':
  32194. case 'OctahedronBufferGeometry':
  32195. case 'TetrahedronGeometry':
  32196. case 'TetrahedronBufferGeometry':
  32197. geometry = new Geometries[ data.type ](
  32198. data.radius,
  32199. data.detail
  32200. );
  32201. break;
  32202. case 'RingGeometry':
  32203. case 'RingBufferGeometry':
  32204. geometry = new Geometries[ data.type ](
  32205. data.innerRadius,
  32206. data.outerRadius,
  32207. data.thetaSegments,
  32208. data.phiSegments,
  32209. data.thetaStart,
  32210. data.thetaLength
  32211. );
  32212. break;
  32213. case 'TorusGeometry':
  32214. case 'TorusBufferGeometry':
  32215. geometry = new Geometries[ data.type ](
  32216. data.radius,
  32217. data.tube,
  32218. data.radialSegments,
  32219. data.tubularSegments,
  32220. data.arc
  32221. );
  32222. break;
  32223. case 'TorusKnotGeometry':
  32224. case 'TorusKnotBufferGeometry':
  32225. geometry = new Geometries[ data.type ](
  32226. data.radius,
  32227. data.tube,
  32228. data.tubularSegments,
  32229. data.radialSegments,
  32230. data.p,
  32231. data.q
  32232. );
  32233. break;
  32234. case 'LatheGeometry':
  32235. case 'LatheBufferGeometry':
  32236. geometry = new Geometries[ data.type ](
  32237. data.points,
  32238. data.segments,
  32239. data.phiStart,
  32240. data.phiLength
  32241. );
  32242. break;
  32243. case 'PolyhedronGeometry':
  32244. case 'PolyhedronBufferGeometry':
  32245. geometry = new Geometries[ data.type ](
  32246. data.vertices,
  32247. data.indices,
  32248. data.radius,
  32249. data.details
  32250. );
  32251. break;
  32252. case 'BufferGeometry':
  32253. geometry = bufferGeometryLoader.parse( data );
  32254. break;
  32255. case 'Geometry':
  32256. geometry = geometryLoader.parse( data, this.texturePath ).geometry;
  32257. break;
  32258. default:
  32259. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  32260. continue;
  32261. }
  32262. geometry.uuid = data.uuid;
  32263. if ( data.name !== undefined ) geometry.name = data.name;
  32264. geometries[ data.uuid ] = geometry;
  32265. }
  32266. }
  32267. return geometries;
  32268. },
  32269. parseMaterials: function ( json, textures ) {
  32270. var materials = {};
  32271. if ( json !== undefined ) {
  32272. var loader = new MaterialLoader();
  32273. loader.setTextures( textures );
  32274. for ( var i = 0, l = json.length; i < l; i ++ ) {
  32275. var data = json[ i ];
  32276. if ( data.type === 'MultiMaterial' ) {
  32277. // Deprecated
  32278. var array = [];
  32279. for ( var j = 0; j < data.materials.length; j ++ ) {
  32280. array.push( loader.parse( data.materials[ j ] ) );
  32281. }
  32282. materials[ data.uuid ] = array;
  32283. } else {
  32284. materials[ data.uuid ] = loader.parse( data );
  32285. }
  32286. }
  32287. }
  32288. return materials;
  32289. },
  32290. parseAnimations: function ( json ) {
  32291. var animations = [];
  32292. for ( var i = 0; i < json.length; i ++ ) {
  32293. var clip = AnimationClip.parse( json[ i ] );
  32294. animations.push( clip );
  32295. }
  32296. return animations;
  32297. },
  32298. parseImages: function ( json, onLoad ) {
  32299. var scope = this;
  32300. var images = {};
  32301. function loadImage( url ) {
  32302. scope.manager.itemStart( url );
  32303. return loader.load( url, function () {
  32304. scope.manager.itemEnd( url );
  32305. }, undefined, function () {
  32306. scope.manager.itemEnd( url );
  32307. scope.manager.itemError( url );
  32308. } );
  32309. }
  32310. if ( json !== undefined && json.length > 0 ) {
  32311. var manager = new LoadingManager( onLoad );
  32312. var loader = new ImageLoader( manager );
  32313. loader.setCrossOrigin( this.crossOrigin );
  32314. for ( var i = 0, l = json.length; i < l; i ++ ) {
  32315. var image = json[ i ];
  32316. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.texturePath + image.url;
  32317. images[ image.uuid ] = loadImage( path );
  32318. }
  32319. }
  32320. return images;
  32321. },
  32322. parseTextures: function ( json, images ) {
  32323. function parseConstant( value, type ) {
  32324. if ( typeof value === 'number' ) return value;
  32325. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  32326. return type[ value ];
  32327. }
  32328. var textures = {};
  32329. if ( json !== undefined ) {
  32330. for ( var i = 0, l = json.length; i < l; i ++ ) {
  32331. var data = json[ i ];
  32332. if ( data.image === undefined ) {
  32333. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  32334. }
  32335. if ( images[ data.image ] === undefined ) {
  32336. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  32337. }
  32338. var texture = new Texture( images[ data.image ] );
  32339. texture.needsUpdate = true;
  32340. texture.uuid = data.uuid;
  32341. if ( data.name !== undefined ) texture.name = data.name;
  32342. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping, TEXTURE_MAPPING );
  32343. if ( data.offset !== undefined ) texture.offset.fromArray( data.offset );
  32344. if ( data.repeat !== undefined ) texture.repeat.fromArray( data.repeat );
  32345. if ( data.center !== undefined ) texture.center.fromArray( data.center );
  32346. if ( data.rotation !== undefined ) texture.rotation = data.rotation;
  32347. if ( data.wrap !== undefined ) {
  32348. texture.wrapS = parseConstant( data.wrap[ 0 ], TEXTURE_WRAPPING );
  32349. texture.wrapT = parseConstant( data.wrap[ 1 ], TEXTURE_WRAPPING );
  32350. }
  32351. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter, TEXTURE_FILTER );
  32352. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter, TEXTURE_FILTER );
  32353. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  32354. if ( data.flipY !== undefined ) texture.flipY = data.flipY;
  32355. textures[ data.uuid ] = texture;
  32356. }
  32357. }
  32358. return textures;
  32359. },
  32360. parseObject: function () {
  32361. var matrix = new Matrix4();
  32362. return function parseObject( data, geometries, materials ) {
  32363. var object;
  32364. function getGeometry( name ) {
  32365. if ( geometries[ name ] === undefined ) {
  32366. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  32367. }
  32368. return geometries[ name ];
  32369. }
  32370. function getMaterial( name ) {
  32371. if ( name === undefined ) return undefined;
  32372. if ( Array.isArray( name ) ) {
  32373. var array = [];
  32374. for ( var i = 0, l = name.length; i < l; i ++ ) {
  32375. var uuid = name[ i ];
  32376. if ( materials[ uuid ] === undefined ) {
  32377. console.warn( 'THREE.ObjectLoader: Undefined material', uuid );
  32378. }
  32379. array.push( materials[ uuid ] );
  32380. }
  32381. return array;
  32382. }
  32383. if ( materials[ name ] === undefined ) {
  32384. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  32385. }
  32386. return materials[ name ];
  32387. }
  32388. switch ( data.type ) {
  32389. case 'Scene':
  32390. object = new Scene();
  32391. if ( data.background !== undefined ) {
  32392. if ( Number.isInteger( data.background ) ) {
  32393. object.background = new Color( data.background );
  32394. }
  32395. }
  32396. if ( data.fog !== undefined ) {
  32397. if ( data.fog.type === 'Fog' ) {
  32398. object.fog = new Fog( data.fog.color, data.fog.near, data.fog.far );
  32399. } else if ( data.fog.type === 'FogExp2' ) {
  32400. object.fog = new FogExp2( data.fog.color, data.fog.density );
  32401. }
  32402. }
  32403. break;
  32404. case 'PerspectiveCamera':
  32405. object = new PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  32406. if ( data.focus !== undefined ) object.focus = data.focus;
  32407. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  32408. if ( data.filmGauge !== undefined ) object.filmGauge = data.filmGauge;
  32409. if ( data.filmOffset !== undefined ) object.filmOffset = data.filmOffset;
  32410. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  32411. break;
  32412. case 'OrthographicCamera':
  32413. object = new OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  32414. break;
  32415. case 'AmbientLight':
  32416. object = new AmbientLight( data.color, data.intensity );
  32417. break;
  32418. case 'DirectionalLight':
  32419. object = new DirectionalLight$1( data.color, data.intensity );
  32420. break;
  32421. case 'PointLight':
  32422. object = new PointLight( data.color, data.intensity, data.distance, data.decay );
  32423. break;
  32424. case 'RectAreaLight':
  32425. object = new RectAreaLight( data.color, data.intensity, data.width, data.height );
  32426. break;
  32427. case 'SpotLight':
  32428. object = new SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  32429. break;
  32430. case 'HemisphereLight':
  32431. object = new HemisphereLight( data.color, data.groundColor, data.intensity );
  32432. break;
  32433. case 'SkinnedMesh':
  32434. console.warn( 'THREE.ObjectLoader.parseObject() does not support SkinnedMesh yet.' );
  32435. case 'Mesh':
  32436. var geometry = getGeometry( data.geometry );
  32437. var material = getMaterial( data.material );
  32438. if ( geometry.bones && geometry.bones.length > 0 ) {
  32439. object = new SkinnedMesh( geometry, material );
  32440. } else {
  32441. object = new Mesh( geometry, material );
  32442. }
  32443. break;
  32444. case 'LOD':
  32445. object = new LOD();
  32446. break;
  32447. case 'Line':
  32448. object = new Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  32449. break;
  32450. case 'LineLoop':
  32451. object = new LineLoop( getGeometry( data.geometry ), getMaterial( data.material ) );
  32452. break;
  32453. case 'LineSegments':
  32454. object = new LineSegments( getGeometry( data.geometry ), getMaterial( data.material ) );
  32455. break;
  32456. case 'PointCloud':
  32457. case 'Points':
  32458. object = new Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  32459. break;
  32460. case 'Sprite':
  32461. object = new Sprite( getMaterial( data.material ) );
  32462. break;
  32463. case 'Group':
  32464. object = new Group();
  32465. break;
  32466. default:
  32467. object = new Object3D();
  32468. }
  32469. object.uuid = data.uuid;
  32470. if ( data.name !== undefined ) object.name = data.name;
  32471. if ( data.matrix !== undefined ) {
  32472. matrix.fromArray( data.matrix );
  32473. matrix.decompose( object.position, object.quaternion, object.scale );
  32474. } else {
  32475. if ( data.position !== undefined ) object.position.fromArray( data.position );
  32476. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  32477. if ( data.quaternion !== undefined ) object.quaternion.fromArray( data.quaternion );
  32478. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  32479. }
  32480. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  32481. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  32482. if ( data.shadow ) {
  32483. if ( data.shadow.bias !== undefined ) object.shadow.bias = data.shadow.bias;
  32484. if ( data.shadow.radius !== undefined ) object.shadow.radius = data.shadow.radius;
  32485. if ( data.shadow.mapSize !== undefined ) object.shadow.mapSize.fromArray( data.shadow.mapSize );
  32486. if ( data.shadow.camera !== undefined ) object.shadow.camera = this.parseObject( data.shadow.camera );
  32487. }
  32488. if ( data.visible !== undefined ) object.visible = data.visible;
  32489. if ( data.userData !== undefined ) object.userData = data.userData;
  32490. if ( data.children !== undefined ) {
  32491. var children = data.children;
  32492. for ( var i = 0; i < children.length; i ++ ) {
  32493. object.add( this.parseObject( children[ i ], geometries, materials ) );
  32494. }
  32495. }
  32496. if ( data.type === 'LOD' ) {
  32497. var levels = data.levels;
  32498. for ( var l = 0; l < levels.length; l ++ ) {
  32499. var level = levels[ l ];
  32500. var child = object.getObjectByProperty( 'uuid', level.object );
  32501. if ( child !== undefined ) {
  32502. object.addLevel( child, level.distance );
  32503. }
  32504. }
  32505. }
  32506. return object;
  32507. };
  32508. }()
  32509. } );
  32510. var TEXTURE_MAPPING = {
  32511. UVMapping: UVMapping,
  32512. CubeReflectionMapping: CubeReflectionMapping,
  32513. CubeRefractionMapping: CubeRefractionMapping,
  32514. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  32515. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  32516. SphericalReflectionMapping: SphericalReflectionMapping,
  32517. CubeUVReflectionMapping: CubeUVReflectionMapping,
  32518. CubeUVRefractionMapping: CubeUVRefractionMapping
  32519. };
  32520. var TEXTURE_WRAPPING = {
  32521. RepeatWrapping: RepeatWrapping,
  32522. ClampToEdgeWrapping: ClampToEdgeWrapping,
  32523. MirroredRepeatWrapping: MirroredRepeatWrapping
  32524. };
  32525. var TEXTURE_FILTER = {
  32526. NearestFilter: NearestFilter,
  32527. NearestMipMapNearestFilter: NearestMipMapNearestFilter,
  32528. NearestMipMapLinearFilter: NearestMipMapLinearFilter,
  32529. LinearFilter: LinearFilter,
  32530. LinearMipMapNearestFilter: LinearMipMapNearestFilter,
  32531. LinearMipMapLinearFilter: LinearMipMapLinearFilter
  32532. };
  32533. /**
  32534. * @author TristanVALCKE / https://github.com/Itee
  32535. * @author moraxy / https://github.com/moraxy
  32536. */
  32537. /* global QUnit */
  32538. QUnit.module( 'Lights', () => {
  32539. QUnit.module.todo( 'SpotLightShadow', () => {
  32540. // INHERITANCE
  32541. QUnit.test( "Extending", ( assert ) => {
  32542. assert.ok( false, "everything's gonna be alright" );
  32543. } );
  32544. // INSTANCING
  32545. QUnit.test( "Instancing", ( assert ) => {
  32546. assert.ok( false, "everything's gonna be alright" );
  32547. } );
  32548. // PUBLIC STUFF
  32549. QUnit.test( "isSpotLightShadow", ( assert ) => {
  32550. assert.ok( false, "everything's gonna be alright" );
  32551. } );
  32552. QUnit.test( "update", ( assert ) => {
  32553. assert.ok( false, "everything's gonna be alright" );
  32554. } );
  32555. // OTHERS
  32556. QUnit.test( "clone/copy", ( assert ) => {
  32557. var a = new SpotLightShadow();
  32558. var b = new SpotLightShadow();
  32559. var c;
  32560. assert.notDeepEqual( a, b, "Newly instanced shadows are not equal" );
  32561. c = a.clone();
  32562. assert.smartEqual( a, c, "Shadows are identical after clone()" );
  32563. c.mapSize.set( 256, 256 );
  32564. assert.notDeepEqual( a, c, "Shadows are different again after change" );
  32565. b.copy( a );
  32566. assert.smartEqual( a, b, "Shadows are identical after copy()" );
  32567. b.mapSize.set( 512, 512 );
  32568. assert.notDeepEqual( a, b, "Shadows are different again after change" );
  32569. } );
  32570. QUnit.test( "toJSON", ( assert ) => {
  32571. var light = new SpotLight();
  32572. var shadow = new SpotLightShadow();
  32573. shadow.bias = 10;
  32574. shadow.radius = 5;
  32575. shadow.mapSize.set( 128, 128 );
  32576. light.shadow = shadow;
  32577. var json = light.toJSON();
  32578. var newLight = new ObjectLoader$1().parse( json );
  32579. assert.smartEqual( newLight.shadow, light.shadow, "Reloaded shadow is equal to the original one" );
  32580. } );
  32581. } );
  32582. } );
  32583. /**
  32584. * @author bhouston / http://clara.io/
  32585. */
  32586. function AnimationLoader( manager ) {
  32587. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  32588. }
  32589. Object.assign( AnimationLoader.prototype, {
  32590. load: function ( url, onLoad, onProgress, onError ) {
  32591. var scope = this;
  32592. var loader = new FileLoader( scope.manager );
  32593. loader.load( url, function ( text ) {
  32594. onLoad( scope.parse( JSON.parse( text ) ) );
  32595. }, onProgress, onError );
  32596. },
  32597. parse: function ( json, onLoad ) {
  32598. var animations = [];
  32599. for ( var i = 0; i < json.length; i ++ ) {
  32600. var clip = AnimationClip.parse( json[ i ] );
  32601. animations.push( clip );
  32602. }
  32603. onLoad( animations );
  32604. }
  32605. } );
  32606. /**
  32607. * @author TristanVALCKE / https://github.com/Itee
  32608. */
  32609. /* global QUnit */
  32610. QUnit.module( 'Loaders', () => {
  32611. QUnit.module.todo( 'AnimationLoader', () => {
  32612. // INSTANCING
  32613. QUnit.test( "Instancing", ( assert ) => {
  32614. assert.ok( false, "everything's gonna be alright" );
  32615. } );
  32616. // PUBLIC STUFF
  32617. QUnit.test( "load", ( assert ) => {
  32618. assert.ok( false, "everything's gonna be alright" );
  32619. } );
  32620. QUnit.test( "parse", ( assert ) => {
  32621. assert.ok( false, "everything's gonna be alright" );
  32622. } );
  32623. } );
  32624. } );
  32625. /**
  32626. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  32627. */
  32628. function AudioLoader( manager ) {
  32629. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  32630. }
  32631. Object.assign( AudioLoader.prototype, {
  32632. load: function ( url, onLoad, onProgress, onError ) {
  32633. var loader = new FileLoader( this.manager );
  32634. loader.setResponseType( 'arraybuffer' );
  32635. loader.load( url, function ( buffer ) {
  32636. var context = AudioContext.getContext();
  32637. context.decodeAudioData( buffer, function ( audioBuffer ) {
  32638. onLoad( audioBuffer );
  32639. } );
  32640. }, onProgress, onError );
  32641. }
  32642. } );
  32643. /**
  32644. * @author TristanVALCKE / https://github.com/Itee
  32645. */
  32646. /* global QUnit */
  32647. QUnit.module( 'Loaders', () => {
  32648. QUnit.module.todo( 'AudioLoader', () => {
  32649. // INSTANCING
  32650. QUnit.test( "Instancing", ( assert ) => {
  32651. assert.ok( false, "everything's gonna be alright" );
  32652. } );
  32653. // PUBLIC STUFF
  32654. QUnit.test( "load", ( assert ) => {
  32655. assert.ok( false, "everything's gonna be alright" );
  32656. } );
  32657. } );
  32658. } );
  32659. /**
  32660. * @author TristanVALCKE / https://github.com/Itee
  32661. */
  32662. /* global QUnit */
  32663. QUnit.module( 'Loaders', () => {
  32664. QUnit.module.todo( 'BufferGeometryLoader', () => {
  32665. // INSTANCING
  32666. QUnit.test( "Instancing", ( assert ) => {
  32667. assert.ok( false, "everything's gonna be alright" );
  32668. } );
  32669. // PUBLIC STUFF
  32670. QUnit.test( "load", ( assert ) => {
  32671. assert.ok( false, "everything's gonna be alright" );
  32672. } );
  32673. QUnit.test( "parse", ( assert ) => {
  32674. assert.ok( false, "everything's gonna be alright" );
  32675. } );
  32676. } );
  32677. } );
  32678. /**
  32679. * @author TristanVALCKE / https://github.com/Itee
  32680. */
  32681. /* global QUnit */
  32682. QUnit.module( 'Loaders', () => {
  32683. QUnit.module.todo( 'Cache', () => {
  32684. // PUBLIC STUFF
  32685. QUnit.test( "add", ( assert ) => {
  32686. assert.ok( false, "everything's gonna be alright" );
  32687. } );
  32688. QUnit.test( "get", ( assert ) => {
  32689. assert.ok( false, "everything's gonna be alright" );
  32690. } );
  32691. QUnit.test( "remove", ( assert ) => {
  32692. assert.ok( false, "everything's gonna be alright" );
  32693. } );
  32694. QUnit.test( "clear", ( assert ) => {
  32695. assert.ok( false, "everything's gonna be alright" );
  32696. } );
  32697. } );
  32698. } );
  32699. /**
  32700. * @author alteredq / http://alteredqualia.com/
  32701. */
  32702. function CompressedTexture( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  32703. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  32704. this.image = { width: width, height: height };
  32705. this.mipmaps = mipmaps;
  32706. // no flipping for cube textures
  32707. // (also flipping doesn't work for compressed textures )
  32708. this.flipY = false;
  32709. // can't generate mipmaps for compressed textures
  32710. // mips must be embedded in DDS files
  32711. this.generateMipmaps = false;
  32712. }
  32713. CompressedTexture.prototype = Object.create( Texture.prototype );
  32714. CompressedTexture.prototype.constructor = CompressedTexture;
  32715. CompressedTexture.prototype.isCompressedTexture = true;
  32716. /**
  32717. * @author mrdoob / http://mrdoob.com/
  32718. *
  32719. * Abstract Base class to block based textures loader (dds, pvr, ...)
  32720. */
  32721. function CompressedTextureLoader( manager ) {
  32722. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  32723. // override in sub classes
  32724. this._parser = null;
  32725. }
  32726. Object.assign( CompressedTextureLoader.prototype, {
  32727. load: function ( url, onLoad, onProgress, onError ) {
  32728. var scope = this;
  32729. var images = [];
  32730. var texture = new CompressedTexture();
  32731. texture.image = images;
  32732. var loader = new FileLoader( this.manager );
  32733. loader.setPath( this.path );
  32734. loader.setResponseType( 'arraybuffer' );
  32735. function loadTexture( i ) {
  32736. loader.load( url[ i ], function ( buffer ) {
  32737. var texDatas = scope._parser( buffer, true );
  32738. images[ i ] = {
  32739. width: texDatas.width,
  32740. height: texDatas.height,
  32741. format: texDatas.format,
  32742. mipmaps: texDatas.mipmaps
  32743. };
  32744. loaded += 1;
  32745. if ( loaded === 6 ) {
  32746. if ( texDatas.mipmapCount === 1 )
  32747. texture.minFilter = LinearFilter;
  32748. texture.format = texDatas.format;
  32749. texture.needsUpdate = true;
  32750. if ( onLoad ) onLoad( texture );
  32751. }
  32752. }, onProgress, onError );
  32753. }
  32754. if ( Array.isArray( url ) ) {
  32755. var loaded = 0;
  32756. for ( var i = 0, il = url.length; i < il; ++ i ) {
  32757. loadTexture( i );
  32758. }
  32759. } else {
  32760. // compressed cubemap texture stored in a single DDS file
  32761. loader.load( url, function ( buffer ) {
  32762. var texDatas = scope._parser( buffer, true );
  32763. if ( texDatas.isCubemap ) {
  32764. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  32765. for ( var f = 0; f < faces; f ++ ) {
  32766. images[ f ] = { mipmaps: [] };
  32767. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  32768. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  32769. images[ f ].format = texDatas.format;
  32770. images[ f ].width = texDatas.width;
  32771. images[ f ].height = texDatas.height;
  32772. }
  32773. }
  32774. } else {
  32775. texture.image.width = texDatas.width;
  32776. texture.image.height = texDatas.height;
  32777. texture.mipmaps = texDatas.mipmaps;
  32778. }
  32779. if ( texDatas.mipmapCount === 1 ) {
  32780. texture.minFilter = LinearFilter;
  32781. }
  32782. texture.format = texDatas.format;
  32783. texture.needsUpdate = true;
  32784. if ( onLoad ) onLoad( texture );
  32785. }, onProgress, onError );
  32786. }
  32787. return texture;
  32788. },
  32789. setPath: function ( value ) {
  32790. this.path = value;
  32791. return this;
  32792. }
  32793. } );
  32794. /**
  32795. * @author TristanVALCKE / https://github.com/Itee
  32796. */
  32797. /* global QUnit */
  32798. QUnit.module( 'Loaders', () => {
  32799. QUnit.module.todo( 'CompressedTextureLoader', () => {
  32800. // INSTANCING
  32801. QUnit.test( "Instancing", ( assert ) => {
  32802. assert.ok( false, "everything's gonna be alright" );
  32803. } );
  32804. // PUBLIC STUFF
  32805. QUnit.test( "load", ( assert ) => {
  32806. assert.ok( false, "everything's gonna be alright" );
  32807. } );
  32808. QUnit.test( "setPath", ( assert ) => {
  32809. assert.ok( false, "everything's gonna be alright" );
  32810. } );
  32811. } );
  32812. } );
  32813. /**
  32814. * @author mrdoob / http://mrdoob.com/
  32815. */
  32816. function CubeTextureLoader( manager ) {
  32817. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  32818. }
  32819. Object.assign( CubeTextureLoader.prototype, {
  32820. crossOrigin: 'Anonymous',
  32821. load: function ( urls, onLoad, onProgress, onError ) {
  32822. var texture = new CubeTexture();
  32823. var loader = new ImageLoader( this.manager );
  32824. loader.setCrossOrigin( this.crossOrigin );
  32825. loader.setPath( this.path );
  32826. var loaded = 0;
  32827. function loadTexture( i ) {
  32828. loader.load( urls[ i ], function ( image ) {
  32829. texture.images[ i ] = image;
  32830. loaded ++;
  32831. if ( loaded === 6 ) {
  32832. texture.needsUpdate = true;
  32833. if ( onLoad ) onLoad( texture );
  32834. }
  32835. }, undefined, onError );
  32836. }
  32837. for ( var i = 0; i < urls.length; ++ i ) {
  32838. loadTexture( i );
  32839. }
  32840. return texture;
  32841. },
  32842. setCrossOrigin: function ( value ) {
  32843. this.crossOrigin = value;
  32844. return this;
  32845. },
  32846. setPath: function ( value ) {
  32847. this.path = value;
  32848. return this;
  32849. }
  32850. } );
  32851. /**
  32852. * @author TristanVALCKE / https://github.com/Itee
  32853. */
  32854. /* global QUnit */
  32855. QUnit.module( 'Loaders', () => {
  32856. QUnit.module.todo( 'CubeTextureLoader', () => {
  32857. // INSTANCING
  32858. QUnit.test( "Instancing", ( assert ) => {
  32859. assert.ok( false, "everything's gonna be alright" );
  32860. } );
  32861. // PUBLIC STUFF
  32862. QUnit.test( "load", ( assert ) => {
  32863. assert.ok( false, "everything's gonna be alright" );
  32864. } );
  32865. QUnit.test( "setCrossOrigin", ( assert ) => {
  32866. assert.ok( false, "everything's gonna be alright" );
  32867. } );
  32868. QUnit.test( "setPath", ( assert ) => {
  32869. assert.ok( false, "everything's gonna be alright" );
  32870. } );
  32871. } );
  32872. } );
  32873. /**
  32874. * @author Nikos M. / https://github.com/foo123/
  32875. *
  32876. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  32877. */
  32878. function DataTextureLoader( manager ) {
  32879. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  32880. // override in sub classes
  32881. this._parser = null;
  32882. }
  32883. Object.assign( DataTextureLoader.prototype, {
  32884. load: function ( url, onLoad, onProgress, onError ) {
  32885. var scope = this;
  32886. var texture = new DataTexture();
  32887. var loader = new FileLoader( this.manager );
  32888. loader.setResponseType( 'arraybuffer' );
  32889. loader.load( url, function ( buffer ) {
  32890. var texData = scope._parser( buffer );
  32891. if ( ! texData ) return;
  32892. if ( undefined !== texData.image ) {
  32893. texture.image = texData.image;
  32894. } else if ( undefined !== texData.data ) {
  32895. texture.image.width = texData.width;
  32896. texture.image.height = texData.height;
  32897. texture.image.data = texData.data;
  32898. }
  32899. texture.wrapS = undefined !== texData.wrapS ? texData.wrapS : ClampToEdgeWrapping;
  32900. texture.wrapT = undefined !== texData.wrapT ? texData.wrapT : ClampToEdgeWrapping;
  32901. texture.magFilter = undefined !== texData.magFilter ? texData.magFilter : LinearFilter;
  32902. texture.minFilter = undefined !== texData.minFilter ? texData.minFilter : LinearMipMapLinearFilter;
  32903. texture.anisotropy = undefined !== texData.anisotropy ? texData.anisotropy : 1;
  32904. if ( undefined !== texData.format ) {
  32905. texture.format = texData.format;
  32906. }
  32907. if ( undefined !== texData.type ) {
  32908. texture.type = texData.type;
  32909. }
  32910. if ( undefined !== texData.mipmaps ) {
  32911. texture.mipmaps = texData.mipmaps;
  32912. }
  32913. if ( 1 === texData.mipmapCount ) {
  32914. texture.minFilter = LinearFilter;
  32915. }
  32916. texture.needsUpdate = true;
  32917. if ( onLoad ) onLoad( texture, texData );
  32918. }, onProgress, onError );
  32919. return texture;
  32920. }
  32921. } );
  32922. /**
  32923. * @author TristanVALCKE / https://github.com/Itee
  32924. */
  32925. /* global QUnit */
  32926. QUnit.module( 'Loaders', () => {
  32927. QUnit.module.todo( 'DataTextureLoader', () => {
  32928. // INSTANCING
  32929. QUnit.test( "Instancing", ( assert ) => {
  32930. assert.ok( false, "everything's gonna be alright" );
  32931. } );
  32932. // PUBLIC STUFF
  32933. QUnit.test( "load", ( assert ) => {
  32934. assert.ok( false, "everything's gonna be alright" );
  32935. } );
  32936. } );
  32937. } );
  32938. /**
  32939. * @author TristanVALCKE / https://github.com/Itee
  32940. */
  32941. /* global QUnit */
  32942. QUnit.module( 'Loaders', () => {
  32943. QUnit.module.todo( 'FileLoader', () => {
  32944. // INSTANCING
  32945. QUnit.test( "Instancing", ( assert ) => {
  32946. assert.ok( false, "everything's gonna be alright" );
  32947. } );
  32948. // PUBLIC STUFF
  32949. QUnit.test( "load", ( assert ) => {
  32950. assert.ok( false, "everything's gonna be alright" );
  32951. } );
  32952. QUnit.test( "setPath", ( assert ) => {
  32953. assert.ok( false, "everything's gonna be alright" );
  32954. } );
  32955. QUnit.test( "setResponseType", ( assert ) => {
  32956. assert.ok( false, "everything's gonna be alright" );
  32957. } );
  32958. QUnit.test( "setWithCredentials", ( assert ) => {
  32959. assert.ok( false, "everything's gonna be alright" );
  32960. } );
  32961. QUnit.test( "setMimeType", ( assert ) => {
  32962. assert.ok( false, "everything's gonna be alright" );
  32963. } );
  32964. QUnit.test( "setRequestHeader", ( assert ) => {
  32965. assert.ok( false, "everything's gonna be alright" );
  32966. } );
  32967. } );
  32968. } );
  32969. /**
  32970. * @author mrdoob / http://mrdoob.com/
  32971. */
  32972. function FontLoader( manager ) {
  32973. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  32974. }
  32975. Object.assign( FontLoader.prototype, {
  32976. load: function ( url, onLoad, onProgress, onError ) {
  32977. var scope = this;
  32978. var loader = new FileLoader( this.manager );
  32979. loader.setPath( this.path );
  32980. loader.load( url, function ( text ) {
  32981. var json;
  32982. try {
  32983. json = JSON.parse( text );
  32984. } catch ( e ) {
  32985. console.warn( 'THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.' );
  32986. json = JSON.parse( text.substring( 65, text.length - 2 ) );
  32987. }
  32988. var font = scope.parse( json );
  32989. if ( onLoad ) onLoad( font );
  32990. }, onProgress, onError );
  32991. },
  32992. parse: function ( json ) {
  32993. return new Font( json );
  32994. },
  32995. setPath: function ( value ) {
  32996. this.path = value;
  32997. return this;
  32998. }
  32999. } );
  33000. /**
  33001. * @author TristanVALCKE / https://github.com/Itee
  33002. */
  33003. /* global QUnit */
  33004. QUnit.module( 'Loaders', () => {
  33005. QUnit.module.todo( 'FontLoader', () => {
  33006. // INSTANCING
  33007. QUnit.test( "Instancing", ( assert ) => {
  33008. assert.ok( false, "everything's gonna be alright" );
  33009. } );
  33010. // PUBLIC STUFF
  33011. QUnit.test( "load", ( assert ) => {
  33012. assert.ok( false, "everything's gonna be alright" );
  33013. } );
  33014. QUnit.test( "parse", ( assert ) => {
  33015. assert.ok( false, "everything's gonna be alright" );
  33016. } );
  33017. QUnit.test( "setPath", ( assert ) => {
  33018. assert.ok( false, "everything's gonna be alright" );
  33019. } );
  33020. } );
  33021. } );
  33022. /**
  33023. * @author TristanVALCKE / https://github.com/Itee
  33024. */
  33025. /* global QUnit */
  33026. QUnit.module( 'Loaders', () => {
  33027. QUnit.module.todo( 'ImageLoader', () => {
  33028. // INSTANCING
  33029. QUnit.test( "Instancing", ( assert ) => {
  33030. assert.ok( false, "everything's gonna be alright" );
  33031. } );
  33032. // PUBLIC STUFF
  33033. QUnit.test( "load", ( assert ) => {
  33034. assert.ok( false, "everything's gonna be alright" );
  33035. } );
  33036. QUnit.test( "setCrossOrigin", ( assert ) => {
  33037. assert.ok( false, "everything's gonna be alright" );
  33038. } );
  33039. QUnit.test( "setPath", ( assert ) => {
  33040. assert.ok( false, "everything's gonna be alright" );
  33041. } );
  33042. } );
  33043. } );
  33044. /**
  33045. * @author TristanVALCKE / https://github.com/Itee
  33046. */
  33047. /* global QUnit */
  33048. QUnit.module( 'Loaders', () => {
  33049. QUnit.module.todo( 'JSONLoader', () => {
  33050. // INSTANCING
  33051. QUnit.test( "Instancing", ( assert ) => {
  33052. assert.ok( false, "everything's gonna be alright" );
  33053. } );
  33054. // PUBLIC STUFF
  33055. QUnit.test( "load", ( assert ) => {
  33056. assert.ok( false, "everything's gonna be alright" );
  33057. } );
  33058. QUnit.test( "setTexturePath", ( assert ) => {
  33059. assert.ok( false, "everything's gonna be alright" );
  33060. } );
  33061. QUnit.test( "parse", ( assert ) => {
  33062. assert.ok( false, "everything's gonna be alright" );
  33063. } );
  33064. } );
  33065. } );
  33066. /**
  33067. * @author TristanVALCKE / https://github.com/Itee
  33068. */
  33069. /* global QUnit */
  33070. QUnit.module( 'Loaders', () => {
  33071. QUnit.module.todo( 'Loader', () => {
  33072. // INSTANCING
  33073. QUnit.test( "Instancing", ( assert ) => {
  33074. assert.ok( false, "everything's gonna be alright" );
  33075. } );
  33076. // STATIC STUFF
  33077. QUnit.test( "Handlers.add", ( assert ) => {
  33078. assert.ok( false, "everything's gonna be alright" );
  33079. } );
  33080. QUnit.test( "Handlers.get", ( assert ) => {
  33081. assert.ok( false, "everything's gonna be alright" );
  33082. } );
  33083. // PUBLIC STUFF
  33084. QUnit.test( "extractUrlBase", ( assert ) => {
  33085. assert.ok( false, "everything's gonna be alright" );
  33086. } );
  33087. QUnit.test( "initMaterials", ( assert ) => {
  33088. assert.ok( false, "everything's gonna be alright" );
  33089. } );
  33090. QUnit.test( "createMaterial", ( assert ) => {
  33091. assert.ok( false, "everything's gonna be alright" );
  33092. } );
  33093. } );
  33094. } );
  33095. /**
  33096. * @author TristanVALCKE / https://github.com/Itee
  33097. */
  33098. /* global QUnit */
  33099. QUnit.module( 'Loaders', () => {
  33100. QUnit.module.todo( 'LoadingManager', () => {
  33101. // INSTANCING
  33102. QUnit.test( "Instancing", ( assert ) => {
  33103. assert.ok( false, "everything's gonna be alright" );
  33104. } );
  33105. // PUBLIC STUFF
  33106. QUnit.test( "onStart", ( assert ) => {
  33107. assert.ok( false, "everything's gonna be alright" );
  33108. } );
  33109. QUnit.test( "onLoad", ( assert ) => {
  33110. assert.ok( false, "everything's gonna be alright" );
  33111. } );
  33112. QUnit.test( "onProgress", ( assert ) => {
  33113. assert.ok( false, "everything's gonna be alright" );
  33114. } );
  33115. QUnit.test( "onError", ( assert ) => {
  33116. assert.ok( false, "everything's gonna be alright" );
  33117. } );
  33118. QUnit.test( "itemStart", ( assert ) => {
  33119. assert.ok( false, "everything's gonna be alright" );
  33120. } );
  33121. QUnit.test( "itemEnd", ( assert ) => {
  33122. assert.ok( false, "everything's gonna be alright" );
  33123. } );
  33124. QUnit.test( "itemError", ( assert ) => {
  33125. assert.ok( false, "everything's gonna be alright" );
  33126. } );
  33127. } );
  33128. } );
  33129. /**
  33130. * @author TristanVALCKE / https://github.com/Itee
  33131. */
  33132. /* global QUnit */
  33133. QUnit.module( 'Loaders', () => {
  33134. QUnit.module.todo( 'MaterialLoader', () => {
  33135. // INSTANCING
  33136. QUnit.test( "Instancing", ( assert ) => {
  33137. assert.ok( false, "everything's gonna be alright" );
  33138. } );
  33139. // PUBLIC STUFF
  33140. QUnit.test( "load", ( assert ) => {
  33141. assert.ok( false, "everything's gonna be alright" );
  33142. } );
  33143. QUnit.test( "setTextures", ( assert ) => {
  33144. assert.ok( false, "everything's gonna be alright" );
  33145. } );
  33146. QUnit.test( "parse", ( assert ) => {
  33147. assert.ok( false, "everything's gonna be alright" );
  33148. } );
  33149. } );
  33150. } );
  33151. /**
  33152. * @author TristanVALCKE / https://github.com/Itee
  33153. */
  33154. /* global QUnit */
  33155. QUnit.module( 'Loaders', () => {
  33156. QUnit.module.todo( 'ObjectLoader', () => {
  33157. // INSTANCING
  33158. QUnit.test( "Instancing", ( assert ) => {
  33159. assert.ok( false, "everything's gonna be alright" );
  33160. } );
  33161. // PUBLIC STUFF
  33162. QUnit.test( "load", ( assert ) => {
  33163. assert.ok( false, "everything's gonna be alright" );
  33164. } );
  33165. QUnit.test( "setTexturePath", ( assert ) => {
  33166. assert.ok( false, "everything's gonna be alright" );
  33167. } );
  33168. QUnit.test( "setCrossOrigin", ( assert ) => {
  33169. assert.ok( false, "everything's gonna be alright" );
  33170. } );
  33171. QUnit.test( "parse", ( assert ) => {
  33172. assert.ok( false, "everything's gonna be alright" );
  33173. } );
  33174. QUnit.test( "parseGeometries", ( assert ) => {
  33175. assert.ok( false, "everything's gonna be alright" );
  33176. } );
  33177. QUnit.test( "parseMaterials", ( assert ) => {
  33178. assert.ok( false, "everything's gonna be alright" );
  33179. } );
  33180. QUnit.test( "parseAnimations", ( assert ) => {
  33181. assert.ok( false, "everything's gonna be alright" );
  33182. } );
  33183. QUnit.test( "parseImages", ( assert ) => {
  33184. assert.ok( false, "everything's gonna be alright" );
  33185. } );
  33186. QUnit.test( "parseTextures", ( assert ) => {
  33187. assert.ok( false, "everything's gonna be alright" );
  33188. } );
  33189. QUnit.test( "parseObject", ( assert ) => {
  33190. assert.ok( false, "everything's gonna be alright" );
  33191. } );
  33192. } );
  33193. } );
  33194. /**
  33195. * @author TristanVALCKE / https://github.com/Itee
  33196. */
  33197. /* global QUnit */
  33198. QUnit.module( 'Loaders', () => {
  33199. QUnit.module.todo( 'TextureLoader', () => {
  33200. // INSTANCING
  33201. QUnit.test( "Instancing", ( assert ) => {
  33202. assert.ok( false, "everything's gonna be alright" );
  33203. } );
  33204. // PUBLIC STUFF
  33205. QUnit.test( "load", ( assert ) => {
  33206. assert.ok( false, "everything's gonna be alright" );
  33207. } );
  33208. QUnit.test( "setCrossOrigin", ( assert ) => {
  33209. assert.ok( false, "everything's gonna be alright" );
  33210. } );
  33211. QUnit.test( "setPath", ( assert ) => {
  33212. assert.ok( false, "everything's gonna be alright" );
  33213. } );
  33214. } );
  33215. } );
  33216. /**
  33217. * @author TristanVALCKE / https://github.com/Itee
  33218. */
  33219. /* global QUnit */
  33220. QUnit.module( 'Materials', () => {
  33221. QUnit.module.todo( 'LineBasicMaterial', () => {
  33222. // INHERITANCE
  33223. QUnit.test( "Extending", ( assert ) => {
  33224. assert.ok( false, "everything's gonna be alright" );
  33225. } );
  33226. // INSTANCING
  33227. QUnit.test( "Instancing", ( assert ) => {
  33228. assert.ok( false, "everything's gonna be alright" );
  33229. } );
  33230. // PUBLIC STUFF
  33231. QUnit.test( "isLineBasicMaterial", ( assert ) => {
  33232. assert.ok( false, "everything's gonna be alright" );
  33233. } );
  33234. QUnit.test( "copy", ( assert ) => {
  33235. assert.ok( false, "everything's gonna be alright" );
  33236. } );
  33237. } );
  33238. } );
  33239. /**
  33240. * @author TristanVALCKE / https://github.com/Itee
  33241. */
  33242. /* global QUnit */
  33243. QUnit.module( 'Materials', () => {
  33244. QUnit.module.todo( 'LineDashedMaterial', () => {
  33245. // INHERITANCE
  33246. QUnit.test( "Extending", ( assert ) => {
  33247. assert.ok( false, "everything's gonna be alright" );
  33248. } );
  33249. // INSTANCING
  33250. QUnit.test( "Instancing", ( assert ) => {
  33251. assert.ok( false, "everything's gonna be alright" );
  33252. } );
  33253. // PUBLIC STUFF
  33254. QUnit.test( "isLineDashedMaterial", ( assert ) => {
  33255. assert.ok( false, "everything's gonna be alright" );
  33256. } );
  33257. QUnit.test( "copy", ( assert ) => {
  33258. assert.ok( false, "everything's gonna be alright" );
  33259. } );
  33260. } );
  33261. } );
  33262. /**
  33263. * @author TristanVALCKE / https://github.com/Itee
  33264. */
  33265. /* global QUnit */
  33266. QUnit.module( 'Materials', () => {
  33267. QUnit.module.todo( 'Material', () => {
  33268. // INSTANCING
  33269. QUnit.test( "Instancing", ( assert ) => {
  33270. assert.ok( false, "everything's gonna be alright" );
  33271. } );
  33272. // PUBLIC STUFF
  33273. QUnit.test( "isMaterial", ( assert ) => {
  33274. assert.ok( false, "everything's gonna be alright" );
  33275. } );
  33276. QUnit.test( "onBeforeCompile", ( assert ) => {
  33277. assert.ok( false, "everything's gonna be alright" );
  33278. } );
  33279. QUnit.test( "setValues", ( assert ) => {
  33280. assert.ok( false, "everything's gonna be alright" );
  33281. } );
  33282. QUnit.test( "toJSON", ( assert ) => {
  33283. assert.ok( false, "everything's gonna be alright" );
  33284. } );
  33285. QUnit.test( "clone", ( assert ) => {
  33286. assert.ok( false, "everything's gonna be alright" );
  33287. } );
  33288. QUnit.test( "copy", ( assert ) => {
  33289. assert.ok( false, "everything's gonna be alright" );
  33290. } );
  33291. QUnit.test( "dispose", ( assert ) => {
  33292. assert.ok( false, "everything's gonna be alright" );
  33293. } );
  33294. } );
  33295. } );
  33296. /**
  33297. * @author TristanVALCKE / https://github.com/Itee
  33298. */
  33299. /* global QUnit */
  33300. QUnit.module( 'Materials', () => {
  33301. QUnit.module.todo( 'MeshBasicMaterial', () => {
  33302. // INHERITANCE
  33303. QUnit.test( "Extending", ( assert ) => {
  33304. assert.ok( false, "everything's gonna be alright" );
  33305. } );
  33306. // INSTANCING
  33307. QUnit.test( "Instancing", ( assert ) => {
  33308. assert.ok( false, "everything's gonna be alright" );
  33309. } );
  33310. // PUBLIC STUFF
  33311. QUnit.test( "isMeshBasicMaterial", ( assert ) => {
  33312. assert.ok( false, "everything's gonna be alright" );
  33313. } );
  33314. QUnit.test( "copy", ( assert ) => {
  33315. assert.ok( false, "everything's gonna be alright" );
  33316. } );
  33317. } );
  33318. } );
  33319. /**
  33320. * @author TristanVALCKE / https://github.com/Itee
  33321. */
  33322. /* global QUnit */
  33323. QUnit.module( 'Materials', () => {
  33324. QUnit.module.todo( 'MeshDepthMaterial', () => {
  33325. // INHERITANCE
  33326. QUnit.test( "Extending", ( assert ) => {
  33327. assert.ok( false, "everything's gonna be alright" );
  33328. } );
  33329. // INSTANCING
  33330. QUnit.test( "Instancing", ( assert ) => {
  33331. assert.ok( false, "everything's gonna be alright" );
  33332. } );
  33333. // PUBLIC STUFF
  33334. QUnit.test( "isMeshDepthMaterial", ( assert ) => {
  33335. assert.ok( false, "everything's gonna be alright" );
  33336. } );
  33337. QUnit.test( "copy", ( assert ) => {
  33338. assert.ok( false, "everything's gonna be alright" );
  33339. } );
  33340. } );
  33341. } );
  33342. /**
  33343. * @author TristanVALCKE / https://github.com/Itee
  33344. */
  33345. /* global QUnit */
  33346. QUnit.module( 'Materials', () => {
  33347. QUnit.module.todo( 'MeshDistanceMaterial', () => {
  33348. // INHERITANCE
  33349. QUnit.test( "Extending", ( assert ) => {
  33350. assert.ok( false, "everything's gonna be alright" );
  33351. } );
  33352. // INSTANCING
  33353. QUnit.test( "Instancing", ( assert ) => {
  33354. assert.ok( false, "everything's gonna be alright" );
  33355. } );
  33356. // PUBLIC STUFF
  33357. QUnit.test( "isMeshDistanceMaterial", ( assert ) => {
  33358. assert.ok( false, "everything's gonna be alright" );
  33359. } );
  33360. QUnit.test( "copy", ( assert ) => {
  33361. assert.ok( false, "everything's gonna be alright" );
  33362. } );
  33363. } );
  33364. } );
  33365. /**
  33366. * @author TristanVALCKE / https://github.com/Itee
  33367. */
  33368. /* global QUnit */
  33369. QUnit.module( 'Materials', () => {
  33370. QUnit.module.todo( 'MeshLambertMaterial', () => {
  33371. // INHERITANCE
  33372. QUnit.test( "Extending", ( assert ) => {
  33373. assert.ok( false, "everything's gonna be alright" );
  33374. } );
  33375. // INSTANCING
  33376. QUnit.test( "Instancing", ( assert ) => {
  33377. assert.ok( false, "everything's gonna be alright" );
  33378. } );
  33379. // PUBLIC STUFF
  33380. QUnit.test( "isMeshLambertMaterial", ( assert ) => {
  33381. assert.ok( false, "everything's gonna be alright" );
  33382. } );
  33383. QUnit.test( "copy", ( assert ) => {
  33384. assert.ok( false, "everything's gonna be alright" );
  33385. } );
  33386. } );
  33387. } );
  33388. /**
  33389. * @author TristanVALCKE / https://github.com/Itee
  33390. */
  33391. /* global QUnit */
  33392. QUnit.module( 'Materials', () => {
  33393. QUnit.module.todo( 'MeshNormalMaterial', () => {
  33394. // INHERITANCE
  33395. QUnit.test( "Extending", ( assert ) => {
  33396. assert.ok( false, "everything's gonna be alright" );
  33397. } );
  33398. // INSTANCING
  33399. QUnit.test( "Instancing", ( assert ) => {
  33400. assert.ok( false, "everything's gonna be alright" );
  33401. } );
  33402. // PUBLIC STUFF
  33403. QUnit.test( "isMeshNormalMaterial", ( assert ) => {
  33404. assert.ok( false, "everything's gonna be alright" );
  33405. } );
  33406. QUnit.test( "copy", ( assert ) => {
  33407. assert.ok( false, "everything's gonna be alright" );
  33408. } );
  33409. } );
  33410. } );
  33411. /**
  33412. * @author TristanVALCKE / https://github.com/Itee
  33413. */
  33414. /* global QUnit */
  33415. QUnit.module( 'Materials', () => {
  33416. QUnit.module.todo( 'MeshPhongMaterial', () => {
  33417. // INHERITANCE
  33418. QUnit.test( "Extending", ( assert ) => {
  33419. assert.ok( false, "everything's gonna be alright" );
  33420. } );
  33421. // INSTANCING
  33422. QUnit.test( "Instancing", ( assert ) => {
  33423. assert.ok( false, "everything's gonna be alright" );
  33424. } );
  33425. // PUBLIC STUFF
  33426. QUnit.test( "isMeshPhongMaterial", ( assert ) => {
  33427. assert.ok( false, "everything's gonna be alright" );
  33428. } );
  33429. QUnit.test( "copy", ( assert ) => {
  33430. assert.ok( false, "everything's gonna be alright" );
  33431. } );
  33432. } );
  33433. } );
  33434. /**
  33435. * @author TristanVALCKE / https://github.com/Itee
  33436. */
  33437. /* global QUnit */
  33438. QUnit.module( 'Materials', () => {
  33439. QUnit.module.todo( 'MeshPhysicalMaterial', () => {
  33440. // INHERITANCE
  33441. QUnit.test( "Extending", ( assert ) => {
  33442. assert.ok( false, "everything's gonna be alright" );
  33443. } );
  33444. // INSTANCING
  33445. QUnit.test( "Instancing", ( assert ) => {
  33446. assert.ok( false, "everything's gonna be alright" );
  33447. } );
  33448. // PUBLIC STUFF
  33449. QUnit.test( "isMeshPhysicalMaterial", ( assert ) => {
  33450. assert.ok( false, "everything's gonna be alright" );
  33451. } );
  33452. QUnit.test( "copy", ( assert ) => {
  33453. assert.ok( false, "everything's gonna be alright" );
  33454. } );
  33455. } );
  33456. } );
  33457. /**
  33458. * @author TristanVALCKE / https://github.com/Itee
  33459. */
  33460. /* global QUnit */
  33461. QUnit.module( 'Materials', () => {
  33462. QUnit.module.todo( 'MeshStandardMaterial', () => {
  33463. // INHERITANCE
  33464. QUnit.test( "Extending", ( assert ) => {
  33465. assert.ok( false, "everything's gonna be alright" );
  33466. } );
  33467. // INSTANCING
  33468. QUnit.test( "Instancing", ( assert ) => {
  33469. assert.ok( false, "everything's gonna be alright" );
  33470. } );
  33471. // PUBLIC STUFF
  33472. QUnit.test( "isMeshStandardMaterial", ( assert ) => {
  33473. assert.ok( false, "everything's gonna be alright" );
  33474. } );
  33475. QUnit.test( "copy", ( assert ) => {
  33476. assert.ok( false, "everything's gonna be alright" );
  33477. } );
  33478. } );
  33479. } );
  33480. /**
  33481. * @author TristanVALCKE / https://github.com/Itee
  33482. */
  33483. /* global QUnit */
  33484. QUnit.module( 'Materials', () => {
  33485. QUnit.module.todo( 'MeshToonMaterial', () => {
  33486. // INHERITANCE
  33487. QUnit.test( "Extending", ( assert ) => {
  33488. assert.ok( false, "everything's gonna be alright" );
  33489. } );
  33490. // INSTANCING
  33491. QUnit.test( "Instancing", ( assert ) => {
  33492. assert.ok( false, "everything's gonna be alright" );
  33493. } );
  33494. // PUBLIC STUFF
  33495. QUnit.test( "isMeshToonMaterial", ( assert ) => {
  33496. assert.ok( false, "everything's gonna be alright" );
  33497. } );
  33498. QUnit.test( "copy", ( assert ) => {
  33499. assert.ok( false, "everything's gonna be alright" );
  33500. } );
  33501. } );
  33502. } );
  33503. /**
  33504. * @author TristanVALCKE / https://github.com/Itee
  33505. */
  33506. /* global QUnit */
  33507. QUnit.module( 'Materials', () => {
  33508. QUnit.module.todo( 'PointsMaterial', () => {
  33509. // INHERITANCE
  33510. QUnit.test( "Extending", ( assert ) => {
  33511. assert.ok( false, "everything's gonna be alright" );
  33512. } );
  33513. // INSTANCING
  33514. QUnit.test( "Instancing", ( assert ) => {
  33515. assert.ok( false, "everything's gonna be alright" );
  33516. } );
  33517. // PUBLIC STUFF
  33518. QUnit.test( "isPointsMaterial", ( assert ) => {
  33519. assert.ok( false, "everything's gonna be alright" );
  33520. } );
  33521. QUnit.test( "copy", ( assert ) => {
  33522. assert.ok( false, "everything's gonna be alright" );
  33523. } );
  33524. } );
  33525. } );
  33526. /**
  33527. * @author TristanVALCKE / https://github.com/Itee
  33528. */
  33529. /* global QUnit */
  33530. QUnit.module( 'Materials', () => {
  33531. QUnit.module.todo( 'RawShaderMaterial', () => {
  33532. // INHERITANCE
  33533. QUnit.test( "Extending", ( assert ) => {
  33534. assert.ok( false, "everything's gonna be alright" );
  33535. } );
  33536. // INSTANCING
  33537. QUnit.test( "Instancing", ( assert ) => {
  33538. assert.ok( false, "everything's gonna be alright" );
  33539. } );
  33540. // PUBLIC STUFF
  33541. QUnit.test( "isRawShaderMaterial", ( assert ) => {
  33542. assert.ok( false, "everything's gonna be alright" );
  33543. } );
  33544. } );
  33545. } );
  33546. /**
  33547. * @author TristanVALCKE / https://github.com/Itee
  33548. */
  33549. /* global QUnit */
  33550. QUnit.module( 'Materials', () => {
  33551. QUnit.module.todo( 'ShaderMaterial', () => {
  33552. // INHERITANCE
  33553. QUnit.test( "Extending", ( assert ) => {
  33554. assert.ok( false, "everything's gonna be alright" );
  33555. } );
  33556. // INSTANCING
  33557. QUnit.test( "Instancing", ( assert ) => {
  33558. assert.ok( false, "everything's gonna be alright" );
  33559. } );
  33560. // PUBLIC STUFF
  33561. QUnit.test( "isShaderwMaterial", ( assert ) => {
  33562. assert.ok( false, "everything's gonna be alright" );
  33563. } );
  33564. QUnit.test( "copy", ( assert ) => {
  33565. assert.ok( false, "everything's gonna be alright" );
  33566. } );
  33567. QUnit.test( "toJSON", ( assert ) => {
  33568. assert.ok( false, "everything's gonna be alright" );
  33569. } );
  33570. } );
  33571. } );
  33572. /**
  33573. * @author TristanVALCKE / https://github.com/Itee
  33574. */
  33575. /* global QUnit */
  33576. QUnit.module( 'Materials', () => {
  33577. QUnit.module.todo( 'LineBasicMaterial', () => {
  33578. // INHERITANCE
  33579. QUnit.test( "Extending", ( assert ) => {
  33580. assert.ok( false, "everything's gonna be alright" );
  33581. } );
  33582. // INSTANCING
  33583. QUnit.test( "Instancing", ( assert ) => {
  33584. assert.ok( false, "everything's gonna be alright" );
  33585. } );
  33586. // PUBLIC STUFF
  33587. QUnit.test( "isShadowMaterial", ( assert ) => {
  33588. assert.ok( false, "everything's gonna be alright" );
  33589. } );
  33590. } );
  33591. } );
  33592. /**
  33593. * @author TristanVALCKE / https://github.com/Itee
  33594. */
  33595. /* global QUnit */
  33596. QUnit.module( 'Materials', () => {
  33597. QUnit.module.todo( 'SpriteMaterial', () => {
  33598. // INHERITANCE
  33599. QUnit.test( "Extending", ( assert ) => {
  33600. assert.ok( false, "everything's gonna be alright" );
  33601. } );
  33602. // INSTANCING
  33603. QUnit.test( "Instancing", ( assert ) => {
  33604. assert.ok( false, "everything's gonna be alright" );
  33605. } );
  33606. // PUBLIC STUFF
  33607. QUnit.test( "isSpriteMaterial", ( assert ) => {
  33608. assert.ok( false, "everything's gonna be alright" );
  33609. } );
  33610. QUnit.test( "copy", ( assert ) => {
  33611. assert.ok( false, "everything's gonna be alright" );
  33612. } );
  33613. } );
  33614. } );
  33615. /**
  33616. * @author bhouston / http://exocortex.com
  33617. * @author TristanVALCKE / https://github.com/Itee
  33618. */
  33619. /* global QUnit */
  33620. QUnit.module( 'Maths', () => {
  33621. QUnit.module.todo( 'Box2', () => {
  33622. // INSTANCING
  33623. QUnit.test( "Instancing", ( assert ) => {
  33624. var a = new Box2();
  33625. assert.ok( a.min.equals( posInf2 ), "Passed!" );
  33626. assert.ok( a.max.equals( negInf2 ), "Passed!" );
  33627. var a = new Box2( zero2.clone(), zero2.clone() );
  33628. assert.ok( a.min.equals( zero2 ), "Passed!" );
  33629. assert.ok( a.max.equals( zero2 ), "Passed!" );
  33630. var a = new Box2( zero2.clone(), one2.clone() );
  33631. assert.ok( a.min.equals( zero2 ), "Passed!" );
  33632. assert.ok( a.max.equals( one2 ), "Passed!" );
  33633. } );
  33634. // PUBLIC STUFF
  33635. QUnit.test( "set", ( assert ) => {
  33636. var a = new Box2();
  33637. a.set( zero2, one2 );
  33638. assert.ok( a.min.equals( zero2 ), "Passed!" );
  33639. assert.ok( a.max.equals( one2 ), "Passed!" );
  33640. } );
  33641. QUnit.test( "setFromPoints", ( assert ) => {
  33642. var a = new Box2();
  33643. a.setFromPoints( [ zero2, one2, two2 ] );
  33644. assert.ok( a.min.equals( zero2 ), "Passed!" );
  33645. assert.ok( a.max.equals( two2 ), "Passed!" );
  33646. a.setFromPoints( [ one2 ] );
  33647. assert.ok( a.min.equals( one2 ), "Passed!" );
  33648. assert.ok( a.max.equals( one2 ), "Passed!" );
  33649. a.setFromPoints( [] );
  33650. assert.ok( a.isEmpty(), "Passed!" );
  33651. } );
  33652. QUnit.test( "setFromCenterAndSize", ( assert ) => {
  33653. assert.ok( false, "everything's gonna be alright" );
  33654. } );
  33655. QUnit.test( "clone", ( assert ) => {
  33656. assert.ok( false, "everything's gonna be alright" );
  33657. } );
  33658. QUnit.test( "copy", ( assert ) => {
  33659. var a = new Box2( zero2.clone(), one2.clone() );
  33660. var b = new Box2().copy( a );
  33661. assert.ok( b.min.equals( zero2 ), "Passed!" );
  33662. assert.ok( b.max.equals( one2 ), "Passed!" );
  33663. // ensure that it is a true copy
  33664. a.min = zero2;
  33665. a.max = one2;
  33666. assert.ok( b.min.equals( zero2 ), "Passed!" );
  33667. assert.ok( b.max.equals( one2 ), "Passed!" );
  33668. } );
  33669. QUnit.test( "empty/makeEmpty", ( assert ) => {
  33670. var a = new Box2();
  33671. assert.ok( a.isEmpty(), "Passed!" );
  33672. var a = new Box2( zero2.clone(), one2.clone() );
  33673. assert.ok( ! a.isEmpty(), "Passed!" );
  33674. a.makeEmpty();
  33675. assert.ok( a.isEmpty(), "Passed!" );
  33676. } );
  33677. QUnit.test( "isEmpty", ( assert ) => {
  33678. assert.ok( false, "everything's gonna be alright" );
  33679. } );
  33680. QUnit.test( "getCenter", ( assert ) => {
  33681. var a = new Box2( zero2.clone(), zero2.clone() );
  33682. assert.ok( a.getCenter().equals( zero2 ), "Passed!" );
  33683. var a = new Box2( zero2, one2 );
  33684. var midpoint = one2.clone().multiplyScalar( 0.5 );
  33685. assert.ok( a.getCenter().equals( midpoint ), "Passed!" );
  33686. } );
  33687. QUnit.test( "getSize", ( assert ) => {
  33688. var a = new Box2( zero2.clone(), zero2.clone() );
  33689. assert.ok( a.getSize().equals( zero2 ), "Passed!" );
  33690. var a = new Box2( zero2.clone(), one2.clone() );
  33691. assert.ok( a.getSize().equals( one2 ), "Passed!" );
  33692. } );
  33693. QUnit.test( "expandByPoint", ( assert ) => {
  33694. var a = new Box2( zero2.clone(), zero2.clone() );
  33695. a.expandByPoint( zero2 );
  33696. assert.ok( a.getSize().equals( zero2 ), "Passed!" );
  33697. a.expandByPoint( one2 );
  33698. assert.ok( a.getSize().equals( one2 ), "Passed!" );
  33699. a.expandByPoint( one2.clone().negate() );
  33700. assert.ok( a.getSize().equals( one2.clone().multiplyScalar( 2 ) ), "Passed!" );
  33701. assert.ok( a.getCenter().equals( zero2 ), "Passed!" );
  33702. } );
  33703. QUnit.test( "expandByVector", ( assert ) => {
  33704. var a = new Box2( zero2.clone(), zero2.clone() );
  33705. a.expandByVector( zero2 );
  33706. assert.ok( a.getSize().equals( zero2 ), "Passed!" );
  33707. a.expandByVector( one2 );
  33708. assert.ok( a.getSize().equals( one2.clone().multiplyScalar( 2 ) ), "Passed!" );
  33709. assert.ok( a.getCenter().equals( zero2 ), "Passed!" );
  33710. } );
  33711. QUnit.test( "expandByScalar", ( assert ) => {
  33712. var a = new Box2( zero2.clone(), zero2.clone() );
  33713. a.expandByScalar( 0 );
  33714. assert.ok( a.getSize().equals( zero2 ), "Passed!" );
  33715. a.expandByScalar( 1 );
  33716. assert.ok( a.getSize().equals( one2.clone().multiplyScalar( 2 ) ), "Passed!" );
  33717. assert.ok( a.getCenter().equals( zero2 ), "Passed!" );
  33718. } );
  33719. QUnit.test( "containsPoint", ( assert ) => {
  33720. var a = new Box2( zero2.clone(), zero2.clone() );
  33721. assert.ok( a.containsPoint( zero2 ), "Passed!" );
  33722. assert.ok( ! a.containsPoint( one2 ), "Passed!" );
  33723. a.expandByScalar( 1 );
  33724. assert.ok( a.containsPoint( zero2 ), "Passed!" );
  33725. assert.ok( a.containsPoint( one2 ), "Passed!" );
  33726. assert.ok( a.containsPoint( one2.clone().negate() ), "Passed!" );
  33727. } );
  33728. QUnit.test( "containsBox", ( assert ) => {
  33729. var a = new Box2( zero2.clone(), zero2.clone() );
  33730. var b = new Box2( zero2.clone(), one2.clone() );
  33731. var c = new Box2( one2.clone().negate(), one2.clone() );
  33732. assert.ok( a.containsBox( a ), "Passed!" );
  33733. assert.ok( ! a.containsBox( b ), "Passed!" );
  33734. assert.ok( ! a.containsBox( c ), "Passed!" );
  33735. assert.ok( b.containsBox( a ), "Passed!" );
  33736. assert.ok( c.containsBox( a ), "Passed!" );
  33737. assert.ok( ! b.containsBox( c ), "Passed!" );
  33738. } );
  33739. QUnit.test( "getParameter", ( assert ) => {
  33740. var a = new Box2( zero2.clone(), one2.clone() );
  33741. var b = new Box2( one2.clone().negate(), one2.clone() );
  33742. assert.ok( a.getParameter( new Vector2( 0, 0 ) ).equals( new Vector2( 0, 0 ) ), "Passed!" );
  33743. assert.ok( a.getParameter( new Vector2( 1, 1 ) ).equals( new Vector2( 1, 1 ) ), "Passed!" );
  33744. assert.ok( b.getParameter( new Vector2( - 1, - 1 ) ).equals( new Vector2( 0, 0 ) ), "Passed!" );
  33745. assert.ok( b.getParameter( new Vector2( 0, 0 ) ).equals( new Vector2( 0.5, 0.5 ) ), "Passed!" );
  33746. assert.ok( b.getParameter( new Vector2( 1, 1 ) ).equals( new Vector2( 1, 1 ) ), "Passed!" );
  33747. } );
  33748. QUnit.test( "intersectsBox", ( assert ) => {
  33749. var a = new Box2( zero2.clone(), zero2.clone() );
  33750. var b = new Box2( zero2.clone(), one2.clone() );
  33751. var c = new Box2( one2.clone().negate(), one2.clone() );
  33752. assert.ok( a.intersectsBox( a ), "Passed!" );
  33753. assert.ok( a.intersectsBox( b ), "Passed!" );
  33754. assert.ok( a.intersectsBox( c ), "Passed!" );
  33755. assert.ok( b.intersectsBox( a ), "Passed!" );
  33756. assert.ok( c.intersectsBox( a ), "Passed!" );
  33757. assert.ok( b.intersectsBox( c ), "Passed!" );
  33758. b.translate( new Vector2( 2, 2 ) );
  33759. assert.ok( ! a.intersectsBox( b ), "Passed!" );
  33760. assert.ok( ! b.intersectsBox( a ), "Passed!" );
  33761. assert.ok( ! b.intersectsBox( c ), "Passed!" );
  33762. } );
  33763. QUnit.test( "clampPoint", ( assert ) => {
  33764. var a = new Box2( zero2.clone(), zero2.clone() );
  33765. var b = new Box2( one2.clone().negate(), one2.clone() );
  33766. assert.ok( a.clampPoint( new Vector2( 0, 0 ) ).equals( new Vector2( 0, 0 ) ), "Passed!" );
  33767. assert.ok( a.clampPoint( new Vector2( 1, 1 ) ).equals( new Vector2( 0, 0 ) ), "Passed!" );
  33768. assert.ok( a.clampPoint( new Vector2( - 1, - 1 ) ).equals( new Vector2( 0, 0 ) ), "Passed!" );
  33769. assert.ok( b.clampPoint( new Vector2( 2, 2 ) ).equals( new Vector2( 1, 1 ) ), "Passed!" );
  33770. assert.ok( b.clampPoint( new Vector2( 1, 1 ) ).equals( new Vector2( 1, 1 ) ), "Passed!" );
  33771. assert.ok( b.clampPoint( new Vector2( 0, 0 ) ).equals( new Vector2( 0, 0 ) ), "Passed!" );
  33772. assert.ok( b.clampPoint( new Vector2( - 1, - 1 ) ).equals( new Vector2( - 1, - 1 ) ), "Passed!" );
  33773. assert.ok( b.clampPoint( new Vector2( - 2, - 2 ) ).equals( new Vector2( - 1, - 1 ) ), "Passed!" );
  33774. } );
  33775. QUnit.test( "distanceToPoint", ( assert ) => {
  33776. var a = new Box2( zero2.clone(), zero2.clone() );
  33777. var b = new Box2( one2.clone().negate(), one2.clone() );
  33778. assert.ok( a.distanceToPoint( new Vector2( 0, 0 ) ) == 0, "Passed!" );
  33779. assert.ok( a.distanceToPoint( new Vector2( 1, 1 ) ) == Math.sqrt( 2 ), "Passed!" );
  33780. assert.ok( a.distanceToPoint( new Vector2( - 1, - 1 ) ) == Math.sqrt( 2 ), "Passed!" );
  33781. assert.ok( b.distanceToPoint( new Vector2( 2, 2 ) ) == Math.sqrt( 2 ), "Passed!" );
  33782. assert.ok( b.distanceToPoint( new Vector2( 1, 1 ) ) == 0, "Passed!" );
  33783. assert.ok( b.distanceToPoint( new Vector2( 0, 0 ) ) == 0, "Passed!" );
  33784. assert.ok( b.distanceToPoint( new Vector2( - 1, - 1 ) ) == 0, "Passed!" );
  33785. assert.ok( b.distanceToPoint( new Vector2( - 2, - 2 ) ) == Math.sqrt( 2 ), "Passed!" );
  33786. } );
  33787. QUnit.test( "intersect", ( assert ) => {
  33788. var a = new Box2( zero2.clone(), zero2.clone() );
  33789. var b = new Box2( zero2.clone(), one2.clone() );
  33790. var c = new Box2( one2.clone().negate(), one2.clone() );
  33791. assert.ok( a.clone().intersect( a ).equals( a ), "Passed!" );
  33792. assert.ok( a.clone().intersect( b ).equals( a ), "Passed!" );
  33793. assert.ok( b.clone().intersect( b ).equals( b ), "Passed!" );
  33794. assert.ok( a.clone().intersect( c ).equals( a ), "Passed!" );
  33795. assert.ok( b.clone().intersect( c ).equals( b ), "Passed!" );
  33796. assert.ok( c.clone().intersect( c ).equals( c ), "Passed!" );
  33797. } );
  33798. QUnit.test( "union", ( assert ) => {
  33799. var a = new Box2( zero2.clone(), zero2.clone() );
  33800. var b = new Box2( zero2.clone(), one2.clone() );
  33801. var c = new Box2( one2.clone().negate(), one2.clone() );
  33802. assert.ok( a.clone().union( a ).equals( a ), "Passed!" );
  33803. assert.ok( a.clone().union( b ).equals( b ), "Passed!" );
  33804. assert.ok( a.clone().union( c ).equals( c ), "Passed!" );
  33805. assert.ok( b.clone().union( c ).equals( c ), "Passed!" );
  33806. } );
  33807. QUnit.test( "translate", ( assert ) => {
  33808. var a = new Box2( zero2.clone(), zero2.clone() );
  33809. var b = new Box2( zero2.clone(), one2.clone() );
  33810. var c = new Box2( one2.clone().negate(), one2.clone() );
  33811. var d = new Box2( one2.clone().negate(), zero2.clone() );
  33812. assert.ok( a.clone().translate( one2 ).equals( new Box2( one2, one2 ) ), "Passed!" );
  33813. assert.ok( a.clone().translate( one2 ).translate( one2.clone().negate() ).equals( a ), "Passed!" );
  33814. assert.ok( d.clone().translate( one2 ).equals( b ), "Passed!" );
  33815. assert.ok( b.clone().translate( one2.clone().negate() ).equals( d ), "Passed!" );
  33816. } );
  33817. QUnit.test( "equals", ( assert ) => {
  33818. assert.ok( false, "everything's gonna be alright" );
  33819. } );
  33820. } );
  33821. } );
  33822. /**
  33823. * @author bhouston / http://exocortex.com
  33824. * @author TristanVALCKE / https://github.com/Itee
  33825. */
  33826. /* global QUnit */
  33827. function compareBox( a, b, threshold ) {
  33828. threshold = threshold || 0.0001;
  33829. return ( a.min.distanceTo( b.min ) < threshold &&
  33830. a.max.distanceTo( b.max ) < threshold );
  33831. }
  33832. QUnit.module( 'Maths', () => {
  33833. QUnit.module.todo( 'Box3', () => {
  33834. // INSTANCING
  33835. QUnit.test( "Instancing", ( assert ) => {
  33836. var a = new Box3();
  33837. assert.ok( a.min.equals( posInf3 ), "Passed!" );
  33838. assert.ok( a.max.equals( negInf3 ), "Passed!" );
  33839. var a = new Box3( zero3.clone(), zero3.clone() );
  33840. assert.ok( a.min.equals( zero3 ), "Passed!" );
  33841. assert.ok( a.max.equals( zero3 ), "Passed!" );
  33842. var a = new Box3( zero3.clone(), one3.clone() );
  33843. assert.ok( a.min.equals( zero3 ), "Passed!" );
  33844. assert.ok( a.max.equals( one3 ), "Passed!" );
  33845. } );
  33846. // PUBLIC STUFF
  33847. QUnit.test( "isBox3", ( assert ) => {
  33848. assert.ok( false, "everything's gonna be alright" );
  33849. } );
  33850. QUnit.test( "set", ( assert ) => {
  33851. var a = new Box3();
  33852. a.set( zero3, one3 );
  33853. assert.ok( a.min.equals( zero3 ), "Passed!" );
  33854. assert.ok( a.max.equals( one3 ), "Passed!" );
  33855. } );
  33856. QUnit.test( "setFromArray", ( assert ) => {
  33857. assert.ok( false, "everything's gonna be alright" );
  33858. } );
  33859. QUnit.test( "setFromBufferAttribute", ( assert ) => {
  33860. var a = new Box3( zero3.clone(), one3.clone() );
  33861. var bigger = new BufferAttribute( new Float32Array( [
  33862. - 2, - 2, - 2, 2, 2, 2, 1.5, 1.5, 1.5, 0, 0, 0
  33863. ] ), 3 );
  33864. var smaller = new BufferAttribute( new Float32Array( [
  33865. - 0.5, - 0.5, - 0.5, 0.5, 0.5, 0.5, 0, 0, 0
  33866. ] ), 3 );
  33867. var newMin = new Vector3( - 2, - 2, - 2 );
  33868. var newMax = new Vector3( 2, 2, 2 );
  33869. a.setFromBufferAttribute( bigger );
  33870. assert.ok( a.min.equals( newMin ), "Bigger box: correct new minimum" );
  33871. assert.ok( a.max.equals( newMax ), "Bigger box: correct new maximum" );
  33872. newMin.set( - 0.5, - 0.5, - 0.5 );
  33873. newMax.set( 0.5, 0.5, 0.5 );
  33874. a.setFromBufferAttribute( smaller );
  33875. assert.ok( a.min.equals( newMin ), "Smaller box: correct new minimum" );
  33876. assert.ok( a.max.equals( newMax ), "Smaller box: correct new maximum" );
  33877. } );
  33878. QUnit.test( "setFromPoints", ( assert ) => {
  33879. var a = new Box3();
  33880. a.setFromPoints( [ zero3, one3, two3 ] );
  33881. assert.ok( a.min.equals( zero3 ), "Passed!" );
  33882. assert.ok( a.max.equals( two3 ), "Passed!" );
  33883. a.setFromPoints( [ one3 ] );
  33884. assert.ok( a.min.equals( one3 ), "Passed!" );
  33885. assert.ok( a.max.equals( one3 ), "Passed!" );
  33886. a.setFromPoints( [] );
  33887. assert.ok( a.isEmpty(), "Passed!" );
  33888. } );
  33889. QUnit.test( "setFromCenterAndSize", ( assert ) => {
  33890. var a = new Box3( zero3.clone(), one3.clone() );
  33891. var b = a.clone();
  33892. var newCenter = one3;
  33893. var newSize = two3;
  33894. a.setFromCenterAndSize( a.getCenter(), a.getSize() );
  33895. assert.ok( a.equals( b ), "Same values: no changes" );
  33896. a.setFromCenterAndSize( newCenter, a.getSize() );
  33897. assert.ok( a.getCenter().equals( newCenter ), "Move center: correct new center" );
  33898. assert.ok( a.getSize().equals( b.getSize() ), "Move center: no change in size" );
  33899. assert.notOk( a.equals( b ), "Move center: no longer equal to old values" );
  33900. a.setFromCenterAndSize( a.getCenter(), newSize );
  33901. assert.ok( a.getCenter().equals( newCenter ), "Resize: no change to center" );
  33902. assert.ok( a.getSize().equals( newSize ), "Resize: correct new size" );
  33903. assert.notOk( a.equals( b ), "Resize: no longer equal to old values" );
  33904. } );
  33905. QUnit.test( "setFromObject/BufferGeometry", ( assert ) => {
  33906. var a = new Box3( zero3.clone(), one3.clone() );
  33907. var object = new Mesh( new BoxBufferGeometry( 2, 2, 2 ) );
  33908. var child = new Mesh( new BoxBufferGeometry( 1, 1, 1 ) );
  33909. object.add( child );
  33910. a.setFromObject( object );
  33911. assert.ok( a.min.equals( new Vector3( - 1, - 1, - 1 ) ), "Correct new minimum" );
  33912. assert.ok( a.max.equals( new Vector3( 1, 1, 1 ) ), "Correct new maximum" );
  33913. } );
  33914. QUnit.test( "clone", ( assert ) => {
  33915. assert.ok( false, "everything's gonna be alright" );
  33916. } );
  33917. QUnit.test( "copy", ( assert ) => {
  33918. var a = new Box3( zero3.clone(), one3.clone() );
  33919. var b = new Box3().copy( a );
  33920. assert.ok( b.min.equals( zero3 ), "Passed!" );
  33921. assert.ok( b.max.equals( one3 ), "Passed!" );
  33922. // ensure that it is a true copy
  33923. a.min = zero3;
  33924. a.max = one3;
  33925. assert.ok( b.min.equals( zero3 ), "Passed!" );
  33926. assert.ok( b.max.equals( one3 ), "Passed!" );
  33927. } );
  33928. QUnit.test( "empty/makeEmpty", ( assert ) => {
  33929. var a = new Box3();
  33930. assert.ok( a.isEmpty(), "Passed!" );
  33931. var a = new Box3( zero3.clone(), one3.clone() );
  33932. assert.ok( ! a.isEmpty(), "Passed!" );
  33933. a.makeEmpty();
  33934. assert.ok( a.isEmpty(), "Passed!" );
  33935. } );
  33936. QUnit.test( "isEmpty", ( assert ) => {
  33937. assert.ok( false, "everything's gonna be alright" );
  33938. } );
  33939. QUnit.test( "getCenter", ( assert ) => {
  33940. var a = new Box3( zero3.clone(), zero3.clone() );
  33941. assert.ok( a.getCenter().equals( zero3 ), "Passed!" );
  33942. var a = new Box3( zero3.clone(), one3.clone() );
  33943. var midpoint = one3.clone().multiplyScalar( 0.5 );
  33944. assert.ok( a.getCenter().equals( midpoint ), "Passed!" );
  33945. } );
  33946. QUnit.test( "getSize", ( assert ) => {
  33947. var a = new Box3( zero3.clone(), zero3.clone() );
  33948. assert.ok( a.getSize().equals( zero3 ), "Passed!" );
  33949. var a = new Box3( zero3.clone(), one3.clone() );
  33950. assert.ok( a.getSize().equals( one3 ), "Passed!" );
  33951. } );
  33952. QUnit.test( "expandByPoint", ( assert ) => {
  33953. var a = new Box3( zero3.clone(), zero3.clone() );
  33954. a.expandByPoint( zero3 );
  33955. assert.ok( a.getSize().equals( zero3 ), "Passed!" );
  33956. a.expandByPoint( one3 );
  33957. assert.ok( a.getSize().equals( one3 ), "Passed!" );
  33958. a.expandByPoint( one3.clone().negate() );
  33959. assert.ok( a.getSize().equals( one3.clone().multiplyScalar( 2 ) ), "Passed!" );
  33960. assert.ok( a.getCenter().equals( zero3 ), "Passed!" );
  33961. } );
  33962. QUnit.test( "expandByVector", ( assert ) => {
  33963. var a = new Box3( zero3.clone(), zero3.clone() );
  33964. a.expandByVector( zero3 );
  33965. assert.ok( a.getSize().equals( zero3 ), "Passed!" );
  33966. a.expandByVector( one3 );
  33967. assert.ok( a.getSize().equals( one3.clone().multiplyScalar( 2 ) ), "Passed!" );
  33968. assert.ok( a.getCenter().equals( zero3 ), "Passed!" );
  33969. } );
  33970. QUnit.test( "expandByScalar", ( assert ) => {
  33971. var a = new Box3( zero3.clone(), zero3.clone() );
  33972. a.expandByScalar( 0 );
  33973. assert.ok( a.getSize().equals( zero3 ), "Passed!" );
  33974. a.expandByScalar( 1 );
  33975. assert.ok( a.getSize().equals( one3.clone().multiplyScalar( 2 ) ), "Passed!" );
  33976. assert.ok( a.getCenter().equals( zero3 ), "Passed!" );
  33977. } );
  33978. QUnit.test( "expandByObject", ( assert ) => {
  33979. var a = new Box3( zero3.clone(), one3.clone() );
  33980. var b = a.clone();
  33981. var bigger = new Mesh( new BoxGeometry( 2, 2, 2 ) );
  33982. var smaller = new Mesh( new BoxGeometry( 0.5, 0.5, 0.5 ) );
  33983. var child = new Mesh( new BoxGeometry( 1, 1, 1 ) );
  33984. // just a bigger box to begin with
  33985. a.expandByObject( bigger );
  33986. assert.ok( a.min.equals( new Vector3( - 1, - 1, - 1 ) ), "Bigger box: correct new minimum" );
  33987. assert.ok( a.max.equals( new Vector3( 1, 1, 1 ) ), "Bigger box: correct new maximum" );
  33988. // a translated, bigger box
  33989. a.copy( b );
  33990. bigger.translateX( 2 );
  33991. a.expandByObject( bigger );
  33992. assert.ok( a.min.equals( new Vector3( 0, - 1, - 1 ) ), "Translated, bigger box: correct new minimum" );
  33993. assert.ok( a.max.equals( new Vector3( 3, 1, 1 ) ), "Translated, bigger box: correct new maximum" );
  33994. // a translated, bigger box with child
  33995. a.copy( b );
  33996. bigger.add( child );
  33997. a.expandByObject( bigger );
  33998. assert.ok( a.min.equals( new Vector3( 0, - 1, - 1 ) ), "Translated, bigger box with child: correct new minimum" );
  33999. assert.ok( a.max.equals( new Vector3( 3, 1, 1 ) ), "Translated, bigger box with child: correct new maximum" );
  34000. // a translated, bigger box with a translated child
  34001. a.copy( b );
  34002. child.translateX( 2 );
  34003. a.expandByObject( bigger );
  34004. assert.ok( a.min.equals( new Vector3( 0, - 1, - 1 ) ), "Translated, bigger box with translated child: correct new minimum" );
  34005. assert.ok( a.max.equals( new Vector3( 4.5, 1, 1 ) ), "Translated, bigger box with translated child: correct new maximum" );
  34006. // a smaller box
  34007. a.copy( b );
  34008. a.expandByObject( smaller );
  34009. assert.ok( a.min.equals( new Vector3( - 0.25, - 0.25, - 0.25 ) ), "Smaller box: correct new minimum" );
  34010. assert.ok( a.max.equals( new Vector3( 1, 1, 1 ) ), "Smaller box: correct new maximum" );
  34011. } );
  34012. QUnit.test( "containsPoint", ( assert ) => {
  34013. var a = new Box3( zero3.clone(), zero3.clone() );
  34014. assert.ok( a.containsPoint( zero3 ), "Passed!" );
  34015. assert.ok( ! a.containsPoint( one3 ), "Passed!" );
  34016. a.expandByScalar( 1 );
  34017. assert.ok( a.containsPoint( zero3 ), "Passed!" );
  34018. assert.ok( a.containsPoint( one3 ), "Passed!" );
  34019. assert.ok( a.containsPoint( one3.clone().negate() ), "Passed!" );
  34020. } );
  34021. QUnit.test( "containsBox", ( assert ) => {
  34022. var a = new Box3( zero3.clone(), zero3.clone() );
  34023. var b = new Box3( zero3.clone(), one3.clone() );
  34024. var c = new Box3( one3.clone().negate(), one3.clone() );
  34025. assert.ok( a.containsBox( a ), "Passed!" );
  34026. assert.ok( ! a.containsBox( b ), "Passed!" );
  34027. assert.ok( ! a.containsBox( c ), "Passed!" );
  34028. assert.ok( b.containsBox( a ), "Passed!" );
  34029. assert.ok( c.containsBox( a ), "Passed!" );
  34030. assert.ok( ! b.containsBox( c ), "Passed!" );
  34031. } );
  34032. QUnit.test( "getParameter", ( assert ) => {
  34033. var a = new Box3( zero3.clone(), one3.clone() );
  34034. var b = new Box3( one3.clone().negate(), one3.clone() );
  34035. assert.ok( a.getParameter( new Vector3( 0, 0, 0 ) ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
  34036. assert.ok( a.getParameter( new Vector3( 1, 1, 1 ) ).equals( new Vector3( 1, 1, 1 ) ), "Passed!" );
  34037. assert.ok( b.getParameter( new Vector3( - 1, - 1, - 1 ) ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
  34038. assert.ok( b.getParameter( new Vector3( 0, 0, 0 ) ).equals( new Vector3( 0.5, 0.5, 0.5 ) ), "Passed!" );
  34039. assert.ok( b.getParameter( new Vector3( 1, 1, 1 ) ).equals( new Vector3( 1, 1, 1 ) ), "Passed!" );
  34040. } );
  34041. QUnit.test( "intersectsBox", ( assert ) => {
  34042. var a = new Box3( zero3.clone(), zero3.clone() );
  34043. var b = new Box3( zero3.clone(), one3.clone() );
  34044. var c = new Box3( one3.clone().negate(), one3.clone() );
  34045. assert.ok( a.intersectsBox( a ), "Passed!" );
  34046. assert.ok( a.intersectsBox( b ), "Passed!" );
  34047. assert.ok( a.intersectsBox( c ), "Passed!" );
  34048. assert.ok( b.intersectsBox( a ), "Passed!" );
  34049. assert.ok( c.intersectsBox( a ), "Passed!" );
  34050. assert.ok( b.intersectsBox( c ), "Passed!" );
  34051. b.translate( new Vector3( 2, 2, 2 ) );
  34052. assert.ok( ! a.intersectsBox( b ), "Passed!" );
  34053. assert.ok( ! b.intersectsBox( a ), "Passed!" );
  34054. assert.ok( ! b.intersectsBox( c ), "Passed!" );
  34055. } );
  34056. QUnit.test( "intersectsSphere", ( assert ) => {
  34057. var a = new Box3( zero3.clone(), one3.clone() );
  34058. var b = new Sphere( zero3.clone(), 1 );
  34059. assert.ok( a.intersectsSphere( b ), "Passed!" );
  34060. b.translate( new Vector3( 2, 2, 2 ) );
  34061. assert.ok( ! a.intersectsSphere( b ), "Passed!" );
  34062. } );
  34063. QUnit.test( "intersectsPlane", ( assert ) => {
  34064. var a = new Box3( zero3.clone(), one3.clone() );
  34065. var b = new Plane( new Vector3( 0, 1, 0 ), 1 );
  34066. var c = new Plane( new Vector3( 0, 1, 0 ), 1.25 );
  34067. var d = new Plane( new Vector3( 0, - 1, 0 ), 1.25 );
  34068. assert.ok( a.intersectsPlane( b ), "Passed!" );
  34069. assert.ok( ! a.intersectsPlane( c ), "Passed!" );
  34070. assert.ok( ! a.intersectsPlane( d ), "Passed!" );
  34071. } );
  34072. QUnit.test( "clampPoint", ( assert ) => {
  34073. var a = new Box3( zero3.clone(), zero3.clone() );
  34074. var b = new Box3( one3.clone().negate(), one3.clone() );
  34075. assert.ok( a.clampPoint( new Vector3( 0, 0, 0 ) ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
  34076. assert.ok( a.clampPoint( new Vector3( 1, 1, 1 ) ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
  34077. assert.ok( a.clampPoint( new Vector3( - 1, - 1, - 1 ) ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
  34078. assert.ok( b.clampPoint( new Vector3( 2, 2, 2 ) ).equals( new Vector3( 1, 1, 1 ) ), "Passed!" );
  34079. assert.ok( b.clampPoint( new Vector3( 1, 1, 1 ) ).equals( new Vector3( 1, 1, 1 ) ), "Passed!" );
  34080. assert.ok( b.clampPoint( new Vector3( 0, 0, 0 ) ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
  34081. assert.ok( b.clampPoint( new Vector3( - 1, - 1, - 1 ) ).equals( new Vector3( - 1, - 1, - 1 ) ), "Passed!" );
  34082. assert.ok( b.clampPoint( new Vector3( - 2, - 2, - 2 ) ).equals( new Vector3( - 1, - 1, - 1 ) ), "Passed!" );
  34083. } );
  34084. QUnit.test( "distanceToPoint", ( assert ) => {
  34085. var a = new Box3( zero3.clone(), zero3.clone() );
  34086. var b = new Box3( one3.clone().negate(), one3.clone() );
  34087. assert.ok( a.distanceToPoint( new Vector3( 0, 0, 0 ) ) == 0, "Passed!" );
  34088. assert.ok( a.distanceToPoint( new Vector3( 1, 1, 1 ) ) == Math.sqrt( 3 ), "Passed!" );
  34089. assert.ok( a.distanceToPoint( new Vector3( - 1, - 1, - 1 ) ) == Math.sqrt( 3 ), "Passed!" );
  34090. assert.ok( b.distanceToPoint( new Vector3( 2, 2, 2 ) ) == Math.sqrt( 3 ), "Passed!" );
  34091. assert.ok( b.distanceToPoint( new Vector3( 1, 1, 1 ) ) == 0, "Passed!" );
  34092. assert.ok( b.distanceToPoint( new Vector3( 0, 0, 0 ) ) == 0, "Passed!" );
  34093. assert.ok( b.distanceToPoint( new Vector3( - 1, - 1, - 1 ) ) == 0, "Passed!" );
  34094. assert.ok( b.distanceToPoint( new Vector3( - 2, - 2, - 2 ) ) == Math.sqrt( 3 ), "Passed!" );
  34095. } );
  34096. QUnit.test( "getBoundingSphere", ( assert ) => {
  34097. var a = new Box3( zero3.clone(), zero3.clone() );
  34098. var b = new Box3( zero3.clone(), one3.clone() );
  34099. var c = new Box3( one3.clone().negate(), one3.clone() );
  34100. assert.ok( a.getBoundingSphere().equals( new Sphere( zero3, 0 ) ), "Passed!" );
  34101. assert.ok( b.getBoundingSphere().equals( new Sphere( one3.clone().multiplyScalar( 0.5 ), Math.sqrt( 3 ) * 0.5 ) ), "Passed!" );
  34102. assert.ok( c.getBoundingSphere().equals( new Sphere( zero3, Math.sqrt( 12 ) * 0.5 ) ), "Passed!" );
  34103. } );
  34104. QUnit.test( "intersect", ( assert ) => {
  34105. var a = new Box3( zero3.clone(), zero3.clone() );
  34106. var b = new Box3( zero3.clone(), one3.clone() );
  34107. var c = new Box3( one3.clone().negate(), one3.clone() );
  34108. assert.ok( a.clone().intersect( a ).equals( a ), "Passed!" );
  34109. assert.ok( a.clone().intersect( b ).equals( a ), "Passed!" );
  34110. assert.ok( b.clone().intersect( b ).equals( b ), "Passed!" );
  34111. assert.ok( a.clone().intersect( c ).equals( a ), "Passed!" );
  34112. assert.ok( b.clone().intersect( c ).equals( b ), "Passed!" );
  34113. assert.ok( c.clone().intersect( c ).equals( c ), "Passed!" );
  34114. } );
  34115. QUnit.test( "union", ( assert ) => {
  34116. var a = new Box3( zero3.clone(), zero3.clone() );
  34117. var b = new Box3( zero3.clone(), one3.clone() );
  34118. var c = new Box3( one3.clone().negate(), one3.clone() );
  34119. assert.ok( a.clone().union( a ).equals( a ), "Passed!" );
  34120. assert.ok( a.clone().union( b ).equals( b ), "Passed!" );
  34121. assert.ok( a.clone().union( c ).equals( c ), "Passed!" );
  34122. assert.ok( b.clone().union( c ).equals( c ), "Passed!" );
  34123. } );
  34124. QUnit.test( "applyMatrix4", ( assert ) => {
  34125. var a = new Box3( zero3.clone(), zero3.clone() );
  34126. var b = new Box3( zero3.clone(), one3.clone() );
  34127. var c = new Box3( one3.clone().negate(), one3.clone() );
  34128. var d = new Box3( one3.clone().negate(), zero3.clone() );
  34129. var m = new Matrix4().makeTranslation( 1, - 2, 1 );
  34130. var t1 = new Vector3( 1, - 2, 1 );
  34131. assert.ok( compareBox( a.clone().applyMatrix4( m ), a.clone().translate( t1 ) ), "Passed!" );
  34132. assert.ok( compareBox( b.clone().applyMatrix4( m ), b.clone().translate( t1 ) ), "Passed!" );
  34133. assert.ok( compareBox( c.clone().applyMatrix4( m ), c.clone().translate( t1 ) ), "Passed!" );
  34134. assert.ok( compareBox( d.clone().applyMatrix4( m ), d.clone().translate( t1 ) ), "Passed!" );
  34135. } );
  34136. QUnit.test( "translate", ( assert ) => {
  34137. var a = new Box3( zero3.clone(), zero3.clone() );
  34138. var b = new Box3( zero3.clone(), one3.clone() );
  34139. var c = new Box3( one3.clone().negate(), one3.clone() );
  34140. var d = new Box3( one3.clone().negate(), zero3.clone() );
  34141. assert.ok( a.clone().translate( one3 ).equals( new Box3( one3, one3 ) ), "Passed!" );
  34142. assert.ok( a.clone().translate( one3 ).translate( one3.clone().negate() ).equals( a ), "Passed!" );
  34143. assert.ok( d.clone().translate( one3 ).equals( b ), "Passed!" );
  34144. assert.ok( b.clone().translate( one3.clone().negate() ).equals( d ), "Passed!" );
  34145. } );
  34146. QUnit.test( "equals", ( assert ) => {
  34147. assert.ok( false, "everything's gonna be alright" );
  34148. } );
  34149. } );
  34150. } );
  34151. /**
  34152. * @author bhouston / http://exocortex.com
  34153. * @author TristanVALCKE / https://github.com/Itee
  34154. */
  34155. /* global QUnit */
  34156. QUnit.module( 'Maths', () => {
  34157. QUnit.module.todo( 'Color', () => {
  34158. // INSTANCING
  34159. QUnit.test( "Instancing", ( assert ) => {
  34160. // default ctor
  34161. var c = new Color();
  34162. assert.ok( c.r, "Red: " + c.r );
  34163. assert.ok( c.g, "Green: " + c.g );
  34164. assert.ok( c.b, "Blue: " + c.b );
  34165. // rgb ctor
  34166. var c = new Color( 1, 1, 1 );
  34167. assert.ok( c.r == 1, "Passed" );
  34168. assert.ok( c.g == 1, "Passed" );
  34169. assert.ok( c.b == 1, "Passed" );
  34170. } );
  34171. // PUBLIC STUFF
  34172. QUnit.test( "isColor", ( assert ) => {
  34173. assert.ok( false, "everything's gonna be alright" );
  34174. } );
  34175. QUnit.test( "set", ( assert ) => {
  34176. var a = new Color();
  34177. var b = new Color( 0.5, 0, 0 );
  34178. var c = new Color( 0xFF0000 );
  34179. var d = new Color( 0, 1.0, 0 );
  34180. a.set( b );
  34181. assert.ok( a.equals( b ), "Set with Color instance" );
  34182. a.set( 0xFF0000 );
  34183. assert.ok( a.equals( c ), "Set with number" );
  34184. a.set( "rgb(0,255,0)" );
  34185. assert.ok( a.equals( d ), "Set with style" );
  34186. } );
  34187. QUnit.test( "setScalar", ( assert ) => {
  34188. assert.ok( false, "everything's gonna be alright" );
  34189. } );
  34190. QUnit.test( "setHex", ( assert ) => {
  34191. var c = new Color();
  34192. c.setHex( 0xFA8072 );
  34193. assert.ok( c.getHex() == 0xFA8072, "Hex: " + c.getHex() );
  34194. } );
  34195. QUnit.test( "setRGB", ( assert ) => {
  34196. assert.ok( false, "everything's gonna be alright" );
  34197. } );
  34198. QUnit.test( "setHSL", ( assert ) => {
  34199. var c = new Color();
  34200. c.setHSL( 0.75, 1.0, 0.25 );
  34201. var hsl = c.getHSL();
  34202. assert.ok( hsl.h == 0.75, "hue: " + hsl.h );
  34203. assert.ok( hsl.s == 1.00, "saturation: " + hsl.s );
  34204. assert.ok( hsl.l == 0.25, "lightness: " + hsl.l );
  34205. } );
  34206. QUnit.test( "setStyle", ( assert ) => {
  34207. assert.ok( false, "everything's gonna be alright" );
  34208. } );
  34209. QUnit.test( "clone", ( assert ) => {
  34210. var c = new Color( 'teal' );
  34211. var c2 = c.clone();
  34212. assert.ok( c2.getHex() == 0x008080, "Hex c2: " + c2.getHex() );
  34213. } );
  34214. QUnit.test( "copy", ( assert ) => {
  34215. assert.ok( false, "everything's gonna be alright" );
  34216. } );
  34217. QUnit.test( "copyGammaToLinear", ( assert ) => {
  34218. var c = new Color();
  34219. var c2 = new Color();
  34220. c2.setRGB( 0.3, 0.5, 0.9 );
  34221. c.copyGammaToLinear( c2 );
  34222. assert.ok( c.r == 0.09, "Red c: " + c.r + " Red c2: " + c2.r );
  34223. assert.ok( c.g == 0.25, "Green c: " + c.g + " Green c2: " + c2.g );
  34224. assert.ok( c.b == 0.81, "Blue c: " + c.b + " Blue c2: " + c2.b );
  34225. } );
  34226. QUnit.test( "copyLinearToGamma", ( assert ) => {
  34227. var c = new Color();
  34228. var c2 = new Color();
  34229. c2.setRGB( 0.09, 0.25, 0.81 );
  34230. c.copyLinearToGamma( c2 );
  34231. assert.ok( c.r == 0.3, "Red c: " + c.r + " Red c2: " + c2.r );
  34232. assert.ok( c.g == 0.5, "Green c: " + c.g + " Green c2: " + c2.g );
  34233. assert.ok( c.b == 0.9, "Blue c: " + c.b + " Blue c2: " + c2.b );
  34234. } );
  34235. QUnit.test( "convertGammaToLinear", ( assert ) => {
  34236. var c = new Color();
  34237. c.setRGB( 0.3, 0.5, 0.9 );
  34238. c.convertGammaToLinear();
  34239. assert.ok( c.r == 0.09, "Red: " + c.r );
  34240. assert.ok( c.g == 0.25, "Green: " + c.g );
  34241. assert.ok( c.b == 0.81, "Blue: " + c.b );
  34242. } );
  34243. QUnit.test( "convertLinearToGamma", ( assert ) => {
  34244. var c = new Color();
  34245. c.setRGB( 4, 9, 16 );
  34246. c.convertLinearToGamma();
  34247. assert.ok( c.r == 2, "Red: " + c.r );
  34248. assert.ok( c.g == 3, "Green: " + c.g );
  34249. assert.ok( c.b == 4, "Blue: " + c.b );
  34250. } );
  34251. QUnit.test( "getHex", ( assert ) => {
  34252. var c = new Color( 'red' );
  34253. var res = c.getHex();
  34254. assert.ok( res == 0xFF0000, "Hex: " + res );
  34255. } );
  34256. QUnit.test( "getHexString", ( assert ) => {
  34257. var c = new Color( 'tomato' );
  34258. var res = c.getHexString();
  34259. assert.ok( res == 'ff6347', "Hex: " + res );
  34260. } );
  34261. QUnit.test( "getHSL", ( assert ) => {
  34262. var c = new Color( 0x80ffff );
  34263. var hsl = c.getHSL();
  34264. assert.ok( hsl.h == 0.5, "hue: " + hsl.h );
  34265. assert.ok( hsl.s == 1.0, "saturation: " + hsl.s );
  34266. assert.ok( ( Math.round( parseFloat( hsl.l ) * 100 ) / 100 ) == 0.75, "lightness: " + hsl.l );
  34267. } );
  34268. QUnit.test( "getStyle", ( assert ) => {
  34269. var c = new Color( 'plum' );
  34270. var res = c.getStyle();
  34271. assert.ok( res == 'rgb(221,160,221)', "style: " + res );
  34272. } );
  34273. QUnit.test( "offsetHSL", ( assert ) => {
  34274. var a = new Color( "hsl(120,50%,50%)" );
  34275. var b = new Color( 0.36, 0.84, 0.648 );
  34276. a.offsetHSL( 0.1, 0.1, 0.1 );
  34277. assert.ok( Math.abs( a.r - b.r ) <= eps, "Check r" );
  34278. assert.ok( Math.abs( a.g - b.g ) <= eps, "Check g" );
  34279. assert.ok( Math.abs( a.b - b.b ) <= eps, "Check b" );
  34280. } );
  34281. QUnit.test( "add", ( assert ) => {
  34282. var a = new Color( 0x0000FF );
  34283. var b = new Color( 0xFF0000 );
  34284. var c = new Color( 0xFF00FF );
  34285. a.add( b );
  34286. assert.ok( a.equals( c ), "Check new value" );
  34287. } );
  34288. QUnit.test( "addColors", ( assert ) => {
  34289. assert.ok( false, "everything's gonna be alright" );
  34290. } );
  34291. QUnit.test( "addScalar", ( assert ) => {
  34292. var a = new Color( 0.1, 0.0, 0.0 );
  34293. var b = new Color( 0.6, 0.5, 0.5 );
  34294. a.addScalar( 0.5 );
  34295. assert.ok( a.equals( b ), "Check new value" );
  34296. } );
  34297. QUnit.test( "sub", ( assert ) => {
  34298. var a = new Color( 0x0000CC );
  34299. var b = new Color( 0xFF0000 );
  34300. var c = new Color( 0x0000AA );
  34301. a.sub( b );
  34302. assert.strictEqual( a.getHex(), 0xCC, "Difference too large" );
  34303. a.sub( c );
  34304. assert.strictEqual( a.getHex(), 0x22, "Difference fine" );
  34305. } );
  34306. QUnit.test( "multiply", ( assert ) => {
  34307. var a = new Color( 1, 0, 0.5 );
  34308. var b = new Color( 0.5, 1, 0.5 );
  34309. var c = new Color( 0.5, 0, 0.25 );
  34310. a.multiply( b );
  34311. assert.ok( a.equals( c ), "Check new value" );
  34312. } );
  34313. QUnit.test( "multiplyScalar", ( assert ) => {
  34314. var a = new Color( 0.25, 0, 0.5 );
  34315. var b = new Color( 0.5, 0, 1 );
  34316. a.multiplyScalar( 2 );
  34317. assert.ok( a.equals( b ), "Check new value" );
  34318. } );
  34319. QUnit.test( "copyHex", ( assert ) => {
  34320. var c = new Color();
  34321. var c2 = new Color( 0xF5FFFA );
  34322. c.copy( c2 );
  34323. assert.ok( c.getHex() == c2.getHex(), "Hex c: " + c.getHex() + " Hex c2: " + c2.getHex() );
  34324. } );
  34325. QUnit.test( "copyColorString", ( assert ) => {
  34326. var c = new Color();
  34327. var c2 = new Color( 'ivory' );
  34328. c.copy( c2 );
  34329. assert.ok( c.getHex() == c2.getHex(), "Hex c: " + c.getHex() + " Hex c2: " + c2.getHex() );
  34330. } );
  34331. QUnit.test( "setRGB", ( assert ) => {
  34332. var c = new Color();
  34333. c.setRGB( 1, 0.2, 0.1 );
  34334. assert.ok( c.r == 1, "Red: " + c.r );
  34335. assert.ok( c.g == 0.2, "Green: " + c.g );
  34336. assert.ok( c.b == 0.1, "Blue: " + c.b );
  34337. } );
  34338. QUnit.test( "lerp", ( assert ) => {
  34339. var c = new Color();
  34340. var c2 = new Color();
  34341. c.setRGB( 0, 0, 0 );
  34342. c.lerp( c2, 0.2 );
  34343. assert.ok( c.r == 0.2, "Red: " + c.r );
  34344. assert.ok( c.g == 0.2, "Green: " + c.g );
  34345. assert.ok( c.b == 0.2, "Blue: " + c.b );
  34346. } );
  34347. QUnit.test( "equals", ( assert ) => {
  34348. var a = new Color( 0.5, 0.0, 1.0 );
  34349. var b = new Color( 0.5, 1.0, 0.0 );
  34350. assert.strictEqual( a.r, b.r, "Components: r is equal" );
  34351. assert.notStrictEqual( a.g, b.g, "Components: g is not equal" );
  34352. assert.notStrictEqual( a.b, b.b, "Components: b is not equal" );
  34353. assert.notOk( a.equals( b ), "equals(): a not equal b" );
  34354. assert.notOk( b.equals( a ), "equals(): b not equal a" );
  34355. a.copy( b );
  34356. assert.strictEqual( a.r, b.r, "Components after copy(): r is equal" );
  34357. assert.strictEqual( a.g, b.g, "Components after copy(): g is equal" );
  34358. assert.strictEqual( a.b, b.b, "Components after copy(): b is equal" );
  34359. assert.ok( a.equals( b ), "equals() after copy(): a equals b" );
  34360. assert.ok( b.equals( a ), "equals() after copy(): b equals a" );
  34361. } );
  34362. QUnit.test( "fromArray", ( assert ) => {
  34363. var a = new Color();
  34364. var array = [ 0.5, 0.6, 0.7, 0, 1, 0 ];
  34365. a.fromArray( array );
  34366. assert.strictEqual( a.r, 0.5, "No offset: check r" );
  34367. assert.strictEqual( a.g, 0.6, "No offset: check g" );
  34368. assert.strictEqual( a.b, 0.7, "No offset: check b" );
  34369. a.fromArray( array, 3 );
  34370. assert.strictEqual( a.r, 0, "With offset: check r" );
  34371. assert.strictEqual( a.g, 1, "With offset: check g" );
  34372. assert.strictEqual( a.b, 0, "With offset: check b" );
  34373. } );
  34374. QUnit.test( "toArray", ( assert ) => {
  34375. var r = 0.5, g = 1.0, b = 0.0;
  34376. var a = new Color( r, g, b );
  34377. var array = a.toArray();
  34378. assert.strictEqual( array[ 0 ], r, "No array, no offset: check r" );
  34379. assert.strictEqual( array[ 1 ], g, "No array, no offset: check g" );
  34380. assert.strictEqual( array[ 2 ], b, "No array, no offset: check b" );
  34381. var array = [];
  34382. a.toArray( array );
  34383. assert.strictEqual( array[ 0 ], r, "With array, no offset: check r" );
  34384. assert.strictEqual( array[ 1 ], g, "With array, no offset: check g" );
  34385. assert.strictEqual( array[ 2 ], b, "With array, no offset: check b" );
  34386. var array = [];
  34387. a.toArray( array, 1 );
  34388. assert.strictEqual( array[ 0 ], undefined, "With array and offset: check [0]" );
  34389. assert.strictEqual( array[ 1 ], r, "With array and offset: check r" );
  34390. assert.strictEqual( array[ 2 ], g, "With array and offset: check g" );
  34391. assert.strictEqual( array[ 3 ], b, "With array and offset: check b" );
  34392. } );
  34393. QUnit.test( "toJSON", ( assert ) => {
  34394. var a = new Color( 0.0, 0.0, 0.0 );
  34395. var b = new Color( 0.0, 0.5, 0.0 );
  34396. var c = new Color( 1.0, 0.0, 0.0 );
  34397. var d = new Color( 1.0, 1.0, 1.0 );
  34398. assert.strictEqual( a.toJSON(), 0x000000, "Check black" );
  34399. assert.strictEqual( b.toJSON(), 0x007F00, "Check half-blue" );
  34400. assert.strictEqual( c.toJSON(), 0xFF0000, "Check red" );
  34401. assert.strictEqual( d.toJSON(), 0xFFFFFF, "Check white" );
  34402. } );
  34403. // OTHERS
  34404. QUnit.test( "setWithNum", ( assert ) => {
  34405. var c = new Color();
  34406. c.set( 0xFF0000 );
  34407. assert.ok( c.r == 1, "Red: " + c.r );
  34408. assert.ok( c.g === 0, "Green: " + c.g );
  34409. assert.ok( c.b === 0, "Blue: " + c.b );
  34410. } );
  34411. QUnit.test( "setWithString", ( assert ) => {
  34412. var c = new Color();
  34413. c.set( 'silver' );
  34414. assert.ok( c.getHex() == 0xC0C0C0, "Hex c: " + c.getHex() );
  34415. } );
  34416. QUnit.test( "setStyleRGBRed", ( assert ) => {
  34417. var c = new Color();
  34418. c.setStyle( 'rgb(255,0,0)' );
  34419. assert.ok( c.r == 1, "Red: " + c.r );
  34420. assert.ok( c.g === 0, "Green: " + c.g );
  34421. assert.ok( c.b === 0, "Blue: " + c.b );
  34422. } );
  34423. QUnit.test( "setStyleRGBARed", ( assert ) => {
  34424. var c = new Color();
  34425. c.setStyle( 'rgba(255,0,0,0.5)' );
  34426. assert.ok( c.r == 1, "Red: " + c.r );
  34427. assert.ok( c.g === 0, "Green: " + c.g );
  34428. assert.ok( c.b === 0, "Blue: " + c.b );
  34429. } );
  34430. QUnit.test( "setStyleRGBRedWithSpaces", ( assert ) => {
  34431. var c = new Color();
  34432. c.setStyle( 'rgb( 255 , 0, 0 )' );
  34433. assert.ok( c.r == 1, "Red: " + c.r );
  34434. assert.ok( c.g === 0, "Green: " + c.g );
  34435. assert.ok( c.b === 0, "Blue: " + c.b );
  34436. } );
  34437. QUnit.test( "setStyleRGBARedWithSpaces", ( assert ) => {
  34438. var c = new Color();
  34439. c.setStyle( 'rgba( 255, 0, 0 , 1 )' );
  34440. assert.ok( c.r == 1, "Red: " + c.r );
  34441. assert.ok( c.g === 0, "Green: " + c.g );
  34442. assert.ok( c.b === 0, "Blue: " + c.b );
  34443. } );
  34444. QUnit.test( "setStyleRGBPercent", ( assert ) => {
  34445. var c = new Color();
  34446. c.setStyle( 'rgb(100%,50%,10%)' );
  34447. assert.ok( c.r == 1, "Red: " + c.r );
  34448. assert.ok( c.g == 0.5, "Green: " + c.g );
  34449. assert.ok( c.b == 0.1, "Blue: " + c.b );
  34450. } );
  34451. QUnit.test( "setStyleRGBAPercent", ( assert ) => {
  34452. var c = new Color();
  34453. c.setStyle( 'rgba(100%,50%,10%, 0.5)' );
  34454. assert.ok( c.r == 1, "Red: " + c.r );
  34455. assert.ok( c.g == 0.5, "Green: " + c.g );
  34456. assert.ok( c.b == 0.1, "Blue: " + c.b );
  34457. } );
  34458. QUnit.test( "setStyleRGBPercentWithSpaces", ( assert ) => {
  34459. var c = new Color();
  34460. c.setStyle( 'rgb( 100% ,50% , 10% )' );
  34461. assert.ok( c.r == 1, "Red: " + c.r );
  34462. assert.ok( c.g == 0.5, "Green: " + c.g );
  34463. assert.ok( c.b == 0.1, "Blue: " + c.b );
  34464. } );
  34465. QUnit.test( "setStyleRGBAPercentWithSpaces", ( assert ) => {
  34466. var c = new Color();
  34467. c.setStyle( 'rgba( 100% ,50% , 10%, 0.5 )' );
  34468. assert.ok( c.r == 1, "Red: " + c.r );
  34469. assert.ok( c.g == 0.5, "Green: " + c.g );
  34470. assert.ok( c.b == 0.1, "Blue: " + c.b );
  34471. } );
  34472. QUnit.test( "setStyleHSLRed", ( assert ) => {
  34473. var c = new Color();
  34474. c.setStyle( 'hsl(360,100%,50%)' );
  34475. assert.ok( c.r == 1, "Red: " + c.r );
  34476. assert.ok( c.g === 0, "Green: " + c.g );
  34477. assert.ok( c.b === 0, "Blue: " + c.b );
  34478. } );
  34479. QUnit.test( "setStyleHSLARed", ( assert ) => {
  34480. var c = new Color();
  34481. c.setStyle( 'hsla(360,100%,50%,0.5)' );
  34482. assert.ok( c.r == 1, "Red: " + c.r );
  34483. assert.ok( c.g === 0, "Green: " + c.g );
  34484. assert.ok( c.b === 0, "Blue: " + c.b );
  34485. } );
  34486. QUnit.test( "setStyleHSLRedWithSpaces", ( assert ) => {
  34487. var c = new Color();
  34488. c.setStyle( 'hsl(360, 100% , 50% )' );
  34489. assert.ok( c.r == 1, "Red: " + c.r );
  34490. assert.ok( c.g === 0, "Green: " + c.g );
  34491. assert.ok( c.b === 0, "Blue: " + c.b );
  34492. } );
  34493. QUnit.test( "setStyleHSLARedWithSpaces", ( assert ) => {
  34494. var c = new Color();
  34495. c.setStyle( 'hsla( 360, 100% , 50%, 0.5 )' );
  34496. assert.ok( c.r == 1, "Red: " + c.r );
  34497. assert.ok( c.g === 0, "Green: " + c.g );
  34498. assert.ok( c.b === 0, "Blue: " + c.b );
  34499. } );
  34500. QUnit.test( "setStyleHexSkyBlue", ( assert ) => {
  34501. var c = new Color();
  34502. c.setStyle( '#87CEEB' );
  34503. assert.ok( c.getHex() == 0x87CEEB, "Hex c: " + c.getHex() );
  34504. } );
  34505. QUnit.test( "setStyleHexSkyBlueMixed", ( assert ) => {
  34506. var c = new Color();
  34507. c.setStyle( '#87cEeB' );
  34508. assert.ok( c.getHex() == 0x87CEEB, "Hex c: " + c.getHex() );
  34509. } );
  34510. QUnit.test( "setStyleHex2Olive", ( assert ) => {
  34511. var c = new Color();
  34512. c.setStyle( '#F00' );
  34513. assert.ok( c.getHex() == 0xFF0000, "Hex c: " + c.getHex() );
  34514. } );
  34515. QUnit.test( "setStyleHex2OliveMixed", ( assert ) => {
  34516. var c = new Color();
  34517. c.setStyle( '#f00' );
  34518. assert.ok( c.getHex() == 0xFF0000, "Hex c: " + c.getHex() );
  34519. } );
  34520. QUnit.test( "setStyleColorName", ( assert ) => {
  34521. var c = new Color();
  34522. c.setStyle( 'powderblue' );
  34523. assert.ok( c.getHex() == 0xB0E0E6, "Hex c: " + c.getHex() );
  34524. } );
  34525. } );
  34526. } );
  34527. /**
  34528. * @author Mugen87 / https://github.com/Mugen87
  34529. *
  34530. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  34531. *
  34532. */
  34533. function Cylindrical( radius, theta, y ) {
  34534. this.radius = ( radius !== undefined ) ? radius : 1.0; // distance from the origin to a point in the x-z plane
  34535. this.theta = ( theta !== undefined ) ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  34536. this.y = ( y !== undefined ) ? y : 0; // height above the x-z plane
  34537. return this;
  34538. }
  34539. Object.assign( Cylindrical.prototype, {
  34540. set: function ( radius, theta, y ) {
  34541. this.radius = radius;
  34542. this.theta = theta;
  34543. this.y = y;
  34544. return this;
  34545. },
  34546. clone: function () {
  34547. return new this.constructor().copy( this );
  34548. },
  34549. copy: function ( other ) {
  34550. this.radius = other.radius;
  34551. this.theta = other.theta;
  34552. this.y = other.y;
  34553. return this;
  34554. },
  34555. setFromVector3: function ( vec3 ) {
  34556. this.radius = Math.sqrt( vec3.x * vec3.x + vec3.z * vec3.z );
  34557. this.theta = Math.atan2( vec3.x, vec3.z );
  34558. this.y = vec3.y;
  34559. return this;
  34560. }
  34561. } );
  34562. /**
  34563. * @author moraxy / https://github.com/moraxy
  34564. * @author TristanVALCKE / https://github.com/Itee
  34565. */
  34566. /* global QUnit */
  34567. QUnit.module( 'Maths', () => {
  34568. QUnit.module.todo( 'Cylindrical', () => {
  34569. // INSTANCING
  34570. QUnit.test( "Instancing", ( assert ) => {
  34571. var a = new Cylindrical();
  34572. var radius = 10.0;
  34573. var theta = Math.PI;
  34574. var y$$1 = 5;
  34575. assert.strictEqual( a.radius, 1.0, "Default values: check radius" );
  34576. assert.strictEqual( a.theta, 0, "Default values: check theta" );
  34577. assert.strictEqual( a.y, 0, "Default values: check y" );
  34578. var a = new Cylindrical( radius, theta, y$$1 );
  34579. assert.strictEqual( a.radius, radius, "Custom values: check radius" );
  34580. assert.strictEqual( a.theta, theta, "Custom values: check theta" );
  34581. assert.strictEqual( a.y, y$$1, "Custom values: check y" );
  34582. } );
  34583. // PUBLIC STUFF
  34584. QUnit.test( "set", ( assert ) => {
  34585. var a = new Cylindrical();
  34586. var radius = 10.0;
  34587. var theta = Math.PI;
  34588. var y$$1 = 5;
  34589. a.set( radius, theta, y$$1 );
  34590. assert.strictEqual( a.radius, radius, "Check radius" );
  34591. assert.strictEqual( a.theta, theta, "Check theta" );
  34592. assert.strictEqual( a.y, y$$1, "Check y" );
  34593. } );
  34594. QUnit.test( "clone", ( assert ) => {
  34595. var radius = 10.0;
  34596. var theta = Math.PI;
  34597. var y$$1 = 5;
  34598. var a = new Cylindrical( radius, theta, y$$1 );
  34599. var b = a.clone();
  34600. assert.propEqual( a, b, "Check a and b are equal after clone()" );
  34601. a.radius = 1;
  34602. assert.notPropEqual( a, b, "Check a and b are not equal after modification" );
  34603. } );
  34604. QUnit.test( "copy", ( assert ) => {
  34605. var radius = 10.0;
  34606. var theta = Math.PI;
  34607. var y$$1 = 5;
  34608. var a = new Cylindrical( radius, theta, y$$1 );
  34609. var b = new Cylindrical().copy( a );
  34610. assert.propEqual( a, b, "Check a and b are equal after copy()" );
  34611. a.radius = 1;
  34612. assert.notPropEqual( a, b, "Check a and b are not equal after modification" );
  34613. } );
  34614. QUnit.test( "setFromVector3", ( assert ) => {
  34615. var a = new Cylindrical( 1, 1, 1 );
  34616. var b = new Vector3( 0, 0, 0 );
  34617. var c = new Vector3( 3, - 1, - 3 );
  34618. var expected = new Cylindrical( Math.sqrt( 9 + 9 ), Math.atan2( 3, - 3 ), - 1 );
  34619. a.setFromVector3( b );
  34620. assert.strictEqual( a.radius, 0, "Zero-length vector: check radius" );
  34621. assert.strictEqual( a.theta, 0, "Zero-length vector: check theta" );
  34622. assert.strictEqual( a.y, 0, "Zero-length vector: check y" );
  34623. a.setFromVector3( c );
  34624. assert.ok( Math.abs( a.radius - expected.radius ) <= eps, "Normal vector: check radius" );
  34625. assert.ok( Math.abs( a.theta - expected.theta ) <= eps, "Normal vector: check theta" );
  34626. assert.ok( Math.abs( a.y - expected.y ) <= eps, "Normal vector: check y" );
  34627. } );
  34628. } );
  34629. } );
  34630. /**
  34631. * @author bhouston / http://exocortex.com
  34632. * @author TristanVALCKE / https://github.com/Itee
  34633. */
  34634. /* global QUnit */
  34635. const eulerZero = new Euler( 0, 0, 0, "XYZ" );
  34636. const eulerAxyz = new Euler( 1, 0, 0, "XYZ" );
  34637. const eulerAzyx = new Euler( 0, 1, 0, "ZYX" );
  34638. function matrixEquals4( a, b, tolerance ) {
  34639. tolerance = tolerance || 0.0001;
  34640. if ( a.elements.length != b.elements.length ) {
  34641. return false;
  34642. }
  34643. for ( var i = 0, il = a.elements.length; i < il; i ++ ) {
  34644. var delta = a.elements[ i ] - b.elements[ i ];
  34645. if ( delta > tolerance ) {
  34646. return false;
  34647. }
  34648. }
  34649. return true;
  34650. }
  34651. function eulerEquals( a, b, tolerance ) {
  34652. tolerance = tolerance || 0.0001;
  34653. var diff = Math.abs( a.x - b.x ) + Math.abs( a.y - b.y ) + Math.abs( a.z - b.z );
  34654. return ( diff < tolerance );
  34655. }
  34656. function quatEquals( a, b, tolerance ) {
  34657. tolerance = tolerance || 0.0001;
  34658. 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 );
  34659. return ( diff < tolerance );
  34660. }
  34661. QUnit.module( 'Maths', () => {
  34662. QUnit.module.todo( 'Euler', () => {
  34663. // INSTANCING
  34664. QUnit.test( "Instancing", ( assert ) => {
  34665. var a = new Euler();
  34666. assert.ok( a.equals( eulerZero ), "Passed!" );
  34667. assert.ok( ! a.equals( eulerAxyz ), "Passed!" );
  34668. assert.ok( ! a.equals( eulerAzyx ), "Passed!" );
  34669. } );
  34670. // STATIC STUFF
  34671. QUnit.test( "RotationOrders", ( assert ) => {
  34672. assert.ok( false, "everything's gonna be alright" );
  34673. } );
  34674. QUnit.test( "DefaultOrder", ( assert ) => {
  34675. assert.ok( false, "everything's gonna be alright" );
  34676. } );
  34677. // PROPERTIES STUFF
  34678. QUnit.test( "x", ( assert ) => {
  34679. assert.ok( false, "everything's gonna be alright" );
  34680. } );
  34681. QUnit.test( "y", ( assert ) => {
  34682. assert.ok( false, "everything's gonna be alright" );
  34683. } );
  34684. QUnit.test( "z", ( assert ) => {
  34685. assert.ok( false, "everything's gonna be alright" );
  34686. } );
  34687. QUnit.test( "order", ( assert ) => {
  34688. assert.ok( false, "everything's gonna be alright" );
  34689. } );
  34690. // PUBLIC STUFF
  34691. QUnit.test( "isEuler", ( assert ) => {
  34692. assert.ok( false, "everything's gonna be alright" );
  34693. } );
  34694. QUnit.test( "set/setFromVector3/toVector3", ( assert ) => {
  34695. var a = new Euler();
  34696. a.set( 0, 1, 0, "ZYX" );
  34697. assert.ok( a.equals( eulerAzyx ), "Passed!" );
  34698. assert.ok( ! a.equals( eulerAxyz ), "Passed!" );
  34699. assert.ok( ! a.equals( eulerZero ), "Passed!" );
  34700. var vec = new Vector3( 0, 1, 0 );
  34701. var b = new Euler().setFromVector3( vec, "ZYX" );
  34702. assert.ok( a.equals( b ), "Passed!" );
  34703. var c = b.toVector3();
  34704. assert.ok( c.equals( vec ), "Passed!" );
  34705. } );
  34706. QUnit.test( "clone/copy/equals", ( assert ) => {
  34707. var a = eulerAxyz.clone();
  34708. assert.ok( a.equals( eulerAxyz ), "Passed!" );
  34709. assert.ok( ! a.equals( eulerZero ), "Passed!" );
  34710. assert.ok( ! a.equals( eulerAzyx ), "Passed!" );
  34711. a.copy( eulerAzyx );
  34712. assert.ok( a.equals( eulerAzyx ), "Passed!" );
  34713. assert.ok( ! a.equals( eulerAxyz ), "Passed!" );
  34714. assert.ok( ! a.equals( eulerZero ), "Passed!" );
  34715. } );
  34716. QUnit.test( "Quaternion.setFromEuler/Euler.fromQuaternion", ( assert ) => {
  34717. var testValues = [ eulerZero, eulerAxyz, eulerAzyx ];
  34718. for ( var i = 0; i < testValues.length; i ++ ) {
  34719. var v = testValues[ i ];
  34720. var q = new Quaternion().setFromEuler( v );
  34721. var v2 = new Euler().setFromQuaternion( q, v.order );
  34722. var q2 = new Quaternion().setFromEuler( v2 );
  34723. assert.ok( quatEquals( q, q2 ), "Passed!" );
  34724. }
  34725. } );
  34726. QUnit.test( "Matrix4.setFromEuler/Euler.fromRotationMatrix", ( assert ) => {
  34727. var testValues = [ eulerZero, eulerAxyz, eulerAzyx ];
  34728. for ( var i = 0; i < testValues.length; i ++ ) {
  34729. var v = testValues[ i ];
  34730. var m = new Matrix4().makeRotationFromEuler( v );
  34731. var v2 = new Euler().setFromRotationMatrix( m, v.order );
  34732. var m2 = new Matrix4().makeRotationFromEuler( v2 );
  34733. assert.ok( matrixEquals4( m, m2, 0.0001 ), "Passed!" );
  34734. }
  34735. } );
  34736. QUnit.test( "reorder", ( assert ) => {
  34737. var testValues = [ eulerZero, eulerAxyz, eulerAzyx ];
  34738. for ( var i = 0; i < testValues.length; i ++ ) {
  34739. var v = testValues[ i ];
  34740. var q = new Quaternion().setFromEuler( v );
  34741. v.reorder( 'YZX' );
  34742. var q2 = new Quaternion().setFromEuler( v );
  34743. assert.ok( quatEquals( q, q2 ), "Passed!" );
  34744. v.reorder( 'ZXY' );
  34745. var q3 = new Quaternion().setFromEuler( v );
  34746. assert.ok( quatEquals( q, q3 ), "Passed!" );
  34747. }
  34748. } );
  34749. QUnit.test( "set/get properties, check callbacks", ( assert ) => {
  34750. var a = new Euler();
  34751. a.onChange( function () {
  34752. assert.step( "set: onChange called" );
  34753. } );
  34754. assert.expect( 8 );
  34755. // should be 4 calls to onChangeCallback
  34756. a.x = 1;
  34757. a.y = 2;
  34758. a.z = 3;
  34759. a.order = "ZYX";
  34760. assert.strictEqual( a.x, 1, "get: check x" );
  34761. assert.strictEqual( a.y, 2, "get: check y" );
  34762. assert.strictEqual( a.z, 3, "get: check z" );
  34763. assert.strictEqual( a.order, "ZYX", "get: check order" );
  34764. } );
  34765. QUnit.test( "clone/copy, check callbacks", ( assert ) => {
  34766. assert.expect( 3 );
  34767. var a = new Euler( 1, 2, 3, "ZXY" );
  34768. var b = new Euler( 4, 5, 6, "XZY" );
  34769. var cb = function () {
  34770. assert.step( "onChange called" );
  34771. };
  34772. a.onChange( cb );
  34773. b.onChange( cb );
  34774. // clone doesn't trigger onChange
  34775. var a = b.clone();
  34776. assert.ok( a.equals( b ), "clone: check if a equals b" );
  34777. // copy triggers onChange once
  34778. var a = new Euler( 1, 2, 3, "ZXY" );
  34779. a.onChange( cb );
  34780. a.copy( b );
  34781. assert.ok( a.equals( b ), "copy: check if a equals b" );
  34782. } );
  34783. QUnit.test( "toArray", ( assert ) => {
  34784. var order = "YXZ";
  34785. var a = new Euler( x, y, z, order );
  34786. var array = a.toArray();
  34787. assert.strictEqual( array[ 0 ], x, "No array, no offset: check x" );
  34788. assert.strictEqual( array[ 1 ], y, "No array, no offset: check y" );
  34789. assert.strictEqual( array[ 2 ], z, "No array, no offset: check z" );
  34790. assert.strictEqual( array[ 3 ], order, "No array, no offset: check order" );
  34791. var array = [];
  34792. a.toArray( array );
  34793. assert.strictEqual( array[ 0 ], x, "With array, no offset: check x" );
  34794. assert.strictEqual( array[ 1 ], y, "With array, no offset: check y" );
  34795. assert.strictEqual( array[ 2 ], z, "With array, no offset: check z" );
  34796. assert.strictEqual( array[ 3 ], order, "With array, no offset: check order" );
  34797. var array = [];
  34798. a.toArray( array, 1 );
  34799. assert.strictEqual( array[ 0 ], undefined, "With array and offset: check [0]" );
  34800. assert.strictEqual( array[ 1 ], x, "With array and offset: check x" );
  34801. assert.strictEqual( array[ 2 ], y, "With array and offset: check y" );
  34802. assert.strictEqual( array[ 3 ], z, "With array and offset: check z" );
  34803. assert.strictEqual( array[ 4 ], order, "With array and offset: check order" );
  34804. } );
  34805. QUnit.test( "fromArray", ( assert ) => {
  34806. assert.expect( 10 );
  34807. var a = new Euler();
  34808. var array = [ x, y, z ];
  34809. var cb = function () {
  34810. assert.step( "onChange called" );
  34811. };
  34812. a.onChange( cb );
  34813. a.fromArray( array );
  34814. assert.strictEqual( a.x, x, "No order: check x" );
  34815. assert.strictEqual( a.y, y, "No order: check y" );
  34816. assert.strictEqual( a.z, z, "No order: check z" );
  34817. assert.strictEqual( a.order, "XYZ", "No order: check order" );
  34818. var a = new Euler();
  34819. var array = [ x, y, z, "ZXY" ];
  34820. a.onChange( cb );
  34821. a.fromArray( array );
  34822. assert.strictEqual( a.x, x, "With order: check x" );
  34823. assert.strictEqual( a.y, y, "With order: check y" );
  34824. assert.strictEqual( a.z, z, "With order: check z" );
  34825. assert.strictEqual( a.order, "ZXY", "With order: check order" );
  34826. } );
  34827. QUnit.test( "onChange", ( assert ) => {
  34828. assert.ok( false, "everything's gonna be alright" );
  34829. } );
  34830. QUnit.test( "onChangeCallback", ( assert ) => {
  34831. assert.ok( false, "everything's gonna be alright" );
  34832. } );
  34833. // OTHERS
  34834. QUnit.test( "gimbalLocalQuat", ( assert ) => {
  34835. // known problematic quaternions
  34836. var q1 = new Quaternion( 0.5207769385244341, - 0.4783214164122354, 0.520776938524434, 0.47832141641223547 );
  34837. var q2 = new Quaternion( 0.11284905712620674, 0.6980437630368944, - 0.11284905712620674, 0.6980437630368944 );
  34838. var eulerOrder = "ZYX";
  34839. // create Euler directly from a Quaternion
  34840. var eViaQ1 = new Euler().setFromQuaternion( q1, eulerOrder ); // there is likely a bug here
  34841. // create Euler from Quaternion via an intermediate Matrix4
  34842. var mViaQ1 = new Matrix4().makeRotationFromQuaternion( q1 );
  34843. var eViaMViaQ1 = new Euler().setFromRotationMatrix( mViaQ1, eulerOrder );
  34844. // the results here are different
  34845. assert.ok( eulerEquals( eViaQ1, eViaMViaQ1 ), "Passed!" ); // this result is correct
  34846. } );
  34847. } );
  34848. } );
  34849. /**
  34850. * @author bhouston / http://exocortex.com
  34851. * @author TristanVALCKE / https://github.com/Itee
  34852. */
  34853. /* global QUnit */
  34854. const unit3 = new Vector3( 1, 0, 0 );
  34855. QUnit.module( 'Maths', () => {
  34856. QUnit.module.todo( 'Frustum', () => {
  34857. // INSTANCING
  34858. QUnit.test( "Instancing", ( assert ) => {
  34859. var a = new Frustum();
  34860. assert.ok( a.planes !== undefined, "Passed!" );
  34861. assert.ok( a.planes.length === 6, "Passed!" );
  34862. var pDefault = new Plane();
  34863. for ( var i = 0; i < 6; i ++ ) {
  34864. assert.ok( a.planes[ i ].equals( pDefault ), "Passed!" );
  34865. }
  34866. var p0 = new Plane( unit3, - 1 );
  34867. var p1 = new Plane( unit3, 1 );
  34868. var p2 = new Plane( unit3, 2 );
  34869. var p3 = new Plane( unit3, 3 );
  34870. var p4 = new Plane( unit3, 4 );
  34871. var p5 = new Plane( unit3, 5 );
  34872. var a = new Frustum( p0, p1, p2, p3, p4, p5 );
  34873. assert.ok( a.planes[ 0 ].equals( p0 ), "Passed!" );
  34874. assert.ok( a.planes[ 1 ].equals( p1 ), "Passed!" );
  34875. assert.ok( a.planes[ 2 ].equals( p2 ), "Passed!" );
  34876. assert.ok( a.planes[ 3 ].equals( p3 ), "Passed!" );
  34877. assert.ok( a.planes[ 4 ].equals( p4 ), "Passed!" );
  34878. assert.ok( a.planes[ 5 ].equals( p5 ), "Passed!" );
  34879. } );
  34880. // PUBLIC STUFF
  34881. QUnit.test( "set", ( assert ) => {
  34882. var a = new Frustum();
  34883. var p0 = new Plane( unit3, - 1 );
  34884. var p1 = new Plane( unit3, 1 );
  34885. var p2 = new Plane( unit3, 2 );
  34886. var p3 = new Plane( unit3, 3 );
  34887. var p4 = new Plane( unit3, 4 );
  34888. var p5 = new Plane( unit3, 5 );
  34889. a.set( p0, p1, p2, p3, p4, p5 );
  34890. assert.ok( a.planes[ 0 ].equals( p0 ), "Check plane #0" );
  34891. assert.ok( a.planes[ 1 ].equals( p1 ), "Check plane #1" );
  34892. assert.ok( a.planes[ 2 ].equals( p2 ), "Check plane #2" );
  34893. assert.ok( a.planes[ 3 ].equals( p3 ), "Check plane #3" );
  34894. assert.ok( a.planes[ 4 ].equals( p4 ), "Check plane #4" );
  34895. assert.ok( a.planes[ 5 ].equals( p5 ), "Check plane #5" );
  34896. } );
  34897. QUnit.test( "clone", ( assert ) => {
  34898. var p0 = new Plane( unit3, - 1 );
  34899. var p1 = new Plane( unit3, 1 );
  34900. var p2 = new Plane( unit3, 2 );
  34901. var p3 = new Plane( unit3, 3 );
  34902. var p4 = new Plane( unit3, 4 );
  34903. var p5 = new Plane( unit3, 5 );
  34904. var b = new Frustum( p0, p1, p2, p3, p4, p5 );
  34905. var a = b.clone();
  34906. assert.ok( a.planes[ 0 ].equals( p0 ), "Passed!" );
  34907. assert.ok( a.planes[ 1 ].equals( p1 ), "Passed!" );
  34908. assert.ok( a.planes[ 2 ].equals( p2 ), "Passed!" );
  34909. assert.ok( a.planes[ 3 ].equals( p3 ), "Passed!" );
  34910. assert.ok( a.planes[ 4 ].equals( p4 ), "Passed!" );
  34911. assert.ok( a.planes[ 5 ].equals( p5 ), "Passed!" );
  34912. // ensure it is a true copy by modifying source
  34913. a.planes[ 0 ].copy( p1 );
  34914. assert.ok( b.planes[ 0 ].equals( p0 ), "Passed!" );
  34915. } );
  34916. QUnit.test( "copy", ( assert ) => {
  34917. var p0 = new Plane( unit3, - 1 );
  34918. var p1 = new Plane( unit3, 1 );
  34919. var p2 = new Plane( unit3, 2 );
  34920. var p3 = new Plane( unit3, 3 );
  34921. var p4 = new Plane( unit3, 4 );
  34922. var p5 = new Plane( unit3, 5 );
  34923. var b = new Frustum( p0, p1, p2, p3, p4, p5 );
  34924. var a = new Frustum().copy( b );
  34925. assert.ok( a.planes[ 0 ].equals( p0 ), "Passed!" );
  34926. assert.ok( a.planes[ 1 ].equals( p1 ), "Passed!" );
  34927. assert.ok( a.planes[ 2 ].equals( p2 ), "Passed!" );
  34928. assert.ok( a.planes[ 3 ].equals( p3 ), "Passed!" );
  34929. assert.ok( a.planes[ 4 ].equals( p4 ), "Passed!" );
  34930. assert.ok( a.planes[ 5 ].equals( p5 ), "Passed!" );
  34931. // ensure it is a true copy by modifying source
  34932. b.planes[ 0 ] = p1;
  34933. assert.ok( a.planes[ 0 ].equals( p0 ), "Passed!" );
  34934. } );
  34935. QUnit.test( "setFromMatrix/makeOrthographic/containsPoint", ( assert ) => {
  34936. var m = new Matrix4().makeOrthographic( - 1, 1, - 1, 1, 1, 100 );
  34937. var a = new Frustum().setFromMatrix( m );
  34938. assert.ok( ! a.containsPoint( new Vector3( 0, 0, 0 ) ), "Passed!" );
  34939. assert.ok( a.containsPoint( new Vector3( 0, 0, - 50 ) ), "Passed!" );
  34940. assert.ok( a.containsPoint( new Vector3( 0, 0, - 1.001 ) ), "Passed!" );
  34941. assert.ok( a.containsPoint( new Vector3( - 1, - 1, - 1.001 ) ), "Passed!" );
  34942. assert.ok( ! a.containsPoint( new Vector3( - 1.1, - 1.1, - 1.001 ) ), "Passed!" );
  34943. assert.ok( a.containsPoint( new Vector3( 1, 1, - 1.001 ) ), "Passed!" );
  34944. assert.ok( ! a.containsPoint( new Vector3( 1.1, 1.1, - 1.001 ) ), "Passed!" );
  34945. assert.ok( a.containsPoint( new Vector3( 0, 0, - 100 ) ), "Passed!" );
  34946. assert.ok( a.containsPoint( new Vector3( - 1, - 1, - 100 ) ), "Passed!" );
  34947. assert.ok( ! a.containsPoint( new Vector3( - 1.1, - 1.1, - 100.1 ) ), "Passed!" );
  34948. assert.ok( a.containsPoint( new Vector3( 1, 1, - 100 ) ), "Passed!" );
  34949. assert.ok( ! a.containsPoint( new Vector3( 1.1, 1.1, - 100.1 ) ), "Passed!" );
  34950. assert.ok( ! a.containsPoint( new Vector3( 0, 0, - 101 ) ), "Passed!" );
  34951. } );
  34952. QUnit.test( "setFromMatrix/makePerspective/containsPoint", ( assert ) => {
  34953. var m = new Matrix4().makePerspective( - 1, 1, 1, - 1, 1, 100 );
  34954. var a = new Frustum().setFromMatrix( m );
  34955. assert.ok( ! a.containsPoint( new Vector3( 0, 0, 0 ) ), "Passed!" );
  34956. assert.ok( a.containsPoint( new Vector3( 0, 0, - 50 ) ), "Passed!" );
  34957. assert.ok( a.containsPoint( new Vector3( 0, 0, - 1.001 ) ), "Passed!" );
  34958. assert.ok( a.containsPoint( new Vector3( - 1, - 1, - 1.001 ) ), "Passed!" );
  34959. assert.ok( ! a.containsPoint( new Vector3( - 1.1, - 1.1, - 1.001 ) ), "Passed!" );
  34960. assert.ok( a.containsPoint( new Vector3( 1, 1, - 1.001 ) ), "Passed!" );
  34961. assert.ok( ! a.containsPoint( new Vector3( 1.1, 1.1, - 1.001 ) ), "Passed!" );
  34962. assert.ok( a.containsPoint( new Vector3( 0, 0, - 99.999 ) ), "Passed!" );
  34963. assert.ok( a.containsPoint( new Vector3( - 99.999, - 99.999, - 99.999 ) ), "Passed!" );
  34964. assert.ok( ! a.containsPoint( new Vector3( - 100.1, - 100.1, - 100.1 ) ), "Passed!" );
  34965. assert.ok( a.containsPoint( new Vector3( 99.999, 99.999, - 99.999 ) ), "Passed!" );
  34966. assert.ok( ! a.containsPoint( new Vector3( 100.1, 100.1, - 100.1 ) ), "Passed!" );
  34967. assert.ok( ! a.containsPoint( new Vector3( 0, 0, - 101 ) ), "Passed!" );
  34968. } );
  34969. QUnit.test( "setFromMatrix/makePerspective/intersectsSphere", ( assert ) => {
  34970. var m = new Matrix4().makePerspective( - 1, 1, 1, - 1, 1, 100 );
  34971. var a = new Frustum().setFromMatrix( m );
  34972. assert.ok( ! a.intersectsSphere( new Sphere( new Vector3( 0, 0, 0 ), 0 ) ), "Passed!" );
  34973. assert.ok( ! a.intersectsSphere( new Sphere( new Vector3( 0, 0, 0 ), 0.9 ) ), "Passed!" );
  34974. assert.ok( a.intersectsSphere( new Sphere( new Vector3( 0, 0, 0 ), 1.1 ) ), "Passed!" );
  34975. assert.ok( a.intersectsSphere( new Sphere( new Vector3( 0, 0, - 50 ), 0 ) ), "Passed!" );
  34976. assert.ok( a.intersectsSphere( new Sphere( new Vector3( 0, 0, - 1.001 ), 0 ) ), "Passed!" );
  34977. assert.ok( a.intersectsSphere( new Sphere( new Vector3( - 1, - 1, - 1.001 ), 0 ) ), "Passed!" );
  34978. assert.ok( ! a.intersectsSphere( new Sphere( new Vector3( - 1.1, - 1.1, - 1.001 ), 0 ) ), "Passed!" );
  34979. assert.ok( a.intersectsSphere( new Sphere( new Vector3( - 1.1, - 1.1, - 1.001 ), 0.5 ) ), "Passed!" );
  34980. assert.ok( a.intersectsSphere( new Sphere( new Vector3( 1, 1, - 1.001 ), 0 ) ), "Passed!" );
  34981. assert.ok( ! a.intersectsSphere( new Sphere( new Vector3( 1.1, 1.1, - 1.001 ), 0 ) ), "Passed!" );
  34982. assert.ok( a.intersectsSphere( new Sphere( new Vector3( 1.1, 1.1, - 1.001 ), 0.5 ) ), "Passed!" );
  34983. assert.ok( a.intersectsSphere( new Sphere( new Vector3( 0, 0, - 99.999 ), 0 ) ), "Passed!" );
  34984. assert.ok( a.intersectsSphere( new Sphere( new Vector3( - 99.999, - 99.999, - 99.999 ), 0 ) ), "Passed!" );
  34985. assert.ok( ! a.intersectsSphere( new Sphere( new Vector3( - 100.1, - 100.1, - 100.1 ), 0 ) ), "Passed!" );
  34986. assert.ok( a.intersectsSphere( new Sphere( new Vector3( - 100.1, - 100.1, - 100.1 ), 0.5 ) ), "Passed!" );
  34987. assert.ok( a.intersectsSphere( new Sphere( new Vector3( 99.999, 99.999, - 99.999 ), 0 ) ), "Passed!" );
  34988. assert.ok( ! a.intersectsSphere( new Sphere( new Vector3( 100.1, 100.1, - 100.1 ), 0 ) ), "Passed!" );
  34989. assert.ok( a.intersectsSphere( new Sphere( new Vector3( 100.1, 100.1, - 100.1 ), 0.2 ) ), "Passed!" );
  34990. assert.ok( ! a.intersectsSphere( new Sphere( new Vector3( 0, 0, - 101 ), 0 ) ), "Passed!" );
  34991. assert.ok( a.intersectsSphere( new Sphere( new Vector3( 0, 0, - 101 ), 1.1 ) ), "Passed!" );
  34992. } );
  34993. QUnit.test( "intersectsObject", ( assert ) => {
  34994. var m = new Matrix4().makePerspective( - 1, 1, 1, - 1, 1, 100 );
  34995. var a = new Frustum().setFromMatrix( m );
  34996. var object = new Mesh( new BoxGeometry( 1, 1, 1 ) );
  34997. var intersects;
  34998. intersects = a.intersectsObject( object );
  34999. assert.notOk( intersects, "No intersection" );
  35000. object.position.set( - 1, - 1, - 1 );
  35001. object.updateMatrixWorld();
  35002. intersects = a.intersectsObject( object );
  35003. assert.ok( intersects, "Successful intersection" );
  35004. object.position.set( 1, 1, 1 );
  35005. object.updateMatrixWorld();
  35006. intersects = a.intersectsObject( object );
  35007. assert.notOk( intersects, "No intersection" );
  35008. } );
  35009. QUnit.test( "intersectsSprite", ( assert ) => {
  35010. var m = new Matrix4().makePerspective( - 1, 1, 1, - 1, 1, 100 );
  35011. var a = new Frustum().setFromMatrix( m );
  35012. var sprite = new Sprite();
  35013. var intersects;
  35014. intersects = a.intersectsSprite( sprite );
  35015. assert.notOk( intersects, "No intersection" );
  35016. sprite.position.set( - 1, - 1, - 1 );
  35017. sprite.updateMatrixWorld();
  35018. intersects = a.intersectsSprite( sprite );
  35019. assert.ok( intersects, "Successful intersection" );
  35020. } );
  35021. QUnit.test( "intersectsSphere", ( assert ) => {
  35022. assert.ok( false, "everything's gonna be alright" );
  35023. } );
  35024. QUnit.test( "intersectsBox", ( assert ) => {
  35025. var m = new Matrix4().makePerspective( - 1, 1, 1, - 1, 1, 100 );
  35026. var a = new Frustum().setFromMatrix( m );
  35027. var box = new Box3( zero3.clone(), one3.clone() );
  35028. var intersects;
  35029. intersects = a.intersectsBox( box );
  35030. assert.notOk( intersects, "No intersection" );
  35031. box.translate( - 1, - 1, - 1 );
  35032. intersects = a.intersectsBox( box );
  35033. assert.ok( intersects, "Successful intersection" );
  35034. } );
  35035. QUnit.test( "containsPoint", ( assert ) => {
  35036. assert.ok( false, "everything's gonna be alright" );
  35037. } );
  35038. } );
  35039. } );
  35040. /**
  35041. * @author tschw
  35042. * @author TristanVALCKE / https://github.com/Itee
  35043. */
  35044. /* global QUnit */
  35045. QUnit.module( 'Maths', () => {
  35046. QUnit.module.todo( 'Interpolant', () => {
  35047. // Since this is an abstract base class, we have to make it concrete in order
  35048. // to QUnit.test its functionality...
  35049. function Mock( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  35050. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  35051. }
  35052. Mock.prototype = Object.create( Interpolant.prototype );
  35053. Mock.prototype.intervalChanged_ = function intervalChanged( i1, t0, t1 ) {
  35054. Mock.captureCall( arguments );
  35055. };
  35056. Mock.prototype.interpolate_ = function interpolate( i1, t0, t, t1 ) {
  35057. Mock.captureCall( arguments );
  35058. return this.copySampleValue_( i1 - 1 );
  35059. };
  35060. Mock.prototype.beforeStart_ = function beforeStart( i, t, t0 ) {
  35061. Mock.captureCall( arguments );
  35062. return this.copySampleValue_( i );
  35063. };
  35064. Mock.prototype.afterEnd_ = function afterEnd( i, tN, t ) {
  35065. Mock.captureCall( arguments );
  35066. return this.copySampleValue_( i );
  35067. };
  35068. // Call capturing facility
  35069. Mock.calls = null;
  35070. Mock.captureCall = function ( args ) {
  35071. if ( Mock.calls !== null ) {
  35072. Mock.calls.push( {
  35073. func: Mock.captureCall.caller.name,
  35074. args: Array.prototype.slice.call( args )
  35075. } );
  35076. }
  35077. };
  35078. // Tests
  35079. // INSTANCING
  35080. QUnit.test( "Instancing", ( assert ) => {
  35081. assert.ok( false, "everything's gonna be alright" );
  35082. } );
  35083. // PUBLIC STUFF
  35084. QUnit.test( "evaluate", ( assert ) => {
  35085. assert.ok( false, "everything's gonna be alright" );
  35086. } );
  35087. // PRIVATE STUFF
  35088. QUnit.test( "DefaultSettings_", ( assert ) => {
  35089. assert.ok( false, "everything's gonna be alright" );
  35090. } );
  35091. QUnit.test( "getSettings_", ( assert ) => {
  35092. assert.ok( false, "everything's gonna be alright" );
  35093. } );
  35094. QUnit.test( "copySampleValue_", ( assert ) => {
  35095. var interpolant = new Mock( null, [ 1, 11, 2, 22, 3, 33 ], 2, [] );
  35096. assert.deepEqual( interpolant.copySampleValue_( 0 ), [ 1, 11 ], "sample fetch (0)" );
  35097. assert.deepEqual( interpolant.copySampleValue_( 1 ), [ 2, 22 ], "sample fetch (1)" );
  35098. assert.deepEqual( interpolant.copySampleValue_( 2 ), [ 3, 33 ], "first sample (2)" );
  35099. } );
  35100. QUnit.test( "evaluate -> intervalChanged_ / interpolate_", ( assert ) => {
  35101. var actual, expect;
  35102. var interpolant = new Mock( [ 11, 22, 33, 44, 55, 66, 77, 88, 99 ], null, 0, null );
  35103. Mock.calls = [];
  35104. interpolant.evaluate( 11 );
  35105. actual = Mock.calls[ 0 ];
  35106. expect = {
  35107. func: 'intervalChanged',
  35108. args: [ 1, 11, 22 ]
  35109. };
  35110. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35111. actual = Mock.calls[ 1 ];
  35112. expect = {
  35113. func: 'interpolate',
  35114. args: [ 1, 11, 11, 22 ]
  35115. };
  35116. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35117. assert.ok( Mock.calls.length === 2, "no further calls" );
  35118. Mock.calls = [];
  35119. interpolant.evaluate( 12 ); // same interval
  35120. actual = Mock.calls[ 0 ];
  35121. expect = {
  35122. func: 'interpolate',
  35123. args: [ 1, 11, 12, 22 ]
  35124. };
  35125. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35126. assert.ok( Mock.calls.length === 1, "no further calls" );
  35127. Mock.calls = [];
  35128. interpolant.evaluate( 22 ); // step forward
  35129. actual = Mock.calls[ 0 ];
  35130. expect = {
  35131. func: 'intervalChanged',
  35132. args: [ 2, 22, 33 ]
  35133. };
  35134. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35135. actual = Mock.calls[ 1 ];
  35136. expect = {
  35137. func: 'interpolate',
  35138. args: [ 2, 22, 22, 33 ]
  35139. };
  35140. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35141. assert.ok( Mock.calls.length === 2 );
  35142. Mock.calls = [];
  35143. interpolant.evaluate( 21 ); // step back
  35144. actual = Mock.calls[ 0 ];
  35145. expect = {
  35146. func: 'intervalChanged',
  35147. args: [ 1, 11, 22 ]
  35148. };
  35149. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35150. actual = Mock.calls[ 1 ];
  35151. expect = {
  35152. func: 'interpolate',
  35153. args: [ 1, 11, 21, 22 ]
  35154. };
  35155. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35156. assert.ok( Mock.calls.length === 2, "no further calls" );
  35157. Mock.calls = [];
  35158. interpolant.evaluate( 20 ); // same interval
  35159. actual = Mock.calls[ 0 ];
  35160. expect = {
  35161. func: 'interpolate',
  35162. args: [ 1, 11, 20, 22 ]
  35163. };
  35164. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35165. assert.ok( Mock.calls.length === 1, "no further calls" );
  35166. Mock.calls = [];
  35167. interpolant.evaluate( 43 ); // two steps forward
  35168. actual = Mock.calls[ 0 ];
  35169. expect = {
  35170. func: 'intervalChanged',
  35171. args: [ 3, 33, 44 ]
  35172. };
  35173. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35174. actual = Mock.calls[ 1 ];
  35175. expect = {
  35176. func: 'interpolate',
  35177. args: [ 3, 33, 43, 44 ]
  35178. };
  35179. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35180. assert.ok( Mock.calls.length === 2, "no further calls" );
  35181. Mock.calls = [];
  35182. interpolant.evaluate( 12 ); // two steps back
  35183. actual = Mock.calls[ 0 ];
  35184. expect = {
  35185. func: 'intervalChanged',
  35186. args: [ 1, 11, 22 ]
  35187. };
  35188. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35189. actual = Mock.calls[ 1 ];
  35190. expect = {
  35191. func: 'interpolate',
  35192. args: [ 1, 11, 12, 22 ]
  35193. };
  35194. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35195. assert.ok( Mock.calls.length === 2, "no further calls" );
  35196. Mock.calls = [];
  35197. interpolant.evaluate( 77 ); // random access
  35198. actual = Mock.calls[ 0 ];
  35199. expect = {
  35200. func: 'intervalChanged',
  35201. args: [ 7, 77, 88 ]
  35202. };
  35203. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35204. actual = Mock.calls[ 1 ];
  35205. expect = {
  35206. func: 'interpolate',
  35207. args: [ 7, 77, 77, 88 ]
  35208. };
  35209. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35210. assert.ok( Mock.calls.length === 2, "no further calls" );
  35211. Mock.calls = [];
  35212. interpolant.evaluate( 80 ); // same interval
  35213. actual = Mock.calls[ 0 ];
  35214. expect = {
  35215. func: 'interpolate',
  35216. args: [ 7, 77, 80, 88 ]
  35217. };
  35218. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35219. assert.ok( Mock.calls.length === 1, "no further calls" );
  35220. Mock.calls = [];
  35221. interpolant.evaluate( 36 ); // random access
  35222. actual = Mock.calls[ 0 ];
  35223. expect = {
  35224. func: 'intervalChanged',
  35225. args: [ 3, 33, 44 ]
  35226. };
  35227. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35228. actual = Mock.calls[ 1 ];
  35229. expect = {
  35230. func: 'interpolate',
  35231. args: [ 3, 33, 36, 44 ]
  35232. };
  35233. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35234. assert.ok( Mock.calls.length === 2, "no further calls" );
  35235. Mock.calls = [];
  35236. interpolant.evaluate( 24 ); // fast reset / loop (2nd)
  35237. actual = Mock.calls[ 0 ];
  35238. expect = {
  35239. func: 'intervalChanged',
  35240. args: [ 2, 22, 33 ]
  35241. };
  35242. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35243. actual = Mock.calls[ 1 ];
  35244. expect = {
  35245. func: 'interpolate',
  35246. args: [ 2, 22, 24, 33 ]
  35247. };
  35248. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35249. assert.ok( Mock.calls.length === 2, "no further calls" );
  35250. Mock.calls = [];
  35251. interpolant.evaluate( 16 ); // fast reset / loop (2nd)
  35252. actual = Mock.calls[ 0 ];
  35253. expect = {
  35254. func: 'intervalChanged',
  35255. args: [ 1, 11, 22 ]
  35256. };
  35257. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35258. actual = Mock.calls[ 1 ];
  35259. expect = {
  35260. func: 'interpolate',
  35261. args: [ 1, 11, 16, 22 ]
  35262. };
  35263. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35264. assert.ok( Mock.calls.length === 2, "no further calls" );
  35265. } );
  35266. QUnit.test( "evaulate -> beforeStart_ [once]", ( assert ) => {
  35267. var actual, expect;
  35268. var interpolant = new Mock( [ 11, 22, 33 ], null, 0, null );
  35269. Mock.calls = [];
  35270. interpolant.evaluate( 10 );
  35271. actual = Mock.calls[ 0 ];
  35272. expect = {
  35273. func: 'beforeStart',
  35274. args: [ 0, 10, 11 ]
  35275. };
  35276. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35277. assert.ok( Mock.calls.length === 1, "no further calls" );
  35278. // Check operation resumes normally and intervalChanged gets called
  35279. Mock.calls = [];
  35280. interpolant.evaluate( 11 );
  35281. actual = Mock.calls[ 0 ];
  35282. expect = {
  35283. func: 'intervalChanged',
  35284. args: [ 1, 11, 22 ]
  35285. };
  35286. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35287. actual = Mock.calls[ 1 ];
  35288. expect = {
  35289. func: 'interpolate',
  35290. args: [ 1, 11, 11, 22 ]
  35291. };
  35292. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35293. assert.ok( Mock.calls.length === 2, "no further calls" );
  35294. // Back off-bounds
  35295. Mock.calls = [];
  35296. interpolant.evaluate( 10 );
  35297. actual = Mock.calls[ 0 ];
  35298. expect = {
  35299. func: 'beforeStart',
  35300. args: [ 0, 10, 11 ]
  35301. };
  35302. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35303. assert.ok( Mock.calls.length === 1, "no further calls" );
  35304. } );
  35305. QUnit.test( "evaluate -> beforeStart_ [twice]", ( assert ) => {
  35306. var actual, expect;
  35307. var interpolant = new Mock( [ 11, 22, 33 ], null, 0, null );
  35308. Mock.calls = [];
  35309. interpolant.evaluate( 10 );
  35310. actual = Mock.calls[ 0 ];
  35311. expect = {
  35312. func: 'beforeStart',
  35313. args: [ 0, 10, 11 ]
  35314. };
  35315. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35316. assert.ok( Mock.calls.length === 1, "no further calls" );
  35317. Mock.calls = []; // again - consider changed state
  35318. interpolant.evaluate( 10 );
  35319. actual = Mock.calls[ 0 ];
  35320. expect = {
  35321. func: 'beforeStart',
  35322. args: [ 0, 10, 11 ]
  35323. };
  35324. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35325. assert.ok( Mock.calls.length === 1, "no further calls" );
  35326. // Check operation resumes normally and intervalChanged gets called
  35327. Mock.calls = [];
  35328. interpolant.evaluate( 11 );
  35329. actual = Mock.calls[ 0 ];
  35330. expect = {
  35331. func: 'intervalChanged',
  35332. args: [ 1, 11, 22 ]
  35333. };
  35334. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35335. actual = Mock.calls[ 1 ];
  35336. expect = {
  35337. func: 'interpolate',
  35338. args: [ 1, 11, 11, 22 ]
  35339. };
  35340. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35341. assert.ok( Mock.calls.length === 2, "no further calls" );
  35342. } );
  35343. QUnit.test( "evaluate -> afterEnd_ [once]", ( assert ) => {
  35344. var actual, expect;
  35345. var interpolant = new Mock( [ 11, 22, 33 ], null, 0, null );
  35346. Mock.calls = [];
  35347. interpolant.evaluate( 33 );
  35348. actual = Mock.calls[ 0 ];
  35349. expect = {
  35350. func: 'afterEnd',
  35351. args: [ 2, 33, 33 ]
  35352. };
  35353. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35354. assert.ok( Mock.calls.length === 1, "no further calls" );
  35355. // Check operation resumes normally and intervalChanged gets called
  35356. Mock.calls = [];
  35357. interpolant.evaluate( 32 );
  35358. actual = Mock.calls[ 0 ];
  35359. expect = {
  35360. func: 'intervalChanged',
  35361. args: [ 2, 22, 33 ]
  35362. };
  35363. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35364. actual = Mock.calls[ 1 ];
  35365. expect = {
  35366. func: 'interpolate',
  35367. args: [ 2, 22, 32, 33 ]
  35368. };
  35369. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35370. assert.ok( Mock.calls.length === 2, "no further calls" );
  35371. // Back off-bounds
  35372. Mock.calls = [];
  35373. interpolant.evaluate( 33 );
  35374. actual = Mock.calls[ 0 ];
  35375. expect = {
  35376. func: 'afterEnd',
  35377. args: [ 2, 33, 33 ]
  35378. };
  35379. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35380. assert.ok( Mock.calls.length === 1, "no further calls" );
  35381. } );
  35382. QUnit.test( "evaluate -> afterEnd_ [twice]", ( assert ) => {
  35383. var actual, expect;
  35384. var interpolant = new Mock( [ 11, 22, 33 ], null, 0, null );
  35385. Mock.calls = [];
  35386. interpolant.evaluate( 33 );
  35387. actual = Mock.calls[ 0 ];
  35388. expect = {
  35389. func: 'afterEnd',
  35390. args: [ 2, 33, 33 ]
  35391. };
  35392. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35393. assert.ok( Mock.calls.length === 1, "no further calls" );
  35394. Mock.calls = []; // again - consider changed state
  35395. interpolant.evaluate( 33 );
  35396. actual = Mock.calls[ 0 ];
  35397. expect = {
  35398. func: 'afterEnd',
  35399. args: [ 2, 33, 33 ]
  35400. };
  35401. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35402. assert.ok( Mock.calls.length === 1, "no further calls" );
  35403. // Check operation resumes normally and intervalChanged gets called
  35404. Mock.calls = [];
  35405. interpolant.evaluate( 32 );
  35406. actual = Mock.calls[ 0 ];
  35407. expect = {
  35408. func: 'intervalChanged',
  35409. args: [ 2, 22, 33 ]
  35410. };
  35411. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35412. actual = Mock.calls[ 1 ];
  35413. expect = {
  35414. func: 'interpolate',
  35415. args: [ 2, 22, 32, 33 ]
  35416. };
  35417. assert.deepEqual( actual, expect, JSON.stringify( expect ) );
  35418. assert.ok( Mock.calls.length === 2, "no further calls" );
  35419. } );
  35420. } );
  35421. } );
  35422. /**
  35423. * @author bhouston / http://exocortex.com
  35424. * @author TristanVALCKE / https://github.com/Itee
  35425. */
  35426. /* global QUnit */
  35427. QUnit.module( 'Maths', () => {
  35428. QUnit.module.todo( 'Line3', () => {
  35429. // INSTANCING
  35430. QUnit.test( "Instancing", ( assert ) => {
  35431. var a = new Line3();
  35432. assert.ok( a.start.equals( zero3 ), "Passed!" );
  35433. assert.ok( a.end.equals( zero3 ), "Passed!" );
  35434. var a = new Line3( two3.clone(), one3.clone() );
  35435. assert.ok( a.start.equals( two3 ), "Passed!" );
  35436. assert.ok( a.end.equals( one3 ), "Passed!" );
  35437. } );
  35438. // PUBLIC STUFF
  35439. QUnit.test( "set", ( assert ) => {
  35440. var a = new Line3();
  35441. a.set( one3, one3 );
  35442. assert.ok( a.start.equals( one3 ), "Passed!" );
  35443. assert.ok( a.end.equals( one3 ), "Passed!" );
  35444. } );
  35445. QUnit.test( "copy/equals", ( assert ) => {
  35446. var a = new Line3( zero3.clone(), one3.clone() );
  35447. var b = new Line3().copy( a );
  35448. assert.ok( b.start.equals( zero3 ), "Passed!" );
  35449. assert.ok( b.end.equals( one3 ), "Passed!" );
  35450. // ensure that it is a true copy
  35451. a.start = zero3;
  35452. a.end = one3;
  35453. assert.ok( b.start.equals( zero3 ), "Passed!" );
  35454. assert.ok( b.end.equals( one3 ), "Passed!" );
  35455. } );
  35456. QUnit.test( "clone/equal", ( assert ) => {
  35457. var a = new Line3();
  35458. var b = new Line3( zero3, new Vector3( 1, 1, 1 ) );
  35459. var c = new Line3( zero3, new Vector3( 1, 1, 0 ) );
  35460. assert.notOk( a.equals( b ), "Check a and b aren't equal" );
  35461. assert.notOk( a.equals( c ), "Check a and c aren't equal" );
  35462. assert.notOk( b.equals( c ), "Check b and c aren't equal" );
  35463. var a = b.clone();
  35464. assert.ok( a.equals( b ), "Check a and b are equal after clone()" );
  35465. assert.notOk( a.equals( c ), "Check a and c aren't equal after clone()" );
  35466. a.set( zero3, zero3 );
  35467. assert.notOk( a.equals( b ), "Check a and b are not equal after modification" );
  35468. } );
  35469. QUnit.test( "getCenter", ( assert ) => {
  35470. assert.ok( false, "everything's gonna be alright" );
  35471. } );
  35472. QUnit.test( "delta", ( assert ) => {
  35473. assert.ok( false, "everything's gonna be alright" );
  35474. } );
  35475. QUnit.test( "distanceSq", ( assert ) => {
  35476. assert.ok( false, "everything's gonna be alright" );
  35477. } );
  35478. QUnit.test( "distance", ( assert ) => {
  35479. var a = new Line3( zero3, zero3 );
  35480. var b = new Line3( zero3, one3 );
  35481. var c = new Line3( one3.clone().negate(), one3 );
  35482. var d = new Line3( two3.clone().multiplyScalar( - 2 ), two3.clone().negate() );
  35483. assert.numEqual( a.distance(), 0, "Check distance for zero-length line" );
  35484. assert.numEqual( b.distance(), Math.sqrt( 3 ), "Check distance for simple line" );
  35485. assert.numEqual( c.distance(), Math.sqrt( 12 ), "Check distance for negative to positive endpoints" );
  35486. assert.numEqual( d.distance(), Math.sqrt( 12 ), "Check distance for negative to negative endpoints" );
  35487. } );
  35488. QUnit.test( "at", ( assert ) => {
  35489. var a = new Line3( one3.clone(), new Vector3( 1, 1, 2 ) );
  35490. assert.ok( a.at( - 1 ).distanceTo( new Vector3( 1, 1, 0 ) ) < 0.0001, "Passed!" );
  35491. assert.ok( a.at( 0 ).distanceTo( one3.clone() ) < 0.0001, "Passed!" );
  35492. assert.ok( a.at( 1 ).distanceTo( new Vector3( 1, 1, 2 ) ) < 0.0001, "Passed!" );
  35493. assert.ok( a.at( 2 ).distanceTo( new Vector3( 1, 1, 3 ) ) < 0.0001, "Passed!" );
  35494. } );
  35495. QUnit.test( "closestPointToPoint/closestPointToPointParameter", ( assert ) => {
  35496. var a = new Line3( one3.clone(), new Vector3( 1, 1, 2 ) );
  35497. // nearby the ray
  35498. assert.ok( a.closestPointToPointParameter( zero3.clone(), true ) == 0, "Passed!" );
  35499. var b1 = a.closestPointToPoint( zero3.clone(), true );
  35500. assert.ok( b1.distanceTo( new Vector3( 1, 1, 1 ) ) < 0.0001, "Passed!" );
  35501. // nearby the ray
  35502. assert.ok( a.closestPointToPointParameter( zero3.clone(), false ) == - 1, "Passed!" );
  35503. var b2 = a.closestPointToPoint( zero3.clone(), false );
  35504. assert.ok( b2.distanceTo( new Vector3( 1, 1, 0 ) ) < 0.0001, "Passed!" );
  35505. // nearby the ray
  35506. assert.ok( a.closestPointToPointParameter( new Vector3( 1, 1, 5 ), true ) == 1, "Passed!" );
  35507. var b = a.closestPointToPoint( new Vector3( 1, 1, 5 ), true );
  35508. assert.ok( b.distanceTo( new Vector3( 1, 1, 2 ) ) < 0.0001, "Passed!" );
  35509. // exactly on the ray
  35510. assert.ok( a.closestPointToPointParameter( one3.clone(), true ) == 0, "Passed!" );
  35511. var c = a.closestPointToPoint( one3.clone(), true );
  35512. assert.ok( c.distanceTo( one3.clone() ) < 0.0001, "Passed!" );
  35513. } );
  35514. QUnit.test( "applyMatrix4", ( assert ) => {
  35515. var a = new Line3( zero3.clone(), two3.clone() );
  35516. var b = new Vector4( two3.x, two3.y, two3.z, 1 );
  35517. var m = new Matrix4().makeTranslation( x, y, z );
  35518. var v = new Vector3( x, y, z );
  35519. a.applyMatrix4( m );
  35520. assert.ok( a.start.equals( v ), "Translation: check start" );
  35521. assert.ok( a.end.equals( new Vector3( 2 + x, 2 + y, 2 + z ) ), "Translation: check start" );
  35522. // reset starting conditions
  35523. a.set( zero3.clone(), two3.clone() );
  35524. m.makeRotationX( Math.PI );
  35525. a.applyMatrix4( m );
  35526. b.applyMatrix4( m );
  35527. assert.ok( a.start.equals( zero3 ), "Rotation: check start" );
  35528. assert.numEqual( a.end.x, b.x / b.w, "Rotation: check end.x" );
  35529. assert.numEqual( a.end.y, b.y / b.w, "Rotation: check end.y" );
  35530. assert.numEqual( a.end.z, b.z / b.w, "Rotation: check end.z" );
  35531. // reset starting conditions
  35532. a.set( zero3.clone(), two3.clone() );
  35533. b.set( two3.x, two3.y, two3.z, 1 );
  35534. m.setPosition( v );
  35535. a.applyMatrix4( m );
  35536. b.applyMatrix4( m );
  35537. assert.ok( a.start.equals( v ), "Both: check start" );
  35538. assert.numEqual( a.end.x, b.x / b.w, "Both: check end.x" );
  35539. assert.numEqual( a.end.y, b.y / b.w, "Both: check end.y" );
  35540. assert.numEqual( a.end.z, b.z / b.w, "Both: check end.z" );
  35541. } );
  35542. QUnit.test( "equals", ( assert ) => {
  35543. assert.ok( false, "everything's gonna be alright" );
  35544. } );
  35545. } );
  35546. } );
  35547. /**
  35548. * @author humbletim / https://github.com/humbletim
  35549. * @author TristanVALCKE / https://github.com/Itee
  35550. */
  35551. /* global QUnit */
  35552. QUnit.module( 'Maths', () => {
  35553. QUnit.module.todo( 'Math', () => {
  35554. // PUBLIC STUFF
  35555. QUnit.test( "generateUUID", ( assert ) => {
  35556. var a = _Math.generateUUID();
  35557. var regex = /[A-Z0-9]{8}-[A-Z0-9]{4}-4[A-Z0-9]{3}-[A-Z0-9]{4}-[A-Z0-9]{12}/i;
  35558. // note the fixed '4' here ----------^
  35559. assert.ok( regex.test( a ), "Generated UUID matches the expected pattern" );
  35560. } );
  35561. QUnit.test( "clamp", ( assert ) => {
  35562. assert.strictEqual( _Math.clamp( 0.5, 0, 1 ), 0.5, "Value already within limits" );
  35563. assert.strictEqual( _Math.clamp( 0, 0, 1 ), 0, "Value equal to one limit" );
  35564. assert.strictEqual( _Math.clamp( - 0.1, 0, 1 ), 0, "Value too low" );
  35565. assert.strictEqual( _Math.clamp( 1.1, 0, 1 ), 1, "Value too high" );
  35566. } );
  35567. QUnit.test( "euclideanModulo", ( assert ) => {
  35568. assert.ok( isNaN( _Math.euclideanModulo( 6, 0 ) ), "Division by zero returns NaN" );
  35569. assert.strictEqual( _Math.euclideanModulo( 6, 1 ), 0, "Divison by trivial divisor" );
  35570. assert.strictEqual( _Math.euclideanModulo( 6, 2 ), 0, "Divison by non-trivial divisor" );
  35571. assert.strictEqual( _Math.euclideanModulo( 6, 5 ), 1, "Divison by itself - 1" );
  35572. assert.strictEqual( _Math.euclideanModulo( 6, 6 ), 0, "Divison by itself" );
  35573. assert.strictEqual( _Math.euclideanModulo( 6, 7 ), 6, "Divison by itself + 1" );
  35574. } );
  35575. QUnit.test( "mapLinear", ( assert ) => {
  35576. assert.strictEqual( _Math.mapLinear( 0.5, 0, 1, 0, 10 ), 5, "Value within range" );
  35577. assert.strictEqual( _Math.mapLinear( 0.0, 0, 1, 0, 10 ), 0, "Value equal to lower boundary" );
  35578. assert.strictEqual( _Math.mapLinear( 1.0, 0, 1, 0, 10 ), 10, "Value equal to upper boundary" );
  35579. } );
  35580. QUnit.test( "lerp", ( assert ) => {
  35581. assert.ok( false, "everything's gonna be alright" );
  35582. } );
  35583. QUnit.test( "smoothstep", ( assert ) => {
  35584. assert.strictEqual( _Math.smoothstep( - 1, 0, 2 ), 0, "Value lower than minimum" );
  35585. assert.strictEqual( _Math.smoothstep( 0, 0, 2 ), 0, "Value equal to minimum" );
  35586. assert.strictEqual( _Math.smoothstep( 0.5, 0, 2 ), 0.15625, "Value within limits" );
  35587. assert.strictEqual( _Math.smoothstep( 1, 0, 2 ), 0.5, "Value within limits" );
  35588. assert.strictEqual( _Math.smoothstep( 1.5, 0, 2 ), 0.84375, "Value within limits" );
  35589. assert.strictEqual( _Math.smoothstep( 2, 0, 2 ), 1, "Value equal to maximum" );
  35590. assert.strictEqual( _Math.smoothstep( 3, 0, 2 ), 1, "Value highter than maximum" );
  35591. } );
  35592. QUnit.test( "smootherstep", ( assert ) => {
  35593. assert.ok( false, "everything's gonna be alright" );
  35594. } );
  35595. QUnit.test( "randInt", ( assert ) => {
  35596. var low = 1, high = 3;
  35597. var a = _Math.randInt( low, high );
  35598. assert.ok( a >= low, "Value equal to or higher than lower limit" );
  35599. assert.ok( a <= high, "Value equal to or lower than upper limit" );
  35600. } );
  35601. QUnit.test( "randFloat", ( assert ) => {
  35602. var low = 1, high = 3;
  35603. var a = _Math.randFloat( low, high );
  35604. assert.ok( a >= low, "Value equal to or higher than lower limit" );
  35605. assert.ok( a <= high, "Value equal to or lower than upper limit" );
  35606. } );
  35607. QUnit.test( "randFloatSpread", ( assert ) => {
  35608. var a = _Math.randFloatSpread( 3 );
  35609. assert.ok( a > - 3 / 2, "Value higher than lower limit" );
  35610. assert.ok( a < 3 / 2, "Value lower than upper limit" );
  35611. } );
  35612. QUnit.test( "degToRad", ( assert ) => {
  35613. assert.strictEqual( _Math.degToRad( 0 ), 0, "0 degrees" );
  35614. assert.strictEqual( _Math.degToRad( 90 ), Math.PI / 2, "90 degrees" );
  35615. assert.strictEqual( _Math.degToRad( 180 ), Math.PI, "180 degrees" );
  35616. assert.strictEqual( _Math.degToRad( 360 ), Math.PI * 2, "360 degrees" );
  35617. } );
  35618. QUnit.test( "radToDeg", ( assert ) => {
  35619. assert.strictEqual( _Math.radToDeg( 0 ), 0, "0 radians" );
  35620. assert.strictEqual( _Math.radToDeg( Math.PI / 2 ), 90, "Math.PI / 2 radians" );
  35621. assert.strictEqual( _Math.radToDeg( Math.PI ), 180, "Math.PI radians" );
  35622. assert.strictEqual( _Math.radToDeg( Math.PI * 2 ), 360, "Math.PI * 2 radians" );
  35623. } );
  35624. QUnit.test( "isPowerOfTwo", ( assert ) => {
  35625. assert.strictEqual( _Math.isPowerOfTwo( 0 ), false, "0 is not a PoT" );
  35626. assert.strictEqual( _Math.isPowerOfTwo( 1 ), true, "1 is a PoT" );
  35627. assert.strictEqual( _Math.isPowerOfTwo( 2 ), true, "2 is a PoT" );
  35628. assert.strictEqual( _Math.isPowerOfTwo( 3 ), false, "3 is not a PoT" );
  35629. assert.strictEqual( _Math.isPowerOfTwo( 4 ), true, "4 is a PoT" );
  35630. } );
  35631. QUnit.test( "ceilPowerOfTwo", ( assert ) => {
  35632. assert.strictEqual( _Math.ceilPowerOfTwo( 1 ), 1, "Closest higher PoT to 1 is 1" );
  35633. assert.strictEqual( _Math.ceilPowerOfTwo( 3 ), 4, "Closest higher PoT to 3 is 4" );
  35634. assert.strictEqual( _Math.ceilPowerOfTwo( 4 ), 4, "Closest higher PoT to 4 is 4" );
  35635. } );
  35636. QUnit.test( "floorPowerOfTwo", ( assert ) => {
  35637. assert.strictEqual( _Math.floorPowerOfTwo( 1 ), 1, "Closest lower PoT to 1 is 1" );
  35638. assert.strictEqual( _Math.floorPowerOfTwo( 3 ), 2, "Closest lower PoT to 3 is 2" );
  35639. assert.strictEqual( _Math.floorPowerOfTwo( 4 ), 4, "Closest lower PoT to 4 is 4" );
  35640. } );
  35641. } );
  35642. } );
  35643. /**
  35644. * @author bhouston / http://exocortex.com
  35645. * @author TristanVALCKE / https://github.com/Itee
  35646. */
  35647. /* global QUnit */
  35648. function matrixEquals3( a, b, tolerance ) {
  35649. tolerance = tolerance || 0.0001;
  35650. if ( a.elements.length != b.elements.length ) {
  35651. return false;
  35652. }
  35653. for ( var i = 0, il = a.elements.length; i < il; i ++ ) {
  35654. var delta = a.elements[ i ] - b.elements[ i ];
  35655. if ( delta > tolerance ) {
  35656. return false;
  35657. }
  35658. }
  35659. return true;
  35660. }
  35661. function toMatrix4( m3 ) {
  35662. var result = new Matrix4();
  35663. var re = result.elements;
  35664. var me = m3.elements;
  35665. re[ 0 ] = me[ 0 ];
  35666. re[ 1 ] = me[ 1 ];
  35667. re[ 2 ] = me[ 2 ];
  35668. re[ 4 ] = me[ 3 ];
  35669. re[ 5 ] = me[ 4 ];
  35670. re[ 6 ] = me[ 5 ];
  35671. re[ 8 ] = me[ 6 ];
  35672. re[ 9 ] = me[ 7 ];
  35673. re[ 10 ] = me[ 8 ];
  35674. return result;
  35675. }
  35676. QUnit.module( 'Maths', () => {
  35677. QUnit.module.todo( 'Matrix3', () => {
  35678. // INSTANCING
  35679. QUnit.test( "Instancing", ( assert ) => {
  35680. var a = new Matrix3();
  35681. assert.ok( a.determinant() == 1, "Passed!" );
  35682. var b = new Matrix3().set( 0, 1, 2, 3, 4, 5, 6, 7, 8 );
  35683. assert.ok( b.elements[ 0 ] == 0 );
  35684. assert.ok( b.elements[ 1 ] == 3 );
  35685. assert.ok( b.elements[ 2 ] == 6 );
  35686. assert.ok( b.elements[ 3 ] == 1 );
  35687. assert.ok( b.elements[ 4 ] == 4 );
  35688. assert.ok( b.elements[ 5 ] == 7 );
  35689. assert.ok( b.elements[ 6 ] == 2 );
  35690. assert.ok( b.elements[ 7 ] == 5 );
  35691. assert.ok( b.elements[ 8 ] == 8 );
  35692. assert.ok( ! matrixEquals3( a, b ), "Passed!" );
  35693. } );
  35694. // PUBLIC STUFF
  35695. QUnit.test( "isMatrix3", ( assert ) => {
  35696. assert.ok( false, "everything's gonna be alright" );
  35697. } );
  35698. QUnit.test( "set", ( assert ) => {
  35699. var b = new Matrix3();
  35700. assert.ok( b.determinant() == 1, "Passed!" );
  35701. b.set( 0, 1, 2, 3, 4, 5, 6, 7, 8 );
  35702. assert.ok( b.elements[ 0 ] == 0 );
  35703. assert.ok( b.elements[ 1 ] == 3 );
  35704. assert.ok( b.elements[ 2 ] == 6 );
  35705. assert.ok( b.elements[ 3 ] == 1 );
  35706. assert.ok( b.elements[ 4 ] == 4 );
  35707. assert.ok( b.elements[ 5 ] == 7 );
  35708. assert.ok( b.elements[ 6 ] == 2 );
  35709. assert.ok( b.elements[ 7 ] == 5 );
  35710. assert.ok( b.elements[ 8 ] == 8 );
  35711. } );
  35712. QUnit.test( "identity", ( assert ) => {
  35713. var b = new Matrix3().set( 0, 1, 2, 3, 4, 5, 6, 7, 8 );
  35714. assert.ok( b.elements[ 0 ] == 0 );
  35715. assert.ok( b.elements[ 1 ] == 3 );
  35716. assert.ok( b.elements[ 2 ] == 6 );
  35717. assert.ok( b.elements[ 3 ] == 1 );
  35718. assert.ok( b.elements[ 4 ] == 4 );
  35719. assert.ok( b.elements[ 5 ] == 7 );
  35720. assert.ok( b.elements[ 6 ] == 2 );
  35721. assert.ok( b.elements[ 7 ] == 5 );
  35722. assert.ok( b.elements[ 8 ] == 8 );
  35723. var a = new Matrix3();
  35724. assert.ok( ! matrixEquals3( a, b ), "Passed!" );
  35725. b.identity();
  35726. assert.ok( matrixEquals3( a, b ), "Passed!" );
  35727. } );
  35728. QUnit.test( "clone", ( assert ) => {
  35729. var a = new Matrix3().set( 0, 1, 2, 3, 4, 5, 6, 7, 8 );
  35730. var b = a.clone();
  35731. assert.ok( matrixEquals3( a, b ), "Passed!" );
  35732. // ensure that it is a true copy
  35733. a.elements[ 0 ] = 2;
  35734. assert.ok( ! matrixEquals3( a, b ), "Passed!" );
  35735. } );
  35736. QUnit.test( "copy", ( assert ) => {
  35737. var a = new Matrix3().set( 0, 1, 2, 3, 4, 5, 6, 7, 8 );
  35738. var b = new Matrix3().copy( a );
  35739. assert.ok( matrixEquals3( a, b ), "Passed!" );
  35740. // ensure that it is a true copy
  35741. a.elements[ 0 ] = 2;
  35742. assert.ok( ! matrixEquals3( a, b ), "Passed!" );
  35743. } );
  35744. QUnit.test( "setFromMatrix4", ( assert ) => {
  35745. assert.ok( false, "everything's gonna be alright" );
  35746. } );
  35747. QUnit.test( "applyToBufferAttribute", ( assert ) => {
  35748. var a = new Matrix3().set( 1, 2, 3, 4, 5, 6, 7, 8, 9 );
  35749. var attr = new Float32BufferAttribute( [ 1, 2, 1, 3, 0, 3 ], 3 );
  35750. var expected = new Float32Array( [ 8, 20, 32, 12, 30, 48 ] );
  35751. var applied = a.applyToBufferAttribute( attr );
  35752. assert.deepEqual( applied.array, expected, "Check resulting buffer" );
  35753. } );
  35754. QUnit.test( "multiply/premultiply", ( assert ) => {
  35755. // both simply just wrap multiplyMatrices
  35756. var a = new Matrix3().set( 2, 3, 5, 7, 11, 13, 17, 19, 23 );
  35757. var b = new Matrix3().set( 29, 31, 37, 41, 43, 47, 53, 59, 61 );
  35758. var expectedMultiply = [ 446, 1343, 2491, 486, 1457, 2701, 520, 1569, 2925 ];
  35759. var expectedPremultiply = [ 904, 1182, 1556, 1131, 1489, 1967, 1399, 1845, 2435 ];
  35760. a.multiply( b );
  35761. assert.deepEqual( a.elements, expectedMultiply, "multiply: check result" );
  35762. a.set( 2, 3, 5, 7, 11, 13, 17, 19, 23 );
  35763. a.premultiply( b );
  35764. assert.deepEqual( a.elements, expectedPremultiply, "premultiply: check result" );
  35765. } );
  35766. QUnit.test( "multiplyMatrices", ( assert ) => {
  35767. // Reference:
  35768. //
  35769. // #!/usr/bin/env python
  35770. // from __future__ import print_function
  35771. // import numpy as np
  35772. // print(
  35773. // np.dot(
  35774. // np.reshape([2, 3, 5, 7, 11, 13, 17, 19, 23], (3, 3)),
  35775. // np.reshape([29, 31, 37, 41, 43, 47, 53, 59, 61], (3, 3))
  35776. // )
  35777. // )
  35778. //
  35779. // [[ 446 486 520]
  35780. // [1343 1457 1569]
  35781. // [2491 2701 2925]]
  35782. var lhs = new Matrix3().set( 2, 3, 5, 7, 11, 13, 17, 19, 23 );
  35783. var rhs = new Matrix3().set( 29, 31, 37, 41, 43, 47, 53, 59, 61 );
  35784. var ans = new Matrix3();
  35785. ans.multiplyMatrices( lhs, rhs );
  35786. assert.ok( ans.elements[ 0 ] == 446 );
  35787. assert.ok( ans.elements[ 1 ] == 1343 );
  35788. assert.ok( ans.elements[ 2 ] == 2491 );
  35789. assert.ok( ans.elements[ 3 ] == 486 );
  35790. assert.ok( ans.elements[ 4 ] == 1457 );
  35791. assert.ok( ans.elements[ 5 ] == 2701 );
  35792. assert.ok( ans.elements[ 6 ] == 520 );
  35793. assert.ok( ans.elements[ 7 ] == 1569 );
  35794. assert.ok( ans.elements[ 8 ] == 2925 );
  35795. } );
  35796. QUnit.test( "multiplyScalar", ( assert ) => {
  35797. var b = new Matrix3().set( 0, 1, 2, 3, 4, 5, 6, 7, 8 );
  35798. assert.ok( b.elements[ 0 ] == 0 );
  35799. assert.ok( b.elements[ 1 ] == 3 );
  35800. assert.ok( b.elements[ 2 ] == 6 );
  35801. assert.ok( b.elements[ 3 ] == 1 );
  35802. assert.ok( b.elements[ 4 ] == 4 );
  35803. assert.ok( b.elements[ 5 ] == 7 );
  35804. assert.ok( b.elements[ 6 ] == 2 );
  35805. assert.ok( b.elements[ 7 ] == 5 );
  35806. assert.ok( b.elements[ 8 ] == 8 );
  35807. b.multiplyScalar( 2 );
  35808. assert.ok( b.elements[ 0 ] == 0 * 2 );
  35809. assert.ok( b.elements[ 1 ] == 3 * 2 );
  35810. assert.ok( b.elements[ 2 ] == 6 * 2 );
  35811. assert.ok( b.elements[ 3 ] == 1 * 2 );
  35812. assert.ok( b.elements[ 4 ] == 4 * 2 );
  35813. assert.ok( b.elements[ 5 ] == 7 * 2 );
  35814. assert.ok( b.elements[ 6 ] == 2 * 2 );
  35815. assert.ok( b.elements[ 7 ] == 5 * 2 );
  35816. assert.ok( b.elements[ 8 ] == 8 * 2 );
  35817. } );
  35818. QUnit.test( "determinant", ( assert ) => {
  35819. var a = new Matrix3();
  35820. assert.ok( a.determinant() == 1, "Passed!" );
  35821. a.elements[ 0 ] = 2;
  35822. assert.ok( a.determinant() == 2, "Passed!" );
  35823. a.elements[ 0 ] = 0;
  35824. assert.ok( a.determinant() == 0, "Passed!" );
  35825. // calculated via http://www.euclideanspace.com/maths/algebra/matrix/functions/determinant/threeD/index.htm
  35826. a.set( 2, 3, 4, 5, 13, 7, 8, 9, 11 );
  35827. assert.ok( a.determinant() == - 73, "Passed!" );
  35828. } );
  35829. QUnit.test( "getInverse", ( assert ) => {
  35830. var identity = new Matrix3();
  35831. var identity4 = new Matrix4();
  35832. var a = new Matrix3();
  35833. var b = new Matrix3().set( 0, 0, 0, 0, 0, 0, 0, 0, 0 );
  35834. var c = new Matrix3().set( 0, 0, 0, 0, 0, 0, 0, 0, 0 );
  35835. b.getInverse( a, false );
  35836. assert.ok( matrixEquals3( a, identity ), "Matrix a is identity matrix" );
  35837. try {
  35838. b.getInverse( c, true );
  35839. assert.ok( false, "Should never get here !" ); // should never get here.
  35840. } catch ( err ) {
  35841. assert.ok( true, "Passed: " + err );
  35842. }
  35843. var testMatrices = [
  35844. new Matrix4().makeRotationX( 0.3 ),
  35845. new Matrix4().makeRotationX( - 0.3 ),
  35846. new Matrix4().makeRotationY( 0.3 ),
  35847. new Matrix4().makeRotationY( - 0.3 ),
  35848. new Matrix4().makeRotationZ( 0.3 ),
  35849. new Matrix4().makeRotationZ( - 0.3 ),
  35850. new Matrix4().makeScale( 1, 2, 3 ),
  35851. new Matrix4().makeScale( 1 / 8, 1 / 2, 1 / 3 )
  35852. ];
  35853. for ( var i = 0, il = testMatrices.length; i < il; i ++ ) {
  35854. var m = testMatrices[ i ];
  35855. a.setFromMatrix4( m );
  35856. var mInverse3 = b.getInverse( a );
  35857. var mInverse = toMatrix4( mInverse3 );
  35858. // the determinant of the inverse should be the reciprocal
  35859. assert.ok( Math.abs( a.determinant() * mInverse3.determinant() - 1 ) < 0.0001, "Passed!" );
  35860. assert.ok( Math.abs( m.determinant() * mInverse.determinant() - 1 ) < 0.0001, "Passed!" );
  35861. var mProduct = new Matrix4().multiplyMatrices( m, mInverse );
  35862. assert.ok( Math.abs( mProduct.determinant() - 1 ) < 0.0001, "Passed!" );
  35863. assert.ok( matrixEquals3( mProduct, identity4 ), "Passed!" );
  35864. }
  35865. } );
  35866. QUnit.test( "transpose", ( assert ) => {
  35867. var a = new Matrix3();
  35868. var b = a.clone().transpose();
  35869. assert.ok( matrixEquals3( a, b ), "Passed!" );
  35870. var b = new Matrix3().set( 0, 1, 2, 3, 4, 5, 6, 7, 8 );
  35871. var c = b.clone().transpose();
  35872. assert.ok( ! matrixEquals3( b, c ), "Passed!" );
  35873. c.transpose();
  35874. assert.ok( matrixEquals3( b, c ), "Passed!" );
  35875. } );
  35876. QUnit.test( "getNormalMatrix", ( assert ) => {
  35877. var a = new Matrix3();
  35878. var b = new Matrix4().set(
  35879. 2, 3, 5, 7,
  35880. 11, 13, 17, 19,
  35881. 23, 29, 31, 37,
  35882. 41, 43, 47, 57
  35883. );
  35884. var expected = new Matrix3().set(
  35885. - 1.2857142857142856, 0.7142857142857143, 0.2857142857142857,
  35886. 0.7428571428571429, - 0.7571428571428571, 0.15714285714285714,
  35887. - 0.19999999999999998, 0.3, - 0.09999999999999999
  35888. );
  35889. a.getNormalMatrix( b );
  35890. assert.ok( matrixEquals3( a, expected ), "Check resulting Matrix3" );
  35891. } );
  35892. QUnit.test( "transposeIntoArray", ( assert ) => {
  35893. assert.ok( false, "everything's gonna be alright" );
  35894. } );
  35895. QUnit.test( "setUvTransform", ( assert ) => {
  35896. var a = new Matrix3().set(
  35897. 0.1767766952966369, 0.17677669529663687, 0.32322330470336313,
  35898. - 0.17677669529663687, 0.1767766952966369, 0.5,
  35899. 0, 0, 1
  35900. );
  35901. var b = new Matrix3();
  35902. var params = {
  35903. centerX: 0.5,
  35904. centerY: 0.5,
  35905. offsetX: 0,
  35906. offsetY: 0,
  35907. repeatX: 0.25,
  35908. repeatY: 0.25,
  35909. rotation: 0.7753981633974483
  35910. };
  35911. var expected = new Matrix3().set(
  35912. 0.1785355940258599, 0.17500011904519763, 0.32323214346447127,
  35913. - 0.17500011904519763, 0.1785355940258599, 0.4982322625096689,
  35914. 0, 0, 1
  35915. );
  35916. a.setUvTransform(
  35917. params.offsetX, params.offsetY,
  35918. params.repeatX, params.repeatY,
  35919. params.rotation,
  35920. params.centerX, params.centerY
  35921. );
  35922. b.identity()
  35923. .translate( - params.centerX, - params.centerY )
  35924. .rotate( params.rotation )
  35925. .scale( params.repeatX, params.repeatY )
  35926. .translate( params.centerX, params.centerY )
  35927. .translate( params.offsetX, params.offsetY );
  35928. assert.ok( matrixEquals3( a, expected ), "Check direct method" );
  35929. assert.ok( matrixEquals3( b, expected ), "Check indirect method" );
  35930. } );
  35931. QUnit.test( "scale", ( assert ) => {
  35932. var a = new Matrix3().set( 1, 2, 3, 4, 5, 6, 7, 8, 9 );
  35933. var expected = new Matrix3().set(
  35934. 0.25, 0.5, 0.75,
  35935. 1, 1.25, 1.5,
  35936. 7, 8, 9
  35937. );
  35938. a.scale( 0.25, 0.25 );
  35939. assert.ok( matrixEquals3( a, expected ), "Check scaling result" );
  35940. } );
  35941. QUnit.test( "rotate", ( assert ) => {
  35942. var a = new Matrix3().set( 1, 2, 3, 4, 5, 6, 7, 8, 9 );
  35943. var expected = new Matrix3().set(
  35944. 3.5355339059327373, 4.949747468305833, 6.363961030678928,
  35945. 2.121320343559643, 2.121320343559643, 2.1213203435596433,
  35946. 7, 8, 9
  35947. );
  35948. a.rotate( Math.PI / 4 );
  35949. assert.ok( matrixEquals3( a, expected ), "Check rotated result" );
  35950. } );
  35951. QUnit.test( "translate", ( assert ) => {
  35952. var a = new Matrix3().set( 1, 2, 3, 4, 5, 6, 7, 8, 9 );
  35953. var expected = new Matrix3().set( 22, 26, 30, 53, 61, 69, 7, 8, 9 );
  35954. a.translate( 3, 7 );
  35955. assert.ok( matrixEquals3( a, expected ), "Check translation result" );
  35956. } );
  35957. QUnit.test( "equals", ( assert ) => {
  35958. var a = new Matrix3().set( 0, 1, 2, 3, 4, 5, 6, 7, 8 );
  35959. var b = new Matrix3().set( 0, - 1, 2, 3, 4, 5, 6, 7, 8 );
  35960. assert.notOk( a.equals( b ), "Check that a does not equal b" );
  35961. assert.notOk( b.equals( a ), "Check that b does not equal a" );
  35962. a.copy( b );
  35963. assert.ok( a.equals( b ), "Check that a equals b after copy()" );
  35964. assert.ok( b.equals( a ), "Check that b equals a after copy()" );
  35965. } );
  35966. QUnit.test( "fromArray", ( assert ) => {
  35967. assert.ok( false, "everything's gonna be alright" );
  35968. } );
  35969. QUnit.test( "toArray", ( assert ) => {
  35970. var a = new Matrix3().set( 1, 2, 3, 4, 5, 6, 7, 8, 9 );
  35971. var noOffset = [ 1, 4, 7, 2, 5, 8, 3, 6, 9 ];
  35972. var withOffset = [ undefined, 1, 4, 7, 2, 5, 8, 3, 6, 9 ];
  35973. var array = a.toArray();
  35974. assert.deepEqual( array, noOffset, "No array, no offset" );
  35975. var array = [];
  35976. a.toArray( array );
  35977. assert.deepEqual( array, noOffset, "With array, no offset" );
  35978. var array = [];
  35979. a.toArray( array, 1 );
  35980. assert.deepEqual( array, withOffset, "With array, with offset" );
  35981. } );
  35982. } );
  35983. } );
  35984. /**
  35985. * @author bhouston / http://exocortex.com
  35986. * @author TristanVALCKE / https://github.com/Itee
  35987. */
  35988. /* global QUnit */
  35989. function matrixEquals4$1( a, b, tolerance ) {
  35990. tolerance = tolerance || 0.0001;
  35991. if ( a.elements.length != b.elements.length ) {
  35992. return false;
  35993. }
  35994. for ( var i = 0, il = a.elements.length; i < il; i ++ ) {
  35995. var delta = a.elements[ i ] - b.elements[ i ];
  35996. if ( delta > tolerance ) {
  35997. return false;
  35998. }
  35999. }
  36000. return true;
  36001. }
  36002. // from Euler.js
  36003. function eulerEquals$1( a, b, tolerance ) {
  36004. tolerance = tolerance || 0.0001;
  36005. var diff = Math.abs( a.x - b.x ) + Math.abs( a.y - b.y ) + Math.abs( a.z - b.z );
  36006. return ( diff < tolerance );
  36007. }
  36008. QUnit.module( 'Maths', () => {
  36009. QUnit.module.todo( 'Matrix4', () => {
  36010. // INSTANCING
  36011. QUnit.test( "Instancing", ( assert ) => {
  36012. var a = new Matrix4();
  36013. assert.ok( a.determinant() == 1, "Passed!" );
  36014. var b = new Matrix4().set( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 );
  36015. assert.ok( b.elements[ 0 ] == 0 );
  36016. assert.ok( b.elements[ 1 ] == 4 );
  36017. assert.ok( b.elements[ 2 ] == 8 );
  36018. assert.ok( b.elements[ 3 ] == 12 );
  36019. assert.ok( b.elements[ 4 ] == 1 );
  36020. assert.ok( b.elements[ 5 ] == 5 );
  36021. assert.ok( b.elements[ 6 ] == 9 );
  36022. assert.ok( b.elements[ 7 ] == 13 );
  36023. assert.ok( b.elements[ 8 ] == 2 );
  36024. assert.ok( b.elements[ 9 ] == 6 );
  36025. assert.ok( b.elements[ 10 ] == 10 );
  36026. assert.ok( b.elements[ 11 ] == 14 );
  36027. assert.ok( b.elements[ 12 ] == 3 );
  36028. assert.ok( b.elements[ 13 ] == 7 );
  36029. assert.ok( b.elements[ 14 ] == 11 );
  36030. assert.ok( b.elements[ 15 ] == 15 );
  36031. assert.ok( ! matrixEquals4$1( a, b ), "Passed!" );
  36032. } );
  36033. // PUBLIC STUFF
  36034. QUnit.test( "isMatrix4", ( assert ) => {
  36035. assert.ok( false, "everything's gonna be alright" );
  36036. } );
  36037. QUnit.test( "set", ( assert ) => {
  36038. var b = new Matrix4();
  36039. assert.ok( b.determinant() == 1, "Passed!" );
  36040. b.set( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 );
  36041. assert.ok( b.elements[ 0 ] == 0 );
  36042. assert.ok( b.elements[ 1 ] == 4 );
  36043. assert.ok( b.elements[ 2 ] == 8 );
  36044. assert.ok( b.elements[ 3 ] == 12 );
  36045. assert.ok( b.elements[ 4 ] == 1 );
  36046. assert.ok( b.elements[ 5 ] == 5 );
  36047. assert.ok( b.elements[ 6 ] == 9 );
  36048. assert.ok( b.elements[ 7 ] == 13 );
  36049. assert.ok( b.elements[ 8 ] == 2 );
  36050. assert.ok( b.elements[ 9 ] == 6 );
  36051. assert.ok( b.elements[ 10 ] == 10 );
  36052. assert.ok( b.elements[ 11 ] == 14 );
  36053. assert.ok( b.elements[ 12 ] == 3 );
  36054. assert.ok( b.elements[ 13 ] == 7 );
  36055. assert.ok( b.elements[ 14 ] == 11 );
  36056. assert.ok( b.elements[ 15 ] == 15 );
  36057. } );
  36058. QUnit.test( "identity", ( assert ) => {
  36059. var b = new Matrix4().set( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 );
  36060. assert.ok( b.elements[ 0 ] == 0 );
  36061. assert.ok( b.elements[ 1 ] == 4 );
  36062. assert.ok( b.elements[ 2 ] == 8 );
  36063. assert.ok( b.elements[ 3 ] == 12 );
  36064. assert.ok( b.elements[ 4 ] == 1 );
  36065. assert.ok( b.elements[ 5 ] == 5 );
  36066. assert.ok( b.elements[ 6 ] == 9 );
  36067. assert.ok( b.elements[ 7 ] == 13 );
  36068. assert.ok( b.elements[ 8 ] == 2 );
  36069. assert.ok( b.elements[ 9 ] == 6 );
  36070. assert.ok( b.elements[ 10 ] == 10 );
  36071. assert.ok( b.elements[ 11 ] == 14 );
  36072. assert.ok( b.elements[ 12 ] == 3 );
  36073. assert.ok( b.elements[ 13 ] == 7 );
  36074. assert.ok( b.elements[ 14 ] == 11 );
  36075. assert.ok( b.elements[ 15 ] == 15 );
  36076. var a = new Matrix4();
  36077. assert.ok( ! matrixEquals4$1( a, b ), "Passed!" );
  36078. b.identity();
  36079. assert.ok( matrixEquals4$1( a, b ), "Passed!" );
  36080. } );
  36081. QUnit.test( "clone", ( assert ) => {
  36082. var a = new Matrix4().set( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 );
  36083. var b = a.clone();
  36084. assert.ok( matrixEquals4$1( a, b ), "Passed!" );
  36085. // ensure that it is a true copy
  36086. a.elements[ 0 ] = 2;
  36087. assert.ok( ! matrixEquals4$1( a, b ), "Passed!" );
  36088. } );
  36089. QUnit.test( "copy", ( assert ) => {
  36090. var a = new Matrix4().set( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 );
  36091. var b = new Matrix4().copy( a );
  36092. assert.ok( matrixEquals4$1( a, b ), "Passed!" );
  36093. // ensure that it is a true copy
  36094. a.elements[ 0 ] = 2;
  36095. assert.ok( ! matrixEquals4$1( a, b ), "Passed!" );
  36096. } );
  36097. QUnit.test( "copyPosition", ( assert ) => {
  36098. var a = new Matrix4().set( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 );
  36099. var b = new Matrix4().set( 1, 2, 3, 0, 5, 6, 7, 0, 9, 10, 11, 0, 13, 14, 15, 16 );
  36100. assert.notOk( matrixEquals4$1( a, b ), "a and b initially not equal" );
  36101. b.copyPosition( a );
  36102. assert.ok( matrixEquals4$1( a, b ), "a and b equal after copyPosition()" );
  36103. } );
  36104. QUnit.test( "makeBasis/extractBasis", ( assert ) => {
  36105. var identityBasis = [ new Vector3( 1, 0, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ) ];
  36106. var a = new Matrix4().makeBasis( identityBasis[ 0 ], identityBasis[ 1 ], identityBasis[ 2 ] );
  36107. var identity = new Matrix4();
  36108. assert.ok( matrixEquals4$1( a, identity ), "Passed!" );
  36109. var testBases = [[ new Vector3( 0, 1, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ) ]];
  36110. for ( var i = 0; i < testBases.length; i ++ ) {
  36111. var testBasis = testBases[ i ];
  36112. var b = new Matrix4().makeBasis( testBasis[ 0 ], testBasis[ 1 ], testBasis[ 2 ] );
  36113. var outBasis = [ new Vector3(), new Vector3(), new Vector3() ];
  36114. b.extractBasis( outBasis[ 0 ], outBasis[ 1 ], outBasis[ 2 ] );
  36115. // check what goes in, is what comes out.
  36116. for ( var j = 0; j < outBasis.length; j ++ ) {
  36117. assert.ok( outBasis[ j ].equals( testBasis[ j ] ), "Passed!" );
  36118. }
  36119. // get the basis out the hard war
  36120. for ( var j = 0; j < identityBasis.length; j ++ ) {
  36121. outBasis[ j ].copy( identityBasis[ j ] );
  36122. outBasis[ j ].applyMatrix4( b );
  36123. }
  36124. // did the multiply method of basis extraction work?
  36125. for ( var j = 0; j < outBasis.length; j ++ ) {
  36126. assert.ok( outBasis[ j ].equals( testBasis[ j ] ), "Passed!" );
  36127. }
  36128. }
  36129. } );
  36130. QUnit.test( "extractRotation", ( assert ) => {
  36131. assert.ok( false, "everything's gonna be alright" );
  36132. } );
  36133. QUnit.test( "makeRotationFromEuler/extractRotation", ( assert ) => {
  36134. var testValues = [
  36135. new Euler( 0, 0, 0, "XYZ" ),
  36136. new Euler( 1, 0, 0, "XYZ" ),
  36137. new Euler( 0, 1, 0, "ZYX" ),
  36138. new Euler( 0, 0, 0.5, "YZX" ),
  36139. new Euler( 0, 0, - 0.5, "YZX" )
  36140. ];
  36141. for ( var i = 0; i < testValues.length; i ++ ) {
  36142. var v = testValues[ i ];
  36143. var m = new Matrix4().makeRotationFromEuler( v );
  36144. var v2 = new Euler().setFromRotationMatrix( m, v.order );
  36145. var m2 = new Matrix4().makeRotationFromEuler( v2 );
  36146. assert.ok( matrixEquals4$1( m, m2, eps ), "makeRotationFromEuler #" + i + ": original and Euler-derived matrices are equal" );
  36147. assert.ok( eulerEquals$1( v, v2, eps ), "makeRotationFromEuler #" + i + ": original and matrix-derived Eulers are equal" );
  36148. var m3 = new Matrix4().extractRotation( m2 );
  36149. var v3 = new Euler().setFromRotationMatrix( m3, v.order );
  36150. assert.ok( matrixEquals4$1( m, m3, eps ), "extractRotation #" + i + ": original and extracted matrices are equal" );
  36151. assert.ok( eulerEquals$1( v, v3, eps ), "extractRotation #" + i + ": original and extracted Eulers are equal" );
  36152. }
  36153. } );
  36154. QUnit.test( "lookAt", ( assert ) => {
  36155. var a = new Matrix4();
  36156. var expected = new Matrix4().identity();
  36157. var eye = new Vector3( 0, 0, 0 );
  36158. var target = new Vector3( 0, 1, - 1 );
  36159. var up = new Vector3( 0, 1, 0 );
  36160. a.lookAt( eye, target, up );
  36161. var rotation = new Euler().setFromRotationMatrix( a );
  36162. assert.numEqual( rotation.x * ( 180 / Math.PI ), 45, "Check the rotation" );
  36163. // eye and target are in the same position
  36164. eye.copy( target );
  36165. a.lookAt( eye, target, up );
  36166. assert.ok( matrixEquals4$1( a, expected ), "Check the result for eye == target" );
  36167. // up and z are parallel
  36168. eye.set( 0, 1, 0 );
  36169. target.set( 0, 0, 0 );
  36170. a.lookAt( eye, target, up );
  36171. expected.set(
  36172. 1, 0, 0, 0,
  36173. 0, 0.0001, 1, 0,
  36174. 0, - 1, 0.0001, 0,
  36175. 0, 0, 0, 1
  36176. );
  36177. assert.ok( matrixEquals4$1( a, expected ), "Check the result for when up and z are parallel" );
  36178. } );
  36179. QUnit.test( "multiply", ( assert ) => {
  36180. assert.ok( false, "everything's gonna be alright" );
  36181. } );
  36182. QUnit.test( "premultiply", ( assert ) => {
  36183. assert.ok( false, "everything's gonna be alright" );
  36184. } );
  36185. QUnit.test( "multiplyMatrices", ( assert ) => {
  36186. // Reference:
  36187. //
  36188. // #!/usr/bin/env python
  36189. // from __future__ import print_function
  36190. // import numpy as np
  36191. // print(
  36192. // np.dot(
  36193. // np.reshape([2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53], (4, 4)),
  36194. // np.reshape([59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131], (4, 4))
  36195. // )
  36196. // )
  36197. //
  36198. // [[ 1585 1655 1787 1861]
  36199. // [ 5318 5562 5980 6246]
  36200. // [10514 11006 11840 12378]
  36201. // [15894 16634 17888 18710]]
  36202. var lhs = new Matrix4().set( 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53 );
  36203. var rhs = new Matrix4().set( 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131 );
  36204. var ans = new Matrix4();
  36205. ans.multiplyMatrices( lhs, rhs );
  36206. assert.ok( ans.elements[ 0 ] == 1585 );
  36207. assert.ok( ans.elements[ 1 ] == 5318 );
  36208. assert.ok( ans.elements[ 2 ] == 10514 );
  36209. assert.ok( ans.elements[ 3 ] == 15894 );
  36210. assert.ok( ans.elements[ 4 ] == 1655 );
  36211. assert.ok( ans.elements[ 5 ] == 5562 );
  36212. assert.ok( ans.elements[ 6 ] == 11006 );
  36213. assert.ok( ans.elements[ 7 ] == 16634 );
  36214. assert.ok( ans.elements[ 8 ] == 1787 );
  36215. assert.ok( ans.elements[ 9 ] == 5980 );
  36216. assert.ok( ans.elements[ 10 ] == 11840 );
  36217. assert.ok( ans.elements[ 11 ] == 17888 );
  36218. assert.ok( ans.elements[ 12 ] == 1861 );
  36219. assert.ok( ans.elements[ 13 ] == 6246 );
  36220. assert.ok( ans.elements[ 14 ] == 12378 );
  36221. assert.ok( ans.elements[ 15 ] == 18710 );
  36222. } );
  36223. QUnit.test( "multiplyScalar", ( assert ) => {
  36224. var b = new Matrix4().set( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 );
  36225. assert.ok( b.elements[ 0 ] == 0 );
  36226. assert.ok( b.elements[ 1 ] == 4 );
  36227. assert.ok( b.elements[ 2 ] == 8 );
  36228. assert.ok( b.elements[ 3 ] == 12 );
  36229. assert.ok( b.elements[ 4 ] == 1 );
  36230. assert.ok( b.elements[ 5 ] == 5 );
  36231. assert.ok( b.elements[ 6 ] == 9 );
  36232. assert.ok( b.elements[ 7 ] == 13 );
  36233. assert.ok( b.elements[ 8 ] == 2 );
  36234. assert.ok( b.elements[ 9 ] == 6 );
  36235. assert.ok( b.elements[ 10 ] == 10 );
  36236. assert.ok( b.elements[ 11 ] == 14 );
  36237. assert.ok( b.elements[ 12 ] == 3 );
  36238. assert.ok( b.elements[ 13 ] == 7 );
  36239. assert.ok( b.elements[ 14 ] == 11 );
  36240. assert.ok( b.elements[ 15 ] == 15 );
  36241. b.multiplyScalar( 2 );
  36242. assert.ok( b.elements[ 0 ] == 0 * 2 );
  36243. assert.ok( b.elements[ 1 ] == 4 * 2 );
  36244. assert.ok( b.elements[ 2 ] == 8 * 2 );
  36245. assert.ok( b.elements[ 3 ] == 12 * 2 );
  36246. assert.ok( b.elements[ 4 ] == 1 * 2 );
  36247. assert.ok( b.elements[ 5 ] == 5 * 2 );
  36248. assert.ok( b.elements[ 6 ] == 9 * 2 );
  36249. assert.ok( b.elements[ 7 ] == 13 * 2 );
  36250. assert.ok( b.elements[ 8 ] == 2 * 2 );
  36251. assert.ok( b.elements[ 9 ] == 6 * 2 );
  36252. assert.ok( b.elements[ 10 ] == 10 * 2 );
  36253. assert.ok( b.elements[ 11 ] == 14 * 2 );
  36254. assert.ok( b.elements[ 12 ] == 3 * 2 );
  36255. assert.ok( b.elements[ 13 ] == 7 * 2 );
  36256. assert.ok( b.elements[ 14 ] == 11 * 2 );
  36257. assert.ok( b.elements[ 15 ] == 15 * 2 );
  36258. } );
  36259. QUnit.test( "applyToBufferAttribute", ( assert ) => {
  36260. var a = new Matrix4().set( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 );
  36261. var attr = new Float32BufferAttribute( [ 1, 2, 1, 3, 0, 3 ], 3 );
  36262. var expected = new Float32BufferAttribute( [
  36263. 0.1666666716337204, 0.4444444477558136, 0.7222222089767456,
  36264. 0.1599999964237213, 0.4399999976158142, 0.7200000286102295
  36265. ], 3 );
  36266. var applied = a.applyToBufferAttribute( attr );
  36267. assert.strictEqual( expected.count, applied.count, "Applied buffer and expected buffer have the same number of entries" );
  36268. for ( var i = 0, l = expected.count; i < l; i ++ ) {
  36269. assert.ok( Math.abs( applied.getX( i ) - expected.getX( i ) ) <= eps, "Check x" );
  36270. assert.ok( Math.abs( applied.getY( i ) - expected.getY( i ) ) <= eps, "Check y" );
  36271. assert.ok( Math.abs( applied.getZ( i ) - expected.getZ( i ) ) <= eps, "Check z" );
  36272. }
  36273. } );
  36274. QUnit.test( "determinant", ( assert ) => {
  36275. var a = new Matrix4();
  36276. assert.ok( a.determinant() == 1, "Passed!" );
  36277. a.elements[ 0 ] = 2;
  36278. assert.ok( a.determinant() == 2, "Passed!" );
  36279. a.elements[ 0 ] = 0;
  36280. assert.ok( a.determinant() == 0, "Passed!" );
  36281. // calculated via http://www.euclideanspace.com/maths/algebra/matrix/functions/determinant/fourD/index.htm
  36282. a.set( 2, 3, 4, 5, - 1, - 21, - 3, - 4, 6, 7, 8, 10, - 8, - 9, - 10, - 12 );
  36283. assert.ok( a.determinant() == 76, "Passed!" );
  36284. } );
  36285. QUnit.test( "transpose", ( assert ) => {
  36286. var a = new Matrix4();
  36287. var b = a.clone().transpose();
  36288. assert.ok( matrixEquals4$1( a, b ), "Passed!" );
  36289. var b = new Matrix4().set( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 );
  36290. var c = b.clone().transpose();
  36291. assert.ok( ! matrixEquals4$1( b, c ), "Passed!" );
  36292. c.transpose();
  36293. assert.ok( matrixEquals4$1( b, c ), "Passed!" );
  36294. } );
  36295. QUnit.test( "setPosition", ( assert ) => {
  36296. assert.ok( false, "everything's gonna be alright" );
  36297. } );
  36298. QUnit.test( "getInverse", ( assert ) => {
  36299. var identity = new Matrix4();
  36300. var a = new Matrix4();
  36301. var b = new Matrix4().set( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
  36302. var c = new Matrix4().set( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
  36303. assert.ok( ! matrixEquals4$1( a, b ), "Passed!" );
  36304. b.getInverse( a, false );
  36305. assert.ok( matrixEquals4$1( b, new Matrix4() ), "Passed!" );
  36306. try {
  36307. b.getInverse( c, true );
  36308. assert.ok( false, "Passed!" ); // should never get here.
  36309. } catch ( err ) {
  36310. assert.ok( true, "Passed!" );
  36311. }
  36312. var testMatrices = [
  36313. new Matrix4().makeRotationX( 0.3 ),
  36314. new Matrix4().makeRotationX( - 0.3 ),
  36315. new Matrix4().makeRotationY( 0.3 ),
  36316. new Matrix4().makeRotationY( - 0.3 ),
  36317. new Matrix4().makeRotationZ( 0.3 ),
  36318. new Matrix4().makeRotationZ( - 0.3 ),
  36319. new Matrix4().makeScale( 1, 2, 3 ),
  36320. new Matrix4().makeScale( 1 / 8, 1 / 2, 1 / 3 ),
  36321. new Matrix4().makePerspective( - 1, 1, 1, - 1, 1, 1000 ),
  36322. new Matrix4().makePerspective( - 16, 16, 9, - 9, 0.1, 10000 ),
  36323. new Matrix4().makeTranslation( 1, 2, 3 )
  36324. ];
  36325. for ( var i = 0, il = testMatrices.length; i < il; i ++ ) {
  36326. var m = testMatrices[ i ];
  36327. var mInverse = new Matrix4().getInverse( m );
  36328. var mSelfInverse = m.clone();
  36329. mSelfInverse.getInverse( mSelfInverse );
  36330. // self-inverse should the same as inverse
  36331. assert.ok( matrixEquals4$1( mSelfInverse, mInverse ), "Passed!" );
  36332. // the determinant of the inverse should be the reciprocal
  36333. assert.ok( Math.abs( m.determinant() * mInverse.determinant() - 1 ) < 0.0001, "Passed!" );
  36334. var mProduct = new Matrix4().multiplyMatrices( m, mInverse );
  36335. // the determinant of the identity matrix is 1
  36336. assert.ok( Math.abs( mProduct.determinant() - 1 ) < 0.0001, "Passed!" );
  36337. assert.ok( matrixEquals4$1( mProduct, identity ), "Passed!" );
  36338. }
  36339. } );
  36340. QUnit.test( "scale", ( assert ) => {
  36341. assert.ok( false, "everything's gonna be alright" );
  36342. } );
  36343. QUnit.test( "getMaxScaleOnAxis", ( assert ) => {
  36344. var a = new Matrix4().set( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 );
  36345. var expected = Math.sqrt( 3 * 3 + 7 * 7 + 11 * 11 );
  36346. assert.ok( Math.abs( a.getMaxScaleOnAxis() - expected ) <= eps, "Check result" );
  36347. } );
  36348. QUnit.test( "makeTranslation", ( assert ) => {
  36349. assert.ok( false, "everything's gonna be alright" );
  36350. } );
  36351. QUnit.test( "makeRotationX", ( assert ) => {
  36352. assert.ok( false, "everything's gonna be alright" );
  36353. } );
  36354. QUnit.test( "makeRotationY", ( assert ) => {
  36355. assert.ok( false, "everything's gonna be alright" );
  36356. } );
  36357. QUnit.test( "makeRotationZ", ( assert ) => {
  36358. assert.ok( false, "everything's gonna be alright" );
  36359. } );
  36360. QUnit.test( "makeRotationAxis", ( assert ) => {
  36361. var axis = new Vector3( 1.5, 0.0, 1.0 ).normalize();
  36362. var radians = _Math.degToRad( 45 );
  36363. var a = new Matrix4().makeRotationAxis( axis, radians );
  36364. var expected = new Matrix4().set(
  36365. 0.9098790095958609, - 0.39223227027636803, 0.13518148560620882, 0,
  36366. 0.39223227027636803, 0.7071067811865476, - 0.588348405414552, 0,
  36367. 0.13518148560620882, 0.588348405414552, 0.7972277715906868, 0,
  36368. 0, 0, 0, 1
  36369. );
  36370. assert.ok( matrixEquals4$1( a, expected ), "Check numeric result" );
  36371. } );
  36372. QUnit.test( "makeScale", ( assert ) => {
  36373. assert.ok( false, "everything's gonna be alright" );
  36374. } );
  36375. QUnit.test( "makeShear", ( assert ) => {
  36376. assert.ok( false, "everything's gonna be alright" );
  36377. } );
  36378. QUnit.test( "compose/decompose", ( assert ) => {
  36379. var tValues = [
  36380. new Vector3(),
  36381. new Vector3( 3, 0, 0 ),
  36382. new Vector3( 0, 4, 0 ),
  36383. new Vector3( 0, 0, 5 ),
  36384. new Vector3( - 6, 0, 0 ),
  36385. new Vector3( 0, - 7, 0 ),
  36386. new Vector3( 0, 0, - 8 ),
  36387. new Vector3( - 2, 5, - 9 ),
  36388. new Vector3( - 2, - 5, - 9 )
  36389. ];
  36390. var sValues = [
  36391. new Vector3( 1, 1, 1 ),
  36392. new Vector3( 2, 2, 2 ),
  36393. new Vector3( 1, - 1, 1 ),
  36394. new Vector3( - 1, 1, 1 ),
  36395. new Vector3( 1, 1, - 1 ),
  36396. new Vector3( 2, - 2, 1 ),
  36397. new Vector3( - 1, 2, - 2 ),
  36398. new Vector3( - 1, - 1, - 1 ),
  36399. new Vector3( - 2, - 2, - 2 )
  36400. ];
  36401. var rValues = [
  36402. new Quaternion(),
  36403. new Quaternion().setFromEuler( new Euler( 1, 1, 0 ) ),
  36404. new Quaternion().setFromEuler( new Euler( 1, - 1, 1 ) ),
  36405. new Quaternion( 0, 0.9238795292366128, 0, 0.38268342717215614 )
  36406. ];
  36407. for ( var ti = 0; ti < tValues.length; ti ++ ) {
  36408. for ( var si = 0; si < sValues.length; si ++ ) {
  36409. for ( var ri = 0; ri < rValues.length; ri ++ ) {
  36410. var t = tValues[ ti ];
  36411. var s = sValues[ si ];
  36412. var r = rValues[ ri ];
  36413. var m = new Matrix4().compose( t, r, s );
  36414. var t2 = new Vector3();
  36415. var r2 = new Quaternion();
  36416. var s2 = new Vector3();
  36417. m.decompose( t2, r2, s2 );
  36418. var m2 = new Matrix4().compose( t2, r2, s2 );
  36419. /*
  36420. // debug code
  36421. var matrixIsSame = matrixEquals4( m, m2 );
  36422. if ( ! matrixIsSame ) {
  36423. console.log( t, s, r );
  36424. console.log( t2, s2, r2 );
  36425. console.log( m, m2 );
  36426. }
  36427. */
  36428. assert.ok( matrixEquals4$1( m, m2 ), "Passed!" );
  36429. }
  36430. }
  36431. }
  36432. } );
  36433. QUnit.test( "makePerspective", ( assert ) => {
  36434. assert.ok( false, "everything's gonna be alright" );
  36435. } );
  36436. QUnit.test( "makeOrthographic", ( assert ) => {
  36437. var a = new Matrix4().makeOrthographic( - 1, 1, - 1, 1, 1, 100 );
  36438. var expected = new Matrix4().set(
  36439. 1, 0, 0, 0,
  36440. 0, - 1, 0, 0,
  36441. 0, 0, - 2 / 99, - 101 / 99,
  36442. 0, 0, 0, 1
  36443. );
  36444. assert.ok( matrixEquals4$1( a, expected ), "Check result" );
  36445. } );
  36446. QUnit.test( "equals", ( assert ) => {
  36447. var a = new Matrix4().set( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 );
  36448. var b = new Matrix4().set( 0, - 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 );
  36449. assert.notOk( a.equals( b ), "Check that a does not equal b" );
  36450. assert.notOk( b.equals( a ), "Check that b does not equal a" );
  36451. a.copy( b );
  36452. assert.ok( a.equals( b ), "Check that a equals b after copy()" );
  36453. assert.ok( b.equals( a ), "Check that b equals a after copy()" );
  36454. } );
  36455. QUnit.test( "fromArray", ( assert ) => {
  36456. assert.ok( false, "everything's gonna be alright" );
  36457. } );
  36458. QUnit.test( "toArray", ( assert ) => {
  36459. var a = new Matrix4().set( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 );
  36460. var noOffset = [ 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ];
  36461. var withOffset = [ undefined, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 ];
  36462. var array = a.toArray();
  36463. assert.deepEqual( array, noOffset, "No array, no offset" );
  36464. var array = [];
  36465. a.toArray( array );
  36466. assert.deepEqual( array, noOffset, "With array, no offset" );
  36467. var array = [];
  36468. a.toArray( array, 1 );
  36469. assert.deepEqual( array, withOffset, "With array, with offset" );
  36470. } );
  36471. } );
  36472. } );
  36473. /**
  36474. * @author bhouston / http://exocortex.com
  36475. * @author TristanVALCKE / https://github.com/Itee
  36476. */
  36477. /* global QUnit */
  36478. function comparePlane( a, b, threshold ) {
  36479. threshold = threshold || 0.0001;
  36480. return ( a.normal.distanceTo( b.normal ) < threshold &&
  36481. Math.abs( a.constant - b.constant ) < threshold );
  36482. }
  36483. QUnit.module( 'Maths', () => {
  36484. QUnit.module.todo( 'Plane', () => {
  36485. // INSTANCING
  36486. QUnit.test( "Instancing", ( assert ) => {
  36487. var a = new Plane();
  36488. assert.ok( a.normal.x == 1, "Passed!" );
  36489. assert.ok( a.normal.y == 0, "Passed!" );
  36490. assert.ok( a.normal.z == 0, "Passed!" );
  36491. assert.ok( a.constant == 0, "Passed!" );
  36492. var a = new Plane( one3.clone(), 0 );
  36493. assert.ok( a.normal.x == 1, "Passed!" );
  36494. assert.ok( a.normal.y == 1, "Passed!" );
  36495. assert.ok( a.normal.z == 1, "Passed!" );
  36496. assert.ok( a.constant == 0, "Passed!" );
  36497. var a = new Plane( one3.clone(), 1 );
  36498. assert.ok( a.normal.x == 1, "Passed!" );
  36499. assert.ok( a.normal.y == 1, "Passed!" );
  36500. assert.ok( a.normal.z == 1, "Passed!" );
  36501. assert.ok( a.constant == 1, "Passed!" );
  36502. } );
  36503. // PUBLIC STUFF
  36504. QUnit.test( "isPlane", ( assert ) => {
  36505. assert.ok( false, "everything's gonna be alright" );
  36506. } );
  36507. QUnit.test( "set", ( assert ) => {
  36508. var a = new Plane();
  36509. assert.ok( a.normal.x == 1, "Passed!" );
  36510. assert.ok( a.normal.y == 0, "Passed!" );
  36511. assert.ok( a.normal.z == 0, "Passed!" );
  36512. assert.ok( a.constant == 0, "Passed!" );
  36513. var b = a.clone().set( new Vector3( x, y, z ), w );
  36514. assert.ok( b.normal.x == x, "Passed!" );
  36515. assert.ok( b.normal.y == y, "Passed!" );
  36516. assert.ok( b.normal.z == z, "Passed!" );
  36517. assert.ok( b.constant == w, "Passed!" );
  36518. } );
  36519. QUnit.test( "setComponents", ( assert ) => {
  36520. var a = new Plane();
  36521. assert.ok( a.normal.x == 1, "Passed!" );
  36522. assert.ok( a.normal.y == 0, "Passed!" );
  36523. assert.ok( a.normal.z == 0, "Passed!" );
  36524. assert.ok( a.constant == 0, "Passed!" );
  36525. var b = a.clone().setComponents( x, y, z, w );
  36526. assert.ok( b.normal.x == x, "Passed!" );
  36527. assert.ok( b.normal.y == y, "Passed!" );
  36528. assert.ok( b.normal.z == z, "Passed!" );
  36529. assert.ok( b.constant == w, "Passed!" );
  36530. } );
  36531. QUnit.test( "setFromNormalAndCoplanarPoint", ( assert ) => {
  36532. var normal = one3.clone().normalize();
  36533. var a = new Plane().setFromNormalAndCoplanarPoint( normal, zero3 );
  36534. assert.ok( a.normal.equals( normal ), "Passed!" );
  36535. assert.ok( a.constant == 0, "Passed!" );
  36536. } );
  36537. QUnit.test( "setFromCoplanarPoints", ( assert ) => {
  36538. var a = new Plane();
  36539. var v1 = new Vector3( 2.0, 0.5, 0.25 );
  36540. var v2 = new Vector3( 2.0, - 0.5, 1.25 );
  36541. var v3 = new Vector3( 2.0, - 3.5, 2.2 );
  36542. var normal = new Vector3( 1, 0, 0 );
  36543. var constant = - 2;
  36544. a.setFromCoplanarPoints( v1, v2, v3 );
  36545. assert.ok( a.normal.equals( normal ), "Check normal" );
  36546. assert.strictEqual( a.constant, constant, "Check constant" );
  36547. } );
  36548. QUnit.test( "clone", ( assert ) => {
  36549. assert.ok( false, "everything's gonna be alright" );
  36550. } );
  36551. QUnit.test( "copy", ( assert ) => {
  36552. var a = new Plane( new Vector3( x, y, z ), w );
  36553. var b = new Plane().copy( a );
  36554. assert.ok( b.normal.x == x, "Passed!" );
  36555. assert.ok( b.normal.y == y, "Passed!" );
  36556. assert.ok( b.normal.z == z, "Passed!" );
  36557. assert.ok( b.constant == w, "Passed!" );
  36558. // ensure that it is a true copy
  36559. a.normal.x = 0;
  36560. a.normal.y = - 1;
  36561. a.normal.z = - 2;
  36562. a.constant = - 3;
  36563. assert.ok( b.normal.x == x, "Passed!" );
  36564. assert.ok( b.normal.y == y, "Passed!" );
  36565. assert.ok( b.normal.z == z, "Passed!" );
  36566. assert.ok( b.constant == w, "Passed!" );
  36567. } );
  36568. QUnit.test( "normalize", ( assert ) => {
  36569. var a = new Plane( new Vector3( 2, 0, 0 ), 2 );
  36570. a.normalize();
  36571. assert.ok( a.normal.length() == 1, "Passed!" );
  36572. assert.ok( a.normal.equals( new Vector3( 1, 0, 0 ) ), "Passed!" );
  36573. assert.ok( a.constant == 1, "Passed!" );
  36574. } );
  36575. QUnit.test( "negate/distanceToPoint", ( assert ) => {
  36576. var a = new Plane( new Vector3( 2, 0, 0 ), - 2 );
  36577. a.normalize();
  36578. assert.ok( a.distanceToPoint( new Vector3( 4, 0, 0 ) ) === 3, "Passed!" );
  36579. assert.ok( a.distanceToPoint( new Vector3( 1, 0, 0 ) ) === 0, "Passed!" );
  36580. a.negate();
  36581. assert.ok( a.distanceToPoint( new Vector3( 4, 0, 0 ) ) === - 3, "Passed!" );
  36582. assert.ok( a.distanceToPoint( new Vector3( 1, 0, 0 ) ) === 0, "Passed!" );
  36583. } );
  36584. QUnit.test( "distanceToPoint", ( assert ) => {
  36585. var a = new Plane( new Vector3( 2, 0, 0 ), - 2 );
  36586. a.normalize();
  36587. assert.ok( a.distanceToPoint( a.projectPoint( zero3.clone() ) ) === 0, "Passed!" );
  36588. assert.ok( a.distanceToPoint( new Vector3( 4, 0, 0 ) ) === 3, "Passed!" );
  36589. } );
  36590. QUnit.test( "distanceToSphere", ( assert ) => {
  36591. var a = new Plane( new Vector3( 1, 0, 0 ), 0 );
  36592. var b = new Sphere( new Vector3( 2, 0, 0 ), 1 );
  36593. assert.ok( a.distanceToSphere( b ) === 1, "Passed!" );
  36594. a.set( new Vector3( 1, 0, 0 ), 2 );
  36595. assert.ok( a.distanceToSphere( b ) === 3, "Passed!" );
  36596. a.set( new Vector3( 1, 0, 0 ), - 2 );
  36597. assert.ok( a.distanceToSphere( b ) === - 1, "Passed!" );
  36598. } );
  36599. QUnit.test( "projectPoint", ( assert ) => {
  36600. var a = new Plane( new Vector3( 1, 0, 0 ), 0 );
  36601. assert.ok( a.projectPoint( new Vector3( 10, 0, 0 ) ).equals( zero3 ), "Passed!" );
  36602. assert.ok( a.projectPoint( new Vector3( - 10, 0, 0 ) ).equals( zero3 ), "Passed!" );
  36603. var a = new Plane( new Vector3( 0, 1, 0 ), - 1 );
  36604. assert.ok( a.projectPoint( new Vector3( 0, 0, 0 ) ).equals( new Vector3( 0, 1, 0 ) ), "Passed!" );
  36605. assert.ok( a.projectPoint( new Vector3( 0, 1, 0 ) ).equals( new Vector3( 0, 1, 0 ) ), "Passed!" );
  36606. } );
  36607. QUnit.test( "isInterestionLine/intersectLine", ( assert ) => {
  36608. var a = new Plane( new Vector3( 1, 0, 0 ), 0 );
  36609. var l1 = new Line3( new Vector3( - 10, 0, 0 ), new Vector3( 10, 0, 0 ) );
  36610. assert.ok( a.intersectsLine( l1 ), "Passed!" );
  36611. assert.ok( a.intersectLine( l1 ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
  36612. var a = new Plane( new Vector3( 1, 0, 0 ), - 3 );
  36613. assert.ok( a.intersectsLine( l1 ), "Passed!" );
  36614. assert.ok( a.intersectLine( l1 ).equals( new Vector3( 3, 0, 0 ) ), "Passed!" );
  36615. var a = new Plane( new Vector3( 1, 0, 0 ), - 11 );
  36616. assert.ok( ! a.intersectsLine( l1 ), "Passed!" );
  36617. assert.ok( a.intersectLine( l1 ) === undefined, "Passed!" );
  36618. var a = new Plane( new Vector3( 1, 0, 0 ), 11 );
  36619. assert.ok( ! a.intersectsLine( l1 ), "Passed!" );
  36620. assert.ok( a.intersectLine( l1 ) === undefined, "Passed!" );
  36621. } );
  36622. QUnit.test( "intersectsBox", ( assert ) => {
  36623. assert.ok( false, "everything's gonna be alright" );
  36624. } );
  36625. QUnit.test( "intersectsSphere", ( assert ) => {
  36626. assert.ok( false, "everything's gonna be alright" );
  36627. } );
  36628. QUnit.test( "coplanarPoint", ( assert ) => {
  36629. var a = new Plane( new Vector3( 1, 0, 0 ), 0 );
  36630. assert.ok( a.distanceToPoint( a.coplanarPoint() ) === 0, "Passed!" );
  36631. var a = new Plane( new Vector3( 0, 1, 0 ), - 1 );
  36632. assert.ok( a.distanceToPoint( a.coplanarPoint() ) === 0, "Passed!" );
  36633. } );
  36634. QUnit.test( "applyMatrix4/translate", ( assert ) => {
  36635. var a = new Plane( new Vector3( 1, 0, 0 ), 0 );
  36636. var m = new Matrix4();
  36637. m.makeRotationZ( Math.PI * 0.5 );
  36638. assert.ok( comparePlane( a.clone().applyMatrix4( m ), new Plane( new Vector3( 0, 1, 0 ), 0 ) ), "Passed!" );
  36639. var a = new Plane( new Vector3( 0, 1, 0 ), - 1 );
  36640. assert.ok( comparePlane( a.clone().applyMatrix4( m ), new Plane( new Vector3( - 1, 0, 0 ), - 1 ) ), "Passed!" );
  36641. m.makeTranslation( 1, 1, 1 );
  36642. assert.ok( comparePlane( a.clone().applyMatrix4( m ), a.clone().translate( new Vector3( 1, 1, 1 ) ) ), "Passed!" );
  36643. } );
  36644. QUnit.test( "equals", ( assert ) => {
  36645. var a = new Plane( new Vector3( 1, 0, 0 ), 0 );
  36646. var b = new Plane( new Vector3( 1, 0, 0 ), 1 );
  36647. var c = new Plane( new Vector3( 0, 1, 0 ), 0 );
  36648. assert.ok( a.normal.equals( b.normal ), "Normals: equal" );
  36649. assert.notOk( a.normal.equals( c.normal ), "Normals: not equal" );
  36650. assert.notStrictEqual( a.constant, b.constant, "Constants: not equal" );
  36651. assert.strictEqual( a.constant, c.constant, "Constants: equal" );
  36652. assert.notOk( a.equals( b ), "Planes: not equal" );
  36653. assert.notOk( a.equals( c ), "Planes: not equal" );
  36654. a.copy( b );
  36655. assert.ok( a.normal.equals( b.normal ), "Normals after copy(): equal" );
  36656. assert.strictEqual( a.constant, b.constant, "Constants after copy(): equal" );
  36657. assert.ok( a.equals( b ), "Planes after copy(): equal" );
  36658. } );
  36659. } );
  36660. } );
  36661. QUnit.module( "Plane" );
  36662. /**
  36663. * @author bhouston / http://exocortex.com
  36664. * @author tschw
  36665. * @author TristanVALCKE / https://github.com/Itee
  36666. */
  36667. /* global QUnit */
  36668. const orders = [ 'XYZ', 'YXZ', 'ZXY', 'ZYX', 'YZX', 'XZY' ];
  36669. const eulerAngles = new Euler( 0.1, - 0.3, 0.25 );
  36670. function qSub( a, b ) {
  36671. var result = new Quaternion();
  36672. result.copy( a );
  36673. result.x -= b.x;
  36674. result.y -= b.y;
  36675. result.z -= b.z;
  36676. result.w -= b.w;
  36677. return result;
  36678. }
  36679. function doSlerpObject( aArr, bArr, t ) {
  36680. var a = new Quaternion().fromArray( aArr ),
  36681. b = new Quaternion().fromArray( bArr ),
  36682. c = new Quaternion().fromArray( aArr );
  36683. c.slerp( b, t );
  36684. return {
  36685. equals: function ( x$$1, y$$1, z$$1, w$$1, maxError ) {
  36686. if ( maxError === undefined ) maxError = Number.EPSILON;
  36687. return Math.abs( x$$1 - c.x ) <= maxError &&
  36688. Math.abs( y$$1 - c.y ) <= maxError &&
  36689. Math.abs( z$$1 - c.z ) <= maxError &&
  36690. Math.abs( w$$1 - c.w ) <= maxError;
  36691. },
  36692. length: c.length(),
  36693. dotA: c.dot( a ),
  36694. dotB: c.dot( b )
  36695. };
  36696. }
  36697. function doSlerpArray( a, b, t ) {
  36698. var result = [ 0, 0, 0, 0 ];
  36699. Quaternion.slerpFlat( result, 0, a, 0, b, 0, t );
  36700. function arrDot( a, b ) {
  36701. return a[ 0 ] * b[ 0 ] + a[ 1 ] * b[ 1 ] +
  36702. a[ 2 ] * b[ 2 ] + a[ 3 ] * b[ 3 ];
  36703. }
  36704. return {
  36705. equals: function ( x$$1, y$$1, z$$1, w$$1, maxError ) {
  36706. if ( maxError === undefined ) maxError = Number.EPSILON;
  36707. return Math.abs( x$$1 - result[ 0 ] ) <= maxError &&
  36708. Math.abs( y$$1 - result[ 1 ] ) <= maxError &&
  36709. Math.abs( z$$1 - result[ 2 ] ) <= maxError &&
  36710. Math.abs( w$$1 - result[ 3 ] ) <= maxError;
  36711. },
  36712. length: Math.sqrt( arrDot( result, result ) ),
  36713. dotA: arrDot( result, a ),
  36714. dotB: arrDot( result, b )
  36715. };
  36716. }
  36717. function slerpTestSkeleton( doSlerp, maxError, assert ) {
  36718. var a, b, result;
  36719. a = [
  36720. 0.6753410084407496,
  36721. 0.4087830051091744,
  36722. 0.32856700410659473,
  36723. 0.5185120064806223
  36724. ];
  36725. b = [
  36726. 0.6602792107657797,
  36727. 0.43647413932562285,
  36728. 0.35119011210236006,
  36729. 0.5001871596632682
  36730. ];
  36731. var maxNormError = 0;
  36732. function isNormal( result ) {
  36733. var normError = Math.abs( 1 - result.length );
  36734. maxNormError = Math.max( maxNormError, normError );
  36735. return normError <= maxError;
  36736. }
  36737. result = doSlerp( a, b, 0 );
  36738. assert.ok( result.equals(
  36739. a[ 0 ], a[ 1 ], a[ 2 ], a[ 3 ], 0 ), "Exactly A @ t = 0" );
  36740. result = doSlerp( a, b, 1 );
  36741. assert.ok( result.equals(
  36742. b[ 0 ], b[ 1 ], b[ 2 ], b[ 3 ], 0 ), "Exactly B @ t = 1" );
  36743. result = doSlerp( a, b, 0.5 );
  36744. assert.ok( Math.abs( result.dotA - result.dotB ) <= Number.EPSILON, "Symmetry at 0.5" );
  36745. assert.ok( isNormal( result ), "Approximately normal (at 0.5)" );
  36746. result = doSlerp( a, b, 0.25 );
  36747. assert.ok( result.dotA > result.dotB, "Interpolating at 0.25" );
  36748. assert.ok( isNormal( result ), "Approximately normal (at 0.25)" );
  36749. result = doSlerp( a, b, 0.75 );
  36750. assert.ok( result.dotA < result.dotB, "Interpolating at 0.75" );
  36751. assert.ok( isNormal( result ), "Approximately normal (at 0.75)" );
  36752. var D = Math.SQRT1_2;
  36753. result = doSlerp( [ 1, 0, 0, 0 ], [ 0, 0, 1, 0 ], 0.5 );
  36754. assert.ok( result.equals( D, 0, D, 0 ), "X/Z diagonal from axes" );
  36755. assert.ok( isNormal( result ), "Approximately normal (X/Z diagonal)" );
  36756. result = doSlerp( [ 0, D, 0, D ], [ 0, - D, 0, D ], 0.5 );
  36757. assert.ok( result.equals( 0, 0, 0, 1 ), "W-Unit from diagonals" );
  36758. assert.ok( isNormal( result ), "Approximately normal (W-Unit)" );
  36759. }
  36760. QUnit.module( 'Maths', () => {
  36761. QUnit.module.todo( 'Quaternion', () => {
  36762. // INSTANCING
  36763. QUnit.test( "Instancing", ( assert ) => {
  36764. var a = new Quaternion();
  36765. assert.ok( a.x == 0, "Passed!" );
  36766. assert.ok( a.y == 0, "Passed!" );
  36767. assert.ok( a.z == 0, "Passed!" );
  36768. assert.ok( a.w == 1, "Passed!" );
  36769. var a = new Quaternion( x, y, z, w );
  36770. assert.ok( a.x === x, "Passed!" );
  36771. assert.ok( a.y === y, "Passed!" );
  36772. assert.ok( a.z === z, "Passed!" );
  36773. assert.ok( a.w === w, "Passed!" );
  36774. } );
  36775. // STATIC STUFF
  36776. QUnit.test( "slerp", ( assert ) => {
  36777. slerpTestSkeleton( doSlerpObject, Number.EPSILON, assert );
  36778. } );
  36779. QUnit.test( "slerpFlat", ( assert ) => {
  36780. slerpTestSkeleton( doSlerpArray, Number.EPSILON, assert );
  36781. } );
  36782. // PROPERTIES
  36783. QUnit.test( "properties", ( assert ) => {
  36784. assert.expect( 8 );
  36785. var a = new Quaternion();
  36786. a.onChange( function () {
  36787. assert.ok( true, "onChange called" );
  36788. } );
  36789. a.x = x;
  36790. a.y = y;
  36791. a.z = z;
  36792. a.w = w;
  36793. assert.strictEqual( a.x, x, "Check x" );
  36794. assert.strictEqual( a.y, y, "Check y" );
  36795. assert.strictEqual( a.z, z, "Check z" );
  36796. assert.strictEqual( a.w, w, "Check w" );
  36797. } );
  36798. QUnit.test( "x", ( assert ) => {
  36799. assert.ok( false, "everything's gonna be alright" );
  36800. } );
  36801. QUnit.test( "y", ( assert ) => {
  36802. assert.ok( false, "everything's gonna be alright" );
  36803. } );
  36804. QUnit.test( "z", ( assert ) => {
  36805. assert.ok( false, "everything's gonna be alright" );
  36806. } );
  36807. QUnit.test( "w", ( assert ) => {
  36808. assert.ok( false, "everything's gonna be alright" );
  36809. } );
  36810. // PUBLIC STUFF
  36811. QUnit.test( "set", ( assert ) => {
  36812. var a = new Quaternion();
  36813. assert.ok( a.x == 0, "Passed!" );
  36814. assert.ok( a.y == 0, "Passed!" );
  36815. assert.ok( a.z == 0, "Passed!" );
  36816. assert.ok( a.w == 1, "Passed!" );
  36817. a.set( x, y, z, w );
  36818. assert.ok( a.x == x, "Passed!" );
  36819. assert.ok( a.y == y, "Passed!" );
  36820. assert.ok( a.z === z, "Passed!" );
  36821. assert.ok( a.w === w, "Passed!" );
  36822. } );
  36823. QUnit.test( "clone", ( assert ) => {
  36824. assert.ok( false, "everything's gonna be alright" );
  36825. } );
  36826. QUnit.test( "copy", ( assert ) => {
  36827. var a = new Quaternion( x, y, z, w );
  36828. var b = new Quaternion().copy( a );
  36829. assert.ok( b.x == x, "Passed!" );
  36830. assert.ok( b.y == y, "Passed!" );
  36831. assert.ok( b.z == z, "Passed!" );
  36832. assert.ok( b.w == w, "Passed!" );
  36833. // ensure that it is a true copy
  36834. a.x = 0;
  36835. a.y = - 1;
  36836. a.z = 0;
  36837. a.w = - 1;
  36838. assert.ok( b.x == x, "Passed!" );
  36839. assert.ok( b.y == y, "Passed!" );
  36840. } );
  36841. QUnit.test( "setFromEuler/setFromQuaternion", ( assert ) => {
  36842. var angles = [ new Vector3( 1, 0, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ) ];
  36843. // ensure euler conversion to/from Quaternion matches.
  36844. for ( var i = 0; i < orders.length; i ++ ) {
  36845. for ( var j = 0; j < angles.length; j ++ ) {
  36846. var eulers2 = new Euler().setFromQuaternion( new Quaternion().setFromEuler( new Euler( angles[ j ].x, angles[ j ].y, angles[ j ].z, orders[ i ] ) ), orders[ i ] );
  36847. var newAngle = new Vector3( eulers2.x, eulers2.y, eulers2.z );
  36848. assert.ok( newAngle.distanceTo( angles[ j ] ) < 0.001, "Passed!" );
  36849. }
  36850. }
  36851. } );
  36852. QUnit.test( "setFromAxisAngle", ( assert ) => {
  36853. // TODO: find cases to validate.
  36854. // assert.ok( true, "Passed!" );
  36855. var zero = new Quaternion();
  36856. var a = new Quaternion().setFromAxisAngle( new Vector3( 1, 0, 0 ), 0 );
  36857. assert.ok( a.equals( zero ), "Passed!" );
  36858. a = new Quaternion().setFromAxisAngle( new Vector3( 0, 1, 0 ), 0 );
  36859. assert.ok( a.equals( zero ), "Passed!" );
  36860. a = new Quaternion().setFromAxisAngle( new Vector3( 0, 0, 1 ), 0 );
  36861. assert.ok( a.equals( zero ), "Passed!" );
  36862. var b1 = new Quaternion().setFromAxisAngle( new Vector3( 1, 0, 0 ), Math.PI );
  36863. assert.ok( ! a.equals( b1 ), "Passed!" );
  36864. var b2 = new Quaternion().setFromAxisAngle( new Vector3( 1, 0, 0 ), - Math.PI );
  36865. assert.ok( ! a.equals( b2 ), "Passed!" );
  36866. b1.multiply( b2 );
  36867. assert.ok( a.equals( b1 ), "Passed!" );
  36868. } );
  36869. QUnit.test( "setFromEuler/setFromRotationMatrix", ( assert ) => {
  36870. // ensure euler conversion for Quaternion matches that of Matrix4
  36871. for ( var i = 0; i < orders.length; i ++ ) {
  36872. var q = new Quaternion().setFromEuler( eulerAngles, orders[ i ] );
  36873. var m = new Matrix4().makeRotationFromEuler( eulerAngles, orders[ i ] );
  36874. var q2 = new Quaternion().setFromRotationMatrix( m );
  36875. assert.ok( qSub( q, q2 ).length() < 0.001, "Passed!" );
  36876. }
  36877. } );
  36878. QUnit.test( "setFromRotationMatrix", ( assert ) => {
  36879. // contrived examples purely to please the god of code coverage...
  36880. // match conditions in various 'else [if]' blocks
  36881. var a = new Quaternion();
  36882. var q = new Quaternion( - 9, - 2, 3, - 4 ).normalize();
  36883. var m = new Matrix4().makeRotationFromQuaternion( q );
  36884. var expected = new Vector4( 0.8581163303210332, 0.19069251784911848, - 0.2860387767736777, 0.38138503569823695 );
  36885. a.setFromRotationMatrix( m );
  36886. assert.ok( Math.abs( a.x - expected.x ) <= eps, "m11 > m22 && m11 > m33: check x" );
  36887. assert.ok( Math.abs( a.y - expected.y ) <= eps, "m11 > m22 && m11 > m33: check y" );
  36888. assert.ok( Math.abs( a.z - expected.z ) <= eps, "m11 > m22 && m11 > m33: check z" );
  36889. assert.ok( Math.abs( a.w - expected.w ) <= eps, "m11 > m22 && m11 > m33: check w" );
  36890. var q = new Quaternion( - 1, - 2, 1, - 1 ).normalize();
  36891. m.makeRotationFromQuaternion( q );
  36892. var expected = new Vector4( 0.37796447300922714, 0.7559289460184544, - 0.37796447300922714, 0.37796447300922714 );
  36893. a.setFromRotationMatrix( m );
  36894. assert.ok( Math.abs( a.x - expected.x ) <= eps, "m22 > m33: check x" );
  36895. assert.ok( Math.abs( a.y - expected.y ) <= eps, "m22 > m33: check y" );
  36896. assert.ok( Math.abs( a.z - expected.z ) <= eps, "m22 > m33: check z" );
  36897. assert.ok( Math.abs( a.w - expected.w ) <= eps, "m22 > m33: check w" );
  36898. } );
  36899. QUnit.test( "setFromUnitVectors", ( assert ) => {
  36900. var a = new Quaternion();
  36901. var b = new Vector3( 1, 0, 0 );
  36902. var c = new Vector3( 0, 1, 0 );
  36903. var expected = new Quaternion( 0, 0, Math.sqrt( 2 ) / 2, Math.sqrt( 2 ) / 2 );
  36904. a.setFromUnitVectors( b, c );
  36905. assert.ok( Math.abs( a.x - expected.x ) <= eps, "Check x" );
  36906. assert.ok( Math.abs( a.y - expected.y ) <= eps, "Check y" );
  36907. assert.ok( Math.abs( a.z - expected.z ) <= eps, "Check z" );
  36908. assert.ok( Math.abs( a.w - expected.w ) <= eps, "Check w" );
  36909. } );
  36910. QUnit.test( "inverse/conjugate", ( assert ) => {
  36911. var a = new Quaternion( x, y, z, w );
  36912. // TODO: add better validation here.
  36913. var b = a.clone().conjugate();
  36914. assert.ok( a.x == - b.x, "Passed!" );
  36915. assert.ok( a.y == - b.y, "Passed!" );
  36916. assert.ok( a.z == - b.z, "Passed!" );
  36917. assert.ok( a.w == b.w, "Passed!" );
  36918. } );
  36919. QUnit.test( "inverse", ( assert ) => {
  36920. assert.expect( 6 );
  36921. var a = new Quaternion( x, y, z, w );
  36922. var inverted = new Quaternion( - 0.2721655269759087, - 0.408248290463863, - 0.5443310539518174, 0.6804138174397717 );
  36923. a.onChange( function () {
  36924. assert.ok( true, "onChange called" );
  36925. } );
  36926. a.inverse();
  36927. assert.ok( Math.abs( a.x - inverted.x ) <= eps, "Check x" );
  36928. assert.ok( Math.abs( a.y - inverted.y ) <= eps, "Check y" );
  36929. assert.ok( Math.abs( a.z - inverted.z ) <= eps, "Check z" );
  36930. assert.ok( Math.abs( a.w - inverted.w ) <= eps, "Check w" );
  36931. } );
  36932. QUnit.test( "dot", ( assert ) => {
  36933. assert.ok( false, "everything's gonna be alright" );
  36934. } );
  36935. QUnit.test( "normalize/length/lengthSq", ( assert ) => {
  36936. var a = new Quaternion( x, y, z, w );
  36937. var b = new Quaternion( - x, - y, - z, - w );
  36938. assert.ok( a.length() != 1, "Passed!" );
  36939. assert.ok( a.lengthSq() != 1, "Passed!" );
  36940. a.normalize();
  36941. assert.ok( a.length() == 1, "Passed!" );
  36942. assert.ok( a.lengthSq() == 1, "Passed!" );
  36943. a.set( 0, 0, 0, 0 );
  36944. assert.ok( a.lengthSq() == 0, "Passed!" );
  36945. assert.ok( a.length() == 0, "Passed!" );
  36946. a.normalize();
  36947. assert.ok( a.lengthSq() == 1, "Passed!" );
  36948. assert.ok( a.length() == 1, "Passed!" );
  36949. } );
  36950. QUnit.test( "multiplyQuaternions/multiply", ( assert ) => {
  36951. var angles = [ new Euler( 1, 0, 0 ), new Euler( 0, 1, 0 ), new Euler( 0, 0, 1 ) ];
  36952. var q1 = new Quaternion().setFromEuler( angles[ 0 ], "XYZ" );
  36953. var q2 = new Quaternion().setFromEuler( angles[ 1 ], "XYZ" );
  36954. var q3 = new Quaternion().setFromEuler( angles[ 2 ], "XYZ" );
  36955. var q = new Quaternion().multiplyQuaternions( q1, q2 ).multiply( q3 );
  36956. var m1 = new Matrix4().makeRotationFromEuler( angles[ 0 ], "XYZ" );
  36957. var m2 = new Matrix4().makeRotationFromEuler( angles[ 1 ], "XYZ" );
  36958. var m3 = new Matrix4().makeRotationFromEuler( angles[ 2 ], "XYZ" );
  36959. var m = new Matrix4().multiplyMatrices( m1, m2 ).multiply( m3 );
  36960. var qFromM = new Quaternion().setFromRotationMatrix( m );
  36961. assert.ok( qSub( q, qFromM ).length() < 0.001, "Passed!" );
  36962. } );
  36963. QUnit.test( "premultiply", ( assert ) => {
  36964. var a = new Quaternion( x, y, z, w );
  36965. var b = new Quaternion( 2 * x, - y, - 2 * z, w );
  36966. var expected = new Quaternion( 42, - 32, - 2, 58 );
  36967. a.premultiply( b );
  36968. assert.ok( Math.abs( a.x - expected.x ) <= eps, "Check x" );
  36969. assert.ok( Math.abs( a.y - expected.y ) <= eps, "Check y" );
  36970. assert.ok( Math.abs( a.z - expected.z ) <= eps, "Check z" );
  36971. assert.ok( Math.abs( a.w - expected.w ) <= eps, "Check w" );
  36972. } );
  36973. QUnit.test( "slerp", ( assert ) => {
  36974. assert.ok( false, "everything's gonna be alright" );
  36975. } );
  36976. QUnit.test( "equals", ( assert ) => {
  36977. var a = new Quaternion( x, y, z, w );
  36978. var b = new Quaternion( - x, - y, - z, - w );
  36979. assert.ok( a.x != b.x, "Passed!" );
  36980. assert.ok( a.y != b.y, "Passed!" );
  36981. assert.ok( ! a.equals( b ), "Passed!" );
  36982. assert.ok( ! b.equals( a ), "Passed!" );
  36983. a.copy( b );
  36984. assert.ok( a.x == b.x, "Passed!" );
  36985. assert.ok( a.y == b.y, "Passed!" );
  36986. assert.ok( a.equals( b ), "Passed!" );
  36987. assert.ok( b.equals( a ), "Passed!" );
  36988. } );
  36989. QUnit.test( "fromArray", ( assert ) => {
  36990. assert.ok( false, "everything's gonna be alright" );
  36991. } );
  36992. QUnit.test( "toArray", ( assert ) => {
  36993. var a = new Quaternion( x, y, z, w );
  36994. var array = a.toArray();
  36995. assert.strictEqual( array[ 0 ], x, "No array, no offset: check x" );
  36996. assert.strictEqual( array[ 1 ], y, "No array, no offset: check y" );
  36997. assert.strictEqual( array[ 2 ], z, "No array, no offset: check z" );
  36998. assert.strictEqual( array[ 3 ], w, "No array, no offset: check w" );
  36999. var array = [];
  37000. a.toArray( array );
  37001. assert.strictEqual( array[ 0 ], x, "With array, no offset: check x" );
  37002. assert.strictEqual( array[ 1 ], y, "With array, no offset: check y" );
  37003. assert.strictEqual( array[ 2 ], z, "With array, no offset: check z" );
  37004. assert.strictEqual( array[ 3 ], w, "With array, no offset: check w" );
  37005. var array = [];
  37006. a.toArray( array, 1 );
  37007. assert.strictEqual( array[ 0 ], undefined, "With array and offset: check [0]" );
  37008. assert.strictEqual( array[ 1 ], x, "With array and offset: check x" );
  37009. assert.strictEqual( array[ 2 ], y, "With array and offset: check y" );
  37010. assert.strictEqual( array[ 3 ], z, "With array and offset: check z" );
  37011. assert.strictEqual( array[ 4 ], w, "With array and offset: check w" );
  37012. } );
  37013. QUnit.test( "onChange", ( assert ) => {
  37014. assert.ok( false, "everything's gonna be alright" );
  37015. } );
  37016. QUnit.test( "onChangeCallback", ( assert ) => {
  37017. assert.ok( false, "everything's gonna be alright" );
  37018. } );
  37019. // OTHERS
  37020. QUnit.test( "multiplyVector3", ( assert ) => {
  37021. var angles = [ new Euler( 1, 0, 0 ), new Euler( 0, 1, 0 ), new Euler( 0, 0, 1 ) ];
  37022. // ensure euler conversion for Quaternion matches that of Matrix4
  37023. for ( var i = 0; i < orders.length; i ++ ) {
  37024. for ( var j = 0; j < angles.length; j ++ ) {
  37025. var q = new Quaternion().setFromEuler( angles[ j ], orders[ i ] );
  37026. var m = new Matrix4().makeRotationFromEuler( angles[ j ], orders[ i ] );
  37027. var v0 = new Vector3( 1, 0, 0 );
  37028. var qv = v0.clone().applyQuaternion( q );
  37029. var mv = v0.clone().applyMatrix4( m );
  37030. assert.ok( qv.distanceTo( mv ) < 0.001, "Passed!" );
  37031. }
  37032. }
  37033. } );
  37034. } );
  37035. } );
  37036. QUnit.module( "Quaternion" );
  37037. /**
  37038. * @author bhouston / http://exocortex.com
  37039. * @author TristanVALCKE / https://github.com/Itee
  37040. */
  37041. /* global QUnit */
  37042. QUnit.module( 'Maths', () => {
  37043. QUnit.module.todo( 'Ray', () => {
  37044. // INSTANCING
  37045. QUnit.test( "Instancing", ( assert ) => {
  37046. var a = new Ray();
  37047. assert.ok( a.origin.equals( zero3 ), "Passed!" );
  37048. assert.ok( a.direction.equals( zero3 ), "Passed!" );
  37049. var a = new Ray( two3.clone(), one3.clone() );
  37050. assert.ok( a.origin.equals( two3 ), "Passed!" );
  37051. assert.ok( a.direction.equals( one3 ), "Passed!" );
  37052. } );
  37053. // PUBLIC STUFF
  37054. QUnit.test( "isRay", ( assert ) => {
  37055. assert.ok( false, "everything's gonna be alright" );
  37056. } );
  37057. QUnit.test( "set", ( assert ) => {
  37058. var a = new Ray();
  37059. a.set( one3, one3 );
  37060. assert.ok( a.origin.equals( one3 ), "Passed!" );
  37061. assert.ok( a.direction.equals( one3 ), "Passed!" );
  37062. } );
  37063. QUnit.test( "recast/clone", ( assert ) => {
  37064. var a = new Ray( one3.clone(), new Vector3( 0, 0, 1 ) );
  37065. assert.ok( a.recast( 0 ).equals( a ), "Passed!" );
  37066. var b = a.clone();
  37067. assert.ok( b.recast( - 1 ).equals( new Ray( new Vector3( 1, 1, 0 ), new Vector3( 0, 0, 1 ) ) ), "Passed!" );
  37068. var c = a.clone();
  37069. assert.ok( c.recast( 1 ).equals( new Ray( new Vector3( 1, 1, 2 ), new Vector3( 0, 0, 1 ) ) ), "Passed!" );
  37070. var d = a.clone();
  37071. var e = d.clone().recast( 1 );
  37072. assert.ok( d.equals( a ), "Passed!" );
  37073. assert.ok( ! e.equals( d ), "Passed!" );
  37074. assert.ok( e.equals( c ), "Passed!" );
  37075. } );
  37076. QUnit.test( "copy/equals", ( assert ) => {
  37077. var a = new Ray( zero3.clone(), one3.clone() );
  37078. var b = new Ray().copy( a );
  37079. assert.ok( b.origin.equals( zero3 ), "Passed!" );
  37080. assert.ok( b.direction.equals( one3 ), "Passed!" );
  37081. // ensure that it is a true copy
  37082. a.origin = zero3;
  37083. a.direction = one3;
  37084. assert.ok( b.origin.equals( zero3 ), "Passed!" );
  37085. assert.ok( b.direction.equals( one3 ), "Passed!" );
  37086. } );
  37087. QUnit.test( "at", ( assert ) => {
  37088. var a = new Ray( one3.clone(), new Vector3( 0, 0, 1 ) );
  37089. assert.ok( a.at( 0 ).equals( one3 ), "Passed!" );
  37090. assert.ok( a.at( - 1 ).equals( new Vector3( 1, 1, 0 ) ), "Passed!" );
  37091. assert.ok( a.at( 1 ).equals( new Vector3( 1, 1, 2 ) ), "Passed!" );
  37092. } );
  37093. QUnit.test( "lookAt", ( assert ) => {
  37094. var a = new Ray( two3.clone(), one3.clone() );
  37095. var target = one3.clone();
  37096. var expected = target.sub( two3 ).normalize();
  37097. a.lookAt( target );
  37098. assert.ok( a.direction.equals( expected ), "Check if we're looking in the right direction" );
  37099. } );
  37100. QUnit.test( "closestPointToPoint", ( assert ) => {
  37101. var a = new Ray( one3.clone(), new Vector3( 0, 0, 1 ) );
  37102. // behind the ray
  37103. var b = a.closestPointToPoint( zero3 );
  37104. assert.ok( b.equals( one3 ), "Passed!" );
  37105. // front of the ray
  37106. var c = a.closestPointToPoint( new Vector3( 0, 0, 50 ) );
  37107. assert.ok( c.equals( new Vector3( 1, 1, 50 ) ), "Passed!" );
  37108. // exactly on the ray
  37109. var d = a.closestPointToPoint( one3 );
  37110. assert.ok( d.equals( one3 ), "Passed!" );
  37111. } );
  37112. QUnit.test( "distanceToPoint", ( assert ) => {
  37113. var a = new Ray( one3.clone(), new Vector3( 0, 0, 1 ) );
  37114. // behind the ray
  37115. var b = a.distanceToPoint( zero3 );
  37116. assert.ok( b === Math.sqrt( 3 ), "Passed!" );
  37117. // front of the ray
  37118. var c = a.distanceToPoint( new Vector3( 0, 0, 50 ) );
  37119. assert.ok( c === Math.sqrt( 2 ), "Passed!" );
  37120. // exactly on the ray
  37121. var d = a.distanceToPoint( one3 );
  37122. assert.ok( d === 0, "Passed!" );
  37123. } );
  37124. QUnit.test( "distanceSqToPoint", ( assert ) => {
  37125. var a = new Ray( one3.clone(), new Vector3( 0, 0, 1 ) );
  37126. // behind the ray
  37127. var b = a.distanceSqToPoint( zero3 );
  37128. assert.ok( b === 3, "Passed!" );
  37129. // front of the ray
  37130. var c = a.distanceSqToPoint( new Vector3( 0, 0, 50 ) );
  37131. assert.ok( c === 2, "Passed!" );
  37132. // exactly on the ray
  37133. var d = a.distanceSqToPoint( one3 );
  37134. assert.ok( d === 0, "Passed!" );
  37135. } );
  37136. QUnit.test( "distanceSqToSegment", ( assert ) => {
  37137. var a = new Ray( one3.clone(), new Vector3( 0, 0, 1 ) );
  37138. var ptOnLine = new Vector3();
  37139. var ptOnSegment = new Vector3();
  37140. //segment in front of the ray
  37141. var v0 = new Vector3( 3, 5, 50 );
  37142. var v1 = new Vector3( 50, 50, 50 ); // just a far away point
  37143. var distSqr = a.distanceSqToSegment( v0, v1, ptOnLine, ptOnSegment );
  37144. assert.ok( ptOnSegment.distanceTo( v0 ) < 0.0001, "Passed!" );
  37145. assert.ok( ptOnLine.distanceTo( new Vector3( 1, 1, 50 ) ) < 0.0001, "Passed!" );
  37146. // ((3-1) * (3-1) + (5-1) * (5-1) = 4 + 16 = 20
  37147. assert.ok( Math.abs( distSqr - 20 ) < 0.0001, "Passed!" );
  37148. //segment behind the ray
  37149. var v0 = new Vector3( - 50, - 50, - 50 ); // just a far away point
  37150. var v1 = new Vector3( - 3, - 5, - 4 );
  37151. var distSqr = a.distanceSqToSegment( v0, v1, ptOnLine, ptOnSegment );
  37152. assert.ok( ptOnSegment.distanceTo( v1 ) < 0.0001, "Passed!" );
  37153. assert.ok( ptOnLine.distanceTo( one3 ) < 0.0001, "Passed!" );
  37154. // ((-3-1) * (-3-1) + (-5-1) * (-5-1) + (-4-1) + (-4-1) = 16 + 36 + 25 = 77
  37155. assert.ok( Math.abs( distSqr - 77 ) < 0.0001, "Passed!" );
  37156. //exact intersection between the ray and the segment
  37157. var v0 = new Vector3( - 50, - 50, - 50 );
  37158. var v1 = new Vector3( 50, 50, 50 );
  37159. var distSqr = a.distanceSqToSegment( v0, v1, ptOnLine, ptOnSegment );
  37160. assert.ok( ptOnSegment.distanceTo( one3 ) < 0.0001, "Passed!" );
  37161. assert.ok( ptOnLine.distanceTo( one3 ) < 0.0001, "Passed!" );
  37162. assert.ok( distSqr < 0.0001, "Passed!" );
  37163. } );
  37164. QUnit.test( "intersectSphere", ( assert ) => {
  37165. var TOL = 0.0001;
  37166. // ray a0 origin located at ( 0, 0, 0 ) and points outward in negative-z direction
  37167. var a0 = new Ray( zero3.clone(), new Vector3( 0, 0, - 1 ) );
  37168. // ray a1 origin located at ( 1, 1, 1 ) and points left in negative-x direction
  37169. var a1 = new Ray( one3.clone(), new Vector3( - 1, 0, 0 ) );
  37170. // sphere (radius of 2) located behind ray a0, should result in null
  37171. var b = new Sphere( new Vector3( 0, 0, 3 ), 2 );
  37172. assert.ok( a0.intersectSphere( b ) === null, "Passed!" );
  37173. // sphere (radius of 2) located in front of, but too far right of ray a0, should result in null
  37174. var b = new Sphere( new Vector3( 3, 0, - 1 ), 2 );
  37175. assert.ok( a0.intersectSphere( b ) === null, "Passed!" );
  37176. // sphere (radius of 2) located below ray a1, should result in null
  37177. var b = new Sphere( new Vector3( 1, - 2, 1 ), 2 );
  37178. assert.ok( a1.intersectSphere( b ) === null, "Passed!" );
  37179. // sphere (radius of 1) located to the left of ray a1, should result in intersection at 0, 1, 1
  37180. var b = new Sphere( new Vector3( - 1, 1, 1 ), 1 );
  37181. assert.ok( a1.intersectSphere( b ).distanceTo( new Vector3( 0, 1, 1 ) ) < TOL, "Passed!" );
  37182. // sphere (radius of 1) located in front of ray a0, should result in intersection at 0, 0, -1
  37183. var b = new Sphere( new Vector3( 0, 0, - 2 ), 1 );
  37184. assert.ok( a0.intersectSphere( b ).distanceTo( new Vector3( 0, 0, - 1 ) ) < TOL, "Passed!" );
  37185. // 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
  37186. var b = new Sphere( new Vector3( 2, 0, - 1 ), 2 );
  37187. assert.ok( a0.intersectSphere( b ).distanceTo( new Vector3( 0, 0, - 1 ) ) < TOL, "Passed!" );
  37188. // same situation as above, but move the sphere a fraction more to the right, and ray a0 should now just miss
  37189. var b = new Sphere( new Vector3( 2.01, 0, - 1 ), 2 );
  37190. assert.ok( a0.intersectSphere( b ) === null, "Passed!" );
  37191. // following QUnit.tests are for situations where the ray origin is inside the sphere
  37192. // sphere (radius of 1) center located at ray a0 origin / sphere surrounds the ray origin, so the first intersect point 0, 0, 1,
  37193. // is behind ray a0. Therefore, second exit point on back of sphere will be returned: 0, 0, -1
  37194. // thus keeping the intersection point always in front of the ray.
  37195. var b = new Sphere( zero3.clone(), 1 );
  37196. assert.ok( a0.intersectSphere( b ).distanceTo( new Vector3( 0, 0, - 1 ) ) < TOL, "Passed!" );
  37197. // sphere (radius of 4) center located behind ray a0 origin / sphere surrounds the ray origin, so the first intersect point 0, 0, 5,
  37198. // is behind ray a0. Therefore, second exit point on back of sphere will be returned: 0, 0, -3
  37199. // thus keeping the intersection point always in front of the ray.
  37200. var b = new Sphere( new Vector3( 0, 0, 1 ), 4 );
  37201. assert.ok( a0.intersectSphere( b ).distanceTo( new Vector3( 0, 0, - 3 ) ) < TOL, "Passed!" );
  37202. // 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,
  37203. // is behind ray a0. Therefore, second exit point on back of sphere will be returned: 0, 0, -5
  37204. // thus keeping the intersection point always in front of the ray.
  37205. var b = new Sphere( new Vector3( 0, 0, - 1 ), 4 );
  37206. assert.ok( a0.intersectSphere( b ).distanceTo( new Vector3( 0, 0, - 5 ) ) < TOL, "Passed!" );
  37207. } );
  37208. QUnit.test( "intersectsSphere", ( assert ) => {
  37209. var a = new Ray( one3.clone(), new Vector3( 0, 0, 1 ) );
  37210. var b = new Sphere( zero3, 0.5 );
  37211. var c = new Sphere( zero3, 1.5 );
  37212. var d = new Sphere( one3, 0.1 );
  37213. var e = new Sphere( two3, 0.1 );
  37214. var f = new Sphere( two3, 1 );
  37215. assert.ok( ! a.intersectsSphere( b ), "Passed!" );
  37216. assert.ok( ! a.intersectsSphere( c ), "Passed!" );
  37217. assert.ok( a.intersectsSphere( d ), "Passed!" );
  37218. assert.ok( ! a.intersectsSphere( e ), "Passed!" );
  37219. assert.ok( ! a.intersectsSphere( f ), "Passed!" );
  37220. } );
  37221. QUnit.test( "distanceToPlane", ( assert ) => {
  37222. assert.ok( false, "everything's gonna be alright" );
  37223. } );
  37224. QUnit.test( "intersectPlane", ( assert ) => {
  37225. var a = new Ray( one3.clone(), new Vector3( 0, 0, 1 ) );
  37226. // parallel plane behind
  37227. var b = new Plane().setFromNormalAndCoplanarPoint( new Vector3( 0, 0, 1 ), new Vector3( 1, 1, - 1 ) );
  37228. assert.ok( a.intersectPlane( b ) === null, "Passed!" );
  37229. // parallel plane coincident with origin
  37230. var c = new Plane().setFromNormalAndCoplanarPoint( new Vector3( 0, 0, 1 ), new Vector3( 1, 1, 0 ) );
  37231. assert.ok( a.intersectPlane( c ) === null, "Passed!" );
  37232. // parallel plane infront
  37233. var d = new Plane().setFromNormalAndCoplanarPoint( new Vector3( 0, 0, 1 ), new Vector3( 1, 1, 1 ) );
  37234. assert.ok( a.intersectPlane( d ).equals( a.origin ), "Passed!" );
  37235. // perpendical ray that overlaps exactly
  37236. var e = new Plane().setFromNormalAndCoplanarPoint( new Vector3( 1, 0, 0 ), one3 );
  37237. assert.ok( a.intersectPlane( e ).equals( a.origin ), "Passed!" );
  37238. // perpendical ray that doesn't overlap
  37239. var f = new Plane().setFromNormalAndCoplanarPoint( new Vector3( 1, 0, 0 ), zero3 );
  37240. assert.ok( a.intersectPlane( f ) === null, "Passed!" );
  37241. } );
  37242. QUnit.test( "intersectsPlane", ( assert ) => {
  37243. var a = new Ray( one3.clone(), new Vector3( 0, 0, 1 ) );
  37244. // parallel plane in front of the ray
  37245. var b = new Plane().setFromNormalAndCoplanarPoint( new Vector3( 0, 0, 1 ), one3.clone().sub( new Vector3( 0, 0, - 1 ) ) );
  37246. assert.ok( a.intersectsPlane( b ), "Passed!" );
  37247. // parallel plane coincident with origin
  37248. var c = new Plane().setFromNormalAndCoplanarPoint( new Vector3( 0, 0, 1 ), one3.clone().sub( new Vector3( 0, 0, 0 ) ) );
  37249. assert.ok( a.intersectsPlane( c ), "Passed!" );
  37250. // parallel plane behind the ray
  37251. var d = new Plane().setFromNormalAndCoplanarPoint( new Vector3( 0, 0, 1 ), one3.clone().sub( new Vector3( 0, 0, 1 ) ) );
  37252. assert.ok( ! a.intersectsPlane( d ), "Passed!" );
  37253. // perpendical ray that overlaps exactly
  37254. var e = new Plane().setFromNormalAndCoplanarPoint( new Vector3( 1, 0, 0 ), one3 );
  37255. assert.ok( a.intersectsPlane( e ), "Passed!" );
  37256. // perpendical ray that doesn't overlap
  37257. var f = new Plane().setFromNormalAndCoplanarPoint( new Vector3( 1, 0, 0 ), zero3 );
  37258. assert.ok( ! a.intersectsPlane( f ), "Passed!" );
  37259. } );
  37260. QUnit.test( "intersectBox", ( assert ) => {
  37261. var TOL = 0.0001;
  37262. var box = new Box3( new Vector3( - 1, - 1, - 1 ), new Vector3( 1, 1, 1 ) );
  37263. var a = new Ray( new Vector3( - 2, 0, 0 ), new Vector3( 1, 0, 0 ) );
  37264. //ray should intersect box at -1,0,0
  37265. assert.ok( a.intersectsBox( box ) === true, "Passed!" );
  37266. assert.ok( a.intersectBox( box ).distanceTo( new Vector3( - 1, 0, 0 ) ) < TOL, "Passed!" );
  37267. var b = new Ray( new Vector3( - 2, 0, 0 ), new Vector3( - 1, 0, 0 ) );
  37268. //ray is point away from box, it should not intersect
  37269. assert.ok( b.intersectsBox( box ) === false, "Passed!" );
  37270. assert.ok( b.intersectBox( box ) === null, "Passed!" );
  37271. var c = new Ray( new Vector3( 0, 0, 0 ), new Vector3( 1, 0, 0 ) );
  37272. // ray is inside box, should return exit point
  37273. assert.ok( c.intersectsBox( box ) === true, "Passed!" );
  37274. assert.ok( c.intersectBox( box ).distanceTo( new Vector3( 1, 0, 0 ) ) < TOL, "Passed!" );
  37275. var d = new Ray( new Vector3( 0, 2, 1 ), new Vector3( 0, - 1, - 1 ).normalize() );
  37276. //tilted ray should intersect box at 0,1,0
  37277. assert.ok( d.intersectsBox( box ) === true, "Passed!" );
  37278. assert.ok( d.intersectBox( box ).distanceTo( new Vector3( 0, 1, 0 ) ) < TOL, "Passed!" );
  37279. var e = new Ray( new Vector3( 1, - 2, 1 ), new Vector3( 0, 1, 0 ).normalize() );
  37280. //handle case where ray is coplanar with one of the boxes side - box in front of ray
  37281. assert.ok( e.intersectsBox( box ) === true, "Passed!" );
  37282. assert.ok( e.intersectBox( box ).distanceTo( new Vector3( 1, - 1, 1 ) ) < TOL, "Passed!" );
  37283. var f = new Ray( new Vector3( 1, - 2, 0 ), new Vector3( 0, - 1, 0 ).normalize() );
  37284. //handle case where ray is coplanar with one of the boxes side - box behind ray
  37285. assert.ok( f.intersectsBox( box ) === false, "Passed!" );
  37286. assert.ok( f.intersectBox( box ) == null, "Passed!" );
  37287. } );
  37288. QUnit.test( "intersectsBox", ( assert ) => {
  37289. assert.ok( false, "everything's gonna be alright" );
  37290. } );
  37291. QUnit.test( "intersectTriangle", ( assert ) => {
  37292. var ray = new Ray();
  37293. var a = new Vector3( 1, 1, 0 );
  37294. var b = new Vector3( 0, 1, 1 );
  37295. var c = new Vector3( 1, 0, 1 );
  37296. var intersect;
  37297. // DdN == 0
  37298. ray.set( ray.origin, zero3.clone() );
  37299. intersect = ray.intersectTriangle( a, b, c, false );
  37300. assert.strictEqual( intersect, null, "No intersection if direction == zero" );
  37301. // DdN > 0, backfaceCulling = true
  37302. ray.set( ray.origin, one3.clone() );
  37303. intersect = ray.intersectTriangle( a, b, c, true );
  37304. assert.strictEqual( intersect, null, "No intersection with backside faces if backfaceCulling is true" );
  37305. // DdN > 0
  37306. ray.set( ray.origin, one3.clone() );
  37307. intersect = ray.intersectTriangle( a, b, c, false );
  37308. assert.ok( Math.abs( intersect.x - 2 / 3 ) <= eps, "Successful intersection: check x" );
  37309. assert.ok( Math.abs( intersect.y - 2 / 3 ) <= eps, "Successful intersection: check y" );
  37310. assert.ok( Math.abs( intersect.z - 2 / 3 ) <= eps, "Successful intersection: check z" );
  37311. // DdN > 0, DdQxE2 < 0
  37312. b.multiplyScalar( - 1 );
  37313. intersect = ray.intersectTriangle( a, b, c, false );
  37314. assert.strictEqual( intersect, null, "No intersection" );
  37315. // DdN > 0, DdE1xQ < 0
  37316. a.multiplyScalar( - 1 );
  37317. intersect = ray.intersectTriangle( a, b, c, false );
  37318. assert.strictEqual( intersect, null, "No intersection" );
  37319. // DdN > 0, DdQxE2 + DdE1xQ > DdN
  37320. b.multiplyScalar( - 1 );
  37321. intersect = ray.intersectTriangle( a, b, c, false );
  37322. assert.strictEqual( intersect, null, "No intersection" );
  37323. // DdN < 0, QdN < 0
  37324. a.multiplyScalar( - 1 );
  37325. b.multiplyScalar( - 1 );
  37326. ray.direction.multiplyScalar( - 1 );
  37327. intersect = ray.intersectTriangle( a, b, c, false );
  37328. assert.strictEqual( intersect, null, "No intersection when looking in the wrong direction" );
  37329. } );
  37330. QUnit.test( "applyMatrix4", ( assert ) => {
  37331. var a = new Ray( one3.clone(), new Vector3( 0, 0, 1 ) );
  37332. var m = new Matrix4();
  37333. assert.ok( a.clone().applyMatrix4( m ).equals( a ), "Passed!" );
  37334. var a = new Ray( zero3.clone(), new Vector3( 0, 0, 1 ) );
  37335. m.makeRotationZ( Math.PI );
  37336. assert.ok( a.clone().applyMatrix4( m ).equals( a ), "Passed!" );
  37337. m.makeRotationX( Math.PI );
  37338. var b = a.clone();
  37339. b.direction.negate();
  37340. var a2 = a.clone().applyMatrix4( m );
  37341. assert.ok( a2.origin.distanceTo( b.origin ) < 0.0001, "Passed!" );
  37342. assert.ok( a2.direction.distanceTo( b.direction ) < 0.0001, "Passed!" );
  37343. a.origin = new Vector3( 0, 0, 1 );
  37344. b.origin = new Vector3( 0, 0, - 1 );
  37345. var a2 = a.clone().applyMatrix4( m );
  37346. assert.ok( a2.origin.distanceTo( b.origin ) < 0.0001, "Passed!" );
  37347. assert.ok( a2.direction.distanceTo( b.direction ) < 0.0001, "Passed!" );
  37348. } );
  37349. QUnit.test( "equals", ( assert ) => {
  37350. assert.ok( false, "everything's gonna be alright" );
  37351. } );
  37352. } );
  37353. } );
  37354. /**
  37355. * @author bhouston / http://exocortex.com
  37356. * @author TristanVALCKE / https://github.com/Itee
  37357. */
  37358. /* global QUnit */
  37359. QUnit.module( 'Maths', () => {
  37360. QUnit.module.todo( 'Sphere', () => {
  37361. // INSTANCING
  37362. QUnit.test( "Instancing", ( assert ) => {
  37363. var a = new Sphere();
  37364. assert.ok( a.center.equals( zero3 ), "Passed!" );
  37365. assert.ok( a.radius == 0, "Passed!" );
  37366. var a = new Sphere( one3.clone(), 1 );
  37367. assert.ok( a.center.equals( one3 ), "Passed!" );
  37368. assert.ok( a.radius == 1, "Passed!" );
  37369. } );
  37370. // PUBLIC STUFF
  37371. QUnit.test( "isSphere", ( assert ) => {
  37372. assert.ok( false, "everything's gonna be alright" );
  37373. } );
  37374. QUnit.test( "set", ( assert ) => {
  37375. var a = new Sphere();
  37376. assert.ok( a.center.equals( zero3 ), "Passed!" );
  37377. assert.ok( a.radius == 0, "Passed!" );
  37378. a.set( one3, 1 );
  37379. assert.ok( a.center.equals( one3 ), "Passed!" );
  37380. assert.ok( a.radius == 1, "Passed!" );
  37381. } );
  37382. QUnit.test( "setFromPoints", ( assert ) => {
  37383. var a = new Sphere();
  37384. var expectedCenter = new Vector3( 0.9330126941204071, 0, 0 );
  37385. var expectedRadius = 1.3676668773461689;
  37386. var optionalCenter = new Vector3( 1, 1, 1 );
  37387. var points = [
  37388. new Vector3( 1, 1, 0 ), new Vector3( 1, 1, 0 ),
  37389. new Vector3( 1, 1, 0 ), new Vector3( 1, 1, 0 ),
  37390. new Vector3( 1, 1, 0 ), new Vector3( 0.8660253882408142, 0.5, 0 ),
  37391. new Vector3( - 0, 0.5, 0.8660253882408142 ), new Vector3( 1.8660253882408142, 0.5, 0 ),
  37392. new Vector3( 0, 0.5, - 0.8660253882408142 ), new Vector3( 0.8660253882408142, 0.5, - 0 ),
  37393. new Vector3( 0.8660253882408142, - 0.5, 0 ), new Vector3( - 0, - 0.5, 0.8660253882408142 ),
  37394. new Vector3( 1.8660253882408142, - 0.5, 0 ), new Vector3( 0, - 0.5, - 0.8660253882408142 ),
  37395. new Vector3( 0.8660253882408142, - 0.5, - 0 ), new Vector3( - 0, - 1, 0 ),
  37396. new Vector3( - 0, - 1, 0 ), new Vector3( 0, - 1, 0 ),
  37397. new Vector3( 0, - 1, - 0 ), new Vector3( - 0, - 1, - 0 ),
  37398. ];
  37399. a.setFromPoints( points );
  37400. assert.ok( Math.abs( a.center.x - expectedCenter.x ) <= eps, "Default center: check center.x" );
  37401. assert.ok( Math.abs( a.center.y - expectedCenter.y ) <= eps, "Default center: check center.y" );
  37402. assert.ok( Math.abs( a.center.z - expectedCenter.z ) <= eps, "Default center: check center.z" );
  37403. assert.ok( Math.abs( a.radius - expectedRadius ) <= eps, "Default center: check radius" );
  37404. var expectedRadius = 2.5946195770400102;
  37405. a.setFromPoints( points, optionalCenter );
  37406. assert.ok( Math.abs( a.center.x - optionalCenter.x ) <= eps, "Optional center: check center.x" );
  37407. assert.ok( Math.abs( a.center.y - optionalCenter.y ) <= eps, "Optional center: check center.y" );
  37408. assert.ok( Math.abs( a.center.z - optionalCenter.z ) <= eps, "Optional center: check center.z" );
  37409. assert.ok( Math.abs( a.radius - expectedRadius ) <= eps, "Optional center: check radius" );
  37410. } );
  37411. QUnit.test( "clone", ( assert ) => {
  37412. assert.ok( false, "everything's gonna be alright" );
  37413. } );
  37414. QUnit.test( "copy", ( assert ) => {
  37415. var a = new Sphere( one3.clone(), 1 );
  37416. var b = new Sphere().copy( a );
  37417. assert.ok( b.center.equals( one3 ), "Passed!" );
  37418. assert.ok( b.radius == 1, "Passed!" );
  37419. // ensure that it is a true copy
  37420. a.center = zero3;
  37421. a.radius = 0;
  37422. assert.ok( b.center.equals( one3 ), "Passed!" );
  37423. assert.ok( b.radius == 1, "Passed!" );
  37424. } );
  37425. QUnit.test( "empty", ( assert ) => {
  37426. var a = new Sphere();
  37427. assert.ok( a.empty(), "Passed!" );
  37428. a.set( one3, 1 );
  37429. assert.ok( ! a.empty(), "Passed!" );
  37430. } );
  37431. QUnit.test( "containsPoint", ( assert ) => {
  37432. var a = new Sphere( one3.clone(), 1 );
  37433. assert.ok( ! a.containsPoint( zero3 ), "Passed!" );
  37434. assert.ok( a.containsPoint( one3 ), "Passed!" );
  37435. } );
  37436. QUnit.test( "distanceToPoint", ( assert ) => {
  37437. var a = new Sphere( one3.clone(), 1 );
  37438. assert.ok( ( a.distanceToPoint( zero3 ) - 0.7320 ) < 0.001, "Passed!" );
  37439. assert.ok( a.distanceToPoint( one3 ) === - 1, "Passed!" );
  37440. } );
  37441. QUnit.test( "intersectsSphere", ( assert ) => {
  37442. var a = new Sphere( one3.clone(), 1 );
  37443. var b = new Sphere( zero3.clone(), 1 );
  37444. var c = new Sphere( zero3.clone(), 0.25 );
  37445. assert.ok( a.intersectsSphere( b ), "Passed!" );
  37446. assert.ok( ! a.intersectsSphere( c ), "Passed!" );
  37447. } );
  37448. QUnit.test( "intersectsBox", ( assert ) => {
  37449. var a = new Sphere();
  37450. var b = new Sphere( new Vector3( - 5, - 5, - 5 ) );
  37451. var box = new Box3( zero3, one3 );
  37452. assert.strictEqual( a.intersectsBox( box ), true, "Check default sphere" );
  37453. assert.strictEqual( b.intersectsBox( box ), false, "Check shifted sphere" );
  37454. } );
  37455. QUnit.test( "intersectsPlane", ( assert ) => {
  37456. var a = new Sphere( zero3.clone(), 1 );
  37457. var b = new Plane( new Vector3( 0, 1, 0 ), 1 );
  37458. var c = new Plane( new Vector3( 0, 1, 0 ), 1.25 );
  37459. var d = new Plane( new Vector3( 0, - 1, 0 ), 1.25 );
  37460. assert.ok( a.intersectsPlane( b ), "Passed!" );
  37461. assert.ok( ! a.intersectsPlane( c ), "Passed!" );
  37462. assert.ok( ! a.intersectsPlane( d ), "Passed!" );
  37463. } );
  37464. QUnit.test( "clampPoint", ( assert ) => {
  37465. var a = new Sphere( one3.clone(), 1 );
  37466. assert.ok( a.clampPoint( new Vector3( 1, 1, 3 ) ).equals( new Vector3( 1, 1, 2 ) ), "Passed!" );
  37467. assert.ok( a.clampPoint( new Vector3( 1, 1, - 3 ) ).equals( new Vector3( 1, 1, 0 ) ), "Passed!" );
  37468. } );
  37469. QUnit.test( "getBoundingBox", ( assert ) => {
  37470. var a = new Sphere( one3.clone(), 1 );
  37471. assert.ok( a.getBoundingBox().equals( new Box3( zero3, two3 ) ), "Passed!" );
  37472. a.set( zero3, 0 );
  37473. assert.ok( a.getBoundingBox().equals( new Box3( zero3, zero3 ) ), "Passed!" );
  37474. } );
  37475. QUnit.test( "applyMatrix4", ( assert ) => {
  37476. var a = new Sphere( one3.clone(), 1 );
  37477. var m = new Matrix4().makeTranslation( 1, - 2, 1 );
  37478. assert.ok( a.clone().applyMatrix4( m ).getBoundingBox().equals( a.getBoundingBox().applyMatrix4( m ) ), "Passed!" );
  37479. } );
  37480. QUnit.test( "translate", ( assert ) => {
  37481. var a = new Sphere( one3.clone(), 1 );
  37482. a.translate( one3.clone().negate() );
  37483. assert.ok( a.center.equals( zero3 ), "Passed!" );
  37484. } );
  37485. QUnit.test( "equals", ( assert ) => {
  37486. var a = new Sphere();
  37487. var b = new Sphere( new Vector3( 1, 0, 0 ) );
  37488. var c = new Sphere( new Vector3( 1, 0, 0 ), 1.0 );
  37489. assert.strictEqual( a.equals( b ), false, "a does not equal b" );
  37490. assert.strictEqual( a.equals( c ), false, "a does not equal c" );
  37491. assert.strictEqual( b.equals( c ), false, "b does not equal c" );
  37492. a.copy( b );
  37493. assert.strictEqual( a.equals( b ), true, "a equals b after copy()" );
  37494. } );
  37495. } );
  37496. } );
  37497. /**
  37498. * @author bhouston / http://clara.io
  37499. * @author WestLangley / http://github.com/WestLangley
  37500. *
  37501. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  37502. *
  37503. * The poles (phi) are at the positive and negative y axis.
  37504. * The equator starts at positive z.
  37505. */
  37506. function Spherical( radius, phi, theta ) {
  37507. this.radius = ( radius !== undefined ) ? radius : 1.0;
  37508. this.phi = ( phi !== undefined ) ? phi : 0; // up / down towards top and bottom pole
  37509. this.theta = ( theta !== undefined ) ? theta : 0; // around the equator of the sphere
  37510. return this;
  37511. }
  37512. Object.assign( Spherical.prototype, {
  37513. set: function ( radius, phi, theta ) {
  37514. this.radius = radius;
  37515. this.phi = phi;
  37516. this.theta = theta;
  37517. return this;
  37518. },
  37519. clone: function () {
  37520. return new this.constructor().copy( this );
  37521. },
  37522. copy: function ( other ) {
  37523. this.radius = other.radius;
  37524. this.phi = other.phi;
  37525. this.theta = other.theta;
  37526. return this;
  37527. },
  37528. // restrict phi to be betwee EPS and PI-EPS
  37529. makeSafe: function () {
  37530. var EPS = 0.000001;
  37531. this.phi = Math.max( EPS, Math.min( Math.PI - EPS, this.phi ) );
  37532. return this;
  37533. },
  37534. setFromVector3: function ( vec3 ) {
  37535. this.radius = vec3.length();
  37536. if ( this.radius === 0 ) {
  37537. this.theta = 0;
  37538. this.phi = 0;
  37539. } else {
  37540. this.theta = Math.atan2( vec3.x, vec3.z ); // equator angle around y-up axis
  37541. this.phi = Math.acos( _Math.clamp( vec3.y / this.radius, - 1, 1 ) ); // polar angle
  37542. }
  37543. return this;
  37544. }
  37545. } );
  37546. /**
  37547. * @author moraxy / https://github.com/moraxy
  37548. * @author TristanVALCKE / https://github.com/Itee
  37549. */
  37550. /* global QUnit */
  37551. QUnit.module( 'Maths', () => {
  37552. QUnit.module.todo( 'Spherical', () => {
  37553. // INSTANCING
  37554. QUnit.test( "Instancing", ( assert ) => {
  37555. var a = new Spherical();
  37556. var radius = 10.0;
  37557. var phi = Math.acos( - 0.5 );
  37558. var theta = Math.sqrt( Math.PI ) * phi;
  37559. assert.strictEqual( a.radius, 1.0, "Default values: check radius" );
  37560. assert.strictEqual( a.phi, 0, "Default values: check phi" );
  37561. assert.strictEqual( a.theta, 0, "Default values: check theta" );
  37562. var a = new Spherical( radius, phi, theta );
  37563. assert.strictEqual( a.radius, radius, "Custom values: check radius" );
  37564. assert.strictEqual( a.phi, phi, "Custom values: check phi" );
  37565. assert.strictEqual( a.theta, theta, "Custom values: check theta" );
  37566. } );
  37567. // PUBLIC STUFF
  37568. QUnit.test( "isSpherical", ( assert ) => {
  37569. assert.ok( false, "everything's gonna be alright" );
  37570. } );
  37571. QUnit.test( "set", ( assert ) => {
  37572. var a = new Spherical();
  37573. var radius = 10.0;
  37574. var phi = Math.acos( - 0.5 );
  37575. var theta = Math.sqrt( Math.PI ) * phi;
  37576. a.set( radius, phi, theta );
  37577. assert.strictEqual( a.radius, radius, "Check radius" );
  37578. assert.strictEqual( a.phi, phi, "Check phi" );
  37579. assert.strictEqual( a.theta, theta, "Check theta" );
  37580. } );
  37581. QUnit.test( "clone", ( assert ) => {
  37582. var radius = 10.0;
  37583. var phi = Math.acos( - 0.5 );
  37584. var theta = Math.sqrt( Math.PI ) * phi;
  37585. var a = new Spherical( radius, phi, theta );
  37586. var b = a.clone();
  37587. assert.propEqual( a, b, "Check a and b are equal after clone()" );
  37588. a.radius = 2.0;
  37589. assert.notPropEqual( a, b, "Check a and b are not equal after modification" );
  37590. } );
  37591. QUnit.test( "copy", ( assert ) => {
  37592. var radius = 10.0;
  37593. var phi = Math.acos( - 0.5 );
  37594. var theta = Math.sqrt( Math.PI ) * phi;
  37595. var a = new Spherical( radius, phi, theta );
  37596. var b = new Spherical().copy( a );
  37597. assert.propEqual( a, b, "Check a and b are equal after copy()" );
  37598. a.radius = 2.0;
  37599. assert.notPropEqual( a, b, "Check a and b are not equal after modification" );
  37600. } );
  37601. QUnit.test( "makeSafe", ( assert ) => {
  37602. var EPS = 0.000001; // from source
  37603. var tooLow = 0.0;
  37604. var tooHigh = Math.PI;
  37605. var justRight = 1.5;
  37606. var a = new Spherical( 1, tooLow, 0 );
  37607. a.makeSafe();
  37608. assert.strictEqual( a.phi, EPS, "Check if small values are set to EPS" );
  37609. a.set( 1, tooHigh, 0 );
  37610. a.makeSafe();
  37611. assert.strictEqual( a.phi, Math.PI - EPS, "Check if high values are set to (Math.PI - EPS)" );
  37612. a.set( 1, justRight, 0 );
  37613. a.makeSafe();
  37614. assert.strictEqual( a.phi, justRight, "Check that valid values don't get changed" );
  37615. } );
  37616. QUnit.test( "setFromVector3", ( assert ) => {
  37617. var a = new Spherical( 1, 1, 1 );
  37618. var b = new Vector3( 0, 0, 0 );
  37619. var c = new Vector3( Math.PI, 1, - Math.PI );
  37620. var expected = new Spherical( 4.554032147688322, 1.3494066171539107, 2.356194490192345 );
  37621. a.setFromVector3( b );
  37622. assert.strictEqual( a.radius, 0, "Zero-length vector: check radius" );
  37623. assert.strictEqual( a.phi, 0, "Zero-length vector: check phi" );
  37624. assert.strictEqual( a.theta, 0, "Zero-length vector: check theta" );
  37625. a.setFromVector3( c );
  37626. assert.ok( Math.abs( a.radius - expected.radius ) <= eps, "Normal vector: check radius" );
  37627. assert.ok( Math.abs( a.phi - expected.phi ) <= eps, "Normal vector: check phi" );
  37628. assert.ok( Math.abs( a.theta - expected.theta ) <= eps, "Normal vector: check theta" );
  37629. } );
  37630. } );
  37631. } );
  37632. /**
  37633. * @author bhouston / http://exocortex.com
  37634. * @author TristanVALCKE / https://github.com/Itee
  37635. */
  37636. /* global QUnit */
  37637. QUnit.module( 'Maths', () => {
  37638. QUnit.module.todo( 'Triangle', () => {
  37639. // INSTANCING
  37640. QUnit.test( "Instancing", ( assert ) => {
  37641. var a = new Triangle();
  37642. assert.ok( a.a.equals( zero3 ), "Passed!" );
  37643. assert.ok( a.b.equals( zero3 ), "Passed!" );
  37644. assert.ok( a.c.equals( zero3 ), "Passed!" );
  37645. var a = new Triangle( one3.clone().negate(), one3.clone(), two3.clone() );
  37646. assert.ok( a.a.equals( one3.clone().negate() ), "Passed!" );
  37647. assert.ok( a.b.equals( one3 ), "Passed!" );
  37648. assert.ok( a.c.equals( two3 ), "Passed!" );
  37649. } );
  37650. // STATIC STUFF
  37651. QUnit.test( "normal", ( assert ) => {
  37652. assert.ok( false, "everything's gonna be alright" );
  37653. } );
  37654. QUnit.test( "barycoordFromPoint", ( assert ) => {
  37655. assert.ok( false, "everything's gonna be alright" );
  37656. } );
  37657. QUnit.test( "containsPoint", ( assert ) => {
  37658. assert.ok( false, "everything's gonna be alright" );
  37659. } );
  37660. // PUBLIC STUFF
  37661. QUnit.test( "set", ( assert ) => {
  37662. var a = new Triangle();
  37663. a.set( one3.clone().negate(), one3, two3 );
  37664. assert.ok( a.a.equals( one3.clone().negate() ), "Passed!" );
  37665. assert.ok( a.b.equals( one3 ), "Passed!" );
  37666. assert.ok( a.c.equals( two3 ), "Passed!" );
  37667. } );
  37668. QUnit.test( "setFromPointsAndIndices", ( assert ) => {
  37669. var a = new Triangle();
  37670. var points = [ one3, one3.clone().negate(), two3 ];
  37671. a.setFromPointsAndIndices( points, 1, 0, 2 );
  37672. assert.ok( a.a.equals( one3.clone().negate() ), "Passed!" );
  37673. assert.ok( a.b.equals( one3 ), "Passed!" );
  37674. assert.ok( a.c.equals( two3 ), "Passed!" );
  37675. } );
  37676. QUnit.test( "clone", ( assert ) => {
  37677. assert.ok( false, "everything's gonna be alright" );
  37678. } );
  37679. QUnit.test( "copy", ( assert ) => {
  37680. var a = new Triangle( one3.clone().negate(), one3.clone(), two3.clone() );
  37681. var b = new Triangle().copy( a );
  37682. assert.ok( b.a.equals( one3.clone().negate() ), "Passed!" );
  37683. assert.ok( b.b.equals( one3 ), "Passed!" );
  37684. assert.ok( b.c.equals( two3 ), "Passed!" );
  37685. // ensure that it is a true copy
  37686. a.a = one3;
  37687. a.b = zero3;
  37688. a.c = zero3;
  37689. assert.ok( b.a.equals( one3.clone().negate() ), "Passed!" );
  37690. assert.ok( b.b.equals( one3 ), "Passed!" );
  37691. assert.ok( b.c.equals( two3 ), "Passed!" );
  37692. } );
  37693. QUnit.test( "area", ( assert ) => {
  37694. var a = new Triangle();
  37695. assert.ok( a.area() == 0, "Passed!" );
  37696. var a = new Triangle( new Vector3( 0, 0, 0 ), new Vector3( 1, 0, 0 ), new Vector3( 0, 1, 0 ) );
  37697. assert.ok( a.area() == 0.5, "Passed!" );
  37698. var a = new Triangle( new Vector3( 2, 0, 0 ), new Vector3( 0, 0, 0 ), new Vector3( 0, 0, 2 ) );
  37699. assert.ok( a.area() == 2, "Passed!" );
  37700. // colinear triangle.
  37701. var a = new Triangle( new Vector3( 2, 0, 0 ), new Vector3( 0, 0, 0 ), new Vector3( 3, 0, 0 ) );
  37702. assert.ok( a.area() == 0, "Passed!" );
  37703. } );
  37704. QUnit.test( "midpoint", ( assert ) => {
  37705. var a = new Triangle();
  37706. assert.ok( a.midpoint().equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
  37707. var a = new Triangle( new Vector3( 0, 0, 0 ), new Vector3( 1, 0, 0 ), new Vector3( 0, 1, 0 ) );
  37708. assert.ok( a.midpoint().equals( new Vector3( 1 / 3, 1 / 3, 0 ) ), "Passed!" );
  37709. var a = new Triangle( new Vector3( 2, 0, 0 ), new Vector3( 0, 0, 0 ), new Vector3( 0, 0, 2 ) );
  37710. assert.ok( a.midpoint().equals( new Vector3( 2 / 3, 0, 2 / 3 ) ), "Passed!" );
  37711. } );
  37712. QUnit.test( "normal", ( assert ) => {
  37713. var a = new Triangle();
  37714. assert.ok( a.normal().equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
  37715. var a = new Triangle( new Vector3( 0, 0, 0 ), new Vector3( 1, 0, 0 ), new Vector3( 0, 1, 0 ) );
  37716. assert.ok( a.normal().equals( new Vector3( 0, 0, 1 ) ), "Passed!" );
  37717. var a = new Triangle( new Vector3( 2, 0, 0 ), new Vector3( 0, 0, 0 ), new Vector3( 0, 0, 2 ) );
  37718. assert.ok( a.normal().equals( new Vector3( 0, 1, 0 ) ), "Passed!" );
  37719. } );
  37720. QUnit.test( "plane", ( assert ) => {
  37721. var a = new Triangle();
  37722. assert.notOk( isNaN( a.plane().distanceToPoint( a.a ) ), "Passed!" );
  37723. assert.notOk( isNaN( a.plane().distanceToPoint( a.b ) ), "Passed!" );
  37724. assert.notOk( isNaN( a.plane().distanceToPoint( a.c ) ), "Passed!" );
  37725. assert.notPropEqual( a.plane().normal, {
  37726. x: NaN,
  37727. y: NaN,
  37728. z: NaN
  37729. }, "Passed!" );
  37730. var a = new Triangle( new Vector3( 0, 0, 0 ), new Vector3( 1, 0, 0 ), new Vector3( 0, 1, 0 ) );
  37731. assert.ok( a.plane().distanceToPoint( a.a ) == 0, "Passed!" );
  37732. assert.ok( a.plane().distanceToPoint( a.b ) == 0, "Passed!" );
  37733. assert.ok( a.plane().distanceToPoint( a.c ) == 0, "Passed!" );
  37734. assert.ok( a.plane().normal.equals( a.normal() ), "Passed!" );
  37735. var a = new Triangle( new Vector3( 2, 0, 0 ), new Vector3( 0, 0, 0 ), new Vector3( 0, 0, 2 ) );
  37736. assert.ok( a.plane().distanceToPoint( a.a ) == 0, "Passed!" );
  37737. assert.ok( a.plane().distanceToPoint( a.b ) == 0, "Passed!" );
  37738. assert.ok( a.plane().distanceToPoint( a.c ) == 0, "Passed!" );
  37739. assert.ok( a.plane().normal.clone().normalize().equals( a.normal() ), "Passed!" );
  37740. } );
  37741. QUnit.test( "barycoordFromPoint", ( assert ) => {
  37742. var a = new Triangle();
  37743. var bad = new Vector3( - 2, - 1, - 1 );
  37744. assert.ok( a.barycoordFromPoint( a.a ).equals( bad ), "Passed!" );
  37745. assert.ok( a.barycoordFromPoint( a.b ).equals( bad ), "Passed!" );
  37746. assert.ok( a.barycoordFromPoint( a.c ).equals( bad ), "Passed!" );
  37747. var a = new Triangle( new Vector3( 0, 0, 0 ), new Vector3( 1, 0, 0 ), new Vector3( 0, 1, 0 ) );
  37748. assert.ok( a.barycoordFromPoint( a.a ).equals( new Vector3( 1, 0, 0 ) ), "Passed!" );
  37749. assert.ok( a.barycoordFromPoint( a.b ).equals( new Vector3( 0, 1, 0 ) ), "Passed!" );
  37750. assert.ok( a.barycoordFromPoint( a.c ).equals( new Vector3( 0, 0, 1 ) ), "Passed!" );
  37751. assert.ok( a.barycoordFromPoint( a.midpoint() ).distanceTo( new Vector3( 1 / 3, 1 / 3, 1 / 3 ) ) < 0.0001, "Passed!" );
  37752. var a = new Triangle( new Vector3( 2, 0, 0 ), new Vector3( 0, 0, 0 ), new Vector3( 0, 0, 2 ) );
  37753. assert.ok( a.barycoordFromPoint( a.a ).equals( new Vector3( 1, 0, 0 ) ), "Passed!" );
  37754. assert.ok( a.barycoordFromPoint( a.b ).equals( new Vector3( 0, 1, 0 ) ), "Passed!" );
  37755. assert.ok( a.barycoordFromPoint( a.c ).equals( new Vector3( 0, 0, 1 ) ), "Passed!" );
  37756. assert.ok( a.barycoordFromPoint( a.midpoint() ).distanceTo( new Vector3( 1 / 3, 1 / 3, 1 / 3 ) ) < 0.0001, "Passed!" );
  37757. } );
  37758. QUnit.test( "containsPoint", ( assert ) => {
  37759. var a = new Triangle();
  37760. assert.ok( ! a.containsPoint( a.a ), "Passed!" );
  37761. assert.ok( ! a.containsPoint( a.b ), "Passed!" );
  37762. assert.ok( ! a.containsPoint( a.c ), "Passed!" );
  37763. var a = new Triangle( new Vector3( 0, 0, 0 ), new Vector3( 1, 0, 0 ), new Vector3( 0, 1, 0 ) );
  37764. assert.ok( a.containsPoint( a.a ), "Passed!" );
  37765. assert.ok( a.containsPoint( a.b ), "Passed!" );
  37766. assert.ok( a.containsPoint( a.c ), "Passed!" );
  37767. assert.ok( a.containsPoint( a.midpoint() ), "Passed!" );
  37768. assert.ok( ! a.containsPoint( new Vector3( - 1, - 1, - 1 ) ), "Passed!" );
  37769. var a = new Triangle( new Vector3( 2, 0, 0 ), new Vector3( 0, 0, 0 ), new Vector3( 0, 0, 2 ) );
  37770. assert.ok( a.containsPoint( a.a ), "Passed!" );
  37771. assert.ok( a.containsPoint( a.b ), "Passed!" );
  37772. assert.ok( a.containsPoint( a.c ), "Passed!" );
  37773. assert.ok( a.containsPoint( a.midpoint() ), "Passed!" );
  37774. assert.ok( ! a.containsPoint( new Vector3( - 1, - 1, - 1 ) ), "Passed!" );
  37775. } );
  37776. QUnit.test( "closestPointToPoint", ( assert ) => {
  37777. var a = new Triangle( new Vector3( - 1, 0, 0 ), new Vector3( 1, 0, 0 ), new Vector3( 0, 1, 0 ) );
  37778. // point lies inside the triangle
  37779. var b0 = a.closestPointToPoint( new Vector3( 0, 0.5, 0 ) );
  37780. assert.ok( b0.equals( new Vector3( 0, 0.5, 0 ) ), "Passed!" );
  37781. // point lies on a vertex
  37782. var b0 = a.closestPointToPoint( a.a );
  37783. assert.ok( b0.equals( a.a ), "Passed!" );
  37784. var b0 = a.closestPointToPoint( a.b );
  37785. assert.ok( b0.equals( a.b ), "Passed!" );
  37786. var b0 = a.closestPointToPoint( a.c );
  37787. assert.ok( b0.equals( a.c ), "Passed!" );
  37788. // point lies on an edge
  37789. var b0 = a.closestPointToPoint( zero3.clone() );
  37790. assert.ok( b0.equals( zero3.clone() ), "Passed!" );
  37791. // point lies outside the triangle
  37792. var b0 = a.closestPointToPoint( new Vector3( - 2, 0, 0 ) );
  37793. assert.ok( b0.equals( new Vector3( - 1, 0, 0 ) ), "Passed!" );
  37794. var b0 = a.closestPointToPoint( new Vector3( 2, 0, 0 ) );
  37795. assert.ok( b0.equals( new Vector3( 1, 0, 0 ) ), "Passed!" );
  37796. var b0 = a.closestPointToPoint( new Vector3( 0, 2, 0 ) );
  37797. assert.ok( b0.equals( new Vector3( 0, 1, 0 ) ), "Passed!" );
  37798. var b0 = a.closestPointToPoint( new Vector3( 0, - 2, 0 ) );
  37799. assert.ok( b0.equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
  37800. } );
  37801. QUnit.test( "equals", ( assert ) => {
  37802. var a = new Triangle(
  37803. new Vector3( 1, 0, 0 ),
  37804. new Vector3( 0, 1, 0 ),
  37805. new Vector3( 0, 0, 1 )
  37806. );
  37807. var b = new Triangle(
  37808. new Vector3( 0, 0, 1 ),
  37809. new Vector3( 0, 1, 0 ),
  37810. new Vector3( 1, 0, 0 )
  37811. );
  37812. var c = new Triangle(
  37813. new Vector3( - 1, 0, 0 ),
  37814. new Vector3( 0, 1, 0 ),
  37815. new Vector3( 0, 0, 1 )
  37816. );
  37817. assert.ok( a.equals( a ), "a equals a" );
  37818. assert.notOk( a.equals( b ), "a does not equal b" );
  37819. assert.notOk( a.equals( c ), "a does not equal c" );
  37820. assert.notOk( b.equals( c ), "b does not equal c" );
  37821. a.copy( b );
  37822. assert.ok( a.equals( a ), "a equals b after copy()" );
  37823. } );
  37824. } );
  37825. } );
  37826. /**
  37827. * @author bhouston / http://exocortex.com
  37828. * @author TristanVALCKE / https://github.com/Itee
  37829. */
  37830. /* global QUnit */
  37831. QUnit.module( 'Maths', () => {
  37832. QUnit.module.todo( 'Vector2', () => {
  37833. // INSTANCING
  37834. QUnit.test( "Instancing", ( assert ) => {
  37835. var a = new Vector2();
  37836. assert.ok( a.x == 0, "Passed!" );
  37837. assert.ok( a.y == 0, "Passed!" );
  37838. var a = new Vector2( x, y );
  37839. assert.ok( a.x === x, "Passed!" );
  37840. assert.ok( a.y === y, "Passed!" );
  37841. } );
  37842. // PROPERTIES // ( [Itee] WHAT ??? o_O )
  37843. QUnit.test( "properties", ( assert ) => {
  37844. var a = new Vector2( 0, 0 );
  37845. var width = 100;
  37846. var height = 200;
  37847. assert.ok( a.width = width, "Set width" );
  37848. assert.ok( a.height = height, "Set height" );
  37849. a.set( width, height );
  37850. assert.strictEqual( a.width, width, "Get width" );
  37851. assert.strictEqual( a.height, height, "Get height" );
  37852. } );
  37853. QUnit.test( "width", ( assert ) => {
  37854. assert.ok( false, "everything's gonna be alright" );
  37855. } );
  37856. QUnit.test( "height", ( assert ) => {
  37857. assert.ok( false, "everything's gonna be alright" );
  37858. } );
  37859. // PUBLIC STUFF
  37860. QUnit.test( "isVector2", ( assert ) => {
  37861. assert.ok( false, "everything's gonna be alright" );
  37862. } );
  37863. QUnit.test( "set", ( assert ) => {
  37864. var a = new Vector2();
  37865. assert.ok( a.x == 0, "Passed!" );
  37866. assert.ok( a.y == 0, "Passed!" );
  37867. a.set( x, y );
  37868. assert.ok( a.x == x, "Passed!" );
  37869. assert.ok( a.y == y, "Passed!" );
  37870. } );
  37871. QUnit.test( "setScalar", ( assert ) => {
  37872. assert.ok( false, "everything's gonna be alright" );
  37873. } );
  37874. QUnit.test( "setX", ( assert ) => {
  37875. assert.ok( false, "everything's gonna be alright" );
  37876. } );
  37877. QUnit.test( "setY", ( assert ) => {
  37878. assert.ok( false, "everything's gonna be alright" );
  37879. } );
  37880. QUnit.test( "setComponent", ( assert ) => {
  37881. assert.ok( false, "everything's gonna be alright" );
  37882. } );
  37883. QUnit.test( "getComponent", ( assert ) => {
  37884. assert.ok( false, "everything's gonna be alright" );
  37885. } );
  37886. QUnit.test( "clone", ( assert ) => {
  37887. assert.ok( false, "everything's gonna be alright" );
  37888. } );
  37889. QUnit.test( "copy", ( assert ) => {
  37890. var a = new Vector2( x, y );
  37891. var b = new Vector2().copy( a );
  37892. assert.ok( b.x == x, "Passed!" );
  37893. assert.ok( b.y == y, "Passed!" );
  37894. // ensure that it is a true copy
  37895. a.x = 0;
  37896. a.y = - 1;
  37897. assert.ok( b.x == x, "Passed!" );
  37898. assert.ok( b.y == y, "Passed!" );
  37899. } );
  37900. QUnit.test( "add", ( assert ) => {
  37901. var a = new Vector2( x, y );
  37902. var b = new Vector2( - x, - y );
  37903. a.add( b );
  37904. assert.ok( a.x == 0, "Passed!" );
  37905. assert.ok( a.y == 0, "Passed!" );
  37906. var c = new Vector2().addVectors( b, b );
  37907. assert.ok( c.x == - 2 * x, "Passed!" );
  37908. assert.ok( c.y == - 2 * y, "Passed!" );
  37909. } );
  37910. QUnit.test( "addScalar", ( assert ) => {
  37911. assert.ok( false, "everything's gonna be alright" );
  37912. } );
  37913. QUnit.test( "addVectors", ( assert ) => {
  37914. assert.ok( false, "everything's gonna be alright" );
  37915. } );
  37916. QUnit.test( "addScaledVector", ( assert ) => {
  37917. var a = new Vector2( x, y );
  37918. var b = new Vector2( 2, 3 );
  37919. var s = 3;
  37920. a.addScaledVector( b, s );
  37921. assert.strictEqual( a.x, x + b.x * s, "Check x" );
  37922. assert.strictEqual( a.y, y + b.y * s, "Check y" );
  37923. } );
  37924. QUnit.test( "sub", ( assert ) => {
  37925. var a = new Vector2( x, y );
  37926. var b = new Vector2( - x, - y );
  37927. a.sub( b );
  37928. assert.ok( a.x == 2 * x, "Passed!" );
  37929. assert.ok( a.y == 2 * y, "Passed!" );
  37930. var c = new Vector2().subVectors( a, a );
  37931. assert.ok( c.x == 0, "Passed!" );
  37932. assert.ok( c.y == 0, "Passed!" );
  37933. } );
  37934. QUnit.test( "subScalar", ( assert ) => {
  37935. assert.ok( false, "everything's gonna be alright" );
  37936. } );
  37937. QUnit.test( "subVectors", ( assert ) => {
  37938. assert.ok( false, "everything's gonna be alright" );
  37939. } );
  37940. QUnit.test( "multiply", ( assert ) => {
  37941. assert.ok( false, "everything's gonna be alright" );
  37942. } );
  37943. QUnit.test( "multiplyScalar", ( assert ) => {
  37944. assert.ok( false, "everything's gonna be alright" );
  37945. } );
  37946. QUnit.test( "divide", ( assert ) => {
  37947. assert.ok( false, "everything's gonna be alright" );
  37948. } );
  37949. QUnit.test( "divideScalar", ( assert ) => {
  37950. assert.ok( false, "everything's gonna be alright" );
  37951. } );
  37952. QUnit.test( "applyMatrix3", ( assert ) => {
  37953. var a = new Vector2( x, y );
  37954. var m = new Matrix3().set( 2, 3, 5, 7, 11, 13, 17, 19, 23 );
  37955. a.applyMatrix3( m );
  37956. assert.strictEqual( a.x, 18, "Check x" );
  37957. assert.strictEqual( a.y, 60, "Check y" );
  37958. } );
  37959. QUnit.test( "min", ( assert ) => {
  37960. assert.ok( false, "everything's gonna be alright" );
  37961. } );
  37962. QUnit.test( "max", ( assert ) => {
  37963. assert.ok( false, "everything's gonna be alright" );
  37964. } );
  37965. QUnit.test( "clamp", ( assert ) => {
  37966. assert.ok( false, "everything's gonna be alright" );
  37967. } );
  37968. QUnit.test( "clampScalar", ( assert ) => {
  37969. assert.ok( false, "everything's gonna be alright" );
  37970. } );
  37971. QUnit.test( "clampLength", ( assert ) => {
  37972. assert.ok( false, "everything's gonna be alright" );
  37973. } );
  37974. QUnit.test( "floor", ( assert ) => {
  37975. assert.ok( false, "everything's gonna be alright" );
  37976. } );
  37977. QUnit.test( "ceil", ( assert ) => {
  37978. assert.ok( false, "everything's gonna be alright" );
  37979. } );
  37980. QUnit.test( "round", ( assert ) => {
  37981. assert.ok( false, "everything's gonna be alright" );
  37982. } );
  37983. QUnit.test( "roundToZero", ( assert ) => {
  37984. assert.ok( false, "everything's gonna be alright" );
  37985. } );
  37986. QUnit.test( "negate", ( assert ) => {
  37987. var a = new Vector2( x, y );
  37988. a.negate();
  37989. assert.ok( a.x == - x, "Passed!" );
  37990. assert.ok( a.y == - y, "Passed!" );
  37991. } );
  37992. QUnit.test( "dot", ( assert ) => {
  37993. var a = new Vector2( x, y );
  37994. var b = new Vector2( - x, - y );
  37995. var c = new Vector2();
  37996. var result = a.dot( b );
  37997. assert.ok( result == ( - x * x - y * y ), "Passed!" );
  37998. var result = a.dot( c );
  37999. assert.ok( result == 0, "Passed!" );
  38000. } );
  38001. QUnit.test( "lengthSq", ( assert ) => {
  38002. assert.ok( false, "everything's gonna be alright" );
  38003. } );
  38004. QUnit.test( "length", ( assert ) => {
  38005. assert.ok( false, "everything's gonna be alright" );
  38006. } );
  38007. QUnit.test( "manhattanLength", ( assert ) => {
  38008. var a = new Vector2( x, 0 );
  38009. var b = new Vector2( 0, - y );
  38010. var c = new Vector2();
  38011. assert.strictEqual( a.manhattanLength(), x, "Positive component" );
  38012. assert.strictEqual( b.manhattanLength(), y, "Negative component" );
  38013. assert.strictEqual( c.manhattanLength(), 0, "Empty component" );
  38014. a.set( x, y );
  38015. assert.strictEqual( a.manhattanLength(), Math.abs( x ) + Math.abs( y ), "Two components" );
  38016. } );
  38017. QUnit.test( "normalize", ( assert ) => {
  38018. var a = new Vector2( x, 0 );
  38019. var b = new Vector2( 0, - y );
  38020. var c = new Vector2();
  38021. a.normalize();
  38022. assert.ok( a.length() == 1, "Passed!" );
  38023. assert.ok( a.x == 1, "Passed!" );
  38024. b.normalize();
  38025. assert.ok( b.length() == 1, "Passed!" );
  38026. assert.ok( b.y == - 1, "Passed!" );
  38027. } );
  38028. QUnit.test( "angle", ( assert ) => {
  38029. assert.ok( false, "everything's gonna be alright" );
  38030. } );
  38031. QUnit.test( "distanceTo", ( assert ) => {
  38032. assert.ok( false, "everything's gonna be alright" );
  38033. } );
  38034. QUnit.test( "distanceToSquared", ( assert ) => {
  38035. assert.ok( false, "everything's gonna be alright" );
  38036. } );
  38037. QUnit.test( "manhattanDistanceTo", ( assert ) => {
  38038. assert.ok( false, "everything's gonna be alright" );
  38039. } );
  38040. QUnit.test( "setLength", ( assert ) => {
  38041. var a = new Vector2( x, 0 );
  38042. assert.ok( a.length() == x, "Passed!" );
  38043. a.setLength( y );
  38044. assert.ok( a.length() == y, "Passed!" );
  38045. var a = new Vector2( 0, 0 );
  38046. assert.ok( a.length() == 0, "Passed!" );
  38047. a.setLength( y );
  38048. assert.ok( a.length() == 0, "Passed!" );
  38049. a.setLength();
  38050. assert.ok( isNaN( a.length() ), "Passed!" );
  38051. } );
  38052. QUnit.test( "lerp", ( assert ) => {
  38053. assert.ok( false, "everything's gonna be alright" );
  38054. } );
  38055. QUnit.test( "lerpVectors", ( assert ) => {
  38056. assert.ok( false, "everything's gonna be alright" );
  38057. } );
  38058. QUnit.test( "equals", ( assert ) => {
  38059. var a = new Vector2( x, 0 );
  38060. var b = new Vector2( 0, - y );
  38061. assert.ok( a.x != b.x, "Passed!" );
  38062. assert.ok( a.y != b.y, "Passed!" );
  38063. assert.ok( ! a.equals( b ), "Passed!" );
  38064. assert.ok( ! b.equals( a ), "Passed!" );
  38065. a.copy( b );
  38066. assert.ok( a.x == b.x, "Passed!" );
  38067. assert.ok( a.y == b.y, "Passed!" );
  38068. assert.ok( a.equals( b ), "Passed!" );
  38069. assert.ok( b.equals( a ), "Passed!" );
  38070. } );
  38071. QUnit.test( "fromArray", ( assert ) => {
  38072. var a = new Vector2();
  38073. var array = [ 1, 2, 3, 4 ];
  38074. a.fromArray( array );
  38075. assert.strictEqual( a.x, 1, "No offset: check x" );
  38076. assert.strictEqual( a.y, 2, "No offset: check y" );
  38077. a.fromArray( array, 2 );
  38078. assert.strictEqual( a.x, 3, "With offset: check x" );
  38079. assert.strictEqual( a.y, 4, "With offset: check y" );
  38080. } );
  38081. QUnit.test( "toArray", ( assert ) => {
  38082. var a = new Vector2( x, y );
  38083. var array = a.toArray();
  38084. assert.strictEqual( array[ 0 ], x, "No array, no offset: check x" );
  38085. assert.strictEqual( array[ 1 ], y, "No array, no offset: check y" );
  38086. var array = [];
  38087. a.toArray( array );
  38088. assert.strictEqual( array[ 0 ], x, "With array, no offset: check x" );
  38089. assert.strictEqual( array[ 1 ], y, "With array, no offset: check y" );
  38090. var array = [];
  38091. a.toArray( array, 1 );
  38092. assert.strictEqual( array[ 0 ], undefined, "With array and offset: check [0]" );
  38093. assert.strictEqual( array[ 1 ], x, "With array and offset: check x" );
  38094. assert.strictEqual( array[ 2 ], y, "With array and offset: check y" );
  38095. } );
  38096. QUnit.test( "fromBufferAttribute", ( assert ) => {
  38097. var a = new Vector2();
  38098. var attr = new BufferAttribute( new Float32Array( [ 1, 2, 3, 4 ] ), 2 );
  38099. a.fromBufferAttribute( attr, 0 );
  38100. assert.strictEqual( a.x, 1, "Offset 0: check x" );
  38101. assert.strictEqual( a.y, 2, "Offset 0: check y" );
  38102. a.fromBufferAttribute( attr, 1 );
  38103. assert.strictEqual( a.x, 3, "Offset 1: check x" );
  38104. assert.strictEqual( a.y, 4, "Offset 1: check y" );
  38105. } );
  38106. QUnit.test( "rotateAround", ( assert ) => {
  38107. assert.ok( false, "everything's gonna be alright" );
  38108. } );
  38109. // TODO (Itee) refactor/split
  38110. QUnit.test( "setX,setY", ( assert ) => {
  38111. var a = new Vector2();
  38112. assert.ok( a.x == 0, "Passed!" );
  38113. assert.ok( a.y == 0, "Passed!" );
  38114. a.setX( x );
  38115. a.setY( y );
  38116. assert.ok( a.x == x, "Passed!" );
  38117. assert.ok( a.y == y, "Passed!" );
  38118. } );
  38119. QUnit.test( "setComponent,getComponent", ( assert ) => {
  38120. var a = new Vector2();
  38121. assert.ok( a.x == 0, "Passed!" );
  38122. assert.ok( a.y == 0, "Passed!" );
  38123. a.setComponent( 0, 1 );
  38124. a.setComponent( 1, 2 );
  38125. assert.ok( a.getComponent( 0 ) == 1, "Passed!" );
  38126. assert.ok( a.getComponent( 1 ) == 2, "Passed!" );
  38127. } );
  38128. QUnit.test( "multiply/divide", ( assert ) => {
  38129. var a = new Vector2( x, y );
  38130. var b = new Vector2( - x, - y );
  38131. a.multiplyScalar( - 2 );
  38132. assert.ok( a.x == x * - 2, "Passed!" );
  38133. assert.ok( a.y == y * - 2, "Passed!" );
  38134. b.multiplyScalar( - 2 );
  38135. assert.ok( b.x == 2 * x, "Passed!" );
  38136. assert.ok( b.y == 2 * y, "Passed!" );
  38137. a.divideScalar( - 2 );
  38138. assert.ok( a.x == x, "Passed!" );
  38139. assert.ok( a.y == y, "Passed!" );
  38140. b.divideScalar( - 2 );
  38141. assert.ok( b.x == - x, "Passed!" );
  38142. assert.ok( b.y == - y, "Passed!" );
  38143. } );
  38144. QUnit.test( "min/max/clamp", ( assert ) => {
  38145. var a = new Vector2( x, y );
  38146. var b = new Vector2( - x, - y );
  38147. var c = new Vector2();
  38148. c.copy( a ).min( b );
  38149. assert.ok( c.x == - x, "Passed!" );
  38150. assert.ok( c.y == - y, "Passed!" );
  38151. c.copy( a ).max( b );
  38152. assert.ok( c.x == x, "Passed!" );
  38153. assert.ok( c.y == y, "Passed!" );
  38154. c.set( - 2 * x, 2 * y );
  38155. c.clamp( b, a );
  38156. assert.ok( c.x == - x, "Passed!" );
  38157. assert.ok( c.y == y, "Passed!" );
  38158. c.set( - 2 * x, 2 * x );
  38159. c.clampScalar( - x, x );
  38160. assert.equal( c.x, - x, "scalar clamp x" );
  38161. assert.equal( c.y, x, "scalar clamp y" );
  38162. } );
  38163. QUnit.test( "rounding", ( assert ) => {
  38164. assert.deepEqual( new Vector2( - 0.1, 0.1 ).floor(), new Vector2( - 1, 0 ), "floor .1" );
  38165. assert.deepEqual( new Vector2( - 0.5, 0.5 ).floor(), new Vector2( - 1, 0 ), "floor .5" );
  38166. assert.deepEqual( new Vector2( - 0.9, 0.9 ).floor(), new Vector2( - 1, 0 ), "floor .9" );
  38167. assert.deepEqual( new Vector2( - 0.1, 0.1 ).ceil(), new Vector2( 0, 1 ), "ceil .1" );
  38168. assert.deepEqual( new Vector2( - 0.5, 0.5 ).ceil(), new Vector2( 0, 1 ), "ceil .5" );
  38169. assert.deepEqual( new Vector2( - 0.9, 0.9 ).ceil(), new Vector2( 0, 1 ), "ceil .9" );
  38170. assert.deepEqual( new Vector2( - 0.1, 0.1 ).round(), new Vector2( 0, 0 ), "round .1" );
  38171. assert.deepEqual( new Vector2( - 0.5, 0.5 ).round(), new Vector2( 0, 1 ), "round .5" );
  38172. assert.deepEqual( new Vector2( - 0.9, 0.9 ).round(), new Vector2( - 1, 1 ), "round .9" );
  38173. assert.deepEqual( new Vector2( - 0.1, 0.1 ).roundToZero(), new Vector2( 0, 0 ), "roundToZero .1" );
  38174. assert.deepEqual( new Vector2( - 0.5, 0.5 ).roundToZero(), new Vector2( 0, 0 ), "roundToZero .5" );
  38175. assert.deepEqual( new Vector2( - 0.9, 0.9 ).roundToZero(), new Vector2( 0, 0 ), "roundToZero .9" );
  38176. assert.deepEqual( new Vector2( - 1.1, 1.1 ).roundToZero(), new Vector2( - 1, 1 ), "roundToZero 1.1" );
  38177. assert.deepEqual( new Vector2( - 1.5, 1.5 ).roundToZero(), new Vector2( - 1, 1 ), "roundToZero 1.5" );
  38178. assert.deepEqual( new Vector2( - 1.9, 1.9 ).roundToZero(), new Vector2( - 1, 1 ), "roundToZero 1.9" );
  38179. } );
  38180. QUnit.test( "length/lengthSq", ( assert ) => {
  38181. var a = new Vector2( x, 0 );
  38182. var b = new Vector2( 0, - y );
  38183. var c = new Vector2();
  38184. assert.ok( a.length() == x, "Passed!" );
  38185. assert.ok( a.lengthSq() == x * x, "Passed!" );
  38186. assert.ok( b.length() == y, "Passed!" );
  38187. assert.ok( b.lengthSq() == y * y, "Passed!" );
  38188. assert.ok( c.length() == 0, "Passed!" );
  38189. assert.ok( c.lengthSq() == 0, "Passed!" );
  38190. a.set( x, y );
  38191. assert.ok( a.length() == Math.sqrt( x * x + y * y ), "Passed!" );
  38192. assert.ok( a.lengthSq() == ( x * x + y * y ), "Passed!" );
  38193. } );
  38194. QUnit.test( "distanceTo/distanceToSquared", ( assert ) => {
  38195. var a = new Vector2( x, 0 );
  38196. var b = new Vector2( 0, - y );
  38197. var c = new Vector2();
  38198. assert.ok( a.distanceTo( c ) == x, "Passed!" );
  38199. assert.ok( a.distanceToSquared( c ) == x * x, "Passed!" );
  38200. assert.ok( b.distanceTo( c ) == y, "Passed!" );
  38201. assert.ok( b.distanceToSquared( c ) == y * y, "Passed!" );
  38202. } );
  38203. QUnit.test( "lerp/clone", ( assert ) => {
  38204. var a = new Vector2( x, 0 );
  38205. var b = new Vector2( 0, - y );
  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, 1 ).equals( b ), "Passed!" );
  38212. } );
  38213. QUnit.test( "setComponent/getComponent exceptions", ( assert ) => {
  38214. var a = new Vector2( 0, 0 );
  38215. assert.throws(
  38216. function () {
  38217. a.setComponent( 2, 0 );
  38218. },
  38219. /index is out of range/,
  38220. "setComponent with an out of range index throws Error"
  38221. );
  38222. assert.throws(
  38223. function () {
  38224. a.getComponent( 2 );
  38225. },
  38226. /index is out of range/,
  38227. "getComponent with an out of range index throws Error"
  38228. );
  38229. } );
  38230. QUnit.test( "setScalar/addScalar/subScalar", ( assert ) => {
  38231. var a = new Vector2( 1, 1 );
  38232. var s = 3;
  38233. a.setScalar( s );
  38234. assert.strictEqual( a.x, s, "setScalar: check x" );
  38235. assert.strictEqual( a.y, s, "setScalar: check y" );
  38236. a.addScalar( s );
  38237. assert.strictEqual( a.x, 2 * s, "addScalar: check x" );
  38238. assert.strictEqual( a.y, 2 * s, "addScalar: check y" );
  38239. a.subScalar( 2 * s );
  38240. assert.strictEqual( a.x, 0, "subScalar: check x" );
  38241. assert.strictEqual( a.y, 0, "subScalar: check y" );
  38242. } );
  38243. QUnit.test( "multiply/divide", ( assert ) => {
  38244. var a = new Vector2( x, y );
  38245. var b = new Vector2( 2 * x, 2 * y );
  38246. var c = new Vector2( 4 * x, 4 * y );
  38247. a.multiply( b );
  38248. assert.strictEqual( a.x, x * b.x, "multiply: check x" );
  38249. assert.strictEqual( a.y, y * b.y, "multiply: check y" );
  38250. b.divide( c );
  38251. assert.strictEqual( b.x, 0.5, "divide: check x" );
  38252. assert.strictEqual( b.y, 0.5, "divide: check y" );
  38253. } );
  38254. } );
  38255. } );
  38256. /**
  38257. * @author bhouston / http://exocortex.com
  38258. * @author TristanVALCKE / https://github.com/Itee
  38259. */
  38260. /* global QUnit */
  38261. QUnit.module( 'Maths', () => {
  38262. QUnit.module.todo( 'Vector3', () => {
  38263. // INSTANCING
  38264. QUnit.test( "Instancing", ( assert ) => {
  38265. var a = new Vector3();
  38266. assert.ok( a.x == 0, "Passed!" );
  38267. assert.ok( a.y == 0, "Passed!" );
  38268. assert.ok( a.z == 0, "Passed!" );
  38269. var a = new Vector3( x, y, z );
  38270. assert.ok( a.x === x, "Passed!" );
  38271. assert.ok( a.y === y, "Passed!" );
  38272. assert.ok( a.z === z, "Passed!" );
  38273. } );
  38274. // PUBLIC STUFF
  38275. QUnit.test( "isVector3", ( assert ) => {
  38276. assert.ok( false, "everything's gonna be alright" );
  38277. } );
  38278. QUnit.test( "set", ( assert ) => {
  38279. var a = new Vector3();
  38280. assert.ok( a.x == 0, "Passed!" );
  38281. assert.ok( a.y == 0, "Passed!" );
  38282. assert.ok( a.z == 0, "Passed!" );
  38283. a.set( x, y, z );
  38284. assert.ok( a.x == x, "Passed!" );
  38285. assert.ok( a.y == y, "Passed!" );
  38286. assert.ok( a.z == z, "Passed!" );
  38287. } );
  38288. QUnit.test( "setScalar", ( assert ) => {
  38289. assert.ok( false, "everything's gonna be alright" );
  38290. } );
  38291. QUnit.test( "setX", ( assert ) => {
  38292. assert.ok( false, "everything's gonna be alright" );
  38293. } );
  38294. QUnit.test( "setY", ( assert ) => {
  38295. assert.ok( false, "everything's gonna be alright" );
  38296. } );
  38297. QUnit.test( "setZ", ( assert ) => {
  38298. assert.ok( false, "everything's gonna be alright" );
  38299. } );
  38300. QUnit.test( "setComponent", ( assert ) => {
  38301. assert.ok( false, "everything's gonna be alright" );
  38302. } );
  38303. QUnit.test( "getComponent", ( assert ) => {
  38304. assert.ok( false, "everything's gonna be alright" );
  38305. } );
  38306. QUnit.test( "clone", ( assert ) => {
  38307. assert.ok( false, "everything's gonna be alright" );
  38308. } );
  38309. QUnit.test( "copy", ( assert ) => {
  38310. var a = new Vector3( x, y, z );
  38311. var b = new Vector3().copy( a );
  38312. assert.ok( b.x == x, "Passed!" );
  38313. assert.ok( b.y == y, "Passed!" );
  38314. assert.ok( b.z == z, "Passed!" );
  38315. // ensure that it is a true copy
  38316. a.x = 0;
  38317. a.y = - 1;
  38318. a.z = - 2;
  38319. assert.ok( b.x == x, "Passed!" );
  38320. assert.ok( b.y == y, "Passed!" );
  38321. assert.ok( b.z == z, "Passed!" );
  38322. } );
  38323. QUnit.test( "add", ( assert ) => {
  38324. var a = new Vector3( x, y, z );
  38325. var b = new Vector3( - x, - y, - z );
  38326. a.add( b );
  38327. assert.ok( a.x == 0, "Passed!" );
  38328. assert.ok( a.y == 0, "Passed!" );
  38329. assert.ok( a.z == 0, "Passed!" );
  38330. var c = new Vector3().addVectors( b, b );
  38331. assert.ok( c.x == - 2 * x, "Passed!" );
  38332. assert.ok( c.y == - 2 * y, "Passed!" );
  38333. assert.ok( c.z == - 2 * z, "Passed!" );
  38334. } );
  38335. QUnit.test( "addScalar", ( assert ) => {
  38336. assert.ok( false, "everything's gonna be alright" );
  38337. } );
  38338. QUnit.test( "addVectors", ( assert ) => {
  38339. assert.ok( false, "everything's gonna be alright" );
  38340. } );
  38341. QUnit.test( "addScaledVector", ( assert ) => {
  38342. var a = new Vector3( x, y, z );
  38343. var b = new Vector3( 2, 3, 4 );
  38344. var s = 3;
  38345. a.addScaledVector( b, s );
  38346. assert.strictEqual( a.x, x + b.x * s, "Check x" );
  38347. assert.strictEqual( a.y, y + b.y * s, "Check y" );
  38348. assert.strictEqual( a.z, z + b.z * s, "Check z" );
  38349. } );
  38350. QUnit.test( "sub", ( assert ) => {
  38351. var a = new Vector3( x, y, z );
  38352. var b = new Vector3( - x, - y, - z );
  38353. a.sub( b );
  38354. assert.ok( a.x == 2 * x, "Passed!" );
  38355. assert.ok( a.y == 2 * y, "Passed!" );
  38356. assert.ok( a.z == 2 * z, "Passed!" );
  38357. var c = new Vector3().subVectors( a, a );
  38358. assert.ok( c.x == 0, "Passed!" );
  38359. assert.ok( c.y == 0, "Passed!" );
  38360. assert.ok( c.z == 0, "Passed!" );
  38361. } );
  38362. QUnit.test( "subScalar", ( assert ) => {
  38363. assert.ok( false, "everything's gonna be alright" );
  38364. } );
  38365. QUnit.test( "subVectors", ( assert ) => {
  38366. assert.ok( false, "everything's gonna be alright" );
  38367. } );
  38368. QUnit.test( "multiply", ( assert ) => {
  38369. assert.ok( false, "everything's gonna be alright" );
  38370. } );
  38371. QUnit.test( "multiplyScalar", ( assert ) => {
  38372. assert.ok( false, "everything's gonna be alright" );
  38373. } );
  38374. QUnit.test( "multiplyVectors", ( assert ) => {
  38375. var a = new Vector3( x, y, z );
  38376. var b = new Vector3( 2, 3, - 5 );
  38377. var c = new Vector3().multiplyVectors( a, b );
  38378. assert.strictEqual( c.x, x * 2, "Check x" );
  38379. assert.strictEqual( c.y, y * 3, "Check y" );
  38380. assert.strictEqual( c.z, z * - 5, "Check z" );
  38381. } );
  38382. QUnit.test( "applyEuler", ( assert ) => {
  38383. var a = new Vector3( x, y, z );
  38384. var euler = new Euler( 90, - 45, 0 );
  38385. var expected = new Vector3( - 2.352970120501014, - 4.7441750936226645, 0.9779234597246458 );
  38386. a.applyEuler( euler );
  38387. assert.ok( Math.abs( a.x - expected.x ) <= eps, "Check x" );
  38388. assert.ok( Math.abs( a.y - expected.y ) <= eps, "Check y" );
  38389. assert.ok( Math.abs( a.z - expected.z ) <= eps, "Check z" );
  38390. } );
  38391. QUnit.test( "applyAxisAngle", ( assert ) => {
  38392. var a = new Vector3( x, y, z );
  38393. var axis = new Vector3( 0, 1, 0 );
  38394. var angle = Math.PI / 4.0;
  38395. var expected = new Vector3( 3 * Math.sqrt( 2 ), 3, Math.sqrt( 2 ) );
  38396. a.applyAxisAngle( axis, angle );
  38397. assert.ok( Math.abs( a.x - expected.x ) <= eps, "Check x" );
  38398. assert.ok( Math.abs( a.y - expected.y ) <= eps, "Check y" );
  38399. assert.ok( Math.abs( a.z - expected.z ) <= eps, "Check z" );
  38400. } );
  38401. QUnit.test( "applyMatrix3", ( assert ) => {
  38402. var a = new Vector3( x, y, z );
  38403. var m = new Matrix3().set( 2, 3, 5, 7, 11, 13, 17, 19, 23 );
  38404. a.applyMatrix3( m );
  38405. assert.strictEqual( a.x, 33, "Check x" );
  38406. assert.strictEqual( a.y, 99, "Check y" );
  38407. assert.strictEqual( a.z, 183, "Check z" );
  38408. } );
  38409. QUnit.test( "applyMatrix4", ( assert ) => {
  38410. var a = new Vector3( x, y, z );
  38411. var b = new Vector4( x, y, z, 1 );
  38412. var m = new Matrix4().makeRotationX( Math.PI );
  38413. a.applyMatrix4( m );
  38414. b.applyMatrix4( m );
  38415. assert.ok( a.x == b.x / b.w, "Passed!" );
  38416. assert.ok( a.y == b.y / b.w, "Passed!" );
  38417. assert.ok( a.z == b.z / b.w, "Passed!" );
  38418. var m = new Matrix4().makeTranslation( 3, 2, 1 );
  38419. a.applyMatrix4( m );
  38420. b.applyMatrix4( m );
  38421. assert.ok( a.x == b.x / b.w, "Passed!" );
  38422. assert.ok( a.y == b.y / b.w, "Passed!" );
  38423. assert.ok( a.z == b.z / b.w, "Passed!" );
  38424. var m = new Matrix4().set(
  38425. 1, 0, 0, 0,
  38426. 0, 1, 0, 0,
  38427. 0, 0, 1, 0,
  38428. 0, 0, 1, 0
  38429. );
  38430. a.applyMatrix4( m );
  38431. b.applyMatrix4( m );
  38432. assert.ok( a.x == b.x / b.w, "Passed!" );
  38433. assert.ok( a.y == b.y / b.w, "Passed!" );
  38434. assert.ok( a.z == b.z / b.w, "Passed!" );
  38435. } );
  38436. QUnit.test( "applyQuaternion", ( assert ) => {
  38437. var a = new Vector3( x, y, z );
  38438. a.applyQuaternion( new Quaternion() );
  38439. assert.strictEqual( a.x, x, "Identity rotation: check x" );
  38440. assert.strictEqual( a.y, y, "Identity rotation: check y" );
  38441. assert.strictEqual( a.z, z, "Identity rotation: check z" );
  38442. a.applyQuaternion( new Quaternion( x, y, z, w ) );
  38443. assert.strictEqual( a.x, 108, "Normal rotation: check x" );
  38444. assert.strictEqual( a.y, 162, "Normal rotation: check y" );
  38445. assert.strictEqual( a.z, 216, "Normal rotation: check z" );
  38446. } );
  38447. QUnit.test( "project", ( assert ) => {
  38448. assert.ok( false, "everything's gonna be alright" );
  38449. } );
  38450. QUnit.test( "unproject", ( assert ) => {
  38451. assert.ok( false, "everything's gonna be alright" );
  38452. } );
  38453. QUnit.test( "transformDirection", ( assert ) => {
  38454. var a = new Vector3( x, y, z );
  38455. var m = new Matrix4();
  38456. var transformed = new Vector3( 0.3713906763541037, 0.5570860145311556, 0.7427813527082074 );
  38457. a.transformDirection( m );
  38458. assert.ok( Math.abs( a.x - transformed.x ) <= eps, "Check x" );
  38459. assert.ok( Math.abs( a.y - transformed.y ) <= eps, "Check y" );
  38460. assert.ok( Math.abs( a.z - transformed.z ) <= eps, "Check z" );
  38461. } );
  38462. QUnit.test( "divide", ( assert ) => {
  38463. assert.ok( false, "everything's gonna be alright" );
  38464. } );
  38465. QUnit.test( "divideScalar", ( assert ) => {
  38466. assert.ok( false, "everything's gonna be alright" );
  38467. } );
  38468. QUnit.test( "min", ( assert ) => {
  38469. assert.ok( false, "everything's gonna be alright" );
  38470. } );
  38471. QUnit.test( "max", ( assert ) => {
  38472. assert.ok( false, "everything's gonna be alright" );
  38473. } );
  38474. QUnit.test( "clamp", ( assert ) => {
  38475. assert.ok( false, "everything's gonna be alright" );
  38476. } );
  38477. QUnit.test( "clampScalar", ( assert ) => {
  38478. var a = new Vector3( - 0.01, 0.5, 1.5 );
  38479. var clamped = new Vector3( 0.1, 0.5, 1.0 );
  38480. a.clampScalar( 0.1, 1.0 );
  38481. assert.ok( Math.abs( a.x - clamped.x ) <= 0.001, "Check x" );
  38482. assert.ok( Math.abs( a.y - clamped.y ) <= 0.001, "Check y" );
  38483. assert.ok( Math.abs( a.z - clamped.z ) <= 0.001, "Check z" );
  38484. } );
  38485. QUnit.test( "clampLength", ( assert ) => {
  38486. assert.ok( false, "everything's gonna be alright" );
  38487. } );
  38488. QUnit.test( "floor", ( assert ) => {
  38489. assert.ok( false, "everything's gonna be alright" );
  38490. } );
  38491. QUnit.test( "ceil", ( assert ) => {
  38492. assert.ok( false, "everything's gonna be alright" );
  38493. } );
  38494. QUnit.test( "round", ( assert ) => {
  38495. assert.ok( false, "everything's gonna be alright" );
  38496. } );
  38497. QUnit.test( "roundToZero", ( assert ) => {
  38498. assert.ok( false, "everything's gonna be alright" );
  38499. } );
  38500. QUnit.test( "negate", ( assert ) => {
  38501. var a = new Vector3( x, y, z );
  38502. a.negate();
  38503. assert.ok( a.x == - x, "Passed!" );
  38504. assert.ok( a.y == - y, "Passed!" );
  38505. assert.ok( a.z == - z, "Passed!" );
  38506. } );
  38507. QUnit.test( "dot", ( assert ) => {
  38508. var a = new Vector3( x, y, z );
  38509. var b = new Vector3( - x, - y, - z );
  38510. var c = new Vector3();
  38511. var result = a.dot( b );
  38512. assert.ok( result == ( - x * x - y * y - z * z ), "Passed!" );
  38513. var result = a.dot( c );
  38514. assert.ok( result == 0, "Passed!" );
  38515. } );
  38516. QUnit.test( "lengthSq", ( assert ) => {
  38517. assert.ok( false, "everything's gonna be alright" );
  38518. } );
  38519. QUnit.test( "length", ( assert ) => {
  38520. assert.ok( false, "everything's gonna be alright" );
  38521. } );
  38522. QUnit.test( "manhattanLength", ( assert ) => {
  38523. var a = new Vector3( x, 0, 0 );
  38524. var b = new Vector3( 0, - y, 0 );
  38525. var c = new Vector3( 0, 0, z );
  38526. var d = new Vector3();
  38527. assert.ok( a.manhattanLength() == x, "Positive x" );
  38528. assert.ok( b.manhattanLength() == y, "Negative y" );
  38529. assert.ok( c.manhattanLength() == z, "Positive z" );
  38530. assert.ok( d.manhattanLength() == 0, "Empty initialization" );
  38531. a.set( x, y, z );
  38532. assert.ok( a.manhattanLength() == Math.abs( x ) + Math.abs( y ) + Math.abs( z ), "All components" );
  38533. } );
  38534. QUnit.test( "normalize", ( assert ) => {
  38535. var a = new Vector3( x, 0, 0 );
  38536. var b = new Vector3( 0, - y, 0 );
  38537. var c = new Vector3( 0, 0, z );
  38538. a.normalize();
  38539. assert.ok( a.length() == 1, "Passed!" );
  38540. assert.ok( a.x == 1, "Passed!" );
  38541. b.normalize();
  38542. assert.ok( b.length() == 1, "Passed!" );
  38543. assert.ok( b.y == - 1, "Passed!" );
  38544. c.normalize();
  38545. assert.ok( c.length() == 1, "Passed!" );
  38546. assert.ok( c.z == 1, "Passed!" );
  38547. } );
  38548. QUnit.test( "setLength", ( assert ) => {
  38549. var a = new Vector3( x, 0, 0 );
  38550. assert.ok( a.length() == x, "Passed!" );
  38551. a.setLength( y );
  38552. assert.ok( a.length() == y, "Passed!" );
  38553. var a = new Vector3( 0, 0, 0 );
  38554. assert.ok( a.length() == 0, "Passed!" );
  38555. a.setLength( y );
  38556. assert.ok( a.length() == 0, "Passed!" );
  38557. a.setLength();
  38558. assert.ok( isNaN( a.length() ), "Passed!" );
  38559. } );
  38560. QUnit.test( "lerp", ( assert ) => {
  38561. assert.ok( false, "everything's gonna be alright" );
  38562. } );
  38563. QUnit.test( "lerpVectors", ( assert ) => {
  38564. assert.ok( false, "everything's gonna be alright" );
  38565. } );
  38566. QUnit.test( "cross", ( assert ) => {
  38567. var a = new Vector3( x, y, z );
  38568. var b = new Vector3( 2 * x, - y, 0.5 * z );
  38569. var crossed = new Vector3( 18, 12, - 18 );
  38570. a.cross( b );
  38571. assert.ok( Math.abs( a.x - crossed.x ) <= eps, "Check x" );
  38572. assert.ok( Math.abs( a.y - crossed.y ) <= eps, "Check y" );
  38573. assert.ok( Math.abs( a.z - crossed.z ) <= eps, "Check z" );
  38574. } );
  38575. QUnit.test( "crossVectors", ( assert ) => {
  38576. var a = new Vector3( x, y, z );
  38577. var b = new Vector3( x, - y, z );
  38578. var c = new Vector3();
  38579. var crossed = new Vector3( 24, 0, - 12 );
  38580. c.crossVectors( a, b );
  38581. assert.ok( Math.abs( c.x - crossed.x ) <= eps, "Check x" );
  38582. assert.ok( Math.abs( c.y - crossed.y ) <= eps, "Check y" );
  38583. assert.ok( Math.abs( c.z - crossed.z ) <= eps, "Check z" );
  38584. } );
  38585. QUnit.test( "projectOnVector", ( assert ) => {
  38586. var a = new Vector3( 1, 0, 0 );
  38587. var b = new Vector3();
  38588. var normal = new Vector3( 10, 0, 0 );
  38589. assert.ok( b.copy( a ).projectOnVector( normal ).equals( new Vector3( 1, 0, 0 ) ), "Passed!" );
  38590. a.set( 0, 1, 0 );
  38591. assert.ok( b.copy( a ).projectOnVector( normal ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
  38592. a.set( 0, 0, - 1 );
  38593. assert.ok( b.copy( a ).projectOnVector( normal ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
  38594. a.set( - 1, 0, 0 );
  38595. assert.ok( b.copy( a ).projectOnVector( normal ).equals( new Vector3( - 1, 0, 0 ) ), "Passed!" );
  38596. } );
  38597. QUnit.test( "projectOnPlane", ( assert ) => {
  38598. var a = new Vector3( 1, 0, 0 );
  38599. var b = new Vector3();
  38600. var normal = new Vector3( 1, 0, 0 );
  38601. assert.ok( b.copy( a ).projectOnPlane( normal ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
  38602. a.set( 0, 1, 0 );
  38603. assert.ok( b.copy( a ).projectOnPlane( normal ).equals( new Vector3( 0, 1, 0 ) ), "Passed!" );
  38604. a.set( 0, 0, - 1 );
  38605. assert.ok( b.copy( a ).projectOnPlane( normal ).equals( new Vector3( 0, 0, - 1 ) ), "Passed!" );
  38606. a.set( - 1, 0, 0 );
  38607. assert.ok( b.copy( a ).projectOnPlane( normal ).equals( new Vector3( 0, 0, 0 ) ), "Passed!" );
  38608. } );
  38609. QUnit.test( "reflect", ( assert ) => {
  38610. var a = new Vector3();
  38611. var normal = new Vector3( 0, 1, 0 );
  38612. var b = new Vector3();
  38613. a.set( 0, - 1, 0 );
  38614. assert.ok( b.copy( a ).reflect( normal ).equals( new Vector3( 0, 1, 0 ) ), "Passed!" );
  38615. a.set( 1, - 1, 0 );
  38616. assert.ok( b.copy( a ).reflect( normal ).equals( new Vector3( 1, 1, 0 ) ), "Passed!" );
  38617. a.set( 1, - 1, 0 );
  38618. normal.set( 0, - 1, 0 );
  38619. assert.ok( b.copy( a ).reflect( normal ).equals( new Vector3( 1, 1, 0 ) ), "Passed!" );
  38620. } );
  38621. QUnit.test( "angleTo", ( assert ) => {
  38622. var a = new Vector3( 0, - 0.18851655680720186, 0.9820700116639124 );
  38623. var b = new Vector3( 0, 0.18851655680720186, - 0.9820700116639124 );
  38624. assert.equal( a.angleTo( a ), 0 );
  38625. assert.equal( a.angleTo( b ), Math.PI );
  38626. var x$$1 = new Vector3( 1, 0, 0 );
  38627. var y$$1 = new Vector3( 0, 1, 0 );
  38628. var z$$1 = new Vector3( 0, 0, 1 );
  38629. assert.equal( x$$1.angleTo( y$$1 ), Math.PI / 2 );
  38630. assert.equal( x$$1.angleTo( z$$1 ), Math.PI / 2 );
  38631. assert.equal( z$$1.angleTo( x$$1 ), Math.PI / 2 );
  38632. assert.ok( Math.abs( x$$1.angleTo( new Vector3( 1, 1, 0 ) ) - ( Math.PI / 4 ) ) < 0.0000001 );
  38633. } );
  38634. QUnit.test( "distanceTo", ( assert ) => {
  38635. assert.ok( false, "everything's gonna be alright" );
  38636. } );
  38637. QUnit.test( "distanceToSquared", ( assert ) => {
  38638. assert.ok( false, "everything's gonna be alright" );
  38639. } );
  38640. QUnit.test( "manhattanDistanceTo", ( assert ) => {
  38641. assert.ok( false, "everything's gonna be alright" );
  38642. } );
  38643. QUnit.test( "setFromSpherical", ( assert ) => {
  38644. var a = new Vector3();
  38645. var phi = Math.acos( - 0.5 );
  38646. var theta = Math.sqrt( Math.PI ) * phi;
  38647. var sph = new Spherical( 10, phi, theta );
  38648. var expected = new Vector3( - 4.677914006701843, - 5, - 7.288149322420796 );
  38649. a.setFromSpherical( sph );
  38650. assert.ok( Math.abs( a.x - expected.x ) <= eps, "Check x" );
  38651. assert.ok( Math.abs( a.y - expected.y ) <= eps, "Check y" );
  38652. assert.ok( Math.abs( a.z - expected.z ) <= eps, "Check z" );
  38653. } );
  38654. QUnit.test( "setFromCylindrical", ( assert ) => {
  38655. var a = new Vector3();
  38656. var cyl = new Cylindrical( 10, Math.PI * 0.125, 20 );
  38657. var expected = new Vector3( 3.826834323650898, 20, 9.238795325112868 );
  38658. a.setFromCylindrical( cyl );
  38659. assert.ok( Math.abs( a.x - expected.x ) <= eps, "Check x" );
  38660. assert.ok( Math.abs( a.y - expected.y ) <= eps, "Check y" );
  38661. assert.ok( Math.abs( a.z - expected.z ) <= eps, "Check z" );
  38662. } );
  38663. QUnit.test( "setFromMatrixPosition", ( assert ) => {
  38664. var a = new Vector3();
  38665. var m = new Matrix4().set( 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53 );
  38666. a.setFromMatrixPosition( m );
  38667. assert.strictEqual( a.x, 7, "Check x" );
  38668. assert.strictEqual( a.y, 19, "Check y" );
  38669. assert.strictEqual( a.z, 37, "Check z" );
  38670. } );
  38671. QUnit.test( "setFromMatrixScale", ( assert ) => {
  38672. var a = new Vector3();
  38673. var m = new Matrix4().set( 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53 );
  38674. var expected = new Vector3( 25.573423705088842, 31.921779399024736, 35.70714214271425 );
  38675. a.setFromMatrixScale( m );
  38676. assert.ok( Math.abs( a.x - expected.x ) <= eps, "Check x" );
  38677. assert.ok( Math.abs( a.y - expected.y ) <= eps, "Check y" );
  38678. assert.ok( Math.abs( a.z - expected.z ) <= eps, "Check z" );
  38679. } );
  38680. QUnit.test( "setFromMatrixColumn", ( assert ) => {
  38681. var a = new Vector3();
  38682. var m = new Matrix4().set( 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53 );
  38683. a.setFromMatrixColumn( m, 0 );
  38684. assert.strictEqual( a.x, 2, "Index 0: check x" );
  38685. assert.strictEqual( a.y, 11, "Index 0: check y" );
  38686. assert.strictEqual( a.z, 23, "Index 0: check z" );
  38687. a.setFromMatrixColumn( m, 2 );
  38688. assert.strictEqual( a.x, 5, "Index 2: check x" );
  38689. assert.strictEqual( a.y, 17, "Index 2: check y" );
  38690. assert.strictEqual( a.z, 31, "Index 2: check z" );
  38691. } );
  38692. QUnit.test( "equals", ( assert ) => {
  38693. var a = new Vector3( x, 0, z );
  38694. var b = new Vector3( 0, - y, 0 );
  38695. assert.ok( a.x != b.x, "Passed!" );
  38696. assert.ok( a.y != b.y, "Passed!" );
  38697. assert.ok( a.z != b.z, "Passed!" );
  38698. assert.ok( ! a.equals( b ), "Passed!" );
  38699. assert.ok( ! b.equals( a ), "Passed!" );
  38700. a.copy( b );
  38701. assert.ok( a.x == b.x, "Passed!" );
  38702. assert.ok( a.y == b.y, "Passed!" );
  38703. assert.ok( a.z == b.z, "Passed!" );
  38704. assert.ok( a.equals( b ), "Passed!" );
  38705. assert.ok( b.equals( a ), "Passed!" );
  38706. } );
  38707. QUnit.test( "fromArray", ( assert ) => {
  38708. var a = new Vector3();
  38709. var array = [ 1, 2, 3, 4, 5, 6 ];
  38710. a.fromArray( array );
  38711. assert.strictEqual( a.x, 1, "No offset: check x" );
  38712. assert.strictEqual( a.y, 2, "No offset: check y" );
  38713. assert.strictEqual( a.z, 3, "No offset: check z" );
  38714. a.fromArray( array, 3 );
  38715. assert.strictEqual( a.x, 4, "With offset: check x" );
  38716. assert.strictEqual( a.y, 5, "With offset: check y" );
  38717. assert.strictEqual( a.z, 6, "With offset: check z" );
  38718. } );
  38719. QUnit.test( "toArray", ( assert ) => {
  38720. var a = new Vector3( x, y, z );
  38721. var array = a.toArray();
  38722. assert.strictEqual( array[ 0 ], x, "No array, no offset: check x" );
  38723. assert.strictEqual( array[ 1 ], y, "No array, no offset: check y" );
  38724. assert.strictEqual( array[ 2 ], z, "No array, no offset: check z" );
  38725. var array = [];
  38726. a.toArray( array );
  38727. assert.strictEqual( array[ 0 ], x, "With array, no offset: check x" );
  38728. assert.strictEqual( array[ 1 ], y, "With array, no offset: check y" );
  38729. assert.strictEqual( array[ 2 ], z, "With array, no offset: check z" );
  38730. var array = [];
  38731. a.toArray( array, 1 );
  38732. assert.strictEqual( array[ 0 ], undefined, "With array and offset: check [0]" );
  38733. assert.strictEqual( array[ 1 ], x, "With array and offset: check x" );
  38734. assert.strictEqual( array[ 2 ], y, "With array and offset: check y" );
  38735. assert.strictEqual( array[ 3 ], z, "With array and offset: check z" );
  38736. } );
  38737. QUnit.test( "fromBufferAttribute", ( assert ) => {
  38738. var a = new Vector3();
  38739. var attr = new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 5, 6 ] ), 3 );
  38740. a.fromBufferAttribute( attr, 0 );
  38741. assert.strictEqual( a.x, 1, "Offset 0: check x" );
  38742. assert.strictEqual( a.y, 2, "Offset 0: check y" );
  38743. assert.strictEqual( a.z, 3, "Offset 0: check z" );
  38744. a.fromBufferAttribute( attr, 1 );
  38745. assert.strictEqual( a.x, 4, "Offset 1: check x" );
  38746. assert.strictEqual( a.y, 5, "Offset 1: check y" );
  38747. assert.strictEqual( a.z, 6, "Offset 1: check z" );
  38748. } );
  38749. // TODO (Itee) refactor/split
  38750. QUnit.test( "setX,setY,setZ", ( assert ) => {
  38751. var a = new Vector3();
  38752. assert.ok( a.x == 0, "Passed!" );
  38753. assert.ok( a.y == 0, "Passed!" );
  38754. assert.ok( a.z == 0, "Passed!" );
  38755. a.setX( x );
  38756. a.setY( y );
  38757. a.setZ( z );
  38758. assert.ok( a.x == x, "Passed!" );
  38759. assert.ok( a.y == y, "Passed!" );
  38760. assert.ok( a.z == z, "Passed!" );
  38761. } );
  38762. QUnit.test( "setComponent,getComponent", ( assert ) => {
  38763. var a = new Vector3();
  38764. assert.ok( a.x == 0, "Passed!" );
  38765. assert.ok( a.y == 0, "Passed!" );
  38766. assert.ok( a.z == 0, "Passed!" );
  38767. a.setComponent( 0, 1 );
  38768. a.setComponent( 1, 2 );
  38769. a.setComponent( 2, 3 );
  38770. assert.ok( a.getComponent( 0 ) == 1, "Passed!" );
  38771. assert.ok( a.getComponent( 1 ) == 2, "Passed!" );
  38772. assert.ok( a.getComponent( 2 ) == 3, "Passed!" );
  38773. } );
  38774. QUnit.test( "setComponent/getComponent exceptions", ( assert ) => {
  38775. var a = new Vector3();
  38776. assert.throws(
  38777. function () {
  38778. a.setComponent( 3, 0 );
  38779. },
  38780. /index is out of range/,
  38781. "setComponent with an out of range index throws Error"
  38782. );
  38783. assert.throws(
  38784. function () {
  38785. a.getComponent( 3 );
  38786. },
  38787. /index is out of range/,
  38788. "getComponent with an out of range index throws Error"
  38789. );
  38790. } );
  38791. QUnit.test( "min/max/clamp", ( assert ) => {
  38792. var a = new Vector3( x, y, z );
  38793. var b = new Vector3( - x, - y, - z );
  38794. var c = new Vector3();
  38795. c.copy( a ).min( b );
  38796. assert.ok( c.x == - x, "Passed!" );
  38797. assert.ok( c.y == - y, "Passed!" );
  38798. assert.ok( c.z == - z, "Passed!" );
  38799. c.copy( a ).max( b );
  38800. assert.ok( c.x == x, "Passed!" );
  38801. assert.ok( c.y == y, "Passed!" );
  38802. assert.ok( c.z == z, "Passed!" );
  38803. c.set( - 2 * x, 2 * y, - 2 * z );
  38804. c.clamp( b, a );
  38805. assert.ok( c.x == - x, "Passed!" );
  38806. assert.ok( c.y == y, "Passed!" );
  38807. assert.ok( c.z == - z, "Passed!" );
  38808. } );
  38809. QUnit.test( "distanceTo/distanceToSquared", ( assert ) => {
  38810. var a = new Vector3( x, 0, 0 );
  38811. var b = new Vector3( 0, - y, 0 );
  38812. var c = new Vector3( 0, 0, z );
  38813. var d = new Vector3();
  38814. assert.ok( a.distanceTo( d ) == x, "Passed!" );
  38815. assert.ok( a.distanceToSquared( d ) == x * x, "Passed!" );
  38816. assert.ok( b.distanceTo( d ) == y, "Passed!" );
  38817. assert.ok( b.distanceToSquared( d ) == y * y, "Passed!" );
  38818. assert.ok( c.distanceTo( d ) == z, "Passed!" );
  38819. assert.ok( c.distanceToSquared( d ) == z * z, "Passed!" );
  38820. } );
  38821. QUnit.test( "setScalar/addScalar/subScalar", ( assert ) => {
  38822. var a = new Vector3();
  38823. var s = 3;
  38824. a.setScalar( s );
  38825. assert.strictEqual( a.x, s, "setScalar: check x" );
  38826. assert.strictEqual( a.y, s, "setScalar: check y" );
  38827. assert.strictEqual( a.z, s, "setScalar: check z" );
  38828. a.addScalar( s );
  38829. assert.strictEqual( a.x, 2 * s, "addScalar: check x" );
  38830. assert.strictEqual( a.y, 2 * s, "addScalar: check y" );
  38831. assert.strictEqual( a.z, 2 * s, "addScalar: check z" );
  38832. a.subScalar( 2 * s );
  38833. assert.strictEqual( a.x, 0, "subScalar: check x" );
  38834. assert.strictEqual( a.y, 0, "subScalar: check y" );
  38835. assert.strictEqual( a.z, 0, "subScalar: check z" );
  38836. } );
  38837. QUnit.test( "multiply/divide", ( assert ) => {
  38838. var a = new Vector3( x, y, z );
  38839. var b = new Vector3( 2 * x, 2 * y, 2 * z );
  38840. var c = new Vector3( 4 * x, 4 * y, 4 * z );
  38841. a.multiply( b );
  38842. assert.strictEqual( a.x, x * b.x, "multiply: check x" );
  38843. assert.strictEqual( a.y, y * b.y, "multiply: check y" );
  38844. assert.strictEqual( a.z, z * b.z, "multiply: check z" );
  38845. b.divide( c );
  38846. assert.ok( Math.abs( b.x - 0.5 ) <= eps, "divide: check z" );
  38847. assert.ok( Math.abs( b.y - 0.5 ) <= eps, "divide: check z" );
  38848. assert.ok( Math.abs( b.z - 0.5 ) <= eps, "divide: check z" );
  38849. } );
  38850. QUnit.test( "multiply/divide", ( assert ) => {
  38851. var a = new Vector3( x, y, z );
  38852. var b = new Vector3( - x, - y, - z );
  38853. a.multiplyScalar( - 2 );
  38854. assert.ok( a.x == x * - 2, "Passed!" );
  38855. assert.ok( a.y == y * - 2, "Passed!" );
  38856. assert.ok( a.z == z * - 2, "Passed!" );
  38857. b.multiplyScalar( - 2 );
  38858. assert.ok( b.x == 2 * x, "Passed!" );
  38859. assert.ok( b.y == 2 * y, "Passed!" );
  38860. assert.ok( b.z == 2 * z, "Passed!" );
  38861. a.divideScalar( - 2 );
  38862. assert.ok( a.x == x, "Passed!" );
  38863. assert.ok( a.y == y, "Passed!" );
  38864. assert.ok( a.z == z, "Passed!" );
  38865. b.divideScalar( - 2 );
  38866. assert.ok( b.x == - x, "Passed!" );
  38867. assert.ok( b.y == - y, "Passed!" );
  38868. assert.ok( b.z == - z, "Passed!" );
  38869. } );
  38870. QUnit.test( "project/unproject", ( assert ) => {
  38871. var a = new Vector3( x, y, z );
  38872. var camera = new PerspectiveCamera( 75, 16 / 9, 0.1, 300.0 );
  38873. var projected = new Vector3( - 0.36653213611158914, - 0.9774190296309043, 1.0506835611870624 );
  38874. a.project( camera );
  38875. assert.ok( Math.abs( a.x - projected.x ) <= eps, "project: check x" );
  38876. assert.ok( Math.abs( a.y - projected.y ) <= eps, "project: check y" );
  38877. assert.ok( Math.abs( a.z - projected.z ) <= eps, "project: check z" );
  38878. a.unproject( camera );
  38879. assert.ok( Math.abs( a.x - x ) <= eps, "unproject: check x" );
  38880. assert.ok( Math.abs( a.y - y ) <= eps, "unproject: check y" );
  38881. assert.ok( Math.abs( a.z - z ) <= eps, "unproject: check z" );
  38882. } );
  38883. QUnit.test( "length/lengthSq", ( assert ) => {
  38884. var a = new Vector3( x, 0, 0 );
  38885. var b = new Vector3( 0, - y, 0 );
  38886. var c = new Vector3( 0, 0, z );
  38887. var d = new Vector3();
  38888. assert.ok( a.length() == x, "Passed!" );
  38889. assert.ok( a.lengthSq() == x * x, "Passed!" );
  38890. assert.ok( b.length() == y, "Passed!" );
  38891. assert.ok( b.lengthSq() == y * y, "Passed!" );
  38892. assert.ok( c.length() == z, "Passed!" );
  38893. assert.ok( c.lengthSq() == z * z, "Passed!" );
  38894. assert.ok( d.length() == 0, "Passed!" );
  38895. assert.ok( d.lengthSq() == 0, "Passed!" );
  38896. a.set( x, y, z );
  38897. assert.ok( a.length() == Math.sqrt( x * x + y * y + z * z ), "Passed!" );
  38898. assert.ok( a.lengthSq() == ( x * x + y * y + z * z ), "Passed!" );
  38899. } );
  38900. QUnit.test( "lerp/clone", ( assert ) => {
  38901. var a = new Vector3( x, 0, z );
  38902. var b = new Vector3( 0, - y, 0 );
  38903. assert.ok( a.lerp( a, 0 ).equals( a.lerp( a, 0.5 ) ), "Passed!" );
  38904. assert.ok( a.lerp( a, 0 ).equals( a.lerp( a, 1 ) ), "Passed!" );
  38905. assert.ok( a.clone().lerp( b, 0 ).equals( a ), "Passed!" );
  38906. assert.ok( a.clone().lerp( b, 0.5 ).x == x * 0.5, "Passed!" );
  38907. assert.ok( a.clone().lerp( b, 0.5 ).y == - y * 0.5, "Passed!" );
  38908. assert.ok( a.clone().lerp( b, 0.5 ).z == z * 0.5, "Passed!" );
  38909. assert.ok( a.clone().lerp( b, 1 ).equals( b ), "Passed!" );
  38910. } );
  38911. } );
  38912. } );
  38913. /**
  38914. * @author bhouston / http://exocortex.com
  38915. * @author TristanVALCKE / https://github.com/Itee
  38916. */
  38917. /* global QUnit */
  38918. QUnit.module( 'Maths', () => {
  38919. QUnit.module.todo( 'Vector4', () => {
  38920. // INSTANCING
  38921. QUnit.test( "Instancing", ( assert ) => {
  38922. var a = new Vector4();
  38923. assert.ok( a.x == 0, "Passed!" );
  38924. assert.ok( a.y == 0, "Passed!" );
  38925. assert.ok( a.z == 0, "Passed!" );
  38926. assert.ok( a.w == 1, "Passed!" );
  38927. var a = new Vector4( x, y, z, w );
  38928. assert.ok( a.x === x, "Passed!" );
  38929. assert.ok( a.y === y, "Passed!" );
  38930. assert.ok( a.z === z, "Passed!" );
  38931. assert.ok( a.w === w, "Passed!" );
  38932. } );
  38933. // PUBLIC STUFF
  38934. QUnit.test( "isVector4", ( assert ) => {
  38935. assert.ok( false, "everything's gonna be alright" );
  38936. } );
  38937. QUnit.test( "set", ( assert ) => {
  38938. var a = new Vector4();
  38939. assert.ok( a.x == 0, "Passed!" );
  38940. assert.ok( a.y == 0, "Passed!" );
  38941. assert.ok( a.z == 0, "Passed!" );
  38942. assert.ok( a.w == 1, "Passed!" );
  38943. a.set( x, y, z, w );
  38944. assert.ok( a.x == x, "Passed!" );
  38945. assert.ok( a.y == y, "Passed!" );
  38946. assert.ok( a.z == z, "Passed!" );
  38947. assert.ok( a.w == w, "Passed!" );
  38948. } );
  38949. QUnit.test( "setScalar", ( assert ) => {
  38950. assert.ok( false, "everything's gonna be alright" );
  38951. } );
  38952. QUnit.test( "setX", ( assert ) => {
  38953. assert.ok( false, "everything's gonna be alright" );
  38954. } );
  38955. QUnit.test( "setY", ( assert ) => {
  38956. assert.ok( false, "everything's gonna be alright" );
  38957. } );
  38958. QUnit.test( "setZ", ( assert ) => {
  38959. assert.ok( false, "everything's gonna be alright" );
  38960. } );
  38961. QUnit.test( "setW", ( assert ) => {
  38962. assert.ok( false, "everything's gonna be alright" );
  38963. } );
  38964. QUnit.test( "setComponent", ( assert ) => {
  38965. assert.ok( false, "everything's gonna be alright" );
  38966. } );
  38967. QUnit.test( "getComponent", ( assert ) => {
  38968. assert.ok( false, "everything's gonna be alright" );
  38969. } );
  38970. QUnit.test( "clone", ( assert ) => {
  38971. assert.ok( false, "everything's gonna be alright" );
  38972. } );
  38973. QUnit.test( "copy", ( assert ) => {
  38974. var a = new Vector4( x, y, z, w );
  38975. var b = new Vector4().copy( a );
  38976. assert.ok( b.x == x, "Passed!" );
  38977. assert.ok( b.y == y, "Passed!" );
  38978. assert.ok( b.z == z, "Passed!" );
  38979. assert.ok( b.w == w, "Passed!" );
  38980. // ensure that it is a true copy
  38981. a.x = 0;
  38982. a.y = - 1;
  38983. a.z = - 2;
  38984. a.w = - 3;
  38985. assert.ok( b.x == x, "Passed!" );
  38986. assert.ok( b.y == y, "Passed!" );
  38987. assert.ok( b.z == z, "Passed!" );
  38988. assert.ok( b.w == w, "Passed!" );
  38989. } );
  38990. QUnit.test( "add", ( assert ) => {
  38991. var a = new Vector4( x, y, z, w );
  38992. var b = new Vector4( - x, - y, - z, - w );
  38993. a.add( b );
  38994. assert.ok( a.x == 0, "Passed!" );
  38995. assert.ok( a.y == 0, "Passed!" );
  38996. assert.ok( a.z == 0, "Passed!" );
  38997. assert.ok( a.w == 0, "Passed!" );
  38998. var c = new Vector4().addVectors( b, b );
  38999. assert.ok( c.x == - 2 * x, "Passed!" );
  39000. assert.ok( c.y == - 2 * y, "Passed!" );
  39001. assert.ok( c.z == - 2 * z, "Passed!" );
  39002. assert.ok( c.w == - 2 * w, "Passed!" );
  39003. } );
  39004. QUnit.test( "addScalar", ( assert ) => {
  39005. assert.ok( false, "everything's gonna be alright" );
  39006. } );
  39007. QUnit.test( "addVectors", ( assert ) => {
  39008. assert.ok( false, "everything's gonna be alright" );
  39009. } );
  39010. QUnit.test( "addScaledVector", ( assert ) => {
  39011. var a = new Vector4( x, y, z, w );
  39012. var b = new Vector4( 6, 7, 8, 9 );
  39013. var s = 3;
  39014. a.addScaledVector( b, s );
  39015. assert.strictEqual( a.x, x + b.x * s, "Check x" );
  39016. assert.strictEqual( a.y, y + b.y * s, "Check y" );
  39017. assert.strictEqual( a.z, z + b.z * s, "Check z" );
  39018. assert.strictEqual( a.w, w + b.w * s, "Check w" );
  39019. } );
  39020. QUnit.test( "sub", ( assert ) => {
  39021. var a = new Vector4( x, y, z, w );
  39022. var b = new Vector4( - x, - y, - z, - w );
  39023. a.sub( b );
  39024. assert.ok( a.x == 2 * x, "Passed!" );
  39025. assert.ok( a.y == 2 * y, "Passed!" );
  39026. assert.ok( a.z == 2 * z, "Passed!" );
  39027. assert.ok( a.w == 2 * w, "Passed!" );
  39028. var c = new Vector4().subVectors( a, a );
  39029. assert.ok( c.x == 0, "Passed!" );
  39030. assert.ok( c.y == 0, "Passed!" );
  39031. assert.ok( c.z == 0, "Passed!" );
  39032. assert.ok( c.w == 0, "Passed!" );
  39033. } );
  39034. QUnit.test( "subScalar", ( assert ) => {
  39035. assert.ok( false, "everything's gonna be alright" );
  39036. } );
  39037. QUnit.test( "subVectors", ( assert ) => {
  39038. assert.ok( false, "everything's gonna be alright" );
  39039. } );
  39040. QUnit.test( "multiplyScalar", ( assert ) => {
  39041. assert.ok( false, "everything's gonna be alright" );
  39042. } );
  39043. QUnit.test( "applyMatrix4", ( assert ) => {
  39044. var a = new Vector4( x, y, z, w );
  39045. var m = new Matrix4().makeRotationX( Math.PI );
  39046. var expected = new Vector4( 2, - 3, - 4, 5 );
  39047. a.applyMatrix4( m );
  39048. assert.ok( Math.abs( a.x - expected.x ) <= eps, "Rotation matrix: check x" );
  39049. assert.ok( Math.abs( a.y - expected.y ) <= eps, "Rotation matrix: check y" );
  39050. assert.ok( Math.abs( a.z - expected.z ) <= eps, "Rotation matrix: check z" );
  39051. assert.ok( Math.abs( a.w - expected.w ) <= eps, "Rotation matrix: check w" );
  39052. a.set( x, y, z, w );
  39053. m.makeTranslation( 5, 7, 11 );
  39054. expected.set( 27, 38, 59, 5 );
  39055. a.applyMatrix4( m );
  39056. assert.ok( Math.abs( a.x - expected.x ) <= eps, "Translation matrix: check x" );
  39057. assert.ok( Math.abs( a.y - expected.y ) <= eps, "Translation matrix: check y" );
  39058. assert.ok( Math.abs( a.z - expected.z ) <= eps, "Translation matrix: check z" );
  39059. assert.ok( Math.abs( a.w - expected.w ) <= eps, "Translation matrix: check w" );
  39060. a.set( x, y, z, w );
  39061. m.set( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0 );
  39062. expected.set( 2, 3, 4, 4 );
  39063. a.applyMatrix4( m );
  39064. assert.ok( Math.abs( a.x - expected.x ) <= eps, "Custom matrix: check x" );
  39065. assert.ok( Math.abs( a.y - expected.y ) <= eps, "Custom matrix: check y" );
  39066. assert.ok( Math.abs( a.z - expected.z ) <= eps, "Custom matrix: check z" );
  39067. assert.ok( Math.abs( a.w - expected.w ) <= eps, "Custom matrix: check w" );
  39068. a.set( x, y, z, w );
  39069. m.set( 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53 );
  39070. expected.set( 68, 224, 442, 664 );
  39071. a.applyMatrix4( m );
  39072. assert.ok( Math.abs( a.x - expected.x ) <= eps, "Bogus matrix: check x" );
  39073. assert.ok( Math.abs( a.y - expected.y ) <= eps, "Bogus matrix: check y" );
  39074. assert.ok( Math.abs( a.z - expected.z ) <= eps, "Bogus matrix: check z" );
  39075. assert.ok( Math.abs( a.w - expected.w ) <= eps, "Bogus matrix: check w" );
  39076. } );
  39077. QUnit.test( "divideScalar", ( assert ) => {
  39078. assert.ok( false, "everything's gonna be alright" );
  39079. } );
  39080. QUnit.test( "setAxisAngleFromQuaternion", ( assert ) => {
  39081. assert.ok( false, "everything's gonna be alright" );
  39082. } );
  39083. QUnit.test( "setAxisAngleFromRotationMatrix", ( assert ) => {
  39084. assert.ok( false, "everything's gonna be alright" );
  39085. } );
  39086. QUnit.test( "min", ( assert ) => {
  39087. assert.ok( false, "everything's gonna be alright" );
  39088. } );
  39089. QUnit.test( "max", ( assert ) => {
  39090. assert.ok( false, "everything's gonna be alright" );
  39091. } );
  39092. QUnit.test( "clamp", ( assert ) => {
  39093. assert.ok( false, "everything's gonna be alright" );
  39094. } );
  39095. QUnit.test( "clampScalar", ( assert ) => {
  39096. var a = new Vector4( - 0.1, 0.01, 0.5, 1.5 );
  39097. var clamped = new Vector4( 0.1, 0.1, 0.5, 1.0 );
  39098. a.clampScalar( 0.1, 1.0 );
  39099. assert.ok( Math.abs( a.x - clamped.x ) <= eps, "Check x" );
  39100. assert.ok( Math.abs( a.y - clamped.y ) <= eps, "Check y" );
  39101. assert.ok( Math.abs( a.z - clamped.z ) <= eps, "Check z" );
  39102. assert.ok( Math.abs( a.w - clamped.w ) <= eps, "Check w" );
  39103. } );
  39104. QUnit.test( "clampLength", ( assert ) => {
  39105. assert.ok( false, "everything's gonna be alright" );
  39106. } );
  39107. QUnit.test( "floor", ( assert ) => {
  39108. assert.ok( false, "everything's gonna be alright" );
  39109. } );
  39110. QUnit.test( "ceil", ( assert ) => {
  39111. assert.ok( false, "everything's gonna be alright" );
  39112. } );
  39113. QUnit.test( "round", ( assert ) => {
  39114. assert.ok( false, "everything's gonna be alright" );
  39115. } );
  39116. QUnit.test( "roundToZero", ( assert ) => {
  39117. assert.ok( false, "everything's gonna be alright" );
  39118. } );
  39119. QUnit.test( "negate", ( assert ) => {
  39120. var a = new Vector4( x, y, z, w );
  39121. a.negate();
  39122. assert.ok( a.x == - x, "Passed!" );
  39123. assert.ok( a.y == - y, "Passed!" );
  39124. assert.ok( a.z == - z, "Passed!" );
  39125. assert.ok( a.w == - w, "Passed!" );
  39126. } );
  39127. QUnit.test( "dot", ( assert ) => {
  39128. var a = new Vector4( x, y, z, w );
  39129. var b = new Vector4( - x, - y, - z, - w );
  39130. var c = new Vector4( 0, 0, 0, 0 );
  39131. var result = a.dot( b );
  39132. assert.ok( result == ( - x * x - y * y - z * z - w * w ), "Passed!" );
  39133. var result = a.dot( c );
  39134. assert.ok( result == 0, "Passed!" );
  39135. } );
  39136. QUnit.test( "lengthSq", ( assert ) => {
  39137. assert.ok( false, "everything's gonna be alright" );
  39138. } );
  39139. QUnit.test( "length", ( assert ) => {
  39140. assert.ok( false, "everything's gonna be alright" );
  39141. } );
  39142. QUnit.test( "manhattanLength", ( assert ) => {
  39143. var a = new Vector4( x, 0, 0, 0 );
  39144. var b = new Vector4( 0, - y, 0, 0 );
  39145. var c = new Vector4( 0, 0, z, 0 );
  39146. var d = new Vector4( 0, 0, 0, w );
  39147. var e = new Vector4( 0, 0, 0, 0 );
  39148. assert.ok( a.manhattanLength() == x, "Positive x" );
  39149. assert.ok( b.manhattanLength() == y, "Negative y" );
  39150. assert.ok( c.manhattanLength() == z, "Positive z" );
  39151. assert.ok( d.manhattanLength() == w, "Positive w" );
  39152. assert.ok( e.manhattanLength() == 0, "Empty initialization" );
  39153. a.set( x, y, z, w );
  39154. assert.ok(
  39155. a.manhattanLength() == Math.abs( x ) + Math.abs( y ) + Math.abs( z ) + Math.abs( w ),
  39156. "All components"
  39157. );
  39158. } );
  39159. QUnit.test( "normalize", ( assert ) => {
  39160. var a = new Vector4( x, 0, 0, 0 );
  39161. var b = new Vector4( 0, - y, 0, 0 );
  39162. var c = new Vector4( 0, 0, z, 0 );
  39163. var d = new Vector4( 0, 0, 0, - w );
  39164. a.normalize();
  39165. assert.ok( a.length() == 1, "Passed!" );
  39166. assert.ok( a.x == 1, "Passed!" );
  39167. b.normalize();
  39168. assert.ok( b.length() == 1, "Passed!" );
  39169. assert.ok( b.y == - 1, "Passed!" );
  39170. c.normalize();
  39171. assert.ok( c.length() == 1, "Passed!" );
  39172. assert.ok( c.z == 1, "Passed!" );
  39173. d.normalize();
  39174. assert.ok( d.length() == 1, "Passed!" );
  39175. assert.ok( d.w == - 1, "Passed!" );
  39176. } );
  39177. QUnit.test( "setLength", ( assert ) => {
  39178. var a = new Vector4( x, 0, 0, 0 );
  39179. assert.ok( a.length() == x, "Passed!" );
  39180. a.setLength( y );
  39181. assert.ok( a.length() == y, "Passed!" );
  39182. var a = new Vector4( 0, 0, 0, 0 );
  39183. assert.ok( a.length() == 0, "Passed!" );
  39184. a.setLength( y );
  39185. assert.ok( a.length() == 0, "Passed!" );
  39186. a.setLength();
  39187. assert.ok( isNaN( a.length() ), "Passed!" );
  39188. } );
  39189. QUnit.test( "lerp", ( assert ) => {
  39190. assert.ok( false, "everything's gonna be alright" );
  39191. } );
  39192. QUnit.test( "lerpVectors", ( assert ) => {
  39193. assert.ok( false, "everything's gonna be alright" );
  39194. } );
  39195. QUnit.test( "equals", ( assert ) => {
  39196. var a = new Vector4( x, 0, z, 0 );
  39197. var b = new Vector4( 0, - y, 0, - w );
  39198. assert.ok( a.x != b.x, "Passed!" );
  39199. assert.ok( a.y != b.y, "Passed!" );
  39200. assert.ok( a.z != b.z, "Passed!" );
  39201. assert.ok( a.w != b.w, "Passed!" );
  39202. assert.ok( ! a.equals( b ), "Passed!" );
  39203. assert.ok( ! b.equals( a ), "Passed!" );
  39204. a.copy( b );
  39205. assert.ok( a.x == b.x, "Passed!" );
  39206. assert.ok( a.y == b.y, "Passed!" );
  39207. assert.ok( a.z == b.z, "Passed!" );
  39208. assert.ok( a.w == b.w, "Passed!" );
  39209. assert.ok( a.equals( b ), "Passed!" );
  39210. assert.ok( b.equals( a ), "Passed!" );
  39211. } );
  39212. QUnit.test( "fromArray", ( assert ) => {
  39213. var a = new Vector4();
  39214. var array = [ 1, 2, 3, 4, 5, 6, 7, 8 ];
  39215. a.fromArray( array );
  39216. assert.strictEqual( a.x, 1, "No offset: check x" );
  39217. assert.strictEqual( a.y, 2, "No offset: check y" );
  39218. assert.strictEqual( a.z, 3, "No offset: check z" );
  39219. assert.strictEqual( a.w, 4, "No offset: check w" );
  39220. a.fromArray( array, 4 );
  39221. assert.strictEqual( a.x, 5, "With offset: check x" );
  39222. assert.strictEqual( a.y, 6, "With offset: check y" );
  39223. assert.strictEqual( a.z, 7, "With offset: check z" );
  39224. assert.strictEqual( a.w, 8, "With offset: check w" );
  39225. } );
  39226. QUnit.test( "toArray", ( assert ) => {
  39227. var a = new Vector4( x, y, z, w );
  39228. var array = a.toArray();
  39229. assert.strictEqual( array[ 0 ], x, "No array, no offset: check x" );
  39230. assert.strictEqual( array[ 1 ], y, "No array, no offset: check y" );
  39231. assert.strictEqual( array[ 2 ], z, "No array, no offset: check z" );
  39232. assert.strictEqual( array[ 3 ], w, "No array, no offset: check w" );
  39233. var array = [];
  39234. a.toArray( array );
  39235. assert.strictEqual( array[ 0 ], x, "With array, no offset: check x" );
  39236. assert.strictEqual( array[ 1 ], y, "With array, no offset: check y" );
  39237. assert.strictEqual( array[ 2 ], z, "With array, no offset: check z" );
  39238. assert.strictEqual( array[ 3 ], w, "With array, no offset: check w" );
  39239. var array = [];
  39240. a.toArray( array, 1 );
  39241. assert.strictEqual( array[ 0 ], undefined, "With array and offset: check [0]" );
  39242. assert.strictEqual( array[ 1 ], x, "With array and offset: check x" );
  39243. assert.strictEqual( array[ 2 ], y, "With array and offset: check y" );
  39244. assert.strictEqual( array[ 3 ], z, "With array and offset: check z" );
  39245. assert.strictEqual( array[ 4 ], w, "With array and offset: check w" );
  39246. } );
  39247. QUnit.test( "fromBufferAttribute", ( assert ) => {
  39248. var a = new Vector4();
  39249. var attr = new BufferAttribute( new Float32Array( [ 1, 2, 3, 4, 5, 6, 7, 8 ] ), 4 );
  39250. a.fromBufferAttribute( attr, 0 );
  39251. assert.strictEqual( a.x, 1, "Offset 0: check x" );
  39252. assert.strictEqual( a.y, 2, "Offset 0: check y" );
  39253. assert.strictEqual( a.z, 3, "Offset 0: check z" );
  39254. assert.strictEqual( a.w, 4, "Offset 0: check w" );
  39255. a.fromBufferAttribute( attr, 1 );
  39256. assert.strictEqual( a.x, 5, "Offset 1: check x" );
  39257. assert.strictEqual( a.y, 6, "Offset 1: check y" );
  39258. assert.strictEqual( a.z, 7, "Offset 1: check z" );
  39259. assert.strictEqual( a.w, 8, "Offset 1: check w" );
  39260. } );
  39261. // TODO (Itee) refactor/split
  39262. QUnit.test( "setX,setY,setZ,setW", ( assert ) => {
  39263. var a = new Vector4();
  39264. assert.ok( a.x == 0, "Passed!" );
  39265. assert.ok( a.y == 0, "Passed!" );
  39266. assert.ok( a.z == 0, "Passed!" );
  39267. assert.ok( a.w == 1, "Passed!" );
  39268. a.setX( x );
  39269. a.setY( y );
  39270. a.setZ( z );
  39271. a.setW( w );
  39272. assert.ok( a.x == x, "Passed!" );
  39273. assert.ok( a.y == y, "Passed!" );
  39274. assert.ok( a.z == z, "Passed!" );
  39275. assert.ok( a.w == w, "Passed!" );
  39276. } );
  39277. QUnit.test( "setComponent,getComponent", ( assert ) => {
  39278. var a = new Vector4();
  39279. assert.ok( a.x == 0, "Passed!" );
  39280. assert.ok( a.y == 0, "Passed!" );
  39281. assert.ok( a.z == 0, "Passed!" );
  39282. assert.ok( a.w == 1, "Passed!" );
  39283. a.setComponent( 0, 1 );
  39284. a.setComponent( 1, 2 );
  39285. a.setComponent( 2, 3 );
  39286. a.setComponent( 3, 4 );
  39287. assert.ok( a.getComponent( 0 ) == 1, "Passed!" );
  39288. assert.ok( a.getComponent( 1 ) == 2, "Passed!" );
  39289. assert.ok( a.getComponent( 2 ) == 3, "Passed!" );
  39290. assert.ok( a.getComponent( 3 ) == 4, "Passed!" );
  39291. } );
  39292. QUnit.test( "setComponent/getComponent exceptions", ( assert ) => {
  39293. var a = new Vector4();
  39294. assert.throws(
  39295. function () {
  39296. a.setComponent( 4, 0 );
  39297. },
  39298. /index is out of range/,
  39299. "setComponent with an out of range index throws Error"
  39300. );
  39301. assert.throws(
  39302. function () {
  39303. a.getComponent( 4 );
  39304. },
  39305. /index is out of range/,
  39306. "getComponent with an out of range index throws Error"
  39307. );
  39308. } );
  39309. QUnit.test( "setScalar/addScalar/subScalar", ( assert ) => {
  39310. var a = new Vector4();
  39311. var s = 3;
  39312. a.setScalar( s );
  39313. assert.strictEqual( a.x, s, "setScalar: check x" );
  39314. assert.strictEqual( a.y, s, "setScalar: check y" );
  39315. assert.strictEqual( a.z, s, "setScalar: check z" );
  39316. assert.strictEqual( a.w, s, "setScalar: check w" );
  39317. a.addScalar( s );
  39318. assert.strictEqual( a.x, 2 * s, "addScalar: check x" );
  39319. assert.strictEqual( a.y, 2 * s, "addScalar: check y" );
  39320. assert.strictEqual( a.z, 2 * s, "addScalar: check z" );
  39321. assert.strictEqual( a.w, 2 * s, "addScalar: check w" );
  39322. a.subScalar( 2 * s );
  39323. assert.strictEqual( a.x, 0, "subScalar: check x" );
  39324. assert.strictEqual( a.y, 0, "subScalar: check y" );
  39325. assert.strictEqual( a.z, 0, "subScalar: check z" );
  39326. assert.strictEqual( a.w, 0, "subScalar: check w" );
  39327. } );
  39328. QUnit.test( "multiply/divide", ( assert ) => {
  39329. var a = new Vector4( x, y, z, w );
  39330. var b = new Vector4( - x, - y, - z, - w );
  39331. a.multiplyScalar( - 2 );
  39332. assert.ok( a.x == x * - 2, "Passed!" );
  39333. assert.ok( a.y == y * - 2, "Passed!" );
  39334. assert.ok( a.z == z * - 2, "Passed!" );
  39335. assert.ok( a.w == w * - 2, "Passed!" );
  39336. b.multiplyScalar( - 2 );
  39337. assert.ok( b.x == 2 * x, "Passed!" );
  39338. assert.ok( b.y == 2 * y, "Passed!" );
  39339. assert.ok( b.z == 2 * z, "Passed!" );
  39340. assert.ok( b.w == 2 * w, "Passed!" );
  39341. a.divideScalar( - 2 );
  39342. assert.ok( a.x == x, "Passed!" );
  39343. assert.ok( a.y == y, "Passed!" );
  39344. assert.ok( a.z == z, "Passed!" );
  39345. assert.ok( a.w == w, "Passed!" );
  39346. b.divideScalar( - 2 );
  39347. assert.ok( b.x == - x, "Passed!" );
  39348. assert.ok( b.y == - y, "Passed!" );
  39349. assert.ok( b.z == - z, "Passed!" );
  39350. assert.ok( b.w == - w, "Passed!" );
  39351. } );
  39352. QUnit.test( "min/max/clamp", ( assert ) => {
  39353. var a = new Vector4( x, y, z, w );
  39354. var b = new Vector4( - x, - y, - z, - w );
  39355. var c = new Vector4();
  39356. c.copy( a ).min( b );
  39357. assert.ok( c.x == - x, "Passed!" );
  39358. assert.ok( c.y == - y, "Passed!" );
  39359. assert.ok( c.z == - z, "Passed!" );
  39360. assert.ok( c.w == - w, "Passed!" );
  39361. c.copy( a ).max( b );
  39362. assert.ok( c.x == x, "Passed!" );
  39363. assert.ok( c.y == y, "Passed!" );
  39364. assert.ok( c.z == z, "Passed!" );
  39365. assert.ok( c.w == w, "Passed!" );
  39366. c.set( - 2 * x, 2 * y, - 2 * z, 2 * w );
  39367. c.clamp( b, a );
  39368. assert.ok( c.x == - x, "Passed!" );
  39369. assert.ok( c.y == y, "Passed!" );
  39370. assert.ok( c.z == - z, "Passed!" );
  39371. assert.ok( c.w == w, "Passed!" );
  39372. } );
  39373. QUnit.test( "length/lengthSq", ( assert ) => {
  39374. var a = new Vector4( x, 0, 0, 0 );
  39375. var b = new Vector4( 0, - y, 0, 0 );
  39376. var c = new Vector4( 0, 0, z, 0 );
  39377. var d = new Vector4( 0, 0, 0, w );
  39378. var e = new Vector4( 0, 0, 0, 0 );
  39379. assert.ok( a.length() == x, "Passed!" );
  39380. assert.ok( a.lengthSq() == x * x, "Passed!" );
  39381. assert.ok( b.length() == y, "Passed!" );
  39382. assert.ok( b.lengthSq() == y * y, "Passed!" );
  39383. assert.ok( c.length() == z, "Passed!" );
  39384. assert.ok( c.lengthSq() == z * z, "Passed!" );
  39385. assert.ok( d.length() == w, "Passed!" );
  39386. assert.ok( d.lengthSq() == w * w, "Passed!" );
  39387. assert.ok( e.length() == 0, "Passed!" );
  39388. assert.ok( e.lengthSq() == 0, "Passed!" );
  39389. a.set( x, y, z, w );
  39390. assert.ok( a.length() == Math.sqrt( x * x + y * y + z * z + w * w ), "Passed!" );
  39391. assert.ok( a.lengthSq() == ( x * x + y * y + z * z + w * w ), "Passed!" );
  39392. } );
  39393. QUnit.test( "lerp/clone", ( assert ) => {
  39394. var a = new Vector4( x, 0, z, 0 );
  39395. var b = new Vector4( 0, - y, 0, - w );
  39396. assert.ok( a.lerp( a, 0 ).equals( a.lerp( a, 0.5 ) ), "Passed!" );
  39397. assert.ok( a.lerp( a, 0 ).equals( a.lerp( a, 1 ) ), "Passed!" );
  39398. assert.ok( a.clone().lerp( b, 0 ).equals( a ), "Passed!" );
  39399. assert.ok( a.clone().lerp( b, 0.5 ).x == x * 0.5, "Passed!" );
  39400. assert.ok( a.clone().lerp( b, 0.5 ).y == - y * 0.5, "Passed!" );
  39401. assert.ok( a.clone().lerp( b, 0.5 ).z == z * 0.5, "Passed!" );
  39402. assert.ok( a.clone().lerp( b, 0.5 ).w == - w * 0.5, "Passed!" );
  39403. assert.ok( a.clone().lerp( b, 1 ).equals( b ), "Passed!" );
  39404. } );
  39405. } );
  39406. } );
  39407. /**
  39408. * @author TristanVALCKE / https://github.com/Itee
  39409. */
  39410. /* global QUnit */
  39411. QUnit.module( 'Maths', () => {
  39412. QUnit.module( 'Interpolants', () => {
  39413. QUnit.module.todo( 'CubicInterpolant', () => {
  39414. // INHERITANCE
  39415. QUnit.test( "Extending", ( assert ) => {
  39416. assert.ok( false, "everything's gonna be alright" );
  39417. } );
  39418. // INSTANCING
  39419. QUnit.test( "Instancing", ( assert ) => {
  39420. assert.ok( false, "everything's gonna be alright" );
  39421. } );
  39422. // PRIVATE STUFF
  39423. QUnit.test( "DefaultSettings_", ( assert ) => {
  39424. assert.ok( false, "everything's gonna be alright" );
  39425. } );
  39426. QUnit.test( "intervalChanged_", ( assert ) => {
  39427. assert.ok( false, "everything's gonna be alright" );
  39428. } );
  39429. QUnit.test( "interpolate_", ( assert ) => {
  39430. assert.ok( false, "everything's gonna be alright" );
  39431. } );
  39432. } );
  39433. } );
  39434. } );
  39435. /**
  39436. * @author TristanVALCKE / https://github.com/Itee
  39437. */
  39438. /* global QUnit */
  39439. QUnit.module( 'Maths', () => {
  39440. QUnit.module( 'Interpolants', () => {
  39441. QUnit.module.todo( 'DiscreteInterpolant', () => {
  39442. // INHERITANCE
  39443. QUnit.test( "Extending", ( assert ) => {
  39444. assert.ok( false, "everything's gonna be alright" );
  39445. } );
  39446. // INSTANCING
  39447. QUnit.test( "Instancing", ( assert ) => {
  39448. assert.ok( false, "everything's gonna be alright" );
  39449. } );
  39450. // PRIVATE STUFF
  39451. QUnit.test( "interpolate_", ( assert ) => {
  39452. assert.ok( false, "everything's gonna be alright" );
  39453. } );
  39454. } );
  39455. } );
  39456. } );
  39457. /**
  39458. * @author TristanVALCKE / https://github.com/Itee
  39459. */
  39460. /* global QUnit */
  39461. QUnit.module( 'Maths', () => {
  39462. QUnit.module( 'Interpolants', () => {
  39463. QUnit.module.todo( 'LinearInterpolant', () => {
  39464. // INHERITANCE
  39465. QUnit.test( "Extending", ( assert ) => {
  39466. assert.ok( false, "everything's gonna be alright" );
  39467. } );
  39468. // INSTANCING
  39469. QUnit.test( "Instancing", ( assert ) => {
  39470. assert.ok( false, "everything's gonna be alright" );
  39471. } );
  39472. // PRIVATE STUFF
  39473. QUnit.test( "interpolate_", ( assert ) => {
  39474. assert.ok( false, "everything's gonna be alright" );
  39475. } );
  39476. } );
  39477. } );
  39478. } );
  39479. /**
  39480. * @author TristanVALCKE / https://github.com/Itee
  39481. */
  39482. /* global QUnit */
  39483. QUnit.module( 'Maths', () => {
  39484. QUnit.module( 'Interpolants', () => {
  39485. QUnit.module.todo( 'QuaternionLinearInterpolant', () => {
  39486. // INHERITANCE
  39487. QUnit.test( "Extending", ( assert ) => {
  39488. assert.ok( false, "everything's gonna be alright" );
  39489. } );
  39490. // INSTANCING
  39491. QUnit.test( "Instancing", ( assert ) => {
  39492. assert.ok( false, "everything's gonna be alright" );
  39493. } );
  39494. // PRIVATE STUFF
  39495. QUnit.test( "interpolate_", ( assert ) => {
  39496. assert.ok( false, "everything's gonna be alright" );
  39497. } );
  39498. } );
  39499. } );
  39500. } );
  39501. /**
  39502. * @author TristanVALCKE / https://github.com/Itee
  39503. */
  39504. /* global QUnit */
  39505. QUnit.module( 'Objects', () => {
  39506. QUnit.module.todo( 'Bone', () => {
  39507. // INHERITANCE
  39508. QUnit.test( "Extending", ( assert ) => {
  39509. assert.ok( false, "everything's gonna be alright" );
  39510. } );
  39511. // INSTANCING
  39512. QUnit.test( "Instancing", ( assert ) => {
  39513. assert.ok( false, "everything's gonna be alright" );
  39514. } );
  39515. // PUBLIC STUFF
  39516. QUnit.test( "isBone", ( assert ) => {
  39517. assert.ok( false, "everything's gonna be alright" );
  39518. } );
  39519. } );
  39520. } );
  39521. /**
  39522. * @author TristanVALCKE / https://github.com/Itee
  39523. */
  39524. /* global QUnit */
  39525. QUnit.module( 'Objects', () => {
  39526. QUnit.module.todo( 'Group', () => {
  39527. // INHERITANCE
  39528. QUnit.test( "Extending", ( assert ) => {
  39529. assert.ok( false, "everything's gonna be alright" );
  39530. } );
  39531. // INSTANCING
  39532. QUnit.test( "Instancing", ( assert ) => {
  39533. assert.ok( false, "everything's gonna be alright" );
  39534. } );
  39535. } );
  39536. } );
  39537. /**
  39538. * @author mikael emtinger / http://gomo.se/
  39539. * @author alteredq / http://alteredqualia.com/
  39540. */
  39541. function LensFlare( texture, size, distance, blending, color ) {
  39542. Object3D.call( this );
  39543. this.lensFlares = [];
  39544. this.positionScreen = new Vector3();
  39545. this.customUpdateCallback = undefined;
  39546. if ( texture !== undefined ) {
  39547. this.add( texture, size, distance, blending, color );
  39548. }
  39549. }
  39550. LensFlare.prototype = Object.assign( Object.create( Object3D.prototype ), {
  39551. constructor: LensFlare,
  39552. isLensFlare: true,
  39553. copy: function ( source ) {
  39554. Object3D.prototype.copy.call( this, source );
  39555. this.positionScreen.copy( source.positionScreen );
  39556. this.customUpdateCallback = source.customUpdateCallback;
  39557. for ( var i = 0, l = source.lensFlares.length; i < l; i ++ ) {
  39558. this.lensFlares.push( source.lensFlares[ i ] );
  39559. }
  39560. return this;
  39561. },
  39562. add: function ( texture, size, distance, blending, color, opacity ) {
  39563. if ( size === undefined ) size = - 1;
  39564. if ( distance === undefined ) distance = 0;
  39565. if ( opacity === undefined ) opacity = 1;
  39566. if ( color === undefined ) color = new Color( 0xffffff );
  39567. if ( blending === undefined ) blending = NormalBlending;
  39568. distance = Math.min( distance, Math.max( 0, distance ) );
  39569. this.lensFlares.push( {
  39570. texture: texture, // THREE.Texture
  39571. size: size, // size in pixels (-1 = use texture.width)
  39572. distance: distance, // distance (0-1) from light source (0=at light source)
  39573. x: 0, y: 0, z: 0, // screen position (-1 => 1) z = 0 is in front z = 1 is back
  39574. scale: 1, // scale
  39575. rotation: 0, // rotation
  39576. opacity: opacity, // opacity
  39577. color: color, // color
  39578. blending: blending // blending
  39579. } );
  39580. },
  39581. /*
  39582. * Update lens flares update positions on all flares based on the screen position
  39583. * Set myLensFlare.customUpdateCallback to alter the flares in your project specific way.
  39584. */
  39585. updateLensFlares: function () {
  39586. var f, fl = this.lensFlares.length;
  39587. var flare;
  39588. var vecX = - this.positionScreen.x * 2;
  39589. var vecY = - this.positionScreen.y * 2;
  39590. for ( f = 0; f < fl; f ++ ) {
  39591. flare = this.lensFlares[ f ];
  39592. flare.x = this.positionScreen.x + vecX * flare.distance;
  39593. flare.y = this.positionScreen.y + vecY * flare.distance;
  39594. flare.wantedRotation = flare.x * Math.PI * 0.25;
  39595. flare.rotation += ( flare.wantedRotation - flare.rotation ) * 0.25;
  39596. }
  39597. }
  39598. } );
  39599. /**
  39600. * @author TristanVALCKE / https://github.com/Itee
  39601. */
  39602. /* global QUnit */
  39603. QUnit.module( 'Objects', () => {
  39604. QUnit.module.todo( 'LensFlare', () => {
  39605. // INHERITANCE
  39606. QUnit.test( "Extending", ( assert ) => {
  39607. assert.ok( false, "everything's gonna be alright" );
  39608. } );
  39609. // INSTANCING
  39610. QUnit.test( "Instancing", ( assert ) => {
  39611. assert.ok( false, "everything's gonna be alright" );
  39612. } );
  39613. // PUBLIC STUFF
  39614. QUnit.test( "isLensFlare", ( assert ) => {
  39615. assert.ok( false, "everything's gonna be alright" );
  39616. } );
  39617. QUnit.test( "copy", ( assert ) => {
  39618. assert.ok( false, "everything's gonna be alright" );
  39619. } );
  39620. QUnit.test( "add", ( assert ) => {
  39621. assert.ok( false, "everything's gonna be alright" );
  39622. } );
  39623. QUnit.test( "updateLensFlares", ( assert ) => {
  39624. assert.ok( false, "everything's gonna be alright" );
  39625. } );
  39626. } );
  39627. } );
  39628. /**
  39629. * @author TristanVALCKE / https://github.com/Itee
  39630. */
  39631. /* global QUnit */
  39632. QUnit.module( 'Objects', () => {
  39633. QUnit.module.todo( 'Line', () => {
  39634. // INHERITANCE
  39635. QUnit.test( "Extending", ( assert ) => {
  39636. assert.ok( false, "everything's gonna be alright" );
  39637. } );
  39638. // INSTANCING
  39639. QUnit.test( "Instancing", ( assert ) => {
  39640. assert.ok( false, "everything's gonna be alright" );
  39641. } );
  39642. // PUBLIC STUFF
  39643. QUnit.test( "isLine", ( assert ) => {
  39644. assert.ok( false, "everything's gonna be alright" );
  39645. } );
  39646. QUnit.test( "raycast", ( assert ) => {
  39647. assert.ok( false, "everything's gonna be alright" );
  39648. } );
  39649. QUnit.test( "clone", ( assert ) => {
  39650. assert.ok( false, "everything's gonna be alright" );
  39651. } );
  39652. } );
  39653. } );
  39654. /**
  39655. * @author TristanVALCKE / https://github.com/Itee
  39656. */
  39657. /* global QUnit */
  39658. QUnit.module( 'Objects', () => {
  39659. QUnit.module.todo( 'LineLoop', () => {
  39660. // INHERITANCE
  39661. QUnit.test( "Extending", ( assert ) => {
  39662. assert.ok( false, "everything's gonna be alright" );
  39663. } );
  39664. // INSTANCING
  39665. QUnit.test( "Instancing", ( assert ) => {
  39666. assert.ok( false, "everything's gonna be alright" );
  39667. } );
  39668. // PUBLIC STUFF
  39669. QUnit.test( "isLineLoop", ( assert ) => {
  39670. assert.ok( false, "everything's gonna be alright" );
  39671. } );
  39672. } );
  39673. } );
  39674. /**
  39675. * @author TristanVALCKE / https://github.com/Itee
  39676. */
  39677. /* global QUnit */
  39678. QUnit.module( 'Objects', () => {
  39679. QUnit.module.todo( 'LineSegments', () => {
  39680. // INHERITANCE
  39681. QUnit.test( "Extending", ( assert ) => {
  39682. assert.ok( false, "everything's gonna be alright" );
  39683. } );
  39684. // INSTANCING
  39685. QUnit.test( "Instancing", ( assert ) => {
  39686. assert.ok( false, "everything's gonna be alright" );
  39687. } );
  39688. // PUBLIC STUFF
  39689. QUnit.test( "isLineSegments", ( assert ) => {
  39690. assert.ok( false, "everything's gonna be alright" );
  39691. } );
  39692. } );
  39693. } );
  39694. /**
  39695. * @author TristanVALCKE / https://github.com/Itee
  39696. */
  39697. /* global QUnit */
  39698. QUnit.module( 'Objects', () => {
  39699. QUnit.module.todo( 'LOD', () => {
  39700. // INHERITANCE
  39701. QUnit.test( "Extending", ( assert ) => {
  39702. assert.ok( false, "everything's gonna be alright" );
  39703. } );
  39704. // INSTANCING
  39705. QUnit.test( "Instancing", ( assert ) => {
  39706. assert.ok( false, "everything's gonna be alright" );
  39707. } );
  39708. // PROPERTIES
  39709. QUnit.test( "levels", ( assert ) => {
  39710. assert.ok( false, "everything's gonna be alright" );
  39711. } );
  39712. // PUBLIC STUFF
  39713. QUnit.test( "isLOD", ( assert ) => {
  39714. assert.ok( false, "everything's gonna be alright" );
  39715. } );
  39716. QUnit.test( "copy", ( assert ) => {
  39717. assert.ok( false, "everything's gonna be alright" );
  39718. } );
  39719. QUnit.test( "addLevel", ( assert ) => {
  39720. assert.ok( false, "everything's gonna be alright" );
  39721. } );
  39722. QUnit.test( "getObjectForDistance", ( assert ) => {
  39723. assert.ok( false, "everything's gonna be alright" );
  39724. } );
  39725. QUnit.test( "raycast", ( assert ) => {
  39726. assert.ok( false, "everything's gonna be alright" );
  39727. } );
  39728. QUnit.test( "update", ( assert ) => {
  39729. assert.ok( false, "everything's gonna be alright" );
  39730. } );
  39731. QUnit.test( "toJSON", ( assert ) => {
  39732. assert.ok( false, "everything's gonna be alright" );
  39733. } );
  39734. } );
  39735. } );
  39736. /**
  39737. * @author TristanVALCKE / https://github.com/Itee
  39738. */
  39739. /* global QUnit */
  39740. QUnit.module( 'Objects', () => {
  39741. QUnit.module.todo( 'Mesh', () => {
  39742. // INHERITANCE
  39743. QUnit.test( "Extending", ( assert ) => {
  39744. assert.ok( false, "everything's gonna be alright" );
  39745. } );
  39746. // INSTANCING
  39747. QUnit.test( "Instancing", ( assert ) => {
  39748. assert.ok( false, "everything's gonna be alright" );
  39749. } );
  39750. // PUBLIC STUFF
  39751. QUnit.test( "isMesh", ( assert ) => {
  39752. assert.ok( false, "everything's gonna be alright" );
  39753. } );
  39754. QUnit.test( "setDrawMode", ( assert ) => {
  39755. assert.ok( false, "everything's gonna be alright" );
  39756. } );
  39757. QUnit.test( "copy", ( assert ) => {
  39758. assert.ok( false, "everything's gonna be alright" );
  39759. } );
  39760. QUnit.test( "updateMorphTargets", ( assert ) => {
  39761. assert.ok( false, "everything's gonna be alright" );
  39762. } );
  39763. QUnit.test( "raycast", ( assert ) => {
  39764. assert.ok( false, "everything's gonna be alright" );
  39765. } );
  39766. QUnit.test( "clone", ( assert ) => {
  39767. assert.ok( false, "everything's gonna be alright" );
  39768. } );
  39769. } );
  39770. } );
  39771. /**
  39772. * @author TristanVALCKE / https://github.com/Itee
  39773. */
  39774. /* global QUnit */
  39775. QUnit.module( 'Objects', () => {
  39776. QUnit.module.todo( 'Points', () => {
  39777. // INHERITANCE
  39778. QUnit.test( "isPoints", ( assert ) => {
  39779. assert.ok( false, "everything's gonna be alright" );
  39780. } );
  39781. // INSTANCING
  39782. QUnit.test( "raycast", ( assert ) => {
  39783. assert.ok( false, "everything's gonna be alright" );
  39784. } );
  39785. // PUBLIC STUFF
  39786. QUnit.test( "clone", ( assert ) => {
  39787. assert.ok( false, "everything's gonna be alright" );
  39788. } );
  39789. } );
  39790. } );
  39791. /**
  39792. * @author TristanVALCKE / https://github.com/Itee
  39793. */
  39794. /* global QUnit */
  39795. QUnit.module( 'Objects', () => {
  39796. QUnit.module.todo( 'Skeleton', () => {
  39797. // INSTANCING
  39798. QUnit.test( "Instancing", ( assert ) => {
  39799. assert.ok( false, "everything's gonna be alright" );
  39800. } );
  39801. // PUBLIC STUFF
  39802. QUnit.test( "calculateInverses", ( assert ) => {
  39803. assert.ok( false, "everything's gonna be alright" );
  39804. } );
  39805. QUnit.test( "pose", ( assert ) => {
  39806. assert.ok( false, "everything's gonna be alright" );
  39807. } );
  39808. QUnit.test( "update", ( assert ) => {
  39809. assert.ok( false, "everything's gonna be alright" );
  39810. } );
  39811. QUnit.test( "clone", ( assert ) => {
  39812. assert.ok( false, "everything's gonna be alright" );
  39813. } );
  39814. } );
  39815. } );
  39816. /**
  39817. * @author TristanVALCKE / https://github.com/Itee
  39818. */
  39819. /* global QUnit */
  39820. QUnit.module( 'Objects', () => {
  39821. QUnit.module.todo( 'SkinnedMesh', () => {
  39822. // INHERITANCE
  39823. QUnit.test( "Extending", ( assert ) => {
  39824. assert.ok( false, "everything's gonna be alright" );
  39825. } );
  39826. // INSTANCING
  39827. QUnit.test( "Instancing", ( assert ) => {
  39828. assert.ok( false, "everything's gonna be alright" );
  39829. } );
  39830. // PUBLIC STUFF
  39831. QUnit.test( "isSkinnedMesh", ( assert ) => {
  39832. assert.ok( false, "everything's gonna be alright" );
  39833. } );
  39834. QUnit.test( "initBones", ( assert ) => {
  39835. assert.ok( false, "everything's gonna be alright" );
  39836. } );
  39837. QUnit.test( "bind", ( assert ) => {
  39838. assert.ok( false, "everything's gonna be alright" );
  39839. } );
  39840. QUnit.test( "pose", ( assert ) => {
  39841. assert.ok( false, "everything's gonna be alright" );
  39842. } );
  39843. QUnit.test( "normalizeSkinWeights", ( assert ) => {
  39844. assert.ok( false, "everything's gonna be alright" );
  39845. } );
  39846. QUnit.test( "updateMatrixWorld", ( assert ) => {
  39847. assert.ok( false, "everything's gonna be alright" );
  39848. } );
  39849. QUnit.test( "clone", ( assert ) => {
  39850. assert.ok( false, "everything's gonna be alright" );
  39851. } );
  39852. } );
  39853. } );
  39854. /**
  39855. * @author TristanVALCKE / https://github.com/Itee
  39856. */
  39857. /* global QUnit */
  39858. QUnit.module( 'Objects', () => {
  39859. QUnit.module.todo( 'Sprite', () => {
  39860. // INHERITANCE
  39861. QUnit.test( "Extending", ( assert ) => {
  39862. assert.ok( false, "everything's gonna be alright" );
  39863. } );
  39864. // INSTANCING
  39865. QUnit.test( "Instancing", ( assert ) => {
  39866. assert.ok( false, "everything's gonna be alright" );
  39867. } );
  39868. // PUBLIC STUFF
  39869. QUnit.test( "isSprite", ( assert ) => {
  39870. assert.ok( false, "everything's gonna be alright" );
  39871. } );
  39872. QUnit.test( "raycast", ( assert ) => {
  39873. assert.ok( false, "everything's gonna be alright" );
  39874. } );
  39875. QUnit.test( "clone", ( assert ) => {
  39876. assert.ok( false, "everything's gonna be alright" );
  39877. } );
  39878. } );
  39879. } );
  39880. /**
  39881. * @author mrdoob / http://mrdoob.com/
  39882. */
  39883. /**
  39884. * @author TristanVALCKE / https://github.com/Itee
  39885. */
  39886. /* global QUnit */
  39887. QUnit.module( 'Renderers', () => {
  39888. QUnit.module.todo( 'WebGL2Renderer', () => {
  39889. // INSTANCING
  39890. QUnit.test( "Instancing", ( assert ) => {
  39891. assert.ok( false, "everything's gonna be alright" );
  39892. } );
  39893. // PUBLIC STUFF
  39894. QUnit.test( "domElement", ( assert ) => {
  39895. assert.ok( false, "everything's gonna be alright" );
  39896. } );
  39897. QUnit.test( "clear", ( assert ) => {
  39898. assert.ok( false, "everything's gonna be alright" );
  39899. } );
  39900. QUnit.test( "setPixelRatio", ( assert ) => {
  39901. assert.ok( false, "everything's gonna be alright" );
  39902. } );
  39903. QUnit.test( "setSize", ( assert ) => {
  39904. assert.ok( false, "everything's gonna be alright" );
  39905. } );
  39906. QUnit.test( "render", ( assert ) => {
  39907. assert.ok( false, "everything's gonna be alright" );
  39908. } );
  39909. } );
  39910. } );
  39911. /**
  39912. * @author TristanVALCKE / https://github.com/Itee
  39913. */
  39914. /* global QUnit */
  39915. QUnit.module( 'Renderers', () => {
  39916. QUnit.module.todo( 'WebGLRenderer', () => {
  39917. // INSTANCING
  39918. QUnit.test( "Instancing", ( assert ) => {
  39919. assert.ok( false, "everything's gonna be alright" );
  39920. } );
  39921. // PUBLIC STUFF
  39922. QUnit.test( "PrayForUs", ( assert ) => {
  39923. assert.ok( false, "everything's gonna be alright" );
  39924. } );
  39925. } );
  39926. } );
  39927. /**
  39928. * @author TristanVALCKE / https://github.com/Itee
  39929. */
  39930. /* global QUnit */
  39931. QUnit.module( 'Renderers', () => {
  39932. QUnit.module.todo( 'WebGLRenderTarget', () => {
  39933. // INHERITANCE
  39934. QUnit.test( "Extending", ( assert ) => {
  39935. assert.ok( false, "everything's gonna be alright" );
  39936. } );
  39937. // INSTANCING
  39938. QUnit.test( "Instancing", ( assert ) => {
  39939. assert.ok( false, "everything's gonna be alright" );
  39940. } );
  39941. // PUBLIC STUFF
  39942. QUnit.test( "isWebGLRenderTarget", ( assert ) => {
  39943. assert.ok( false, "everything's gonna be alright" );
  39944. } );
  39945. QUnit.test( "setSize", ( assert ) => {
  39946. assert.ok( false, "everything's gonna be alright" );
  39947. } );
  39948. QUnit.test( "clone", ( assert ) => {
  39949. assert.ok( false, "everything's gonna be alright" );
  39950. } );
  39951. QUnit.test( "copy", ( assert ) => {
  39952. assert.ok( false, "everything's gonna be alright" );
  39953. } );
  39954. QUnit.test( "dispose", ( assert ) => {
  39955. assert.ok( false, "everything's gonna be alright" );
  39956. } );
  39957. } );
  39958. } );
  39959. /**
  39960. * @author TristanVALCKE / https://github.com/Itee
  39961. */
  39962. /* global QUnit */
  39963. QUnit.module( 'Renderers', () => {
  39964. QUnit.module.todo( 'WebGLRenderTargetCube', () => {
  39965. // INSTANCING
  39966. QUnit.test( "Instancing", ( assert ) => {
  39967. assert.ok( false, "everything's gonna be alright" );
  39968. } );
  39969. // PUBLIC STUFF
  39970. QUnit.test( "isWebGLRenderTargetCube", ( assert ) => {
  39971. assert.ok( false, "everything's gonna be alright" );
  39972. } );
  39973. } );
  39974. } );
  39975. /**
  39976. * @author TristanVALCKE / https://github.com/Itee
  39977. */
  39978. /* global QUnit */
  39979. QUnit.module( 'Renderers', () => {
  39980. QUnit.module( 'Shaders', () => {
  39981. QUnit.module.todo( 'ShaderChunk', () => {
  39982. QUnit.test( 'write me !', ( assert ) => {
  39983. assert.ok( false, "everything's gonna be alright" );
  39984. } );
  39985. } );
  39986. } );
  39987. } );
  39988. /**
  39989. * @author TristanVALCKE / https://github.com/Itee
  39990. */
  39991. /* global QUnit */
  39992. QUnit.module( 'Renderers', () => {
  39993. QUnit.module( 'Shaders', () => {
  39994. QUnit.module.todo( 'ShaderLib', () => {
  39995. QUnit.test( 'write me !', ( assert ) => {
  39996. assert.ok( false, "everything's gonna be alright" );
  39997. } );
  39998. } );
  39999. } );
  40000. } );
  40001. /**
  40002. * @author TristanVALCKE / https://github.com/Itee
  40003. */
  40004. /* global QUnit */
  40005. QUnit.module( 'Renderers', () => {
  40006. QUnit.module( 'Shaders', () => {
  40007. QUnit.module.todo( 'UniformsLib', () => {
  40008. // PUBLIC STUFF
  40009. QUnit.test( "merge", ( assert ) => {
  40010. assert.ok( false, "everything's gonna be alright" );
  40011. } );
  40012. QUnit.test( "clone", ( assert ) => {
  40013. assert.ok( false, "everything's gonna be alright" );
  40014. } );
  40015. } );
  40016. } );
  40017. } );
  40018. /**
  40019. * @author TristanVALCKE / https://github.com/Itee
  40020. */
  40021. /* global QUnit */
  40022. QUnit.module( 'Renderers', () => {
  40023. QUnit.module( 'Shaders', () => {
  40024. QUnit.module.todo( 'UniformsUtils', () => {
  40025. QUnit.test( 'write me !', ( assert ) => {
  40026. assert.ok( false, "everything's gonna be alright" );
  40027. } );
  40028. } );
  40029. } );
  40030. } );
  40031. /**
  40032. * @author TristanVALCKE / https://github.com/Itee
  40033. */
  40034. /* global QUnit */
  40035. QUnit.module( 'Renderers', () => {
  40036. QUnit.module( 'WebGL', () => {
  40037. QUnit.module.todo( 'WebGLAttributes', () => {
  40038. // INSTANCING
  40039. QUnit.test( "Instancing", ( assert ) => {
  40040. assert.ok( false, "everything's gonna be alright" );
  40041. } );
  40042. // PUBLIC STUFF
  40043. QUnit.test( "get", ( assert ) => {
  40044. assert.ok( false, "everything's gonna be alright" );
  40045. } );
  40046. QUnit.test( "remove", ( assert ) => {
  40047. assert.ok( false, "everything's gonna be alright" );
  40048. } );
  40049. QUnit.test( "update", ( assert ) => {
  40050. assert.ok( false, "everything's gonna be alright" );
  40051. } );
  40052. } );
  40053. } );
  40054. } );
  40055. /**
  40056. * @author TristanVALCKE / https://github.com/Itee
  40057. */
  40058. /* global QUnit */
  40059. QUnit.module( 'Renderers', () => {
  40060. QUnit.module( 'WebGL', () => {
  40061. QUnit.module.todo( 'WebGLBackground', () => {
  40062. // INSTANCING
  40063. QUnit.test( "Instancing", ( assert ) => {
  40064. assert.ok( false, "everything's gonna be alright" );
  40065. } );
  40066. // PUBLIC STUFF
  40067. QUnit.test( "getClearColor", ( assert ) => {
  40068. assert.ok( false, "everything's gonna be alright" );
  40069. } );
  40070. QUnit.test( "setClearColor", ( assert ) => {
  40071. assert.ok( false, "everything's gonna be alright" );
  40072. } );
  40073. QUnit.test( "getClearAlpha", ( assert ) => {
  40074. assert.ok( false, "everything's gonna be alright" );
  40075. } );
  40076. QUnit.test( "setClearAlpha", ( assert ) => {
  40077. assert.ok( false, "everything's gonna be alright" );
  40078. } );
  40079. QUnit.test( "render", ( assert ) => {
  40080. assert.ok( false, "everything's gonna be alright" );
  40081. } );
  40082. } );
  40083. } );
  40084. } );
  40085. /**
  40086. * @author TristanVALCKE / https://github.com/Itee
  40087. */
  40088. /* global QUnit */
  40089. QUnit.module( 'Renderers', () => {
  40090. QUnit.module( 'WebGL', () => {
  40091. QUnit.module.todo( 'WebGLBufferRenderer', () => {
  40092. // INSTANCING
  40093. QUnit.test( "Instancing", ( assert ) => {
  40094. assert.ok( false, "everything's gonna be alright" );
  40095. } );
  40096. // PUBLIC STUFF
  40097. QUnit.test( "setMode", ( assert ) => {
  40098. assert.ok( false, "everything's gonna be alright" );
  40099. } );
  40100. QUnit.test( "render", ( assert ) => {
  40101. assert.ok( false, "everything's gonna be alright" );
  40102. } );
  40103. QUnit.test( "renderInstances", ( assert ) => {
  40104. assert.ok( false, "everything's gonna be alright" );
  40105. } );
  40106. } );
  40107. } );
  40108. } );
  40109. /**
  40110. * @author TristanVALCKE / https://github.com/Itee
  40111. */
  40112. /* global QUnit */
  40113. QUnit.module( 'Renderers', () => {
  40114. QUnit.module( 'WebGL', () => {
  40115. QUnit.module.todo( 'WebGLCapabilities', () => {
  40116. // INSTANCING
  40117. QUnit.test( "Instancing", ( assert ) => {
  40118. assert.ok( false, "everything's gonna be alright" );
  40119. } );
  40120. // PUBLIC STUFF
  40121. QUnit.test( "getMaxAnisotropy", ( assert ) => {
  40122. assert.ok( false, "everything's gonna be alright" );
  40123. } );
  40124. QUnit.test( "getMaxPrecision", ( assert ) => {
  40125. assert.ok( false, "everything's gonna be alright" );
  40126. } );
  40127. QUnit.test( "precision", ( assert ) => {
  40128. assert.ok( false, "everything's gonna be alright" );
  40129. } );
  40130. QUnit.test( "logarithmicDepthBuffer", ( assert ) => {
  40131. assert.ok( false, "everything's gonna be alright" );
  40132. } );
  40133. QUnit.test( "maxTextures", ( assert ) => {
  40134. assert.ok( false, "everything's gonna be alright" );
  40135. } );
  40136. QUnit.test( "maxVertexTextures", ( assert ) => {
  40137. assert.ok( false, "everything's gonna be alright" );
  40138. } );
  40139. QUnit.test( "maxTextureSize", ( assert ) => {
  40140. assert.ok( false, "everything's gonna be alright" );
  40141. } );
  40142. QUnit.test( "maxCubemapSize", ( assert ) => {
  40143. assert.ok( false, "everything's gonna be alright" );
  40144. } );
  40145. QUnit.test( "maxAttributes", ( assert ) => {
  40146. assert.ok( false, "everything's gonna be alright" );
  40147. } );
  40148. QUnit.test( "maxVertexUniforms", ( assert ) => {
  40149. assert.ok( false, "everything's gonna be alright" );
  40150. } );
  40151. QUnit.test( "maxVaryings", ( assert ) => {
  40152. assert.ok( false, "everything's gonna be alright" );
  40153. } );
  40154. QUnit.test( "maxFragmentUniforms", ( assert ) => {
  40155. assert.ok( false, "everything's gonna be alright" );
  40156. } );
  40157. QUnit.test( "vertexTextures", ( assert ) => {
  40158. assert.ok( false, "everything's gonna be alright" );
  40159. } );
  40160. QUnit.test( "floatFragmentTextures", ( assert ) => {
  40161. assert.ok( false, "everything's gonna be alright" );
  40162. } );
  40163. QUnit.test( "floatVertexTextures", ( assert ) => {
  40164. assert.ok( false, "everything's gonna be alright" );
  40165. } );
  40166. } );
  40167. } );
  40168. } );
  40169. /**
  40170. * @author TristanVALCKE / https://github.com/Itee
  40171. */
  40172. /* global QUnit */
  40173. QUnit.module( 'Renderers', () => {
  40174. QUnit.module( 'WebGL', () => {
  40175. QUnit.module.todo( 'WebGLClipping', () => {
  40176. // INSTANCING
  40177. QUnit.test( "Instancing", ( assert ) => {
  40178. assert.ok( false, "everything's gonna be alright" );
  40179. } );
  40180. // PUBLIC STUFF
  40181. QUnit.test( "init", ( assert ) => {
  40182. assert.ok( false, "everything's gonna be alright" );
  40183. } );
  40184. QUnit.test( "beginShadows", ( assert ) => {
  40185. assert.ok( false, "everything's gonna be alright" );
  40186. } );
  40187. QUnit.test( "endShadows", ( assert ) => {
  40188. assert.ok( false, "everything's gonna be alright" );
  40189. } );
  40190. QUnit.test( "setState", ( assert ) => {
  40191. assert.ok( false, "everything's gonna be alright" );
  40192. } );
  40193. } );
  40194. } );
  40195. } );
  40196. /**
  40197. * @author TristanVALCKE / https://github.com/Itee
  40198. */
  40199. /* global QUnit */
  40200. QUnit.module( 'Renderers', () => {
  40201. QUnit.module( 'WebGL', () => {
  40202. QUnit.module.todo( 'WebGLExtensions', () => {
  40203. // INSTANCING
  40204. QUnit.test( "Instancing", ( assert ) => {
  40205. assert.ok( false, "everything's gonna be alright" );
  40206. } );
  40207. // PUBLIC STUFF
  40208. QUnit.test( "get", ( assert ) => {
  40209. assert.ok( false, "everything's gonna be alright" );
  40210. } );
  40211. } );
  40212. } );
  40213. } );
  40214. /**
  40215. * @author TristanVALCKE / https://github.com/Itee
  40216. */
  40217. /* global QUnit */
  40218. QUnit.module( 'Renderers', () => {
  40219. QUnit.module( 'WebGL', () => {
  40220. QUnit.module.todo( 'WebGLFlareRenderer', () => {
  40221. // INSTANCING
  40222. QUnit.test( "Instancing", ( assert ) => {
  40223. assert.ok( false, "everything's gonna be alright" );
  40224. } );
  40225. // PUBLIC STUFF
  40226. QUnit.test( "render", ( assert ) => {
  40227. assert.ok( false, "everything's gonna be alright" );
  40228. } );
  40229. } );
  40230. } );
  40231. } );
  40232. /**
  40233. * @author TristanVALCKE / https://github.com/Itee
  40234. */
  40235. /* global QUnit */
  40236. QUnit.module( 'Renderers', () => {
  40237. QUnit.module( 'WebGL', () => {
  40238. QUnit.module.todo( 'WebGLGeometries', () => {
  40239. // INSTANCING
  40240. QUnit.test( "Instancing", ( assert ) => {
  40241. assert.ok( false, "everything's gonna be alright" );
  40242. } );
  40243. // PUBLIC STUFF
  40244. QUnit.test( "get", ( assert ) => {
  40245. assert.ok( false, "everything's gonna be alright" );
  40246. } );
  40247. QUnit.test( "update", ( assert ) => {
  40248. assert.ok( false, "everything's gonna be alright" );
  40249. } );
  40250. QUnit.test( "getWireframeAttribute", ( assert ) => {
  40251. assert.ok( false, "everything's gonna be alright" );
  40252. } );
  40253. } );
  40254. } );
  40255. } );
  40256. /**
  40257. * @author TristanVALCKE / https://github.com/Itee
  40258. */
  40259. /* global QUnit */
  40260. QUnit.module( 'Renderers', () => {
  40261. QUnit.module( 'WebGL', () => {
  40262. QUnit.module.todo( 'WebGLIndexedBufferRenderer', () => {
  40263. // INSTANCING
  40264. QUnit.test( "Instancing", ( assert ) => {
  40265. assert.ok( false, "everything's gonna be alright" );
  40266. } );
  40267. // PUBLIC STUFF
  40268. QUnit.test( "setMode", ( assert ) => {
  40269. assert.ok( false, "everything's gonna be alright" );
  40270. } );
  40271. QUnit.test( "setIndex", ( assert ) => {
  40272. assert.ok( false, "everything's gonna be alright" );
  40273. } );
  40274. QUnit.test( "render", ( assert ) => {
  40275. assert.ok( false, "everything's gonna be alright" );
  40276. } );
  40277. QUnit.test( "renderInstances", ( assert ) => {
  40278. assert.ok( false, "everything's gonna be alright" );
  40279. } );
  40280. } );
  40281. } );
  40282. } );
  40283. /**
  40284. * @author TristanVALCKE / https://github.com/Itee
  40285. */
  40286. /* global QUnit */
  40287. QUnit.module( 'Renderers', () => {
  40288. QUnit.module( 'WebGL', () => {
  40289. QUnit.module.todo( 'WebGLLights', () => {
  40290. // INSTANCING
  40291. QUnit.test( "Instancing", ( assert ) => {
  40292. assert.ok( false, "everything's gonna be alright" );
  40293. } );
  40294. // PUBLIC STUFF
  40295. QUnit.test( "setup", ( assert ) => {
  40296. assert.ok( false, "everything's gonna be alright" );
  40297. } );
  40298. QUnit.test( "state", ( assert ) => {
  40299. assert.ok( false, "everything's gonna be alright" );
  40300. } );
  40301. } );
  40302. } );
  40303. } );
  40304. /**
  40305. * @author TristanVALCKE / https://github.com/Itee
  40306. */
  40307. /* global QUnit */
  40308. QUnit.module( 'Renderers', () => {
  40309. QUnit.module( 'WebGL', () => {
  40310. QUnit.module.todo( 'WebGLMorphtargets', () => {
  40311. // INSTANCING
  40312. QUnit.test( "Instancing", ( assert ) => {
  40313. assert.ok( false, "everything's gonna be alright" );
  40314. } );
  40315. // PUBLIC STUFF
  40316. QUnit.test( "update", ( assert ) => {
  40317. assert.ok( false, "everything's gonna be alright" );
  40318. } );
  40319. } );
  40320. } );
  40321. } );
  40322. /**
  40323. * @author TristanVALCKE / https://github.com/Itee
  40324. */
  40325. /* global QUnit */
  40326. QUnit.module( 'Renderers', () => {
  40327. QUnit.module( 'WebGL', () => {
  40328. QUnit.module.todo( 'WebGLObjects', () => {
  40329. // INSTANCING
  40330. QUnit.test( "Instancing", ( assert ) => {
  40331. assert.ok( false, "everything's gonna be alright" );
  40332. } );
  40333. // PUBLIC STUFF
  40334. QUnit.test( "update", ( assert ) => {
  40335. assert.ok( false, "everything's gonna be alright" );
  40336. } );
  40337. QUnit.test( "clear", ( assert ) => {
  40338. assert.ok( false, "everything's gonna be alright" );
  40339. } );
  40340. } );
  40341. } );
  40342. } );
  40343. /**
  40344. * @author TristanVALCKE / https://github.com/Itee
  40345. */
  40346. /* global QUnit */
  40347. QUnit.module( 'Renderers', () => {
  40348. QUnit.module( 'WebGL', () => {
  40349. QUnit.module.todo( 'WebGLProgram', () => {
  40350. // INSTANCING
  40351. QUnit.test( "Instancing", ( assert ) => {
  40352. assert.ok( false, "everything's gonna be alright" );
  40353. } );
  40354. // PROPERTIES
  40355. QUnit.test( "uniforms", ( assert ) => {
  40356. assert.ok( false, "everything's gonna be alright" );
  40357. } );
  40358. QUnit.test( "attributes", ( assert ) => {
  40359. assert.ok( false, "everything's gonna be alright" );
  40360. } );
  40361. // PUBLIC STUFF
  40362. QUnit.test( "getUniforms", ( assert ) => {
  40363. assert.ok( false, "everything's gonna be alright" );
  40364. } );
  40365. QUnit.test( "getAttributes", ( assert ) => {
  40366. assert.ok( false, "everything's gonna be alright" );
  40367. } );
  40368. QUnit.test( "destroy", ( assert ) => {
  40369. assert.ok( false, "everything's gonna be alright" );
  40370. } );
  40371. } );
  40372. } );
  40373. } );
  40374. /**
  40375. * @author TristanVALCKE / https://github.com/Itee
  40376. */
  40377. /* global QUnit */
  40378. QUnit.module( 'Renderers', () => {
  40379. QUnit.module( 'WebGL', () => {
  40380. QUnit.module.todo( 'WebGLPrograms', () => {
  40381. // INSTANCING
  40382. QUnit.test( "Instancing", ( assert ) => {
  40383. assert.ok( false, "everything's gonna be alright" );
  40384. } );
  40385. // PUBLIC STUFF
  40386. QUnit.test( "getParameters", ( assert ) => {
  40387. assert.ok( false, "everything's gonna be alright" );
  40388. } );
  40389. QUnit.test( "getProgramCode", ( assert ) => {
  40390. assert.ok( false, "everything's gonna be alright" );
  40391. } );
  40392. QUnit.test( "acquireProgram", ( assert ) => {
  40393. assert.ok( false, "everything's gonna be alright" );
  40394. } );
  40395. QUnit.test( "releaseProgram", ( assert ) => {
  40396. assert.ok( false, "everything's gonna be alright" );
  40397. } );
  40398. QUnit.test( "programs", ( assert ) => {
  40399. assert.ok( false, "everything's gonna be alright" );
  40400. } );
  40401. } );
  40402. } );
  40403. } );
  40404. /**
  40405. * @author TristanVALCKE / https://github.com/Itee
  40406. */
  40407. /* global QUnit */
  40408. QUnit.module( 'Renderers', () => {
  40409. QUnit.module( 'WebGL', () => {
  40410. QUnit.module.todo( 'WebGLProperties', () => {
  40411. // INSTANCING
  40412. QUnit.test( "Instancing", ( assert ) => {
  40413. assert.ok( false, "everything's gonna be alright" );
  40414. } );
  40415. // PUBLIC STUFF
  40416. QUnit.test( "get", ( assert ) => {
  40417. assert.ok( false, "everything's gonna be alright" );
  40418. } );
  40419. QUnit.test( "remove", ( assert ) => {
  40420. assert.ok( false, "everything's gonna be alright" );
  40421. } );
  40422. QUnit.test( "clear", ( assert ) => {
  40423. assert.ok( false, "everything's gonna be alright" );
  40424. } );
  40425. } );
  40426. } );
  40427. } );
  40428. /**
  40429. * @author TristanVALCKE / https://github.com/Itee
  40430. */
  40431. /* global QUnit */
  40432. QUnit.module( 'Renderers', () => {
  40433. QUnit.module( 'WebGL', () => {
  40434. QUnit.module.todo( 'WebGLRenderLists', () => {
  40435. // INSTANCING
  40436. QUnit.test( "Instancing", ( assert ) => {
  40437. assert.ok( false, "everything's gonna be alright" );
  40438. } );
  40439. // PUBLIC STUFF
  40440. QUnit.test( "get", ( assert ) => {
  40441. assert.ok( false, "everything's gonna be alright" );
  40442. } );
  40443. QUnit.test( "dispose", ( assert ) => {
  40444. assert.ok( false, "everything's gonna be alright" );
  40445. } );
  40446. } );
  40447. } );
  40448. } );
  40449. /**
  40450. * @author TristanVALCKE / https://github.com/Itee
  40451. */
  40452. /* global QUnit */
  40453. QUnit.module( 'Renderers', () => {
  40454. QUnit.module( 'WebGL', () => {
  40455. QUnit.module.todo( 'WebGLShader', () => {
  40456. // INSTANCING
  40457. QUnit.test( "Instancing", ( assert ) => {
  40458. assert.ok( false, "everything's gonna be alright" );
  40459. } );
  40460. } );
  40461. } );
  40462. } );
  40463. /**
  40464. * @author TristanVALCKE / https://github.com/Itee
  40465. */
  40466. /* global QUnit */
  40467. QUnit.module( 'Renderers', () => {
  40468. QUnit.module( 'WebGL', () => {
  40469. QUnit.module.todo( 'WebGLShadowMap', () => {
  40470. // INSTANCING
  40471. QUnit.test( "Instancing", ( assert ) => {
  40472. assert.ok( false, "everything's gonna be alright" );
  40473. } );
  40474. // PUBLIC STUFF
  40475. QUnit.test( "render", ( assert ) => {
  40476. assert.ok( false, "everything's gonna be alright" );
  40477. } );
  40478. } );
  40479. } );
  40480. } );
  40481. /**
  40482. * @author TristanVALCKE / https://github.com/Itee
  40483. */
  40484. /* global QUnit */
  40485. QUnit.module( 'Renderers', () => {
  40486. QUnit.module( 'WebGL', () => {
  40487. QUnit.module.todo( 'WebGLSpriteRenderer', () => {
  40488. // INSTANCING
  40489. QUnit.test( "Instancing", ( assert ) => {
  40490. assert.ok( false, "everything's gonna be alright" );
  40491. } );
  40492. // PUBLIC STUFF
  40493. QUnit.test( "render", ( assert ) => {
  40494. assert.ok( false, "everything's gonna be alright" );
  40495. } );
  40496. } );
  40497. } );
  40498. } );
  40499. /**
  40500. * @author TristanVALCKE / https://github.com/Itee
  40501. */
  40502. /* global QUnit */
  40503. QUnit.module( 'Renderers', () => {
  40504. QUnit.module( 'WebGL', () => {
  40505. QUnit.module.todo( 'WebGLState', () => {
  40506. // INSTANCING
  40507. QUnit.test( "Instancing", ( assert ) => {
  40508. assert.ok( false, "everything's gonna be alright" );
  40509. } );
  40510. // PUBLIC STUFF
  40511. QUnit.test( "buffers", ( assert ) => {
  40512. assert.ok( false, "everything's gonna be alright" );
  40513. } );
  40514. QUnit.test( "initAttributes", ( assert ) => {
  40515. assert.ok( false, "everything's gonna be alright" );
  40516. } );
  40517. QUnit.test( "enableAttribute", ( assert ) => {
  40518. assert.ok( false, "everything's gonna be alright" );
  40519. } );
  40520. QUnit.test( "enableAttributeAndDivisor", ( assert ) => {
  40521. assert.ok( false, "everything's gonna be alright" );
  40522. } );
  40523. QUnit.test( "disableUnusedAttributes", ( assert ) => {
  40524. assert.ok( false, "everything's gonna be alright" );
  40525. } );
  40526. QUnit.test( "enable", ( assert ) => {
  40527. assert.ok( false, "everything's gonna be alright" );
  40528. } );
  40529. QUnit.test( "disable", ( assert ) => {
  40530. assert.ok( false, "everything's gonna be alright" );
  40531. } );
  40532. QUnit.test( "getCompressedTextureFormats", ( assert ) => {
  40533. assert.ok( false, "everything's gonna be alright" );
  40534. } );
  40535. QUnit.test( "useProgram", ( assert ) => {
  40536. assert.ok( false, "everything's gonna be alright" );
  40537. } );
  40538. QUnit.test( "setBlending", ( assert ) => {
  40539. assert.ok( false, "everything's gonna be alright" );
  40540. } );
  40541. QUnit.test( "setMaterial", ( assert ) => {
  40542. assert.ok( false, "everything's gonna be alright" );
  40543. } );
  40544. QUnit.test( "setFlipSided", ( assert ) => {
  40545. assert.ok( false, "everything's gonna be alright" );
  40546. } );
  40547. QUnit.test( "setCullFace", ( assert ) => {
  40548. assert.ok( false, "everything's gonna be alright" );
  40549. } );
  40550. QUnit.test( "setLineWidth", ( assert ) => {
  40551. assert.ok( false, "everything's gonna be alright" );
  40552. } );
  40553. QUnit.test( "setPolygonOffset", ( assert ) => {
  40554. assert.ok( false, "everything's gonna be alright" );
  40555. } );
  40556. QUnit.test( "setScissorTest", ( assert ) => {
  40557. assert.ok( false, "everything's gonna be alright" );
  40558. } );
  40559. QUnit.test( "activeTexture", ( assert ) => {
  40560. assert.ok( false, "everything's gonna be alright" );
  40561. } );
  40562. QUnit.test( "bindTexture", ( assert ) => {
  40563. assert.ok( false, "everything's gonna be alright" );
  40564. } );
  40565. QUnit.test( "compressedTexImage2D", ( assert ) => {
  40566. assert.ok( false, "everything's gonna be alright" );
  40567. } );
  40568. QUnit.test( "texImage2D", ( assert ) => {
  40569. assert.ok( false, "everything's gonna be alright" );
  40570. } );
  40571. QUnit.test( "scissor", ( assert ) => {
  40572. assert.ok( false, "everything's gonna be alright" );
  40573. } );
  40574. QUnit.test( "viewport", ( assert ) => {
  40575. assert.ok( false, "everything's gonna be alright" );
  40576. } );
  40577. QUnit.test( "reset", ( assert ) => {
  40578. assert.ok( false, "everything's gonna be alright" );
  40579. } );
  40580. } );
  40581. } );
  40582. } );
  40583. /**
  40584. * @author TristanVALCKE / https://github.com/Itee
  40585. */
  40586. /* global QUnit */
  40587. QUnit.module( 'Renderers', () => {
  40588. QUnit.module( 'WebGL', () => {
  40589. QUnit.module.todo( 'WebGLTextures', () => {
  40590. // INSTANCING
  40591. QUnit.test( "Instancing", ( assert ) => {
  40592. assert.ok( false, "everything's gonna be alright" );
  40593. } );
  40594. // PUBLIC STUFF
  40595. QUnit.test( "setTexture2D", ( assert ) => {
  40596. assert.ok( false, "everything's gonna be alright" );
  40597. } );
  40598. QUnit.test( "setTextureCube", ( assert ) => {
  40599. assert.ok( false, "everything's gonna be alright" );
  40600. } );
  40601. QUnit.test( "setTextureCubeDynamic", ( assert ) => {
  40602. assert.ok( false, "everything's gonna be alright" );
  40603. } );
  40604. QUnit.test( "setupRenderTarget", ( assert ) => {
  40605. assert.ok( false, "everything's gonna be alright" );
  40606. } );
  40607. QUnit.test( "updateRenderTargetMipmap", ( assert ) => {
  40608. assert.ok( false, "everything's gonna be alright" );
  40609. } );
  40610. } );
  40611. } );
  40612. } );
  40613. /**
  40614. * @author TristanVALCKE / https://github.com/Itee
  40615. */
  40616. /* global QUnit */
  40617. QUnit.module( 'Renderers', () => {
  40618. QUnit.module( 'WebGL', () => {
  40619. QUnit.module.todo( 'WebGLUniforms', () => {
  40620. // INSTANCING
  40621. QUnit.test( "Instancing", ( assert ) => {
  40622. assert.ok( false, "everything's gonna be alright" );
  40623. } );
  40624. // PUBLIC STUFF
  40625. QUnit.test( "setValue", ( assert ) => {
  40626. assert.ok( false, "everything's gonna be alright" );
  40627. } );
  40628. QUnit.test( "setOptional", ( assert ) => {
  40629. assert.ok( false, "everything's gonna be alright" );
  40630. } );
  40631. QUnit.test( "upload", ( assert ) => {
  40632. assert.ok( false, "everything's gonna be alright" );
  40633. } );
  40634. QUnit.test( "seqWithValue", ( assert ) => {
  40635. assert.ok( false, "everything's gonna be alright" );
  40636. } );
  40637. } );
  40638. } );
  40639. } );
  40640. /**
  40641. * @author TristanVALCKE / https://github.com/Itee
  40642. */
  40643. /* global QUnit */
  40644. QUnit.module( 'Renderers', () => {
  40645. QUnit.module( 'WebGL', () => {
  40646. QUnit.module.todo( 'WebGLUtils', () => {
  40647. // INSTANCING
  40648. QUnit.test( "Instancing", ( assert ) => {
  40649. assert.ok( false, "everything's gonna be alright" );
  40650. } );
  40651. // PUBLIC STUFF
  40652. QUnit.test( "convert", ( assert ) => {
  40653. assert.ok( false, "everything's gonna be alright" );
  40654. } );
  40655. } );
  40656. } );
  40657. } );
  40658. /**
  40659. * @author TristanVALCKE / https://github.com/Itee
  40660. */
  40661. /* global QUnit */
  40662. QUnit.module( 'Renderers', () => {
  40663. QUnit.module( 'WebGL', () => {
  40664. QUnit.module.todo( 'WebVRManager', () => {
  40665. // INSTANCING
  40666. QUnit.test( "Instancing", ( assert ) => {
  40667. assert.ok( false, "everything's gonna be alright" );
  40668. } );
  40669. // PUBLIC STUFF
  40670. QUnit.test( "getDevice", ( assert ) => {
  40671. assert.ok( false, "everything's gonna be alright" );
  40672. } );
  40673. QUnit.test( "setDevice", ( assert ) => {
  40674. assert.ok( false, "everything's gonna be alright" );
  40675. } );
  40676. QUnit.test( "getCamera", ( assert ) => {
  40677. assert.ok( false, "everything's gonna be alright" );
  40678. } );
  40679. QUnit.test( "getStandingMatrix", ( assert ) => {
  40680. assert.ok( false, "everything's gonna be alright" );
  40681. } );
  40682. QUnit.test( "submitFrame", ( assert ) => {
  40683. assert.ok( false, "everything's gonna be alright" );
  40684. } );
  40685. QUnit.test( "dispose", ( assert ) => {
  40686. assert.ok( false, "everything's gonna be alright" );
  40687. } );
  40688. } );
  40689. } );
  40690. } );
  40691. /**
  40692. * @author TristanVALCKE / https://github.com/Itee
  40693. */
  40694. /* global QUnit */
  40695. QUnit.module( 'Fog', () => {
  40696. QUnit.module.todo( 'Scene', () => {
  40697. // INHERITANCE
  40698. QUnit.test( "Extending", ( assert ) => {
  40699. assert.ok( false, "everything's gonna be alright" );
  40700. } );
  40701. // INSTANCING
  40702. QUnit.test( "Instancing", ( assert ) => {
  40703. assert.ok( false, "everything's gonna be alright" );
  40704. } );
  40705. // PUBLIC STUFF
  40706. QUnit.test( "isFog", ( assert ) => {
  40707. assert.ok( false, "everything's gonna be alright" );
  40708. } );
  40709. QUnit.test( "clone", ( assert ) => {
  40710. assert.ok( false, "everything's gonna be alright" );
  40711. } );
  40712. QUnit.test( "toJSON", ( assert ) => {
  40713. assert.ok( false, "everything's gonna be alright" );
  40714. } );
  40715. } );
  40716. } );
  40717. /**
  40718. * @author TristanVALCKE / https://github.com/Itee
  40719. */
  40720. /* global QUnit */
  40721. QUnit.module( 'FoxExp2', () => {
  40722. QUnit.module.todo( 'Scene', () => {
  40723. // INHERITANCE
  40724. QUnit.test( "Extending", ( assert ) => {
  40725. assert.ok( false, "everything's gonna be alright" );
  40726. } );
  40727. // INSTANCING
  40728. QUnit.test( "Instancing", ( assert ) => {
  40729. assert.ok( false, "everything's gonna be alright" );
  40730. } );
  40731. // PUBLIC STUFF
  40732. QUnit.test( "isFogExp2", ( assert ) => {
  40733. assert.ok( false, "everything's gonna be alright" );
  40734. } );
  40735. QUnit.test( "clone", ( assert ) => {
  40736. assert.ok( false, "everything's gonna be alright" );
  40737. } );
  40738. QUnit.test( "toJSON", ( assert ) => {
  40739. assert.ok( false, "everything's gonna be alright" );
  40740. } );
  40741. } );
  40742. } );
  40743. /**
  40744. * @author TristanVALCKE / https://github.com/Itee
  40745. */
  40746. /* global QUnit */
  40747. QUnit.module( 'Scenes', () => {
  40748. QUnit.module.todo( 'Scene', () => {
  40749. // INHERITANCE
  40750. QUnit.test( "Extending", ( assert ) => {
  40751. assert.ok( false, "everything's gonna be alright" );
  40752. } );
  40753. // INSTANCING
  40754. QUnit.test( "Instancing", ( assert ) => {
  40755. assert.ok( false, "everything's gonna be alright" );
  40756. } );
  40757. // PUBLIC STUFF
  40758. QUnit.test( "isScene", ( assert ) => {
  40759. assert.ok( false, "everything's gonna be alright" );
  40760. } );
  40761. QUnit.test( "copy", ( assert ) => {
  40762. assert.ok( false, "everything's gonna be alright" );
  40763. } );
  40764. QUnit.test( "toJSON", ( assert ) => {
  40765. assert.ok( false, "everything's gonna be alright" );
  40766. } );
  40767. } );
  40768. } );
  40769. /**
  40770. * @author TristanVALCKE / https://github.com/Itee
  40771. */
  40772. /* global QUnit */
  40773. QUnit.module( 'Textures', () => {
  40774. QUnit.module.todo( 'CanvasTexture', () => {
  40775. // INHERITANCE
  40776. QUnit.test( "Extending", ( assert ) => {
  40777. assert.ok( false, "everything's gonna be alright" );
  40778. } );
  40779. // INSTANCING
  40780. QUnit.test( "Instancing", ( assert ) => {
  40781. assert.ok( false, "everything's gonna be alright" );
  40782. } );
  40783. // PUBLIC STUFF
  40784. QUnit.test( "isCanvasTexture", ( assert ) => {
  40785. assert.ok( false, "everything's gonna be alright" );
  40786. } );
  40787. } );
  40788. } );
  40789. /**
  40790. * @author TristanVALCKE / https://github.com/Itee
  40791. */
  40792. /* global QUnit */
  40793. QUnit.module( 'Textures', () => {
  40794. QUnit.module.todo( 'CompressedTexture', () => {
  40795. // INHERITANCE
  40796. QUnit.test( "Extending", ( assert ) => {
  40797. assert.ok( false, "everything's gonna be alright" );
  40798. } );
  40799. // INSTANCING
  40800. QUnit.test( "Instancing", ( assert ) => {
  40801. assert.ok( false, "everything's gonna be alright" );
  40802. } );
  40803. // PUBLIC STUFF
  40804. QUnit.test( "isCompressedTexture", ( assert ) => {
  40805. assert.ok( false, "everything's gonna be alright" );
  40806. } );
  40807. } );
  40808. } );
  40809. /**
  40810. * @author TristanVALCKE / https://github.com/Itee
  40811. */
  40812. /* global QUnit */
  40813. QUnit.module( 'Textures', () => {
  40814. QUnit.module.todo( 'CubeTexture', () => {
  40815. // INHERITANCE
  40816. QUnit.test( "Extending", ( assert ) => {
  40817. assert.ok( false, "everything's gonna be alright" );
  40818. } );
  40819. // INSTANCING
  40820. QUnit.test( "Instancing", ( assert ) => {
  40821. assert.ok( false, "everything's gonna be alright" );
  40822. } );
  40823. // PROPERTIES
  40824. QUnit.test( "images", ( assert ) => {
  40825. assert.ok( false, "everything's gonna be alright" );
  40826. } );
  40827. // PUBLIC STUFF
  40828. QUnit.test( "isCubeTexture", ( assert ) => {
  40829. assert.ok( false, "everything's gonna be alright" );
  40830. } );
  40831. } );
  40832. } );
  40833. /**
  40834. * @author TristanVALCKE / https://github.com/Itee
  40835. */
  40836. /* global QUnit */
  40837. QUnit.module( 'Textures', () => {
  40838. QUnit.module.todo( 'DataTexture', () => {
  40839. // INHERITANCE
  40840. QUnit.test( "Extending", ( assert ) => {
  40841. assert.ok( false, "everything's gonna be alright" );
  40842. } );
  40843. // INSTANCING
  40844. QUnit.test( "Instancing", ( assert ) => {
  40845. assert.ok( false, "everything's gonna be alright" );
  40846. } );
  40847. // PUBLIC STUFF
  40848. QUnit.test( "isDataTexture", ( assert ) => {
  40849. assert.ok( false, "everything's gonna be alright" );
  40850. } );
  40851. } );
  40852. } );
  40853. /**
  40854. * @author Matt DesLauriers / @mattdesl
  40855. * @author atix / arthursilber.de
  40856. */
  40857. /**
  40858. * @author TristanVALCKE / https://github.com/Itee
  40859. */
  40860. /* global QUnit */
  40861. QUnit.module( 'Textures', () => {
  40862. QUnit.module.todo( 'DepthTexture', () => {
  40863. // INHERITANCE
  40864. QUnit.test( "Extending", ( assert ) => {
  40865. assert.ok( false, "everything's gonna be alright" );
  40866. } );
  40867. // INSTANCING
  40868. QUnit.test( "Instancing", ( assert ) => {
  40869. assert.ok( false, "everything's gonna be alright" );
  40870. } );
  40871. // PUBLIC STUFF
  40872. QUnit.test( "isDepthTexture", ( assert ) => {
  40873. assert.ok( false, "everything's gonna be alright" );
  40874. } );
  40875. } );
  40876. } );
  40877. /**
  40878. * @author TristanVALCKE / https://github.com/Itee
  40879. */
  40880. /* global QUnit */
  40881. QUnit.module( 'Textures', () => {
  40882. QUnit.module.todo( 'Texture', () => {
  40883. // INSTANCING
  40884. QUnit.test( "Instancing", ( assert ) => {
  40885. assert.ok( false, "everything's gonna be alright" );
  40886. } );
  40887. // PROPERTIES
  40888. QUnit.test( "needsUpdate", ( assert ) => {
  40889. assert.ok( false, "everything's gonna be alright" );
  40890. } );
  40891. // PUBLIC STUFF
  40892. QUnit.test( "isTexture", ( assert ) => {
  40893. assert.ok( false, "everything's gonna be alright" );
  40894. } );
  40895. QUnit.test( "clone", ( assert ) => {
  40896. assert.ok( false, "everything's gonna be alright" );
  40897. } );
  40898. QUnit.test( "copy", ( assert ) => {
  40899. assert.ok( false, "everything's gonna be alright" );
  40900. } );
  40901. QUnit.test( "toJSON", ( assert ) => {
  40902. assert.ok( false, "everything's gonna be alright" );
  40903. } );
  40904. QUnit.test( "dispose", ( assert ) => {
  40905. assert.ok( false, "everything's gonna be alright" );
  40906. } );
  40907. QUnit.test( "transformUv", ( assert ) => {
  40908. assert.ok( false, "everything's gonna be alright" );
  40909. } );
  40910. } );
  40911. } );
  40912. /**
  40913. * @author mrdoob / http://mrdoob.com/
  40914. */
  40915. /**
  40916. * @author TristanVALCKE / https://github.com/Itee
  40917. */
  40918. /* global QUnit */
  40919. QUnit.module( 'Textures', () => {
  40920. QUnit.module.todo( 'VideoTexture', () => {
  40921. // INHERITANCE
  40922. QUnit.test( "Extending", ( assert ) => {
  40923. assert.ok( false, "everything's gonna be alright" );
  40924. } );
  40925. // INSTANCING
  40926. QUnit.test( "Instancing", ( assert ) => {
  40927. assert.ok( false, "everything's gonna be alright" );
  40928. } );
  40929. // PUBLIC STUFF
  40930. QUnit.test( "isVideoTexture", ( assert ) => {
  40931. assert.ok( false, "everything's gonna be alright" );
  40932. } );
  40933. } );
  40934. } );
  40935. /**
  40936. * @author TristanVALCKE / https://github.com/Itee
  40937. */
  40938. //src
  40939. //src/animation
  40940. //src/animation/tracks
  40941. //src/audio
  40942. //src/cameras
  40943. //src/core
  40944. //src/extras
  40945. //src/extras/core
  40946. //src/extras/curves
  40947. //src/extras/objects
  40948. //src/geometries
  40949. //src/helpers
  40950. //src/lights
  40951. //src/loaders
  40952. //src/materials
  40953. //src/math
  40954. //src/math/interpolants
  40955. //src/objects
  40956. //src/renderers
  40957. //src/renderers/shaders
  40958. //src/renderers/webgl
  40959. //src/renderers/webvr
  40960. //src/scenes
  40961. //src/textures
  40962. } );
  40963. })));
粤ICP备19079148号